/*
 * Design System oficial do AviCore (Prompt Mestre Parte 4 — Identidade
 * Visual): preto/branco/laranja/cinza como base, com verde e vermelho só
 * como variação discreta de status (nunca cor de marca). Os nomes de
 * variável antigos (--teal/--wheat) foram mantidos de propósito — são
 * referenciados em dezenas de telas — só o VALOR mudou, pra laranja.
 * --teal = acento primário (botão/link/ativo). --wheat = acento
 * secundário (mesma família, tom mais suave — menu ativo, badge).
 */
:root {
    --paper: #F5F4F2;
    --surface: #FFFFFF;
    --surface-2: #F0EFEC;
    --ink: #1A1A18;
    --ink-soft: #55534E;
    --ink-faint: #84817A;
    --line: #E1DED8;
    --line-strong: #CBC7BE;
    --teal: #D9631B;
    --teal-ink: #A84813;
    --teal-solid: #A84813;
    --wheat: #D9631B;
    --wheat-bg: #FBE8D9;
    --wheat-ink: #9A4A12;
    --danger: #B23A3A;
    --danger-bg: #FBEAEA;
    --sucesso: #3F7D4E;
    --sucesso-bg: #E7F3E9;
    --radius: 8px;
    --sidebar-w: 240px;
    --sidebar-w-collapsed: 68px;
    --topbar-h: 56px;
}

[data-bs-theme="dark"] {
    --paper: #171614;
    --surface: #201F1C;
    --surface-2: #262521;
    --ink: #EFEEEA;
    --ink-soft: #BFBBB2;
    --ink-faint: #8B877E;
    --line: #35332D;
    --line-strong: #46433B;
    --teal: #F0925A;
    --teal-ink: #FBCBA0;
    --teal-solid: #A84813;
    --wheat: #F0925A;
    --wheat-bg: #3B2611;
    --wheat-ink: #F5B57E;
    --danger: #E48080;
    --danger-bg: #3A2323;
    --sucesso: #7FBE8E;
    --sucesso-bg: #1E3323;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-bs-theme="light"]) {
        --paper: #171614;
        --surface: #201F1C;
        --surface-2: #262521;
        --ink: #EFEEEA;
        --ink-soft: #BFBBB2;
        --ink-faint: #8B877E;
        --line: #35332D;
        --line-strong: #46433B;
        --teal: #F0925A;
        --teal-ink: #FBCBA0;
        --teal-solid: #A84813;
        --wheat: #F0925A;
        --wheat-bg: #3B2611;
        --wheat-ink: #F5B57E;
        --danger: #E48080;
        --danger-bg: #3A2323;
        --sucesso: #7FBE8E;
        --sucesso-bg: #1E3323;
    }
}

* { box-sizing: border-box; }

/* Acessibilidade: link "pular pro conteúdo" — invisível até ganhar foco
   por teclado (Tab), primeiro elemento focável da página. */
.skip-link {
    position: absolute; left: -9999px; top: 0; z-index: 3000;
    background: var(--teal-solid); color: #fff;
    padding: 10px 16px; border-radius: 0 0 8px 0;
    font-size: var(--fs-caption); text-decoration: none;
}
.skip-link:focus { left: 0; }

/*
 * Tipografia oficial (Design System, Prompt Mestre Parte 4) — escala
 * única pra título/subtítulo/texto/legenda/indicador/menu/botão/alerta.
 * Nenhuma tela deve usar tamanho de fonte fora desta escala.
 */
:root {
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --fs-display: 1.75rem;   /* 28px — número grande de KPI/hero */
    --fs-h1: 1.35rem;        /* 21.6px — título de página (.page-title) */
    --fs-h2: 1.05rem;        /* 16.8px — subtítulo de seção/card (h6 dentro de acf-card) */
    --fs-body: 0.875rem;     /* 14px — texto padrão */
    --fs-caption: 0.8125rem; /* 13px — .page-sub, legenda, texto secundário */
    --fs-label: 0.75rem;     /* 12px — rótulo uppercase (acf-kpi-titulo, stat-card .label) */
    --fs-micro: 0.6875rem;   /* 11px — timestamp, texto ínfimo */
    --lh-tight: 1.2;
    --lh-normal: 1.55;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: var(--fs-body);
    line-height: var(--lh-normal);
    transition: background .15s ease, color .15s ease;
}

