:root {
    --primary-color: #003366;
    --primary-hover: #002244;
    --accent-color: #00fcdf;
    --bg-light: #f4f6f9;
    --text-color: #333333;
    --border-color: #cccccc;
    --sidebar-width: 250px;
    --white: #ffffff;
    --danger: #c0392b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

html, body {
    height: 100%;
}

body {
    background-color: var(--bg-light);
    color: var(--text-color);
    display: flex;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary-color);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    flex-shrink: 0;
    z-index: 40;
    transition: width 0.2s ease;
    overflow: hidden;
    position: relative;
}

.sidebar-inner {
    width: 100%;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
}

body.sidebar-collapsed .sidebar {
    width: 52px;
}

.sidebar-header {
    padding: 0.75rem;
    background-color: var(--primary-hover);
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-height: 64px;
    position: relative;
    z-index: 2;
}

.sidebar-brand {
    text-align: left;
    min-width: 0;
    flex: 1;
}

body.sidebar-collapsed .sidebar-brand,
body.sidebar-collapsed .sidebar-menu {
    display: none !important;
}

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
}

.sidebar-header small {
    opacity: 0.85;
    font-size: 0.78rem;
    white-space: nowrap;
}

.sidebar-menu {
    list-style: none;
    margin-top: 0.75rem;
}

.sidebar-menu li a {
    display: block;
    padding: 0.85rem 1.15rem;
    color: #ecf0f1;
    text-decoration: none;
    font-size: 0.88rem;
    line-height: 1.3;
    transition: background 0.2s;
    white-space: nowrap;
}

.sidebar-menu li a:hover,
.sidebar-menu li.active a {
    background-color: rgba(255, 255, 255, 0.15);
    border-left: 4px solid var(--accent-color);
}

.sidebar-footer {
    padding: 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.75rem;
    line-height: 1.4;
}

.footer-note {
    opacity: 0.75;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 30;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

.view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.view[hidden] {
    display: none !important;
}

.top-bar {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 1rem;
    background: var(--white);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    z-index: 3;
    pointer-events: auto;
}

.menu-toggle:hover {
    background: rgba(255, 255, 255, 0.22);
}

.menu-toggle:active {
    background: rgba(255, 255, 255, 0.3);
}

body.sidebar-collapsed .sidebar-header {
    justify-content: center;
    padding: 0.75rem 0.4rem;
}

body.sidebar-collapsed .sidebar {
    cursor: pointer;
}

.top-bar-title h2 {
    font-size: 0.95rem;
    color: var(--primary-color);
    letter-spacing: 0.02em;
}

.top-bar-title p {
    font-size: 0.78rem;
    color: #666;
}

.info-bubble {
    margin-bottom: 0.75rem;
    padding: 0.7rem 0.85rem;
    background: #eef6ff;
    border: 1px solid #b8d4f0;
    border-left: 4px solid var(--primary-color);
    border-radius: 8px;
    font-size: 0.82rem;
    line-height: 1.45;
    color: #1a3a5c;
}

.info-bubble p + p {
    margin-top: 0.45rem;
}

.info-bubble a {
    color: var(--primary-color);
    font-weight: 600;
}

.filters-panel {
    margin: 0.55rem 0.85rem 0.4rem;
    padding: 0.7rem 0.9rem;
    background: var(--white);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent-color);
    border-radius: 6px;
    flex-shrink: 0;
}

.filters-intro h1 {
    font-size: 1rem;
    color: var(--primary-color);
    margin-bottom: 0.1rem;
}

.filters-intro p {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 0.55rem;
}

body.has-results .filters-intro p,
body.has-results .filters-hint {
    display: none;
}

.filters-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
    gap: 0.65rem;
    align-items: end;
}

.filters-form-cursado {
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
}

@media (min-width: 1101px) {
    .filters-form-cursado {
        grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
    }
}

.week-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.55rem;
    padding: 0.45rem 0.55rem;
    background: #eef3f8;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    flex-shrink: 0;
}

.week-label {
    flex: 1;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0;
}

.btn-week {
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.btn-week:hover {
    background: var(--primary-hover);
}

.btn-week:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.horario-grid thead th .th-date {
    display: block;
    font-size: 0.7rem;
    font-weight: 500;
    opacity: 0.9;
    margin-top: 0.1rem;
}

.filters-form-consulta {
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
}

.consulta-form {
    grid-template-columns: minmax(0, 1fr) auto;
}

.consulta-field {
    max-width: 520px;
}

.filter-field label {
    display: block;
    margin-bottom: 0.2rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--primary-color);
}

.combo {
    position: relative;
}

.combo-input {
    width: 100%;
    padding: 0.4rem 1.7rem 0.4rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    background: #fff;
}

.combo-input:focus {
    outline: 2px solid rgba(0, 252, 223, 0.55);
    border-color: var(--primary-color);
}

.combo-clear {
    position: absolute;
    right: 0.3rem;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    color: #888;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    width: 1.35rem;
    height: 1.35rem;
}

.combo-clear:hover {
    color: var(--danger);
}

.combo-list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 2px);
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    list-style: none;
    z-index: 50;
}

