/* ============================================================
   Controle de Merenda Escolar - Estilo Moderno 2026
   Tecnologias: CSS Grid, dvh, clamp(), glassmorphism,
   scroll-driven, :has(), accent-color, prefers-reduced-motion
   ============================================================ */

/* ============================
   1. DESIGN TOKENS + fluid typography
   ============================ */
:root {
    --topbar-h: 52px;
    --sidebar-w: 230px;
    --mobile-nav-h: 62px;
    --green: #2e7d32;
    --green-dark: #1b5e20;
    --green-light: #4caf50;
    --green-bg: #e8f5e9;
    --radius: 10px;
    --shadow: 0 1px 4px rgba(0,0,0,.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,.1);
    /* Fluid typography: escala entre 320px e 1440px */
    --text-xs:   clamp(0.65rem, 0.6rem + 0.2vw, 0.75rem);
    --text-sm:   clamp(0.8rem,  0.75rem + 0.2vw, 0.9rem);
    --text-base: clamp(0.9rem,  0.85rem + 0.3vw, 1rem);
    --text-lg:   clamp(1.1rem,  1rem + 0.4vw, 1.35rem);
    --text-xl:   clamp(1.3rem,  1.15rem + 0.6vw, 1.8rem);
}

/* ═══════════════════════════════════════════
   DARK MODE — Variáveis e overrides
   ═══════════════════════════════════════════ */
html[data-theme="dark"] {
    --green-bg: #0f2611;
}

html[data-theme="dark"] body,
body[data-theme="dark"] {
    background: #0b1120;
    color: #f1f5f9;
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .card-header {
    background: #111827;
    border-color: #1e293b;
    color: #f1f5f9;
}

html[data-theme="dark"] .card-header {
    border-bottom-color: #1e293b;
}

html[data-theme="dark"] .bg-light {
    background: #0b1120 !important;
}

html[data-theme="dark"] .text-muted {
    color: #94a3b8 !important;
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background: #1e293b;
    border-color: #334155;
    color: #f1f5f9;
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    background: #1e293b;
    border-color: #4caf50;
    box-shadow: 0 0 0 3px rgba(76,175,80,.25);
}

html[data-theme="dark"] .form-control::placeholder {
    color: #64748b;
}

html[data-theme="dark"] .form-label {
    color: #cbd5e1;
}

html[data-theme="dark"] .input-group-text {
    background: #1e293b;
    border-color: #334155;
    color: #94a3b8;
}

html[data-theme="dark"] .form-check-label {
    color: #cbd5e1;
}

html[data-theme="dark"] .table {
    color: #e2e8f0;
}

html[data-theme="dark"] .table th {
    background: #1e293b;
    color: #94a3b8;
    border-bottom-color: #334155;
}

html[data-theme="dark"] .table td {
    border-bottom-color: #1e293b;
    color: #cbd5e1;
}

html[data-theme="dark"] .table-hover tbody tr:hover {
    background: #1e293b;
}

html[data-theme="dark"] .table-hover tbody tr:hover td {
    background: #1e293b;
}

html[data-theme="dark"] .modal-content {
    background: #111827;
    border-color: #1e293b;
}

html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
    border-color: #1e293b;
}

html[data-theme="dark"] .modal-header {
    background: #111827;
    color: #f1f5f9;
}

html[data-theme="dark"] .modal-body {
    color: #cbd5e1;
}

