/* =========================================================================
   Central de Atas — design system inspirado nas diretrizes da Apple (HIG)
   Clareza, deferência e profundidade: muito respiro, cantos suaves,
   sombras discretas, tipografia SF e um único azul de destaque.
   ========================================================================= */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f0f3;
  --surface-hover: #f7f7f9;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --separator: rgba(0, 0, 0, 0.08);
  --separator-strong: rgba(0, 0, 0, 0.12);

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.1);

  --green: #248a3d;   --green-bg: rgba(52, 199, 89, 0.14);
  --amber: #9a6400;   --amber-bg: rgba(255, 159, 10, 0.16);
  --red: #d70015;     --red-bg: rgba(255, 59, 48, 0.13);

  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.22);
  --topbar-bg: rgba(245, 245, 247, 0.72);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --surface-hover: #262628;
    --text: #f5f5f7;
    --text-2: #aeaeb2;
    --text-3: #8e8e93;
    --separator: rgba(255, 255, 255, 0.1);
    --separator-strong: rgba(255, 255, 255, 0.16);
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-soft: rgba(10, 132, 255, 0.18);
    --green: #30d158; --green-bg: rgba(48, 209, 88, 0.18);
    --amber: #ffb340; --amber-bg: rgba(255, 159, 10, 0.2);
    --red: #ff453a;   --red-bg: rgba(255, 69, 58, 0.2);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.6);
    --topbar-bg: rgba(28, 28, 30, 0.72);
  }
}

* { box-sizing: border-box; }
/* Garante que o atributo [hidden] vença regras de display (ex.: .sheet-overlay{display:flex}). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.logo { font-size: 26px; line-height: 1; }
em { color: var(--red); font-style: normal; }

/* ---------- Campos base ---------- */
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 11px 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: border-color .15s, background .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, select:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
textarea { resize: vertical; min-height: 44px; }
input[type="date"] { min-height: 44px; }

/* ---------- Botões (pílula, estilo Apple) ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: none; border-radius: 980px;
  padding: 9px 18px; font-size: 15px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, transform .08s, opacity .15s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-plain { background: transparent; color: var(--accent); padding: 9px 10px; }
.btn-plain:hover { opacity: .7; }
.btn-block { width: 100%; justify-content: center; }
.btn-link {
  background: none; border: none; color: var(--accent);
  cursor: pointer; padding: 4px 6px; font-size: 14px; font-weight: 500; border-radius: 6px;
}
.btn-link:hover { background: var(--accent-soft); }
.btn-perigo { color: var(--red); }
.btn-perigo:hover { background: var(--red-bg); }

/* =========================================================================
   Login
   ========================================================================= */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  background: var(--surface); border-radius: 24px; padding: 40px 32px;
  width: 100%; max-width: 380px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 18px; text-align: center;
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 4px; }
.login-brand .logo { font-size: 44px; }
.login-brand h1 { margin: 6px 0 0; font-size: 24px; letter-spacing: -0.02em; }
.login-brand p { margin: 0; font-size: 13px; color: var(--text-2); }
.login-local { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; text-align: left; }
.login-local label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.btn-microsoft {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--separator);
  padding: 13px 16px; border-radius: 12px; font-weight: 500; text-decoration: none;
  transition: background .15s, transform .08s;
}
.btn-microsoft:hover { background: var(--surface-hover); }
.btn-microsoft:active { transform: scale(0.98); }
#acesso-local { border-top: 1px solid var(--separator); padding-top: 14px; }
#acesso-local summary {
  cursor: pointer; color: var(--text-3); font-size: 13px; list-style: none; user-select: none;
}
#acesso-local summary::-webkit-details-marker { display: none; }
#acesso-local summary:hover { color: var(--text-2); }

/* =========================================================================
   Topbar (translúcida, com blur)
   ========================================================================= */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: var(--topbar-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}
.topbar-brand { display: flex; align-items: center; gap: 11px; }
.topbar-brand strong { display: block; font-size: 16px; letter-spacing: -0.01em; }
.topbar-brand small { color: var(--text-3); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.usuario { color: var(--text-2); font-size: 13px; margin-right: 4px; }

.container { max-width: 1240px; margin: 0 auto; padding: 28px 24px 64px; }

/* =========================================================================
   Cartões de estatística
   ========================================================================= */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 28px; }
