/* Controle Financeiro — design system
   Paleta categórica e status validados (contraste + daltonismo) pela skill
   dataviz — ver references/palette.md. Não alterar esses hex sem revalidar. */

:root {
  color-scheme: light;

  /* Marca */
  --brand: #17a673;
  --brand-dark: #0e7a54;
  --brand-soft: #e3f5ee;
  --brand-ink: #08281d;

  /* Casco (sidebar) */
  --ink-900: #0e1512;
  --ink-800: #131f1a;
  --ink-700: #1b2b23;
  --ink-600: #2a3d33;
  --ink-ring: rgba(255, 255, 255, 0.08);

  /* Superfícies de conteúdo */
  --paper: #f7f6f2;
  --surface: #ffffff;
  --surface-raised: #ffffff;

  /* Texto */
  --text-primary: #14201b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --text-on-brand: #f3fbf8;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.16);
  --gridline: #e1e0d9;

  /* Status (quitada / parcial / aberta) — fixo, nunca reaproveitado p/ série */
  --good: #0ca30c;
  --good-soft: #e5f6e3;
  --warning: #c98500;
  --warning-soft: #fdf1d9;
  --critical: #d03b3b;
  --critical-soft: #fbe8e6;

  /* Paleta categórica dos gráficos (ordem fixa — nunca ciclar) */
  --chart-1: #2a78d6;
  --chart-2: #eb6834;
  --chart-3: #1baf7a;
  --chart-4: #eda100;
  --chart-5: #e87ba4;
  --chart-6: #008300;
  --chart-7: #4a3aa7;
  --chart-8: #e34948;

  --font-display: "Space Grotesk", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 1px 2px rgba(14, 21, 18, 0.04), 0 8px 24px -12px rgba(14, 21, 18, 0.12);
  --sidebar-w: 256px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
  color: var(--text-primary);
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ */
/* Casco: sidebar + conteúdo                                          */
/* ------------------------------------------------------------------ */

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

.sidebar-toggle-input { position: absolute; opacity: 0; pointer-events: none; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--ink-900);
  color: var(--text-on-brand);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 20;
  transition: width 0.2s ease, flex-basis 0.2s ease, padding 0.2s ease;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 24px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--ink-ring);
}

.sidebar__mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.sidebar__mark svg { width: 20px; height: 20px; }

.sidebar__wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.25;
  color: #ffffff;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__section {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
  padding: 16px 12px 6px;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar__link svg { width: 18px; height: 18px; flex: none; opacity: 0.9; }

.sidebar__link:hover {
  background: var(--ink-700);
  color: #ffffff;
}

.sidebar__link.is-active {
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}

.sidebar__link.is-active svg { opacity: 1; }

.sidebar__user {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--ink-ring);
  display: flex;
  flex-direction: column;
}

.sidebar__user-nome {
  font-size: 13.5px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 16px;
}

.sidebar__logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  background: none;
  border: 0;
  padding: 0;
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--critical);
  cursor: pointer;
  opacity: 0.82;
  transition: opacity 0.15s ease;
}

.sidebar__logout svg { width: 13px; height: 13px; flex: none; }

.sidebar__logout:hover { opacity: 1; }

.sidebar-scrim {
  display: none;
}

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

.app-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-topbar__burger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  flex: none;
}

.app-topbar__burger svg { width: 18px; height: 18px; }

.app-content {
  flex: 1;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 36px 32px 64px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-header h1 { font-size: 24px; }

.page-header__subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 2px;
}

/* ------------------------------------------------------------------ */
/* Cards, grids                                                       */
/* ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 20px;
}

.card__title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 2px;
}

.card__hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 14px;
  line-height: 1.5;
}

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-form { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }

@media (max-width: 900px) {
  .grid-2, .grid-4, .grid-form { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------ */
/* KPI tiles                                                          */
/* ------------------------------------------------------------------ */

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kpi__icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi__icon svg { width: 16px; height: 16px; }