h1, h2, h3, h4, h5, h6 { font-family: var(--font-sans); line-height: var(--lh-tight); font-weight: 600; margin: 0; }
/* Views legadas usam <h4>/<h6> soltos como título de página/seção — sem
   isto, cada tela herdava um tamanho de fonte diferente do user-agent. */
h4 { font-size: var(--fs-h1); }
h5 { font-size: var(--fs-h2); }
h6 { font-size: var(--fs-h2); }

a { color: var(--teal-ink); }

/* ---------- Auth (login) ---------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 2rem;
}
.auth-brand {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 4px;
    color: var(--teal-ink);
}
.auth-sub {
    font-size: 13px;
    color: var(--ink-faint);
    margin: 0 0 1.5rem;
}
.field { margin-bottom: 1rem; }
.field label {
    display: block;
    font-size: 12.5px;
    color: var(--ink-soft);
    margin-bottom: 4px;
    font-weight: 500;
}
.field input, .field select {
    width: 100%;
    height: 40px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    padding: 0 12px;
    font-size: 14px;
}
.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--teal) 25%, transparent);
}
/* Tamanho único e pequeno pra todo botão do sistema (padronização —
   antes cada tela tinha uma mistura de .btn/.btn-sm de tamanhos
   diferentes; .btn-sm nem funcionava, ver comentário abaixo). */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border-radius: var(--radius);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: filter .12s ease, transform .1s ease, background .12s ease, box-shadow .12s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn-primary {
    /* --teal-solid (não --teal) pro texto branco atingir contraste WCAG AA
       (4.5:1) — --teal puro só dá 3.65:1 com branco, reprova AA. Valor
       fixo entre os 2 temas de propósito: é uma superfície pintada, não
       texto sobre --surface, então não precisa (nem deve) clarear no
       dark mode como --teal-ink faz. */
    background: var(--teal-solid);
    border-color: var(--teal-solid);
    color: #fff;
}
.btn-primary:hover { filter: brightness(1.05); }
/* width:100% só faz sentido no form de login/instalador (1 botão, cartão
   estreito) — sem este escopo, TODO botão "Salvar"/"Novo" do sistema
   (dezenas de telas CRUD) herdava largura total do modal/form, ficando
   gigante. Bug real, corrigido aqui na raiz em vez de tela por tela. */
.auth-shell-premium .btn-primary, .auth-shell .btn-primary { width: 100%; }

/* .btn-sm: mesmo tamanho do .btn base agora (padronizado), a classe só
   fica de bobeira em quem já usava pra não quebrar nada. */
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; gap: 5px; }
.alert {
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 1rem;
}
.alert-danger { background: var(--danger-bg); color: var(--danger); }
/* .login-alert: escondido até JS mostrar erro. Antes usava a classe
   utilitária Bootstrap .d-flex (display:flex !important), que sempre
   vencia o display:none inline — alerta vazio aparecia sempre. */
.login-alert { display: none; align-items: center; gap: 8px; }
.login-alert.show { display: flex; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: none;
    background: var(--teal-solid);
    border-right: 1px solid var(--teal-solid);
    transition: width .18s ease;
    overflow: hidden;
}
.app-shell.collapsed .sidebar { width: var(--sidebar-w-collapsed); }

