/* =========================================================
   ARQUIVO ESCOLAR — ESTILOS GERAIS & VARIÁVEIS
   ========================================================= */
:root {
    --app-navy: #142b49;
    --app-navy-light: #1d3c61;
    --app-accent: #4779b8;
    --app-accent-soft: #eaf1fb;
    --app-header-height: 78px;
    --app-mobile-header-height: 68px;
    --app-sidebar-width: 258px;
    --app-text: #26364a;
    --app-muted: #8390a3;
    --app-border: #e5eaf1;
    --app-background: #f3f6fa;
    
    --bg-body: #f8f9fa;
    --bg-card: #ffffff;
    --text-main: #212529;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    --sidebar-bg: #17365d;
    --header-bg: #ffffff;
}

[data-bs-theme="dark"] {
    --bg-body: #121824;
    --bg-card: #1e2636;
    --text-main: #f1f3f5;
    --text-muted: #9099a2;
    --border-color: #2c3548;
    --sidebar-bg: #0d1b2a;
    --header-bg: #1e2636;
    --app-background: #121824;
    --app-text: #f1f3f5;
    --app-border: #2c3548;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text-main);
    background-color: var(--bg-body) !important;
}

/* Layout Shell */
.app-shell {
    display: block;
    min-height: 100vh;
    padding-top: var(--app-header-height);
    padding-left: var(--app-sidebar-width);
    background: var(--bg-body);
}

.app-main {
    width: 100%;
    min-width: 0;
    min-height: calc(100vh - var(--app-header-height));
    margin: 0;
    padding: 30px;
    background: var(--bg-body);
}

/* Header (Desktop) */
.app-header {
    position: fixed;
    top: 0;
    right: 0;
    left: var(--app-sidebar-width);
    z-index: 1050;
    width: auto;
    height: var(--app-header-height);
    min-height: var(--app-header-height);
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 3px 12px rgb(18 39 65 / 4%);
}

.header-left {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-context {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 13px;
}

.header-context-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: grid;
    place-items: center;
    color: #315b8b;
    background: #edf3fa;
    border: 1px solid #e2ebf6;
    border-radius: 11px;
    font-size: 1.05rem;
}

.header-context-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.header-breadcrumb {
    color: var(--text-main);
    font-size: .9rem;
    font-weight: 700;
    line-height: 1.2;
}

.header-page-context {
    color: var(--text-muted);
    font-size: .75rem;
    line-height: 1.2;
}

.sidebar-toggle {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: none;
    align-items: center;
    justify-content: center;
    color: #294866;
    background: #f3f6fa;
    border: 1px solid #e2e9f2;
    border-radius: 10px;
    font-size: 1.05rem;
    cursor: pointer;
    transition: background 160ms ease, color 160ms ease;
}

.sidebar-toggle:hover {
    color: #1d5d9e;
    background: #e8eff8;
}

.sidebar-toggle:focus-visible,
.sidebar-overlay:focus-visible {
    outline: 3px solid rgb(71 121 184 / 45%);
    outline-offset: 3px;
}

/* User & Logout */
.app-header-actions {
    min-width: 0;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 20px;
}

.app-header-user {
    min-width: 0;
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    gap: 11px;
}

.app-user-avatar {
    width: 41px;
    height: 41px;
    flex: 0 0 41px;
    display: grid;
    place-items: center;
    color: #315b8b;
    background: #f0f4f9;
    border: 1px solid #e3eaf2;
    border-radius: 50%;
    font-size: .9rem;
}

.app-user-details {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
}