.kpi--brand .kpi__icon { background: var(--brand-soft); color: var(--brand-dark); }
.kpi--good .kpi__icon { background: var(--good-soft); color: var(--good); }
.kpi--critical .kpi__icon { background: var(--critical-soft); color: var(--critical); }
.kpi--neutral .kpi__icon { background: #eef0ff; color: var(--chart-7); }
.kpi--accent-a .kpi__icon { background: #fdece2; color: var(--chart-2); }
.kpi--accent-b .kpi__icon { background: #e2f3ec; color: var(--chart-3); }

.kpi__label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.kpi__value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.kpi__caption {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------------ */
/* Gráficos                                                            */
/* ------------------------------------------------------------------ */

.chart-card canvas { max-width: 100%; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.chart-legend__item { display: flex; align-items: center; gap: 6px; }

.chart-legend__swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

.chart-empty {
  color: var(--text-muted);
  font-size: 13.5px;
  padding: 24px 0;
  text-align: center;
}

/* Tabela de apoio sob um gráfico — os mesmos números em texto (leitor de
   tela, cópia, print), discreta para não competir com o gráfico. */
.chart-table {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--gridline);
  font-size: 12.5px;
}

.chart-table td, .chart-table th { padding: 5px 8px; }

/* Barras de saldo divergente (quem deve pra quem) */
.balance-row {
  display: grid;
  grid-template-columns: 120px 1fr 96px;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  font-size: 13.5px;
}

.balance-row__name { font-weight: 500; }

.balance-row__track {
  position: relative;
  height: 10px;
  background: var(--gridline);
  border-radius: 999px;
  overflow: visible;
}

.balance-row__track::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -3px;
  bottom: -3px;
  width: 1px;
  background: var(--border-strong);
}

.balance-row__fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
}

.balance-row__fill.is-positive { left: 50%; background: var(--good); }
.balance-row__fill.is-negative { right: 50%; background: var(--critical); }

.balance-row__value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.balance-row__value.is-positive { color: var(--good); }
.balance-row__value.is-negative { color: var(--critical); }

/* ------------------------------------------------------------------ */
/* Tabelas                                                             */
/* ------------------------------------------------------------------ */

.table-wrap { overflow-x: auto; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
}

th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--paper); }

.num { text-align: right; font-variant-numeric: tabular-nums; }

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.th-sort:hover { color: var(--text-primary); }
.th-sort.is-active { color: var(--brand); }

.th-sort__arrow { font-size: 9px; line-height: 1; }
.th-sort__arrow--muted { opacity: 0; transition: opacity 0.1s ease; }
.th-sort:hover .th-sort__arrow--muted { opacity: 0.45; }

/* ------------------------------------------------------------------ */
/* Badges / status                                                     */
/* ------------------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge--good { background: var(--good-soft); color: var(--good); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--critical { background: var(--critical-soft); color: var(--critical); }
.badge--muted { background: var(--paper); color: var(--text-secondary); border: 1px solid var(--border); }

/* ------------------------------------------------------------------ */
/* Botões                                                              */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand);
  color: var(--text-on-brand);
  border: 0;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font-body);
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover { background: var(--paper); }

.btn-danger { background: var(--critical); }
.btn-danger:hover { background: #ad2f2f; }

.btn-icon { padding: 6px 9px; }

.btn:disabled {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: not-allowed;
}
.btn:disabled:hover { background: var(--surface); }

/* ------------------------------------------------------------------ */
/* Barra de ações em lote (seleção de linhas)                          */
/* ------------------------------------------------------------------ */

.bulk-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  min-height: 34px;
}

.col-check { width: 34px; padding-right: 0 !important; }

/* ------------------------------------------------------------------ */
/* Formulários                                                         */
/* ------------------------------------------------------------------ */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.field--full { grid-column: 1 / -1; }

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

input, select, textarea {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 0;
  border-color: var(--brand);
}

.form-actions { margin-top: 18px; display: flex; gap: 10px; }

.checklist {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  background: var(--paper);
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
}

.checklist label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  font-size: 13.5px;
  color: var(--text-primary);
  padding: 6px 8px;
  border-radius: 6px;
}

.checklist label:hover { background: var(--surface); }
.checklist input { width: auto; }

input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); }

.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-bar .field { margin-bottom: 0; min-width: 160px; }

.preset-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.preset-row__divider {
  width: 1px;
  align-self: stretch;
  background: var(--border-strong);
  margin: 0 2px;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.preset-chip:hover { background: var(--paper); color: var(--text-primary); }

.preset-chip.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--text-on-brand);
  font-weight: 600;
}

/* ------------------------------------------------------------------ */
/* Banners / mensagens                                                */
/* ------------------------------------------------------------------ */

.banner {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.5;
}

.banner-ok { background: var(--good-soft); color: #0a6b0a; }
.banner-erro { background: var(--critical-soft); color: #9c2c2c; }

.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }

/* ------------------------------------------------------------------ */
/* Responsivo                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 24px 0 48px rgba(0, 0, 0, 0.2);
  }

  .sidebar-toggle-input:checked ~ .sidebar { transform: translateX(0); }

  .sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 12, 0.4);
    z-index: 15;
  }

  .sidebar-toggle-input:checked ~ .sidebar-scrim { display: block; }

  .app-content { padding: 24px 16px 48px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* Telas estreitas de verdade (celular): cada campo do filtro ocupa a
     linha inteira, senão o <input type="date"> nativo espreme contra o
     vizinho. Não mexe no desktop (regra base .filter-bar .field acima). */
  .filter-bar .field { min-width: 100%; }
}

@media (min-width: 961px) {
  /* Nesse breakpoint o checkbox vira "recolher": marcado esconde a sidebar
     (ao contrário do mobile, onde marcado é que abre a gaveta). */
  .sidebar-toggle-input:checked ~ .sidebar {
    width: 0;
    flex-basis: 0;
    padding-left: 0;
    padding-right: 0;
    overflow: hidden;
    border-right: 0;
  }
}

@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr; }
  .balance-row { grid-template-columns: 84px 1fr 74px; }
}