.sidebar-brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255,255,255,.18);
    white-space: nowrap;
}
.sidebar-brand .mark {
    width: 28px; height: 28px; border-radius: 7px;
    background: rgba(255,255,255,.2); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; flex: none;
}
.sidebar-brand .name { font-weight: 600; font-size: 15px; color: #fff; }
.app-shell.collapsed .sidebar-brand .name { display: none; }

.sidebar-menu { list-style: none; margin: 0; padding: 8px; }
.sidebar-menu a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 7px;
    color: rgba(255,255,255,.82); text-decoration: none; font-size: 13.5px;
    white-space: nowrap;
}
.sidebar-menu a:hover { background: rgba(255,255,255,.14); color: #fff; }
.sidebar-menu a.active { background: rgba(255,255,255,.22); color: #fff; }
.sidebar-menu .icon {
    width: 18px; height: 18px; flex: none;
    border-radius: 4px; background: rgba(255,255,255,.3);
}
.app-shell.collapsed .sidebar-menu span.label { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px;
    background: var(--surface);
    position: sticky; top: 0; z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.icon-btn {
    width: 34px; height: 34px; border-radius: 7px;
    border: 1px solid var(--line); background: var(--surface);
    color: var(--ink-soft); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); }
.search-box {
    height: 34px; width: 260px; border-radius: 7px;
    border: 1px solid var(--line); background: var(--surface-2);
    padding: 0 10px; font-size: 13px; color: var(--ink);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--wheat-bg); color: var(--wheat-ink);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 12.5px;
}

.content { padding: 1.5rem; flex: 1; }
.page-title { font-size: var(--fs-h1); font-weight: 600; margin: 0 0 4px; line-height: var(--lh-tight); }
.page-sub { font-size: var(--fs-caption); color: var(--ink-faint); margin: 0 0 1.25rem; }

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 10px; padding: 14px 16px;
}
.stat-card .label { font-size: var(--fs-label); color: var(--ink-faint); text-transform: uppercase; letter-spacing: .4px; }
.stat-card .value { font-size: var(--fs-display); font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }

.panel {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 10px; padding: 1.25rem;
}

@media (max-width: 1024px) {
    /*
     * Bug real de responsividade corrigido (Prompt Mestre Parte 4):
     * antes, `.sidebar` (fixed, 240px) sobrepunha o conteúdo em TODO
     * carregamento de página no celular, sem nenhuma forma de fechar —
     * `.main` ficava 100% da largura por baixo, mas visualmente coberto
     * pelos primeiros 240px. Agora o menu nasce fora da tela
     * (off-canvas) e só aparece com o toggle, como overlay com backdrop.
     * Breakpoint em 1024px (não 760px) pra cobrir tablets em pé também
     * (768px), onde o sidebar fixo de 240px deixava o conteúdo apertado.
     */
    .sidebar {
        position: fixed; z-index: 25; height: 100vh; width: var(--sidebar-w) !important;
        top: 0; left: calc(-1 * var(--sidebar-w));
        transition: left .2s ease;
    }
    .app-shell.mobile-aberto .sidebar { left: 0; }
    .sidebar-backdrop {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 24;
    }
    .app-shell.mobile-aberto .sidebar-backdrop { display: block; }
    .app-shell.collapsed .sidebar-brand .name,
    .app-shell.collapsed .sidebar-menu span.label { display: block; } /* no mobile, "collapsed" (desktop) não se aplica — sempre mostra o rótulo quando o off-canvas está aberto */
    .search-box { display: none; }
    .content { padding: 1rem; }
    .cards-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .cards-grid { grid-template-columns: 1fr; }
    .cmdk-box { max-width: calc(100vw - 24px); }
}

/* =====================================================================
   ACABAMENTO — identidade visual premium (prompt 10)
   ===================================================================== */

/* Loading bar global (topo da página, dispara em todo fetch) */
#loading-bar {
    position: fixed; top: 0; left: 0; height: 2.5px; width: 0%;
    background: var(--wheat); z-index: 2000;
    transition: width .25s ease, opacity .3s ease;
    opacity: 0;
}
#loading-bar.active { opacity: 1; }

