:root {
    --primary: #ef4444;
    --primary-hover: #dc2626;
    --sidebar-bg: #ffffff;
    --main-bg: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --accent-soft: #f1f5f9;
    --sidebar-active: #f1f5f9;
    --radius-lg: 12px;
    --radius-md: 8px;
    --glass: rgba(255, 255, 255, 0.7);
}

[data-theme="dark"] {
    --primary: #f87171;
    --primary-hover: #ef4444;
    --sidebar-bg: #0f172a;
    --main-bg: #020617;
    --card-bg: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --accent-soft: #1e293b;
    --sidebar-active: #334155;
    --glass: rgba(15, 23, 42, 0.7);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

body {
    display: flex;
    height: 100vh;
    background-color: var(--main-bg);
    color: var(--text-main);
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    padding: 10px 0 30px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 12px 16px;
    text-align: left;
    font-size: 0.95rem;
    cursor: pointer;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
}

.nav-btn i {
    width: 18px;
}

.nav-btn:hover {
    background-color: var(--accent-soft);
    color: var(--text-main);
}

.nav-btn.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--main-bg);
    position: relative;
}

/* Header / Top Bar */
.header {
    background: var(--glass);
    backdrop-filter: blur(12px);
    padding: 16px 40px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 15px;
}

.header-title-area h2 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.tabs {
    background: var(--accent-soft);
    padding: 4px;
    border-radius: 10px;
    display: flex;
    gap: 4px;
}

.tab-btn {
    padding: 8px 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
}

.tab-btn.active {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.theme-toggle,
.print-btn {
    background: var(--accent-soft);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-main);
}

.theme-toggle:hover,
.print-btn:hover {
    background: var(--border);
}

/* Search Bar */
.search-container {
    margin-bottom: 24px;
    position: relative;
}

.search-container input {
    width: 100%;
    padding: 12px 44px 12px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
}

.search-container input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.search-container i,
.search-container svg {
    position: absolute !important;
    right: 14px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    color: var(--text-muted);
    width: 18px !important;
    height: 18px !important;
    pointer-events: none;
}

/* Content Area */
.content-area {
    padding: 40px;
    overflow-y: auto;
    flex: 1;
}

