/**
 * Escola 360 — UI Polish (camada final, carregada depois de theme-modern.css)
 *
 * Objetivo: acabamento profissional e consistente em TODAS as páginas.
 *  1. Sidebar sem sobreposição (rodapé compacto, menu rolável com fade).
 *  2. Botão do Assistente IA sempre no canto inferior direito.
 *  3. Botões, cards, tabelas, formulários, badges e estados vazios unificados.
 *  4. Correções de sobreposição: stepper do cadastro, cartões de estatística
 *     estreitos, pílulas de status do cabeçalho, barras fixas de ação.
 *  5. Movimento sutil (entrada de conteúdo, hover) respeitando reduced-motion.
 */

:root {
    --ui-ease: cubic-bezier(.2, .8, .2, 1);
    --ui-ring: 0 0 0 4px rgba(37, 99, 235, .18);
    --ui-radius: 14px;
    --ui-radius-sm: 10px;
    --ui-shadow-1: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 20px rgba(16, 24, 40, .05);
    --ui-shadow-2: 0 10px 30px rgba(16, 24, 40, .10);
}

/* =========================================================
   1. SIDEBAR — nada por cima do menu
   ========================================================= */
.sidebar { display: flex !important; flex-direction: column !important; }
.sidebar__header { flex: 0 0 auto; }
.sidebar__nav {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    padding: 6px 10px 18px !important;
    scrollbar-gutter: stable;
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 22px), transparent);
            mask-image: linear-gradient(to bottom, #000 calc(100% - 22px), transparent);
}
.sidebar__section-title { margin: 12px 6px 4px !important; }
.sidebar__menu { gap: 1px !important; }
.sidebar__item { min-height: 38px !important; padding: 0 12px !important; font-size: .86rem !important; }
.sidebar__footer {
    flex: 0 0 auto;
    padding: 8px 12px 6px !important;
    border-top: 1px solid var(--e360-line) !important;
    background: #fff;
}
.sidebar__user { padding: 8px 10px !important; }
.sidebar__user-avatar { width: 34px !important; height: 34px !important; }
.sidebar__user-name { max-width: 120px !important; }
.sidebar__govex {
    flex: 0 0 auto;
    margin-top: 0 !important;
    padding: 6px 12px 10px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.sidebar__govex div { font-size: .58rem !important; letter-spacing: .1em; margin: 0 !important; }
.sidebar__govex img { height: 16px !important; }
.sidebar__govex > div > div { display: inline-flex; align-items: center; gap: 8px; }
@media (max-height: 760px) {
    .sidebar__govex { display: none !important; }
    .sidebar__item { min-height: 36px !important; }
}
.app--sidebar-collapsed .sidebar__govex { display: none !important; }

/* =========================================================
   2. ASSISTENTE IA — canto inferior direito, nunca sobre o conteúdo útil
   ========================================================= */
.e360ai-fab {
    left: auto !important;
    right: 22px !important;
    bottom: 22px !important;
    top: auto !important;
    height: 50px !important;
    padding: 0 18px 0 14px !important;
    font-size: .86rem !important;
    z-index: 900 !important;
}
.e360ai-fab .e360ai-fabpulse { display: none !important; }
.e360ai-fab { width: 52px; height: 52px !important; padding: 0 !important; justify-content: center !important; overflow: hidden; transition: width .25s var(--ui-ease), padding .25s var(--ui-ease), box-shadow .2s !important; }
.e360ai-fab .e360ai-fab-txt { display: none !important; }
.e360ai-fab:hover, .e360ai-fab:focus-visible { width: auto; padding: 0 18px 0 14px !important; }
.e360ai-fab:hover .e360ai-fab-txt, .e360ai-fab:focus-visible .e360ai-fab-txt { display: inline !important; }
/* Páginas com barra de ação fixa no rodapé: sobe o botão */
body:has(.sticky.bottom-4) .e360ai-fab,
body:has(.attendance-actions-bar) .e360ai-fab { bottom: 104px !important; }
.e360ai-panel, .e360ai-window { z-index: 950 !important; }
body.e360-no-assistant .e360ai-fab, body.e360-no-assistant .e360ai-panel { display: none !important; }

/* =========================================================
   3. BOTÕES
   ========================================================= */
.btn, button.btn, a.btn {
    border-radius: var(--ui-radius-sm) !important;
    font-weight: 600 !important;
    letter-spacing: .01em;
    min-height: 42px;
    padding: .6rem 1.1rem !important;
    gap: .5rem;
    transition: transform .15s var(--ui-ease), box-shadow .2s var(--ui-ease), background .2s, color .2s, border-color .2s !important;
    text-shadow: none !important;
}
.btn i, .btn .ph { font-size: 1.05em; line-height: 1; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0) scale(.98); }
.btn:focus-visible { box-shadow: var(--ui-ring) !important; outline: none !important; }
.btn--primary, .btn-primary {
    background: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%) !important;
    color: #fff !important;
    border: 1px solid transparent !important;
    box-shadow: 0 6px 16px rgba(37, 99, 235, .28) !important;
}
.btn--primary:hover:not(:disabled), .btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #1D4ED8 0%, #2563EB 100%) !important;
    box-shadow: 0 10px 22px rgba(37, 99, 235, .34) !important;
}
.btn--secondary, .btn--outline, .btn-secondary, .btn-outline {
    background: #fff !important;
    color: #1F2937 !important;
    border: 1px solid #D0D5DD !important;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .05) !important;
}
.btn--secondary:hover:not(:disabled), .btn--outline:hover:not(:disabled) {
    border-color: #2563EB !important;
    color: #1D4ED8 !important;
    background: #F5F8FF !important;
}
.btn--outline::after { display: none !important; }
.btn--ghost { color: #475467 !important; }
.btn--ghost:hover:not(:disabled) { background: #F2F4F7 !important; color: #101828 !important; }
.btn--danger, .btn-danger { background: #DC2626 !important; color: #fff !important; border-color: transparent !important; }
.btn--danger:hover:not(:disabled) { background: #B91C1C !important; }
.btn--success { background: linear-gradient(135deg, #059669, #10B981) !important; }
.btn--sm, .btn-sm { min-height: 34px; padding: .35rem .75rem !important; font-size: .8rem !important; }
.btn--icon, .action-btn { min-width: 38px; min-height: 38px; padding: 0 !important; border-radius: 10px !important; }
.btn:disabled, .btn--disabled { transform: none !important; box-shadow: none !important; }

/* Grupos de ações do cabeçalho: alinhados e sem quebra estranha */
.header__actions, .page-actions, .card__actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

/* =========================================================
   4. CARDS, TABELAS, FORMULÁRIOS
   ========================================================= */
.card, .table-card, .stat-card, .filters, .grades-filters, .panel {
    border-radius: var(--ui-radius) !important;
    box-shadow: var(--ui-shadow-1) !important;
    border: 1px solid rgba(230, 234, 242, .9) !important;
}
.card__header, .table-card__header, .card-header {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--e360-line);
}
.card__title, .card-title { font-weight: 700; color: var(--e360-ink); letter-spacing: -.01em; }

/* Cartões de estatística: nunca cortam o rótulo */
.stats-grid, .stats-row, .kpi-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    gap: 1rem !important;
}
.stat-card { min-width: 0; align-items: center !important; padding: 1.1rem 1.25rem !important; }
.stat-card__icon { width: 48px !important; height: 48px !important; flex-shrink: 0; border-radius: 12px !important; }
.stat-card__value { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat-card__label { font-size: .8rem; color: var(--e360-muted); white-space: normal !important; overflow: visible !important; line-height: 1.25; }
.stat-card > div:not(.stat-card__icon) { min-width: 0; }

/* Tabelas: cabeçalho fixo, linhas com respiro e hover */
.table-card, .table-container, .table-responsive, .table-wrapper { overflow-x: auto; }
table.table, .table-card table, .data-table { width: 100%; border-collapse: separate; border-spacing: 0; }
table.table thead th, .table-card thead th, .data-table thead th, .coordinator-table thead th {
    position: sticky; top: 0; z-index: 1;
    background: #F8FAFC; color: #475467;
    font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    padding: .8rem 1rem; border-bottom: 1px solid var(--e360-line); white-space: nowrap;
}
table.table tbody td, .table-card tbody td, .data-table tbody td, .coordinator-table tbody td {
    padding: .8rem 1rem; border-bottom: 1px solid #EEF2F6; vertical-align: middle; font-size: .875rem;
}
table.table tbody tr:hover td, .table-card tbody tr:hover td, .data-table tbody tr:hover td { background: #F7FAFF; }
table.table tbody tr:last-child td { border-bottom: none; }
.coordinator-table { min-width: 640px; }

/* Formulários */
.form-control, .form-input, .form-select, .filter-select, input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea {
    border-radius: var(--ui-radius-sm) !important;
    border: 1px solid #D0D5DD !important;
    background: #fff !important;
    transition: border-color .15s, box-shadow .15s !important;
}
.form-control:focus, .form-input:focus, .form-select:focus, .filter-select:focus, input:focus, select:focus, textarea:focus {
    border-color: #2563EB !important;
    box-shadow: var(--ui-ring) !important;
    outline: none !important;
}
.form-label, label.label { font-size: .8rem; font-weight: 600; color: #344054; margin-bottom: .35rem; display: block; }
.form-group, .form-field { margin-bottom: 1rem; }
.form-hint { font-size: .75rem; color: var(--e360-muted); margin-top: .3rem; }
.form-error, .field-error { font-size: .75rem; color: #DC2626; margin-top: .3rem; }
.form-grid, .form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }

/* Badges e pílulas de status */
.badge, .status, .status-badge, .chip {
    display: inline-flex; align-items: center; gap: .35rem;
    border-radius: 999px; padding: .25rem .65rem;
    font-size: .72rem; font-weight: 700; white-space: nowrap; line-height: 1.3;
}
.attendance-api-status { white-space: nowrap; max-width: 260px; overflow: hidden; }
.attendance-api-status span:last-child { overflow: hidden; text-overflow: ellipsis; }

/* =========================================================
   5. ESTADOS VAZIOS / ERRO / CARREGANDO (bloco, não inline)
   ========================================================= */
.state-block[hidden], .empty-state[hidden], [hidden] { display: none !important; }
.state-block, .empty-state, .error-state, .records-empty, .teacher-empty, .acc-empty, .camera-live-empty {
    display: flex !important; flex-direction: column; align-items: center; justify-content: center;
    gap: .35rem; text-align: center; padding: 2.4rem 1rem !important;
    color: var(--e360-muted);
}
.state-block i, .empty-state i, .records-empty i {
    font-size: 2.2rem; color: #98A2B3; margin-bottom: .35rem;
    width: 64px; height: 64px; display: inline-flex; align-items: center; justify-content: center;
    background: #F2F4F7; border-radius: 50%;
}
.state-block strong, .empty-state strong, .records-empty strong { display: block; color: var(--e360-ink); font-size: .95rem; font-weight: 700; }
.state-block span, .empty-state span, .records-empty span { display: block; font-size: .85rem; max-width: 420px; }
.state-block .btn, .empty-state .btn { margin-top: .75rem; }
.state-block--error strong { color: #B42318; }
.state-block--error i { color: #B42318; background: #FEF3F2; }

/* =========================================================
   6. STEPPER (cadastro de aluno) — markup stepper__item
   ========================================================= */
.stepper {
    display: flex; align-items: flex-start; gap: .25rem; flex-wrap: wrap;
    padding: 1rem 1.25rem; margin-bottom: 1.25rem;
    background: #fff; border: 1px solid var(--e360-line); border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow-1);
}
.stepper__item { display: flex; align-items: center; gap: .75rem; flex: 1 1 0; min-width: 150px; padding: .35rem .5rem; border-radius: 10px; }
.stepper__number {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: #F2F4F7; color: #667085; font-weight: 800; font-size: .85rem;
    border: 2px solid transparent; transition: all .2s;
}
.stepper__info { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.stepper__title { font-size: .85rem; font-weight: 700; color: #667085; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper__subtitle { font-size: .72rem; color: #98A2B3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper__connector { flex: 0 0 24px; height: 2px; background: #E4E7EC; margin-top: 18px; border-radius: 2px; }
.stepper__item--active .stepper__number { background: #2563EB; color: #fff; box-shadow: 0 0 0 4px rgba(37, 99, 235, .15); }
.stepper__item--active .stepper__title { color: #1D4ED8; }
.stepper__item--completed .stepper__number { background: #ECFDF3; color: #027A48; border-color: #A6F4C5; }
.stepper__item--completed .stepper__title { color: #027A48; }
.enrollment-wizard__step--active { display: block; }
@media (max-width: 900px) {
    .stepper__connector { display: none; }
    .stepper__item { min-width: 45%; }
    .stepper__subtitle { display: none; }
}

/* =========================================================
   7. CABEÇALHO DE PÁGINA E TIPOGRAFIA
   ========================================================= */
.page-title, .content__title, h1.page-heading { display: flex; align-items: center; gap: .6rem; font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; color: var(--e360-ink); }
.page-subtitle, .content__subtitle { color: var(--e360-muted); margin-top: .2rem; }
.breadcrumb, .breadcrumbs { font-size: .82rem; color: var(--e360-muted); display: flex; align-items: center; gap: .4rem; }
.breadcrumb a:hover { color: #1D4ED8; }

/* Barra de ação da chamada: fixa no rodapé, sem cobrir o conteúdo */
.attendance-page main, .attendance-page .app__main { padding-bottom: 120px !important; }
.attendance-page .sticky.bottom-4 { position: fixed !important; bottom: 16px !important; left: calc(var(--sidebar-width, 260px) + 32px); right: 32px; z-index: 40; margin: 0 !important; }
.app--sidebar-collapsed .attendance-page .sticky.bottom-4, body:has(.app--sidebar-collapsed) .attendance-page .sticky.bottom-4 { left: calc(var(--sidebar-width-collapsed, 72px) + 32px); }
@media (max-width: 1023px) { .attendance-page .sticky.bottom-4 { left: 12px; right: 12px; } }
.coordinator-table-wrap, .table-wrap { overflow-x: auto; max-width: 100%; }

/* Popover de notificações (sino do cabeçalho) */
.header__action { position: relative; }
.ui-notif { position: absolute; top: calc(100% + 10px); right: 0; width: 340px; max-width: calc(100vw - 32px); background: #fff; border: 1px solid var(--e360-line); border-radius: var(--ui-radius); box-shadow: var(--ui-shadow-2); z-index: 1200; text-align: left; overflow: hidden; animation: ui-rise .2s var(--ui-ease); }
.ui-notif__head { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--e360-line); font-weight: 700; font-size: .85rem; color: var(--e360-ink); }
.ui-notif__list { max-height: 360px; overflow-y: auto; }
.ui-notif__item { display: flex; gap: .7rem; padding: .7rem 1rem; border-bottom: 1px solid #F2F4F7; font-size: .82rem; color: #344054; text-decoration: none; }
.ui-notif__item:hover { background: #F7FAFF; }
.ui-notif__item i { font-size: 1.1rem; color: #2563EB; flex-shrink: 0; margin-top: .1rem; }
.ui-notif__item strong { display: block; color: var(--e360-ink); font-weight: 600; }
.ui-notif__item small { color: var(--e360-muted); }
.ui-notif__empty { padding: 1.4rem 1rem; text-align: center; color: var(--e360-muted); font-size: .82rem; }
.ui-notif__foot { padding: .6rem 1rem; border-top: 1px solid var(--e360-line); text-align: center; font-size: .8rem; }
.ui-notif__foot a { color: #1D4ED8; font-weight: 600; }
.header__action-badge:empty { display: none; }

/* Abas e seletores de período: estado ativo consistente */
.period-btn, .tab-btn, .filter-chip { border-radius: 999px; padding: .4rem .9rem; font-size: .8rem; font-weight: 600; border: 1px solid #D0D5DD; background: #fff; color: #475467; cursor: pointer; transition: all .15s; }
.period-btn.active, .tab-btn.active, .filter-chip.active, .period-btn[aria-selected="true"] { background: #2563EB; color: #fff; border-color: #2563EB; }

/* Barra de ação fixa (chamada/notas): respiro para não cobrir conteúdo */
.sticky.bottom-4 { margin-top: 1rem; }
.attendance-page .content, .attendance-page main { padding-bottom: 7rem !important; }
.sticky.bottom-4 > div, .attendance-actions-bar {
    border-radius: var(--ui-radius) !important;
    box-shadow: 0 -4px 24px rgba(16, 24, 40, .12), var(--ui-shadow-2) !important;
}

/* Modais */
.modal, .modal-content, .modal__content { border-radius: var(--ui-radius) !important; box-shadow: var(--ui-shadow-2) !important; }
.modal-overlay, .modal-backdrop { backdrop-filter: blur(3px); }

/* Toasts */
.toast { border-radius: 12px !important; box-shadow: var(--ui-shadow-2) !important; }

/* =========================================================
   8. MOVIMENTO SUTIL
   ========================================================= */
@keyframes ui-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.content > *:not(script):not(style) { animation: ui-rise .35s var(--ui-ease) both; }
.content > *:nth-child(2) { animation-delay: .04s; }
.content > *:nth-child(3) { animation-delay: .08s; }
.content > *:nth-child(4) { animation-delay: .12s; }
.card:hover, .stat-card:hover { box-shadow: var(--ui-shadow-2) !important; }
@media (prefers-reduced-motion: reduce) {
    .content > * { animation: none !important; }
    .btn:hover { transform: none !important; }
}

/* =========================================================
   9. RESPONSIVO
   ========================================================= */
@media (max-width: 1024px) {
    .header { padding: 1rem 1.25rem !important; }
    .content { padding-left: 1rem !important; padding-right: 1rem !important; }
}
@media (max-width: 640px) {
    .header__actions .btn, .page-actions .btn { flex: 1 1 auto; justify-content: center; }
    .stats-grid { grid-template-columns: 1fr 1fr !important; }
    .e360ai-fab { right: 14px !important; bottom: 14px !important; padding: 0 12px !important; }
    .e360ai-fab-txt { display: none !important; }
}