/* Sidebar: grupos colapsáveis + ícones FontAwesome */
.sidebar { display: flex; flex-direction: column; }
.sidebar-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding-bottom: 1rem; }
.sidebar-group-title {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; margin: 2px 6px 0; border-radius: 7px;
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px;
    color: rgba(255,255,255,.65); cursor: pointer; user-select: none; white-space: nowrap;
    transition: background .12s ease, color .12s ease;
}
.sidebar-group-title:hover { color: #fff; background: rgba(255,255,255,.12); }
.sidebar-group-title i.chev { transition: transform .18s ease; font-size: 10px; }
.sidebar-group-title.collapsed i.chev { transform: rotate(-90deg); }
.app-shell.collapsed .sidebar-group-title { justify-content: center; }
.app-shell.collapsed .sidebar-group-title span, .app-shell.collapsed .sidebar-group-title i.chev { display: none; }

.sidebar-menu a i.nav-icon { width: 16px; text-align: center; flex: none; font-size: 13.5px; }
.sidebar-menu a { position: relative; transition: background .12s ease, color .12s ease, padding-left .12s ease; }
.sidebar-menu a:hover { padding-left: 13px; }
.sidebar-menu a.active { font-weight: 500; }
.sidebar-menu a.active::before {
    content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px;
    background: #fff; border-radius: 0 3px 3px 0;
}
.sidebar-menu .fav-star {
    margin-left: auto; opacity: 0; font-size: 12px; color: rgba(255,255,255,.55);
    flex: none; transition: opacity .12s ease, color .12s ease;
}
.sidebar-menu li:hover .fav-star, .sidebar-menu .fav-star.is-fav { opacity: 1; }
.sidebar-menu .fav-star.is-fav { color: #fff; }
.app-shell.collapsed .fav-star { display: none; }

/* Breadcrumb */
.breadcrumb-bar {
    display: flex; align-items: center; gap: 6px;
    font-size: 12.5px; color: var(--ink-faint); margin-bottom: .75rem;
}
.breadcrumb-bar a { color: var(--ink-faint); text-decoration: none; }
.breadcrumb-bar a:hover { color: var(--teal-ink); }
.breadcrumb-bar .sep { opacity: .5; font-size: 10px; }
.breadcrumb-bar .current { color: var(--ink); font-weight: 500; }

/* Cards com leve elevação e hover (sensação "app desktop") */
.stat-card, .panel {
    transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
.stat-card { display: flex; align-items: center; gap: 12px; }
.stat-card .stat-icon {
    width: 38px; height: 38px; border-radius: 9px; flex: none;
    display: flex; align-items: center; justify-content: center;
    background: var(--wheat-bg); color: var(--wheat-ink); font-size: 16px;
}
.stat-card:hover, .panel:hover { border-color: var(--line-strong); }
.stat-card .stat-body { min-width: 0; }

/* Fade-in de conteúdo ao navegar */
.content { animation: aviFadeIn .22s ease; }
@keyframes aviFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.icon-btn { position: relative; transition: background .12s ease, transform .1s ease; }
.icon-btn:active { transform: scale(.94); }
.btn, .btn-primary { transition: filter .12s ease, transform .1s ease; }
.btn:active { transform: scale(.98); }

/* Badge de notificação no sino */
.notif-dot {
    position: absolute; top: 4px; right: 4px; width: 8px; height: 8px;
    border-radius: 50%; background: var(--danger); border: 2px solid var(--surface);
}
.notif-panel {
    position: absolute; top: calc(var(--topbar-h) + 4px); right: 16px; width: 340px; max-height: 420px;
    overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0,0,0,.14); z-index: 40; display: none;
}
.notif-panel.show { display: block; }
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
.notif-item:last-child { border-bottom: none; }
.notif-item .titulo { font-weight: 500; margin-bottom: 2px; }
.notif-item .quando { font-size: 11px; color: var(--ink-faint); }
.notif-item.unread { background: var(--wheat-bg); }

/* Command palette (pesquisa global) */
.cmdk-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 100;
    display: none; align-items: flex-start; justify-content: center; padding-top: 10vh;
}
.cmdk-backdrop.show { display: flex; }
.cmdk-box {
    width: 100%; max-width: 560px; background: var(--surface); border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25); overflow: hidden; border: 1px solid var(--line);
}
.cmdk-input {
    width: 100%; border: none; padding: 16px 18px; font-size: 15px;
    background: transparent; color: var(--ink); border-bottom: 1px solid var(--line);
}
.cmdk-input:focus { outline: none; }
.cmdk-results { max-height: 340px; overflow-y: auto; padding: 6px; }
.cmdk-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 7px;
    color: var(--ink); text-decoration: none; font-size: 13.5px; cursor: pointer;
}
.cmdk-item i { width: 16px; text-align: center; color: var(--ink-faint); }
.cmdk-item:hover, .cmdk-item.sel { background: var(--surface-2); }
.cmdk-item .grp { margin-left: auto; font-size: 11px; color: var(--ink-faint); }

