/* ============================================================
   EXPRESSO MILLENIUM · Sistema Financeiro & Logística
   Design System — mobile-first · identidade oficial
   ============================================================ */

:root {
  /* Paleta oficial */
  --ink:        #0b110c;   /* verde quase-preto (base escura) */
  --ink-2:      #131a13;   /* superfície escura elevada */
  --ink-3:      #1c261c;   /* borda/linha em fundo escuro */
  --brand:      #82bb27;   /* verde principal */
  --brand-2:    #6db643;   /* verde médio */
  --lime:       #f2e610;   /* amarelo-lima (destaque) */
  --paper:      #fbfdf8;   /* off-white */
  --black:      #010101;

  /* Neutros derivados (tema claro do app) */
  --bg:         #f3f5ef;   /* fundo do app */
  --surface:    #ffffff;   /* cartões */
  --surface-2:  #f7f9f3;
  --line:       #e5e9df;   /* divisórias */
  --text:       #162014;   /* texto principal */
  --muted:      #6b7669;   /* texto secundário */
  --muted-2:    #9aa596;

  /* Semânticos */
  --pos:        #2fa84f;   /* positivo / receita */
  --neg:        #e0483d;   /* negativo / despesa */
  --warn:       #e8a317;

  /* Gradiente da marca */
  --grad: linear-gradient(135deg, #6db643 0%, #82bb27 52%, #b9d92e 100%);
  --grad-lime: linear-gradient(135deg, #82bb27 0%, #f2e610 100%);

  /* Ritmo */
  --r-sm: 10px;
  --r:    14px;
  --r-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(11,17,12,.06), 0 1px 3px rgba(11,17,12,.05);
  --shadow:    0 4px 16px rgba(11,17,12,.08);
  --shadow-lg: 0 18px 40px rgba(11,17,12,.16);

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --display: "Kanit", var(--font);

  --header-h: 60px;
  --nav-h: 64px;          /* bottom nav mobile */
  --sidebar-w: 250px;

  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
img { max-width: 100%; display: block; }
/* ícones inline (SVG sem width explícito) — tamanho padrão pela fonte */
svg:not([width]) { width: 1.15em; height: 1.15em; flex: none; vertical-align: middle; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--brand); color: #fff; }
[hidden] { display: none !important; }

h1,h2,h3,h4 { font-family: var(--display); font-weight: 600; line-height: 1.15; letter-spacing: -0.01em; }
.display { font-family: var(--display); }

/* números tabulares p/ finanças */
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ---------- Utilitários ---------- */
.eyebrow { font-size: .68rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.gap-1 { gap: .4rem; } .gap-2 { gap: .8rem; } .gap-3 { gap: 1.2rem; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { align-items: center; justify-content: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.txt-sm { font-size: .82rem; } .txt-xs { font-size: .72rem; }
.mt-1{margin-top:.4rem}.mt-2{margin-top:.8rem}.mt-3{margin-top:1.2rem}.mt-4{margin-top:1.8rem}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  height: 46px; padding: 0 1.15rem; border-radius: var(--r-sm);
  font-weight: 600; font-size: .92rem; letter-spacing: .01em;
  transition: transform .12s ease, background .2s, box-shadow .2s, border-color .2s, opacity .2s;
  white-space: nowrap; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #06210a; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-2); }
.btn-grad { background: var(--grad); color: #06210a; box-shadow: 0 6px 18px rgba(130,187,39,.35); }
.btn-grad:hover { filter: brightness(1.03); }
.btn-dark { background: var(--ink); color: var(--paper); }
.btn-dark:hover { background: #06210a; }
.btn-ghost { background: transparent; color: var(--text); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--brand); color: #2f6e10; }
.btn-block { width: 100%; }
.btn-lg { height: 54px; font-size: 1rem; }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn-icon { width: 44px; height: 44px; padding: 0; border-radius: var(--r-sm); }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: .35rem; }
.field > label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.input, .select, textarea.input {
  width: 100%; height: 48px; padding: 0 .9rem;
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: var(--r-sm); font-size: .95rem; transition: border-color .18s, box-shadow .18s;
}
textarea.input { height: auto; padding: .7rem .9rem; min-height: 96px; resize: vertical; line-height: 1.45; }
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(130,187,39,.18);
}
.input::placeholder { color: var(--muted-2); }
.input-group { position: relative; }
.input-group .input { padding-left: 2.6rem; }
.input-group .ig-icon { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted-2); pointer-events: none; }

/* ---------- Cartão ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 1.1rem; }
.card-h { padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.card-h h3 { font-size: 1rem; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: .35rem; height: 24px; padding: 0 .55rem; border-radius: 999px; font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.badge-fixo { background: #eef4e2; color: #4d7a15; }
.badge-var  { background: #fef7d6; color: #977300; }
.badge-pos  { background: #e4f6e9; color: var(--pos); }
.badge-neg  { background: #fde9e7; color: var(--neg); }
.badge-role { background: var(--ink); color: var(--brand); }

/* ============================================================
   LOGIN
   ============================================================ */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(130,187,39,.22), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(242,230,16,.12), transparent 55%),
    var(--ink);
  position: relative; overflow: hidden;
}
.login::after {
  content:""; position:absolute; inset:0; pointer-events:none;
  background-image: linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 44px 44px; mask-image: radial-gradient(circle at 50% 30%, #000, transparent 75%);
}
.login-card {
  position: relative; z-index: 1; width: 100%; max-width: 400px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--r-lg); padding: 2rem 1.6rem; backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg); color: var(--paper);
}
.login-card .logo { height: 40px; width: auto; margin: 0 auto 1.4rem; }
.login-card h1 { font-size: 1.5rem; text-align: center; }
.login-card .sub { text-align: center; color: rgba(251,253,248,.6); font-size: .88rem; margin-top: .25rem; margin-bottom: 1.6rem; }
.login-card .field > label { color: rgba(251,253,248,.7); }
.login-card .input {
  background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.14); color: var(--paper);
}
.login-card .input::placeholder { color: rgba(251,253,248,.4); }
.login-card .input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(130,187,39,.25); }
.login-err { background: rgba(224,72,61,.14); border: 1px solid rgba(224,72,61,.4); color: #ffb4ad; font-size: .84rem; padding: .6rem .8rem; border-radius: var(--r-sm); }
.login-foot { text-align: center; margin-top: 1.4rem; font-size: .74rem; color: rgba(251,253,248,.4); }

/* ============================================================
   APP SHELL
   ============================================================ */
.app { min-height: 100dvh; }

/* Sidebar (desktop) */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--ink); color: var(--paper);
  display: none; flex-direction: column; padding: 1.1rem .8rem;
}
.sidebar .brand { display: flex; align-items: center; gap: .6rem; padding: .4rem .5rem 1.2rem; }
.sidebar .brand img { height: 30px; width: auto; }
.side-nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.side-nav a {
  display: flex; align-items: center; gap: .8rem; padding: .7rem .7rem; border-radius: var(--r-sm);
  color: rgba(251,253,248,.72); font-weight: 500; font-size: .92rem; transition: background .16s, color .16s;
}
.side-nav a svg { width: 20px; height: 20px; flex: none; }
.side-nav a:hover { background: rgba(255,255,255,.05); color: var(--paper); }
.side-nav a.active { background: var(--grad); color: #06210a; font-weight: 600; }
.side-sep { font-size: .64rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: rgba(251,253,248,.35); padding: 1rem .7rem .4rem; }
.side-foot { margin-top: auto; border-top: 1px solid var(--ink-3); padding-top: .8rem; }
.side-user { display: flex; align-items: center; gap: .6rem; padding: .5rem; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--grad); color:#06210a; display: grid; place-items: center; font-family: var(--display); font-weight: 700; flex: none; }

/* Topbar (mobile) */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--header-h);
  background: var(--ink); color: var(--paper);
  display: flex; align-items: center; gap: .6rem; padding: 0 1rem;
}
.topbar img.logo { height: 26px; width: auto; }
.topbar .tb-title { font-family: var(--display); font-weight: 600; font-size: 1.05rem; }
.topbar .btn-icon { color: var(--paper); }