/* Tables (Horarios) */
.table-wrapper {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 16px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

th {
    background-color: var(--accent-soft);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.time-col {
    background-color: var(--accent-soft);
    font-weight: 600;
    width: 160px;
    white-space: nowrap;
    color: var(--text-main);
}

.recreo-row {
    background-color: var(--accent-soft);
    font-weight: 800;
    letter-spacing: 0.3em;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Accordion (Temarios) */
.accordion-item {
    background: var(--card-bg);
    border: 1px solid var(--border);
    margin-bottom: 12px;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.accordion-header {
    padding: 18px 24px;
    background: var(--card-bg);
    cursor: pointer;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.accordion-header:hover {
    background-color: var(--accent-soft);
}

.accordion-content {
    padding: 8px 24px 24px;
    display: none;
    border-top: 1px solid var(--border);
}

.topic-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.topic-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background 0.2s;
}

.topic-item:hover {
    background: var(--accent-soft);
}

.checkbox-container {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    gap: 10px;
    flex: 1;
}

.checkbox-container input {
    display: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.checkbox-container input:checked+.checkmark {
    background-color: var(--primary);
    border-color: var(--primary);
}

.checkbox-container input:checked+.checkmark::after {
    content: '✓';
    color: white;
    font-size: 14px;
    font-weight: bold;
}

.checkbox-container input:checked~.topic-text {
    color: var(--text-muted);
    text-decoration: line-through;
}

.topic-text {
    font-size: 0.95rem;
    color: var(--text-main);
}

.hidden {
    display: none;
}

.menu-toggle {
    display: none;
    background: var(--accent-soft);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-main);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 900;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 600px) {
    .header {
        flex-wrap: wrap;
        padding: 10px 16px;
        gap: 8px;
    }

    .header-title-area {
        width: 100%;
        justify-content: space-between;
        order: 1;
    }

    .top-actions {
        width: 100%;
        justify-content: space-between;
        order: 2;
        margin-top: 4px;
    }

    .tabs {
        flex: 1;
    }

    .tab-btn {
        flex: 1;
        text-align: center;
        padding: 6px 4px;
    }

    .print-btn {
        display: none;
    }
}

.scroll-hint {
    display: none;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

@media (max-width: 992px) {
    .scroll-hint {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: flex;
    }

    .header {
        padding: 12px 20px;
    }

    .content-area {
        padding: 24px 16px;
    }

    .header-title-area h2 {
        font-size: 1.1rem;
    }

    .top-actions {
        gap: 8px;
    }

    .tab-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .time-col {
        width: 130px;
        font-size: 0.75rem;
        padding: 10px 5px;
        white-space: nowrap;
    }

    th,
    td {
        padding: 10px;
        font-size: 0.85rem;
    }

    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
    }
}

@media print {

    .sidebar,
    .top-actions,
    .search-container,
    .checkmark,
    .footer,
    .menu-toggle,
    .sidebar-overlay {
        display: none !important;
    }

    .content-area {
        padding: 0;
    }

    .header {
        border: none;
    }

    .main-content {
        display: block;
    }
}

.footer {
    padding: 20px 40px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--glass);
    backdrop-filter: blur(12px);
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.footer b {
    color: var(--primary);
    font-weight: 700;
}

/* Install App Button */
.install-btn {
    background: var(--accent-soft);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-main);
}

.install-btn:hover {
    background: var(--border);
}

.install-btn i {
    width: 18px;
}

/* Highlight Classes for Schedule */
.current-day-col {
    background-color: rgba(239, 68, 68, 0.08) !important;
}

.current-class {
    background-color: var(--primary) !important;
    color: white !important;
    border-radius: 8px;
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    border: none !important;
    font-weight: 600;
}

.current-class small {
    color: rgba(255, 255, 255, 0.8) !important;
}

.current-time-row .time-col {
    color: var(--primary);
    font-weight: 700;
}

/* Organigrama Styles */
.org-chart-wrapper {
    margin-top: 40px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.org-chart-title {
    text-align: center;
    color: var(--primary);
    margin-bottom: 20px;
    font-size: 1.25rem;
    font-weight: 700;
}

.tree-container {
    overflow-x: auto;
    padding-bottom: 20px;
    text-align: center;
    -webkit-overflow-scrolling: touch;
}

.tree {
    display: inline-block;
}

.tree ul {
    padding-top: 20px;
    position: relative;
    transition: all 0.5s;
    display: flex;
    justify-content: center;
    padding-left: 0;
    min-width: max-content;
}

.tree li {
    float: left;
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 20px 5px 0 5px;
    transition: all 0.5s;
}

/* Connectors */
.tree li::before, .tree li::after{
    content: '';
    position: absolute; top: 0; right: 50%;
    border-top: 2px solid var(--primary);
    width: 50%; height: 20px;
    opacity: 0.6;
}
.tree li::after{
    right: auto; left: 50%;
    border-left: 2px solid var(--primary);
}

/* Remove connectors from first/last children */
.tree li:only-of-type::after, .tree li:only-of-type::before {
    display: none;
}
.tree li:only-of-type{ padding-top: 0;}

.tree li:first-of-type::before, .tree li:last-of-type::after{
    border: 0 none;
}

.tree li:last-of-type::before{
    border-right: 2px solid var(--primary);
    border-radius: 0 5px 0 0;
}
.tree li:first-of-type::after{
    border-radius: 5px 0 0 0;
}

/* Downward connectors from parents */
.tree ul ul::before{
    content: '';
    position: absolute; top: 0; left: 50%;
    border-left: 2px solid var(--primary);
    width: 0; height: 20px;
    opacity: 0.6;
}

/* The Nodes */
.tree li .org-node {
    border: 1px solid var(--primary);
    padding: 12px 18px;
    text-decoration: none;
    color: var(--text-main);
    background: var(--main-bg);
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
    border-radius: var(--radius-md);
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    position: relative;
    z-index: 2;
}

.tree li .org-node:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Special Root Node */
.tree li .root-node {
    background: var(--primary);
    color: white;
    font-size: 0.95rem;
    padding: 14px 24px;
}

/* Secretary Node */
/* Secretary Node */
.tree > ul > li > ul.branches-wrapper {
    margin-top: 0;
    padding-top: 60px;
}

.tree > ul > li > ul.branches-wrapper::before {
    height: 60px;
}

.secretary-wrapper {
    position: absolute;
    top: 30px;
    left: calc(50% + 20px);
    transform: translateY(-50%);
    z-index: 3;
}

.secretary-wrapper::before {
    content: "";
    position: absolute;
    top: 50%;
    right: 100%;
    width: 20px;
    border-top: 2px solid var(--primary);
    opacity: 0.6;
}

.secretary-node {
    border: 1px dashed var(--primary);
    padding: 8px 14px;
    background: var(--accent-soft);
    color: var(--text-main);
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    white-space: nowrap;
}

/* Custom styling for pa-wrapper bridge handles via inline styles now */

/* --- Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border);
    overflow: hidden;
    transform: scale(1);
    transition: transform 0.3s ease;
}

.modal-header {
    background: var(--accent-soft);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-main);
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-modal:hover {
    color: var(--primary);
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.modal-body.hidden {
    display: none;
}

#nota-code-input,
#salon-select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    margin-bottom: 15px;
    background: var(--main-bg);
    color: var(--text-main);
}

#nota-code-input:focus,
#salon-select:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

#salon-select {
    cursor: pointer;
}

#salon-select option {
    background: var(--card-bg);
    color: var(--text-main);
    padding: 8px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
    font-size: 1rem;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.error-msg {
    color: #ef4444;
    font-size: 0.85rem;
    margin-bottom: 15px;
    margin-top: -10px;
    font-weight: 500;
}

.status-msg {
    color: var(--primary);
    font-size: 0.85rem;
    margin-bottom: 15px;
    font-weight: 500;
}

/* --- Notas View Styles --- */
.notas-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.notas-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 30px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    text-align: center;
}

.notas-card h3 {
    color: var(--primary);
    font-size: 1.5rem;
    margin-bottom: 5px;
}

.notas-card .student-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 25px;
}

.notas-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 25px;
}

.nota-item {
    background: var(--accent-soft);
    padding: 15px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
}

.nota-item span {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 5px;
}

.nota-item strong {
    font-size: 1.4rem;
    color: var(--text-main);
}

.nota-score {
    background: var(--primary);
    color: white;
    padding: 15px;
    border-radius: var(--radius-md);
    font-size: 1.8rem;
    font-weight: 700;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}