html[data-theme="dark"] .topbar {
    background: linear-gradient(135deg, #1b5e20, #0d3b0f);
}

html[data-theme="dark"] .sidebar-desktop {
    background: #0f172a;
    border-right-color: #1e293b;
}

html[data-theme="dark"] .sidebar-desktop .nav-link {
    color: #94a3b8;
}

html[data-theme="dark"] .sidebar-desktop .nav-link:hover {
    background: #1e293b;
    color: #e2e8f0;
}

html[data-theme="dark"] .sidebar-desktop .nav-link.active {
    background: #2e7d32;
    color: #fff !important;
}

html[data-theme="dark"] .nav-tabs {
    border-bottom-color: #1e293b;
}

html[data-theme="dark"] .nav-tabs .nav-link {
    color: #94a3b8;
}

html[data-theme="dark"] .nav-tabs .nav-link:hover {
    background: #1e293b;
    color: #4caf50;
}

html[data-theme="dark"] .mobile-nav {
    background: rgba(15, 23, 42, 0.95);
    border-top-color: #1e293b;
}

html[data-theme="dark"] .mobile-nav-item {
    color: #64748b;
}

html[data-theme="dark"] .dropdown-menu {
    background: #111827;
    border-color: #1e293b;
}

html[data-theme="dark"] .dropdown-item {
    color: #cbd5e1;
}

html[data-theme="dark"] .dropdown-item:hover {
    background: #1e293b;
    color: #f1f5f9;
}

html[data-theme="dark"] .dropdown-divider {
    border-color: #1e293b;
}

html[data-theme="dark"] .btn-close {
    filter: invert(1);
}

html[data-theme="dark"] .page-header h4 {
    color: #f1f5f9;
}

html[data-theme="dark"] .nav-header {
    color: #64748b;
}

html[data-theme="dark"] .progress {
    background: #1e293b;
}

/* Transições suaves */
body, .card, .card-header, .sidebar-desktop, .topbar, .mobile-nav,
.form-control, .form-select, .input-group-text, .table, .table th, .table td,
.modal-content, .modal-header, .modal-footer, .dropdown-menu, .dropdown-item {
    transition: background 0.3s, border-color 0.3s, color 0.3s;
}

/* ============================
   2. BASE + smooth scroll + accent-color
   ============================ */
* { -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
    background: #f0f2f5;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: var(--text-base);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0);
    accent-color: var(--green);
}

/* 3. TEXT-WRAP: BALANCE nos headings */
h1, h2, h3, h4, h5, h6 { text-wrap: balance; }

/* 4. Animação fade-in nos cards (scroll-driven + fallback) */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
.card, .dash-stat-card {
    animation: fadeUp .4s ease-out both;
    animation-timeline: view();
    animation-range: entry 0% entry 100%;
}
@supports not (animation-timeline: view()) {
    .card, .dash-stat-card { animation: fadeUp .35s ease-out both; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* 5. VIEW TRANSITIONS API - crossfade entre páginas */
::view-transition-old(root) {
    animation: fadeOut .15s ease-out;
}
::view-transition-new(root) {
    animation: fadeIn .25s ease-in;
}
@keyframes fadeOut { to { opacity: 0; } }
@keyframes fadeIn  { from { opacity: 0; } }

/* Dá nomes de transição aos elementos principais */
.topbar           { view-transition-name: topbar; }
.sidebar-desktop  { view-transition-name: sidebar; }
.main-content     { view-transition-name: main-content; }
.mobile-nav       { view-transition-name: mobile-nav; }

/* ============================
   BASE
   ============================ */
* { -webkit-tap-highlight-color: transparent; }
body {
    background: #f0f2f5;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    min-height: 100dvh; /* usa dvh para mobile com barra de endereÃ§o */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ============================
   TOPBAR
   ============================ */
.topbar {
    height: var(--topbar-h);
    background: linear-gradient(135deg, var(--green-dark), var(--green));
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
    z-index: 1030;
}
.topbar .nav-link,
.topbar .btn,
.topbar .navbar-brand { color: #fff !important; }
.topbar .nav-link:hover,
.topbar .btn:hover { color: #fff !important; }
.avatar-circle {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem;
}
.brand-badge { transition: transform .2s; }
.brand-badge:hover { transform: scale(1.1); }

/* NotificaÃ§Ã£o pulsante */
.pulse {
    animation: pulse-anim 2s infinite;
}
@keyframes pulse-anim {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.25); }
}

/* ============================
   PWA INSTALL TOAST
   ============================ */
.pwa-toast {
    position: fixed; top: var(--topbar-h); left: 0; right: 0;
    z-index: 2000; background: #fff; border-bottom: 3px solid var(--green);
    box-shadow: var(--shadow-md); padding: 10px 16px;
}
.pwa-toast-inner {
    display: flex; align-items: center; gap: 10px;
    max-width: 600px; margin: 0 auto;
}

/* ============================
   LAYOUT PRINCIPAL
   ============================ */
.app-layout {
    display: flex;
    padding-top: var(--topbar-h);
    min-height: 100vh;
}

/* Sidebar Desktop */
.sidebar-desktop {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: #fff;
    border-right: 1px solid #e8e8e8;
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    z-index: 1020;
    overflow: hidden;
}
.sidebar-scroll {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0 80px 0;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* Itens do Menu Lateral */
.sidebar-desktop .nav-item { margin: 0 6px; }
.sidebar-desktop .nav-link,
.offcanvas .nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 14px; border-radius: 8px;
    color: #555; font-size: .88rem; font-weight: 500;
    text-decoration: none; transition: all .15s;
}
.sidebar-desktop .nav-link:hover,
.offcanvas .nav-link:hover {
    background: var(--green-bg); color: var(--green);
}
.sidebar-desktop .nav-link.active,
.offcanvas .nav-link.active {
    background: var(--green); color: #fff !important;
    box-shadow: 0 2px 8px rgba(46,125,50,.3);
}
.sidebar-desktop .nav-link i,
.offcanvas .nav-link i { font-size: 1.1rem; width: 22px; text-align: center; }

.nav-header {
    font-size: .65rem; letter-spacing: .08em; font-weight: 700;
    color: #999; padding: 12px 20px 4px; text-transform: uppercase;
}
.nav-divider { margin: 6px 14px; opacity: .6; }

/* Sidebar Offcanvas Mobile */
.offcanvas .nav-item { margin: 0 8px; }
.offcanvas .nav-link { margin-bottom: 1px; }

/* ConteÃºdo Principal */
.main-content {
    flex: 1; margin-left: var(--sidebar-w);
    padding: 20px 24px 100px 24px;
    max-width: 100%;
    min-height: calc(100vh - var(--topbar-h));
}
@media (max-width: 991.98px) {
    .main-content { margin-left: 0; padding: 16px 14px 100px 14px; }
}

/* ============================
   CARDS
   ============================ */
.card {
    border: none; border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 1rem;
    transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    background: #fff; border-bottom: 1px solid #f0f0f0;
    border-radius: var(--radius) var(--radius) 0 0 !important;
    font-weight: 600; padding: 14px 18px;
}
.card-header.bg-success,
.card-header.bg-danger,
.card-header.bg-warning,
.card-header.bg-info { border-bottom: none; }

/* Cards do Dashboard */
.dash-stat-card {
    border-radius: var(--radius); border: none;
    box-shadow: var(--shadow); transition: all .2s;
    cursor: pointer; text-decoration: none; color: inherit;
}
.dash-stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.dash-stat-card .card-body { padding: 18px 16px; }
.dash-stat-card .stat-icon {
    font-size: 2rem; opacity: .8;
}

/* ============================
   TABELAS
   ============================ */
.table { margin-bottom: 0; }
.table th {
    font-weight: 600; font-size: .78rem;
    text-transform: uppercase; letter-spacing: .04em;
    white-space: nowrap; color: #777;
    background: #fafbfc; padding: 12px 14px;
}
.table td { padding: 12px 14px; vertical-align: middle; font-size: .88rem; }
.table-hover tbody tr:hover { background: #f8fdf9; }
.table-responsive { border-radius: var(--radius); }

/* ============================
   BADGES & BOTÃ•ES
   ============================ */
.badge { font-weight: 500; font-size: .72rem; padding: 5px 10px; border-radius: 6px; }
.btn { font-weight: 500; border-radius: 7px; padding: 8px 16px; transition: all .15s; }
.btn:hover { transform: translateY(-1px); }
.btn-sm { padding: 5px 10px; border-radius: 5px; font-size: .8rem; }
.btn-success { background: var(--green); border-color: var(--green); }
.btn-success:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn-outline-success { color: var(--green); border-color: var(--green); }
.btn-outline-success:hover { background: var(--green); color: #fff; }

/* ============================
   FORMULÃRIOS
   ============================ */
.form-control, .form-select {
    border-radius: 7px; border: 1px solid #dee2e6;
    padding: 9px 12px; font-size: .9rem; transition: all .15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--green-light); box-shadow: 0 0 0 3px rgba(76,175,80,.15);
}
.form-label { font-weight: 500; font-size: .85rem; color: #555; margin-bottom: 4px; }

/* ============================
   MODAIS
   ============================ */
.modal-content { border: none; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid #f0f0f0; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #f0f0f0; }

/* ============================
   NAV TABS
   ============================ */
.nav-tabs { border-bottom: 2px solid #eee; gap: 4px; }
.nav-tabs .nav-link {
    border: none; color: #888; padding: 10px 18px;
    font-weight: 500; border-radius: 8px 8px 0 0; transition: all .15s;
}
.nav-tabs .nav-link:hover { color: var(--green); background: var(--green-bg); }
.nav-tabs .nav-link.active {
    color: var(--green); background: transparent;
    border-bottom: 3px solid var(--green); font-weight: 600;
}

/* ============================
   BARRA INFERIOR MOBILE
   ============================ */
.mobile-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--mobile-nav-h);
    background: #fff; border-top: 1px solid #e8e8e8;
    display: flex; justify-content: space-around; align-items: center;
    z-index: 1025;
    padding-bottom: env(safe-area-inset-bottom, 0);
    box-shadow: 0 -2px 10px rgba(0,0,0,.06);
}
.mobile-nav-item {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px;
    color: #999; text-decoration: none;
    font-size: .65rem; font-weight: 500;
    border: none; background: none;
    padding: 6px 10px; min-width: 56px;
    transition: color .15s; cursor: pointer;
}
.mobile-nav-item i { font-size: 1.35rem; transition: transform .15s; }
.mobile-nav-item.active { color: var(--green); }
.mobile-nav-item.active i { transform: scale(1.15); }
.mobile-nav-item:active i { transform: scale(.9); }

/* Ajuste de padding-bottom no mobile */
@media (max-width: 991.98px) {
    .main-content { padding-bottom: calc(var(--mobile-nav-h) + 24px + env(safe-area-inset-bottom, 0)); }
}

/* ============================
   BOTÃƒO VOLTAR AO TOPO
   ============================ */
.scroll-top-btn {
    position: fixed; bottom: calc(var(--mobile-nav-h) + 16px + env(safe-area-inset-bottom, 0));
    right: 16px; z-index: 1024;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--green); color: #fff; border: none;
    box-shadow: 0 2px 12px rgba(0,0,0,.25);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; cursor: pointer;
    opacity: 0; transform: translateY(20px);
    transition: all .25s ease; pointer-events: none;
}
.scroll-top-btn.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.scroll-top-btn:active { transform: scale(.9); }

/* ESTILO RESPONSIVO COMPLETO - MOBILE FIRST + CSS GRID + dvh + TABELAS CARD
   ============================================================ */

/* Grid automÃ¡tico para cards (substitui row/col-md-X) */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}
.grid-cards-sm {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .75rem;
}
.grid-cards .card { margin-bottom: 0; }

/* main-content com dvh */
.main-content {
    flex: 1; margin-left: var(--sidebar-w);
    padding: 20px 24px 100px 24px;
    max-width: 100%;
    min-height: calc(100dvh - var(--topbar-h));
}
@media (max-width: 991.98px) {
    .main-content { margin-left: 0; padding: 16px 14px 100px 14px; }
}

/* ============================
   APP LAYOUT com dvh
   ============================ */
.app-layout {
    display: flex;
    padding-top: var(--topbar-h);
    min-height: 100dvh;
}

/* ============================
   TABELAS RESPONSIVAS: viram cards no mobile
   ============================ */
@media (max-width: 575.98px) {
    /* CabeÃ§alho da tabela some no mobile */
    .table-card thead { display: none; }

    /* Cada linha vira um card */
    .table-card tbody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 4px 8px;
        padding: 12px 10px;
        border-bottom: 1px solid #eee;
        background: #fff;
        margin-bottom: 6px;
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }
    .table-card tbody td {
        display: flex; flex-direction: column;
        padding: 4px 6px; border: none;
        font-size: .82rem; white-space: normal;
    }
    /* RÃ³tulo via data-label */
    .table-card tbody td::before {
        content: attr(data-label);
        font-size: .65rem; font-weight: 700;
        text-transform: uppercase; color: #888;
        letter-spacing: .03em; margin-bottom: 2px;
    }
    /* CÃ©lulas de aÃ§Ã£o ocupam linha inteira */
    .table-card tbody td:last-child {
        grid-column: 1 / -1;
        flex-direction: row; justify-content: flex-end;
        gap: 6px; padding-top: 8px;
        border-top: 1px solid #f0f0f0; margin-top: 4px;
    }
    .table-card tbody td:last-child::before { display: none; }
    .table-card tbody td:first-child { font-weight: 600; }
}

/* ============================
   BARRA INFERIOR MELHORADA
   ============================ */
@media (max-width: 991.98px) {
    .mobile-nav {
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        background: rgba(255,255,255,.95);
    }
    .mobile-nav-item {
        position: relative; padding: 4px 8px;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-nav-item.active::before {
        content: ''; position: absolute; top: 0; left: 25%; right: 25%; height: 3px;
        background: var(--green); border-radius: 0 0 3px 3px;
    }
}

/* ============================
   ALERTAS / TOAST FLASH
   ============================ */
.toast-flash {
    border-left: 4px solid var(--green) !important;
    animation: slideDown .3s ease-out;
}
.toast-flash.alert-danger { border-left-color: #dc3545 !important; }
.toast-flash.alert-warning { border-left-color: #ffc107 !important; }

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================
   UTILITÃRIOS
   ============================ */
.cursor-pointer { cursor: pointer; }
.page-header {
    display: flex; justify-content: space-between;
    align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px;
}
.page-header h4 { margin: 0; font-weight: 700; color: #333; }
.progress { background: #e9ecef; border-radius: 10px; height: 20px; }
.progress-bar { font-size: .68rem; font-weight: 600; border-radius: 10px; }

@media (max-width: 575.98px) {
    .btn-group.w-100 { flex-wrap: wrap; }
    .table th, .table td { padding: 8px 10px; font-size: .78rem; }
}

/* ============================
   PWA / STANDALONE
   ============================ */
@media (display-mode: standalone) {
    .topbar { padding-top: env(safe-area-inset-top, 0); }
    body { padding-top: 0; }
}