/* Conteúdo */
.main { padding: 1rem 1rem calc(var(--nav-h) + var(--safe-b) + 1rem); max-width: 1200px; margin: 0 auto; }
.page-head { margin: .3rem 0 1rem; }
.page-head h1 { font-size: 1.5rem; }
.page-head p { color: var(--muted); font-size: .9rem; margin-top: .15rem; }

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: stretch; box-shadow: 0 -6px 20px rgba(11,17,12,.06);
}
.bottom-nav a {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: .64rem; font-weight: 600; letter-spacing: .02em; position: relative;
}
.bottom-nav a svg { width: 23px; height: 23px; }
.bottom-nav a.active { color: #4d7a15; }
.bottom-nav a.active::before { content:""; position:absolute; top:0; width:32px; height:3px; border-radius:0 0 4px 4px; background: var(--grad); }

/* FAB (registrar rápido — funcionário) */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 45;
  width: 58px; height: 58px; border-radius: 50%; background: var(--grad); color: #06210a;
  display: grid; place-items: center; box-shadow: 0 10px 26px rgba(130,187,39,.5);
}
.fab svg { width: 26px; height: 26px; }

/* ---------- KPIs / métricas ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: .9rem; box-shadow: var(--shadow-sm); }
.kpi .kpi-label { font-size: .74rem; color: var(--muted); font-weight: 600; }
.kpi .kpi-val { font-family: var(--display); font-weight: 600; font-size: 1.5rem; margin-top: .2rem; line-height: 1; }
.kpi .kpi-sub { font-size: .72rem; margin-top: .3rem; }

/* menu mobile (drawer) reaproveita side-nav */
.drawer-scrim { position: fixed; inset: 0; background: rgba(11,17,12,.5); z-index: 49; opacity: 0; pointer-events: none; transition: opacity .25s; }
.drawer-scrim.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: 82%; max-width: 300px; z-index: 50; background: var(--ink); color: var(--paper); transform: translateX(-100%); transition: transform .28s cubic-bezier(.4,0,.2,1); display: flex; flex-direction: column; padding: 1.1rem .8rem; }
.drawer.open { transform: none; }