.app-user-details strong {
    max-width: 230px;
    overflow: hidden;
    color: var(--text-main);
    font-size: .82rem;
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-user-role {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: .72rem;
    line-height: 1.2;
}

.user-status-dot {
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    background: #26966a;
    border-radius: 50%;
}

.app-header-divider {
    width: 1px;
    height: 34px;
    flex: 0 0 1px;
    background: var(--border-color);
}

.app-logout-form {
    margin: 0;
    display: flex;
    flex: 0 0 auto;
}

.app-logout-button {
    min-width: 88px;
    min-height: 39px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-main);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: .8rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 1px 2px rgb(20 43 73 / 3%);
    transition: background 150ms ease, border-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.app-logout-button i {
    font-size: .85rem;
}

.app-logout-button:hover {
    color: #a52b32;
    background: #fff7f7;
    border-color: #eccfd1;
    box-shadow: 0 2px 5px rgb(165 43 50 / 5%);
}

/* Sidebar Desktop */
.app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    width: var(--app-sidebar-width);
    height: 100vh;
    margin: 0;
    padding: 0 15px 18px;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    color: #fff;
    background: linear-gradient(180deg, #172f4c 0%, #10243b 100%);
    border-right: 1px solid rgb(255 255 255 / 5%);
    scrollbar-width: thin;
    scrollbar-color: #49627d transparent;
}

.sidebar-brand {
    height: var(--app-header-height);
    min-height: var(--app-header-height);
    max-height: var(--app-header-height);
    flex: 0 0 auto;
    margin: 0 -15px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(125deg, rgb(255 255 255 / 5%), rgb(255 255 255 / 1%));
}

.sidebar-brand-symbol {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(145deg, #3976b6, #285589);
    border: 1px solid rgb(255 255 255 / 15%);
    border-radius: 12px;
    box-shadow: 0 5px 14px rgb(0 0 0 / 14%);
    font-size: 1.15rem;
}

.sidebar-brand-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-brand-copy strong {
    color: #fff;
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.2;
}

.sidebar-brand-copy span {
    color: #9fb5cf;
    font-size: .6rem;
    font-weight: 700;
    letter-spacing: .105em;
    line-height: 1.2;
}

.sidebar-divider {
    height: 1px;
    flex: 0 0 1px;
    margin: 0 -15px 18px;
    background: rgb(255 255 255 / 10%);
}

.sidebar-content {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-section-label {
    padding: 0 10px;
    color: #a7bad0;
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .11em;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-link {
    position: relative;
    min-height: 42px;
    padding: 0 11px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #c5d1e0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    text-decoration: none;
    transition: color 160ms ease, background 160ms ease, border-color 160ms ease;
}

.sidebar-link:hover:not(.is-active) {
    color: #fff;
    background: rgb(255 255 255 / 7%);
}

.sidebar-link.is-active {
    color: #fff;
    background: linear-gradient(100deg, #2869ae, #2473c4);
    border-color: rgb(255 255 255 / 10%);
    box-shadow: 0 4px 10px rgb(0 0 0 / 10%);
}

.sidebar-link-icon {
    width: 22px;
    flex: 0 0 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #a7bedb;
    font-size: .95rem;
}

.sidebar-link.is-active .sidebar-link-icon {
    color: #fff;
}

.sidebar-link-label {
    flex: 1;
    font-size: .83rem;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: .005em;
}

.sidebar-active-indicator {
    position: absolute;
    top: 8px;
    right: -1px;
    bottom: 8px;
    width: 3px;
    background: #82b7ff;
    border-radius: 3px 0 0 3px;
}

/* Rodapé Sidebar */
.sidebar-footer {
    flex: 0 0 auto;
    margin: 20px 0 0;
    padding: 12px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgb(255 255 255 / 4%);
    border: 1px solid rgb(255 255 255 / 8%);
    border-radius: 10px;
}

.sidebar-footer-icon {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: grid;
    place-items: center;
    color: #a9ceff;
    background: rgb(255 255 255 / 7%);
    border-radius: 8px;
    font-size: .8rem;
}

.sidebar-footer-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-footer-copy strong {
    color: #e1eaf5;
    font-size: .68rem;
    font-weight: 600;
}

.sidebar-footer-copy span {
    color: #9fb1c8;
    font-size: .65rem;
}

.sidebar-overlay {
    display: none;
}

/* Bootstrap Theme Overrides for Dark Mode */
.card, .dropdown-menu {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}

.table {
    color: var(--text-main) !important;
}

.table-light {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
}

.btn-primary {
    color: #fff;
    background-color: #1d3c61;
    border-color: #1d3c61;
}

.extra-small {
    font-size: 0.7rem !important;
}

.py-2\.5 {
    padding-top: 0.6rem !important;
    padding-bottom: 0.6rem !important;
}

/* Responsividade Avançada: Conversão de Tabelas em Cards para Mobile (< 768px) */
@media (max-width: 767.98px) {
    .table-responsive-cards table,
    .table-responsive-cards thead,
    .table-responsive-cards tbody,
    .table-responsive-cards th,
    .table-responsive-cards td,
    .table-responsive-cards tr {
        display: block;
    }

    .table-responsive-cards thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .table-responsive-cards tr {
        border: 1px solid var(--border-color);
        border-radius: 0.5rem;
        margin-bottom: 1rem;
        background-color: var(--bg-card);
        padding: 0.75rem;
        box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.05);
    }

    .table-responsive-cards td {
        position: relative;
        padding: 0.5rem 0 0.5rem 45% !important;
        text-align: right !important;
        border: none !important;
        border-bottom: 1px solid var(--border-color) !important;
        font-size: 0.875rem;
    }

    .table-responsive-cards td:last-child {
        border-bottom: none !important;
        text-align: center !important;
        padding-left: 0 !important;
        padding-top: 0.75rem !important;
    }

    .table-responsive-cards td::before {
        position: absolute;
        top: 0.5rem;
        left: 0;
        width: 40%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        color: var(--text-muted);
        content: attr(data-label);
    }
}

/* Media Queries (Responsividade) */
@media (max-width: 1000px) and (min-width: 769px) {
    :root {
        --app-sidebar-width: 225px;
    }

    .app-header {
        padding-right: 18px;
        padding-left: 18px;
        gap: 12px;
    }

    .header-page-context {
        display: none;
    }

    .app-header-actions {
        gap: 12px;
    }

    .app-main {
        padding: 24px;
    }
}

@media (max-width: 768px) {
    .app-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: var(--app-mobile-header-height);
        min-height: var(--app-mobile-header-height);
        padding: 0 14px;
        gap: 10px;
        z-index: 1050;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .header-left {
        flex: 1 1 auto;
        gap: 9px;
    }

    .header-context {
        gap: 9px;
    }

    .header-page-context {
        display: none;
    }

    .app-header-actions {
        flex: 0 1 auto;
        gap: 8px;
    }

    .app-user-details strong {
        max-width: 120px;
    }

    .app-header-divider {
        display: none;
    }

    .app-logout-button {
        min-width: 38px;
        width: 38px;
        min-height: 38px;
        padding: 0;
    }

    .app-logout-button span {
        display: none;
    }

    .app-shell {
        min-height: 100vh;
        padding-top: var(--app-mobile-header-height);
        padding-left: 0;
    }

    .app-main {
        width: 100%;
        min-width: 0;
        min-height: calc(100vh - var(--app-mobile-header-height));
        padding: 20px 16px;
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 1080;
        width: min(280px, 85vw);
        max-width: 85vw;
        height: 100vh;
        height: 100dvh;
        margin: 0;
        padding: 0 15px 18px;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        transform: translateX(-105%);
        visibility: hidden;
        pointer-events: none;
        box-shadow: 12px 0 35px rgb(0 0 0 / 28%);
        transition: transform 260ms cubic-bezier(.22, 1, .36, 1), visibility 260ms;
    }

    .app-sidebar.is-open {
        transform: translateX(0);
        visibility: visible;
        pointer-events: auto;
    }

    .sidebar-brand {
        height: var(--app-mobile-header-height);
        min-height: var(--app-mobile-header-height);
        max-height: var(--app-mobile-header-height);
        padding: 0 15px;
    }

    .sidebar-divider {
        margin-bottom: 16px;
    }

    .sidebar-content {
        gap: 20px;
    }

    .sidebar-link {
        min-height: 44px;
    }

    .sidebar-footer {
        display: flex;
        margin-top: 20px;
    }

    .sidebar-overlay:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: 1070;
        display: block;
        width: 100%;
        height: 100%;
        padding: 0;
        border: 0;
        background: rgb(9 21 36 / 55%);
        cursor: pointer;
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
        animation: sidebar-overlay-in 180ms ease-out;
    }

    body.sidebar-open {
        overflow: hidden;
        touch-action: none;
    }
}

@media (max-width: 480px) {
    .app-header {
        padding: 0 10px;
        gap: 8px;
    }

    .sidebar-toggle {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
    }

    .header-left {
        gap: 8px;
    }

    .header-context {
        gap: 8px;
    }

    .header-context-icon {
        display: none;
    }

    .header-breadcrumb {
        font-size: .76rem;
    }

    .app-header-actions {
        gap: 8px;
    }

    .app-user-avatar {
        width: 32px;
        height: 32px;
        flex-basis: 32px;
    }

    .app-user-details strong {
        max-width: 95px;
        font-size: .69rem;
    }

    .app-user-role {
        font-size: .66rem;
    }

    .app-logout-button {
        min-width: 35px;
        width: 35px;
        min-height: 35px;
    }

    .app-main {
        padding: 18px 12px;
    }

    .sidebar-brand-symbol {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
        font-size: 1rem;
    }

    .sidebar-footer {
        display: none;
    }
}

@keyframes sidebar-overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar,
    .sidebar-overlay,
    .sidebar-link,
    .app-logout-button,
    .sidebar-toggle {
        animation: none;
        transition: none;
    }
}

@media (min-width: 769px) {
    .app-sidebar {
        transform: none;
        visibility: visible;
        pointer-events: auto;
    }

    .sidebar-overlay {
        display: none !important;
    }
}