.combo-list li {
    padding: 0.45rem 0.6rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.combo-list li:hover,
.combo-list li.active {
    background: rgba(0, 51, 102, 0.08);
}

.combo-list li.muted {
    color: #888;
    cursor: default;
}

.filters-actions {
    display: flex;
    gap: 0.4rem;
    padding-bottom: 1px;
}

.btn {
    padding: 0.4rem 0.9rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.filters-hint {
    margin-top: 0.45rem;
    font-size: 0.78rem;
    color: #777;
}

.results-panel {
    margin: 0 0.85rem 0.55rem;
    padding: 0.55rem 0.7rem 0.7rem;
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.results-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.4rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.results-meta-left {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.results-meta h2 {
    font-size: 0.95rem;
    color: var(--primary-color);
}

.results-meta p {
    font-size: 0.78rem;
    color: #666;
}

.btn-print {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}

.btn-print:hover {
    background: var(--primary-hover);
}

.btn-print[hidden] {
    display: none !important;
}

.grid-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.horario-grid {
    width: 100%;
    min-height: 100%;
    height: auto;
    border-collapse: collapse;
    table-layout: fixed;
}

.horario-grid th,
.horario-grid td {
    border: 1px solid var(--border-color);
    vertical-align: top;
}

.horario-grid thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.45rem 0.25rem;
    text-align: center;
}

.horario-grid .col-hora {
    width: 104px;
    background: var(--primary-hover);
}

.horario-grid tbody tr {
    height: auto;
}

.horario-grid tbody th {
    background: #e8eef5;
    color: var(--primary-color);
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
    padding: 0.3rem 0.2rem;
    white-space: nowrap;
}

.horario-grid td {
    padding: 0.2rem;
    background: #fafbfc;
}

.horario-grid tr:nth-child(even) td {
    background: #f3f6f9;
}

.slot-card {
    display: block;
    margin-bottom: 0.25rem;
    padding: 0.3rem 0.35rem;
    border-radius: 3px;
    border-left: 3px solid var(--accent-color);
    background: rgba(0, 51, 102, 0.06);
    color: var(--text-color);
    font-size: 0.8rem;
    line-height: 1.3;
}

.slot-card:last-child {
    margin-bottom: 0;
}

.slot-card .slot-materia {
    display: block;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.1rem;
    font-size: 0.85rem;
}

.slot-card .slot-docentes {
    display: block;
    color: #1a4a7a;
    font-weight: 600;
    margin-bottom: 0.1rem;
    font-size: 0.78rem;
}

.slot-card .slot-meta {
    display: block;
    color: #555;
    font-size: 0.76rem;
}

.slot-card .slot-time {
    display: block;
    font-size: 0.72rem;
    color: #777;
    margin-top: 0.1rem;
}

.empty-state {
    margin-top: 0.75rem;
    text-align: center;
    color: #777;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.consulta-results {
    overflow: auto;
}

.consulta-card {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    min-height: 0;
    height: 100%;
}

.consulta-header h2 {
    font-size: 1.15rem;
    color: var(--primary-color);
    margin-bottom: 0.35rem;
}

.consulta-mail {
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
    flex-wrap: wrap;
    font-size: 0.92rem;
}

.consulta-mail span {
    font-weight: 700;
    color: var(--primary-color);
}

.consulta-mail a {
    color: #0b5cab;
    word-break: break-all;
}

.consulta-table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.consulta-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.consulta-table th,
.consulta-table td {
    border: 1px solid var(--border-color);
    padding: 0.55rem 0.6rem;
    text-align: left;
    vertical-align: top;
}

.consulta-table thead th {
    position: sticky;
    top: 0;
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
}

.consulta-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.consulta-table thead th.sortable:hover {
    background: var(--primary-hover);
}

.consulta-table thead th.sortable .sort-ind {
    opacity: 0.45;
    font-size: 0.75em;
    margin-left: 0.25rem;
}

.consulta-table thead th.sorted-asc .sort-ind,
.consulta-table thead th.sorted-desc .sort-ind {
    opacity: 1;
}

.consulta-table tbody tr:nth-child(even) {
    background: #f3f6f9;
}

.consulta-table a {
    color: #0b5cab;
}

.status-panel {
    margin: 0 0.85rem 0.55rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.status-panel:empty,
.status-panel[hidden] {
    display: none;
}

.status-panel.error {
    color: var(--danger);
    background: #fdecea;
    border: 1px solid #f5c6cb;
    padding: 0.55rem 0.75rem;
    border-radius: 4px;
}

.status-panel.loading {
    color: #555;
}

@media (max-width: 1100px) {
    .filters-form,
    .filters-form-cursado,
    .filters-form-consulta {
        grid-template-columns: 1fr 1fr;
    }

    .filters-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 800px) {
    body {
        overflow: auto;
        height: auto;
        max-height: none;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 52px;
        transition: width 0.2s ease;
        transform: none;
    }

    body.sidebar-collapsed .sidebar,
    body:not(.menu-open) .sidebar {
        width: 52px;
    }

    body:not(.menu-open) .sidebar-brand,
    body:not(.menu-open) .sidebar-menu {
        display: none !important;
    }

    body:not(.menu-open) .sidebar-header {
        justify-content: center;
        padding: 0.75rem 0.4rem;
    }

    body.menu-open .sidebar {
        width: var(--sidebar-width);
        transform: none;
    }

    body.menu-open .sidebar-brand,
    body.menu-open .sidebar-menu {
        display: block !important;
    }

    body.menu-open .sidebar-brand {
        flex: 1;
        min-width: 0;
    }

    body.menu-open .sidebar-header {
        justify-content: flex-start;
        padding: 0.75rem;
    }

    body.menu-open .sidebar-backdrop {
        display: block;
    }

    .main-content {
        overflow: visible;
        margin-left: 52px;
    }

    .view {
        overflow: visible;
    }

    .filters-form,
    .consulta-form {
        grid-template-columns: 1fr;
    }

    .filters-panel,
    .results-panel,
    .status-panel {
        margin-left: 0.65rem;
        margin-right: 0.65rem;
    }

    .results-panel {
        flex: none;
        overflow: visible;
    }

    .grid-scroll,
    .consulta-table-wrap {
        overflow: auto;
        max-height: none;
    }

    .horario-grid {
        height: auto;
        min-width: 860px;
    }

    .top-bar-title h2 {
        font-size: 0.85rem;
    }
}