.card {
  background: var(--surface); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.card .rotulo { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.card .rotulo::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.card.vigente .rotulo::before { background: #34c759; }
.card.alerta .rotulo::before { background: #ff9f0a; }
.card.expirada .rotulo::before { background: #ff3b30; }
.card .valor { font-size: 30px; font-weight: 600; letter-spacing: -0.03em; margin-top: 6px; }
.card .valor.moeda { font-size: 22px; }

/* =========================================================================
   Toolbar
   ========================================================================= */
.toolbar { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.campo-busca { position: relative; flex: 1; min-width: 240px; }
.campo-busca svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.campo-busca input { padding-left: 40px; border-radius: 980px; }
.pill-select {
  width: auto; min-width: 150px; border-radius: 980px; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5L6 8.5L10 4.5' stroke='%2386868b' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  cursor: pointer;
}

/* =========================================================================
   Tabela (arejada, sem linhas duras)
   ========================================================================= */
.tabela-wrap { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow-x: auto; }
.tabela { width: 100%; border-collapse: collapse; min-width: 940px; }
.tabela th, .tabela td { padding: 15px 16px; text-align: left; vertical-align: top; }
.tabela thead th {
  font-size: 12px; font-weight: 500; color: var(--text-3);
  border-bottom: 1px solid var(--separator); position: sticky; top: 0;
}
.tabela tbody td { border-bottom: 1px solid var(--separator); }
.tabela tbody tr:last-child td { border-bottom: none; }
.tabela tbody tr { transition: background .12s; }
.tabela tbody tr:hover { background: var(--surface-hover); }
.tabela .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tabela .objeto { max-width: 260px; color: var(--text-2); }
.tabela .objeto .clamp {
  display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden;
}
.tabela .empresa-nome { font-weight: 500; }
.sub { display: block; font-size: 12px; color: var(--text-3); font-weight: 400; margin-top: 3px; }

.vazio { padding: 64px 24px; text-align: center; color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.vazio-emoji { font-size: 44px; }
.vazio p { margin: 0; }

/* ---------- Badges de vigência ---------- */
.badge { display: inline-block; padding: 4px 11px; border-radius: 980px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.vigente { background: var(--green-bg); color: var(--green); }
.badge.expira_em_breve { background: var(--amber-bg); color: var(--amber); }
.badge.expirada { background: var(--red-bg); color: var(--red); }

/* =========================================================================
   Sheet (nova / editar) — modal estilo iOS/macOS
   ========================================================================= */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade .2s ease;
}
.sheet {
  background: var(--bg); border-radius: 22px;
  width: 100%; max-width: 660px; max-height: 92dvh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: sheet-in .28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--separator);
  background: var(--surface); position: sticky; top: 0;
}
.sheet-head h2 { margin: 0; font-size: 17px; text-align: center; letter-spacing: -0.01em; }
.sheet-head .btn-plain:first-child { justify-self: start; }
.sheet-head .btn-primary { justify-self: end; }
.sheet-body { padding: 20px 16px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 22px; }

/* Grupos no estilo "lista agrupada" da Apple */
.grupo { display: flex; flex-direction: column; gap: 9px; }
.grupo-titulo { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; padding: 0 4px; }
.grupo-campos {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm);
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.grupo-campos label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.grupo-campos .col2 { grid-column: 1 / -1; }

/* Campo de moeda com prefixo R$ */
.campo-moeda { position: relative; display: flex; align-items: center; }
.campo-moeda span { position: absolute; left: 13px; color: var(--text-3); font-size: 15px; pointer-events: none; }
.campo-moeda input { padding-left: 34px; text-align: right; font-variant-numeric: tabular-nums; }

/* Controle segmentado (Eletrônico / Ofício) */
.segmented { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.segmented label {
  flex: 1; text-align: center; padding: 8px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer;
  transition: background .18s, box-shadow .18s;
}
.segmented input:checked + label { background: var(--surface); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + label { box-shadow: 0 0 0 3px var(--accent-soft); }

/* Campo de arquivo */
.campo-arquivo { display: flex; flex-direction: column; gap: 6px; }
.campo-arquivo input[type="file"] { padding: 10px; font-size: 13px; cursor: pointer; }
.campo-arquivo input[type="file"]::file-selector-button {
  border: none; background: var(--accent-soft); color: var(--accent);
  padding: 7px 13px; border-radius: 980px; font: inherit; font-weight: 500; margin-right: 12px; cursor: pointer;
}
.campo-arquivo-dica { font-size: 12px; color: var(--text-3); }

/* =========================================================================
   Diversos
   ========================================================================= */
.erro { color: var(--red); font-size: 13px; margin: 0; padding: 0 4px; }
.erro:empty { display: none; }
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: rgba(30, 30, 32, 0.92); color: #fff; padding: 12px 22px; border-radius: 14px;
  box-shadow: var(--shadow-lg); z-index: 200; font-size: 14px; font-weight: 500;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  animation: toast-in .3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.erro-toast { background: rgba(215, 0, 21, 0.94); }

@keyframes fade { from { opacity: 0; } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px) scale(0.98); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }

/* =========================================================================
   Alternador de visualização + saldo na tabela
   ========================================================================= */
.view-bar { margin-bottom: 18px; }
.view-toggle { width: 260px; }
.export-só-lista { }

.saldo-cel { min-width: 150px; }
.saldo-cel .valor-num { font-weight: 500; }
.saldo-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; width: 140px; }
.saldo-bar > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.saldo-bar.alto > i { background: var(--amber); }
.saldo-bar.esgotado > i { background: var(--red); }
.saldo-sub { display: block; font-size: 11px; color: var(--text-3); margin-top: 4px; }

/* =========================================================================
   Painel (gráficos)
   ========================================================================= */
#painel { --series-1: #2a78d6; --st-good: #0ca30c; --st-warn: #fab219; --st-crit: #d03b3b;
  --axis: #898781; --grid: #e1e0d9; }
@media (prefers-color-scheme: dark) {
  #painel { --series-1: #3987e5; --grid: #2c2c2a; }
}
.painel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card { background: var(--surface); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow-sm); }
.chart-card.col-span-2 { grid-column: 1 / -1; }
.chart-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.chart-card svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-card svg text { fill: var(--text-2); font-size: 11px; font-family: inherit; }
.chart-card svg .lbl-forte { fill: var(--text); font-weight: 600; }
.chart-card svg .eixo { stroke: var(--grid); stroke-width: 1; }
.chart-mark { transition: opacity .12s; cursor: default; }
.chart-mark:hover { opacity: 0.82; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; font-size: 12.5px; color: var(--text-2); }
.chart-legend .item { display: flex; align-items: center; gap: 7px; }
.chart-legend .dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.chart-vazio { color: var(--text-3); font-size: 13px; padding: 24px 0; text-align: center; }
.hero-saldo { display: flex; flex-direction: column; gap: 4px; }
.hero-saldo .num { font-size: 30px; font-weight: 600; letter-spacing: -0.03em; color: var(--accent); }
.hero-saldo .cap { font-size: 13px; color: var(--text-2); }
.hero-barra { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; display: flex; margin-top: 8px; }
.hero-barra > .consumido { background: var(--text-3); }
.hero-barra > .saldo { background: var(--accent); }

#chart-tooltip {
  position: fixed; z-index: 300; pointer-events: none;
  background: rgba(30, 30, 32, 0.94); color: #fff; padding: 7px 11px; border-radius: 9px;
  font-size: 12.5px; line-height: 1.35; box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); white-space: nowrap;
}
#chart-tooltip b { font-weight: 600; }

/* =========================================================================
   Movimentações (livro de consumos dentro da sheet)
   ========================================================================= */
.mov-nota { font-size: 13px; color: var(--text-3); }
.mov-resumo { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 10px; }
.mov-resumo strong { font-size: 15px; color: var(--accent); font-weight: 600; }
.mov-lista { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.mov-item { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; }
.mov-item .mov-info { flex: 1; min-width: 0; }
.mov-item .mov-info b { font-weight: 600; }
.mov-item .mov-info span { color: var(--text-3); }
.mov-item .mov-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mov-del { border: none; background: none; color: var(--red); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.mov-del:hover { background: var(--red-bg); }
.mov-form { display: grid; grid-template-columns: 1.1fr 1fr; gap: 10px; align-items: end; border-top: 1px solid var(--separator); padding-top: 14px; }
.mov-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.mov-form .col2 { grid-column: 1 / -1; }
.mov-form input { padding: 9px 11px; }

/* =========================================================================
   Ficha para impressão / PDF
   ========================================================================= */
#ficha-print { display: none; }
@media print {
  body > *:not(#ficha-print) { display: none !important; }
  #ficha-print { display: block !important; color: #000; font-size: 12px; }
  .ficha { padding: 8px; }
  .ficha h1 { font-size: 20px; margin: 0 0 2px; }
  .ficha .ficha-sub { color: #555; margin: 0 0 16px; font-size: 12px; }
  .ficha-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px; }
  .ficha-grid .full { grid-column: 1 / -1; }
  .ficha-campo { border-bottom: 1px solid #ddd; padding-bottom: 6px; }
  .ficha-campo .rot { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: #777; }
  .ficha-campo .val { font-size: 13px; }
  .ficha-badge { display: inline-block; border: 1px solid #999; border-radius: 4px; padding: 1px 8px; font-size: 11px; }
  .ficha table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 11px; }
  .ficha table th, .ficha table td { border: 1px solid #ccc; padding: 5px 7px; text-align: left; }
  .ficha-rodape { margin-top: 24px; font-size: 10px; color: #888; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 640px) {
  .container { padding: 20px 16px 48px; }
  .grupo-campos { grid-template-columns: 1fr; padding: 14px; }
  .grupo-campos .col2 { grid-column: auto; }
  .painel-grid { grid-template-columns: 1fr; }
  .chart-card.col-span-2 { grid-column: auto; }
  .mov-form { grid-template-columns: 1fr; }
  .usuario { display: none; }
  .topbar { padding: 10px 16px; }
  .btn-primary span { display: none; }
  .sheet-overlay { padding: 0; align-items: flex-end; }
  .sheet { max-width: none; max-height: 94dvh; border-radius: 22px 22px 0 0; animation: sheet-up .3s cubic-bezier(0.2, 0.8, 0.2, 1); }
}
@keyframes sheet-up { from { transform: translateY(100%); } }