/* ---------- Responsivo ---------- */
@media (min-width: 900px) {
  .sidebar { display: flex; }
  .topbar, .bottom-nav, .fab, .menu-btn { display: none; }
  .app { padding-left: var(--sidebar-w); }
  .main { padding: 1.8rem 2rem 2.4rem; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); gap: 1rem; }
  .page-head h1 { font-size: 1.9rem; }
}
@media (min-width: 700px) and (max-width: 899px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}

/* utils grid */
.grid { display: grid; gap: 1rem; }
@media (min-width: 900px){ .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3,1fr);} }

/* ---------- Cards-resumo (Painel) ---------- */
.summary-card { display: block; transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease; }
.summary-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #d5ddca; }
.summary-card .card-h h3 { display: flex; align-items: center; gap: .5rem; }
.summary-card .ver { display: inline-flex; align-items: center; gap: .3rem; color: #4d7a15; font-weight: 600; font-size: .8rem; margin-top: .9rem; }
.summary-card:hover .ver { gap: .5rem; }
.mini-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .35rem 0; border-bottom: 1px dashed var(--line); font-size: .86rem; }
.mini-row:last-child { border-bottom: none; }
.big-num { font-family: var(--display); font-weight: 600; font-size: 1.9rem; line-height: 1; }

/* ---------- Tabelas ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th { text-align: left; font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: .6rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: .6rem .7rem; border-bottom: 1px solid var(--line); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--surface-2); }

/* ---------- Acordeão de categorias (Despesas) ---------- */
.cat-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); margin-bottom: .7rem; overflow: hidden; }
.cat-block > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .9rem 1.1rem; font-size: .95rem; }
.cat-block > summary::-webkit-details-marker { display: none; }
.cat-block > summary::after { content: "⌄"; color: var(--muted-2); font-size: 1.1rem; transition: transform .2s; margin-left: .3rem; }
.cat-block[open] > summary::after { transform: rotate(180deg); }
.cat-block > summary:hover { background: var(--surface-2); }
.cat-block .tbl { border-top: 1px solid var(--line); }
.cat-block .tbl th { background: var(--surface-2); }
.cat-dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }

/* ---------- Upload / Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--r); background: var(--surface-2);
  padding: 1.6rem 1rem; text-align: center; cursor: pointer; transition: border-color .18s, background .18s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: #f2f8e8; }
.dropzone .dz-ic { width: 46px; height: 46px; border-radius: 14px; margin: 0 auto .6rem; display: grid; place-items: center; background: var(--grad); color: #06210a; }
.dropzone .dz-ic svg { width: 24px; height: 24px; }
.dropzone b { font-size: .95rem; }
.dropzone p { color: var(--muted); font-size: .8rem; margin-top: .2rem; }

/* miniaturas de fotos */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .6rem; }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .thumb-n { position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 6px; background: rgba(11,17,12,.72); color: #fff; font-size: .68rem; font-weight: 700; display: grid; place-items: center; }
.thumb .thumb-x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 6px; background: rgba(224,72,61,.92); color: #fff; display: grid; place-items: center; }
.thumb .thumb-x svg { width: 13px; height: 13px; }

/* lista de documentos/envios */
.doc-item { display: flex; align-items: center; gap: .8rem; padding: .8rem; border-bottom: 1px solid var(--line); }
.doc-item:last-child { border-bottom: none; }
.doc-ic { width: 42px; height: 42px; border-radius: 11px; flex: none; display: grid; place-items: center; }
.doc-ic.nf { background: #eef4e2; color: #4d7a15; }
.doc-ic.comprovante { background: var(--ink); color: var(--brand); }
.doc-meta { flex: 1 1 auto; min-width: 0; }
.doc-meta b { font-size: .9rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta span { font-size: .74rem; color: var(--muted); }

/* toast */
.toast-wrap { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: .5rem; align-items: center; width: max-content; max-width: 90vw; }
@media (min-width:900px){ .toast-wrap { bottom: 24px; } }
.toast { background: var(--ink); color: var(--paper); padding: .7rem 1rem; border-radius: 999px; font-size: .86rem; font-weight: 500; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: .5rem; animation: toast-in .25s ease; }
.toast.ok { background: #26611a; } .toast.err { background: #a5271e; }
.toast svg { width: 17px; height: 17px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* form de recebimentos — empilha no mobile */
@media (max-width: 680px) {
  #recForm { grid-template-columns: 1fr 1fr !important; }
  #recForm .field:first-child { grid-column: 1 / -1; }
  #recForm .btn-grad { grid-column: 1 / -1; }
}

/* Assistente IA — chat */
.chat-card { display: flex; flex-direction: column; height: calc(100dvh - 230px); min-height: 400px; padding: 0; overflow: hidden; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 1rem; }
.chat-bubble { max-width: 84%; padding: .7rem .9rem; border-radius: 14px; margin-bottom: .7rem; font-size: .92rem; line-height: 1.45; word-wrap: break-word; }
.chat-bubble.bot { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-top-left-radius: 4px; }
.chat-bubble.me { background: var(--grad); color: #06210a; margin-left: auto; border-top-right-radius: 4px; font-weight: 500; }
.chat-bubble.bot svg { width: 16px; height: 16px; vertical-align: -3px; color: var(--brand-2); }
.chat-bubble.err { background: #fdecea; color: #a5271e; border-color: #f5c6c2; }
.chat-sugs { display: flex; flex-wrap: wrap; gap: .5rem; margin: .2rem 0 .3rem; }
.chat-sug { text-align: left; font-size: .82rem; padding: .5rem .75rem; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; cursor: pointer; color: var(--text); transition: .15s; }
.chat-sug:hover { border-color: var(--brand); background: var(--surface-2); }
.chat-input { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--line); background: var(--surface); }
.chat-input .input { flex: 1; }
.chat-input .btn { width: 48px; padding: 0; flex: none; }
.chat-input .btn svg { width: 18px; height: 18px; }
.typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--brand-2); animation: typing 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%,60%,100% { opacity: .3; } 30% { opacity: 1; } }

/* gráficos — altura travada (Chart.js com maintainAspectRatio:false) */
.chartbox { position: relative; width: 100%; height: clamp(220px, 30vw, 300px); }
.chartbox.sm { height: 130px; }
.chartbox.mini { width: 108px; height: 108px; flex: none; }
.chartbox canvas { display: block; }

/* spinner */
.spin { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen { min-height: 100dvh; display: grid; place-items: center; background: var(--ink); }
.loading-screen .spin { width: 30px; height: 30px; border-color: rgba(130,187,39,.3); border-top-color: var(--brand); }