/* Tour guiado */
.tour-highlight { position: relative; z-index: 101; box-shadow: 0 0 0 4px var(--wheat), 0 0 0 9999px rgba(0,0,0,.45); border-radius: 8px; }
.tour-tip {
    position: fixed; z-index: 102; max-width: 260px; background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: 10px; padding: 14px; box-shadow: 0 12px 32px rgba(0,0,0,.25);
    font-size: 13px;
}
.tour-tip .tour-actions { display: flex; justify-content: space-between; margin-top: 10px; }

/* Botão de banner (ex.: "Continuar implantação") — não usa .btn-primary
   de propósito, aquela classe é width:100% (pensada pro form de login). */
.btn-onb {
    display: inline-flex; align-items: center; gap: 6px;
    height: 30px; padding: 0 14px; width: auto;
    background: var(--teal-solid); border: 1px solid var(--teal-solid); color: #fff;
    border-radius: var(--radius); font-size: 12.5px; font-weight: 500;
    text-decoration: none; white-space: nowrap; cursor: pointer;
    transition: filter .12s ease, transform .1s ease, box-shadow .12s ease;
}
.btn-onb:hover { filter: brightness(1.08); color: #fff; box-shadow: 0 3px 10px rgba(0,0,0,.15); transform: translateY(-1px); }
.btn-onb:active { transform: translateY(0) scale(.97); }

/* ---------- Login premium ---------- */
.auth-shell-premium {
    min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr;
    background: var(--paper);
}
/* Painel de marca do login: cor do sistema (--paper/--surface-2), não mais
   gradiente laranja — o laranja agora só aparece nos pintainhos da
   ilustração (acento), como no resto do produto. */
.auth-brand-panel {
    background: linear-gradient(175deg, var(--paper) 0%, var(--surface-2) 100%);
    color: var(--ink); display: flex; flex-direction: column; justify-content: space-between;
    padding: 3.5rem 3.5rem 0; position: relative; overflow: hidden;
}
.auth-brand-content { position: relative; z-index: 2; }
.auth-brand-panel .mark-big {
    width: 56px; height: 56px; border-radius: 14px; background: var(--teal-solid); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 22px; margin-bottom: 1.5rem;
}
.auth-brand-panel h1 { font-size: 30px; font-weight: 600; margin: 0 0 .75rem; color: var(--ink); }
.auth-brand-panel p { font-size: 14.5px; color: var(--ink-soft); max-width: 360px; line-height: 1.6; }
.auth-brand-panel .features { margin-top: 2rem; display: flex; flex-direction: column; gap: .85rem; }
.auth-brand-panel .features li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--ink-soft); list-style: none; }
.auth-brand-panel .features i { color: var(--teal-ink); width: 16px; text-align: center; }

/* Ilustração "do pintainho ao embarque" — cenário em silhuetas, sem foto
   de banco de imagens: aviário + galinhas adultas translúcidas ao fundo,
   pintainhos sólidos em laranja (acento) em primeiro plano. */
.auth-farm-illustration {
    width: 100%; height: 230px; display: block; position: relative; z-index: 1; flex: none;
}
.auth-farm-illustration .avi-sol { fill: var(--wheat-bg); }
.auth-farm-illustration .avi-camada-aviario { color: var(--ink); opacity: .16; }
.auth-farm-illustration .avi-camada-galinhas { color: var(--ink); opacity: .3; }
.auth-farm-illustration .avi-chao { stroke: var(--line-strong); stroke-width: 1.5; }
.auth-farm-illustration .avi-camada-pintainhos { color: var(--teal-solid); }
.auth-farm-illustration .avi-camada-pintainhos use { filter: drop-shadow(0 3px 5px rgba(0,0,0,.12)); }
.auth-farm-illustration use { fill: currentColor; }

.auth-form-panel { display: flex; align-items: center; justify-content: center; padding: 2rem; }
@media (max-width: 860px) {
    .auth-shell-premium { grid-template-columns: 1fr; }
    .auth-brand-panel { display: none; }
}
