:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11,11,11,0.10);
  --gridline: #e1e0d9;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --warning: #b9790a;
  --warning-bg: #fab21922;
  --critical: #d03b3b;
  --critical-bg: #d03b3b1a;
  --accent-bg: #2a78d61a;
  --trial: #2a78d6;
  --shadow: 0 1px 2px rgba(11,11,11,0.04), 0 8px 24px -12px rgba(11,11,11,0.12);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255,255,255,0.10);
    --gridline: #2c2c2a;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --good: #0ca30c;
    --warning: #fab219;
    --warning-bg: #fab21922;
    --critical: #e66767;
    --critical-bg: #e667671f;
    --accent-bg: #3987e51f;
    --trial: #3987e5;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --border: rgba(255,255,255,0.10);
  --gridline: #2c2c2a;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --warning: #fab219;
  --warning-bg: #fab21922;
  --critical: #e66767;
  --critical-bg: #e667671f;
  --accent-bg: #3987e51f;
  --trial: #3987e5;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
body { min-height: 100vh; }
a { color: inherit; }

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 20px 80px;
}

/* ---------- Navbar ---------- */
.navbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.nav-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 0.95rem; flex-shrink: 0; }
.brand-logo { width: 22px; height: 22px; border-radius: 6px; display: block; }
.nav-links { display: flex; gap: 4px; flex: 1; justify-content: center; }
.nav-links-inicio { justify-content: flex-start; }
.nav-links a {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.87rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
}
.nav-links a:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-links a.active { background: var(--surface-2); color: var(--accent); }
.nav-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.nav-user button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
}
.nav-user button:hover { color: var(--text-primary); border-color: var(--text-muted); }
.nav-user .icon-btn { width: 32px; height: 32px; padding: 0; }

header.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
header.top h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
header.top p { margin: 0; color: var(--text-secondary); font-size: 0.92rem; max-width: 58ch; }

.secao-titulo { font-size: 0.82rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 0 0 10px; }

.periodo-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.periodo-nav h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; white-space: nowrap; }
.periodo-nav .icon-btn { width: 30px; height: 30px; flex-shrink: 0; }
.periodo-nav #btn-hoje { margin-left: 4px; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { color: var(--text-primary); border-color: var(--text-muted); }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 24px; }
.stats.cols-3 { grid-template-columns: repeat(3, 1fr); }
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-tile .n { font-size: 1.7rem; font-weight: 600; line-height: 1.1; margin-bottom: 4px; }
.stat-tile .l { font-size: 0.8rem; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.trial, .dot.pendente { background: var(--trial); }
.dot.ativo, .dot.pago { background: var(--good); }
.dot.inativo { background: var(--warning); }
.dot.cancelado, .dot.atrasado { background: var(--critical); }
.dot.total { background: var(--text-muted); }

/* ---------- Banners ---------- */
.banner {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
}
.banner strong { color: var(--text-primary); }
.banner button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.85rem; flex-shrink: 0; }

.error-banner {
  background: var(--surface-1);
  border: 1px solid var(--critical);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
  font-size: 0.88rem;
  color: var(--text-primary);
  display: none;
}
.error-banner.show { display: block; }
.error-banner code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 0.85em; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="text"], .toolbar input[type="date"], .toolbar select {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.88rem;
  font-family: inherit;
}
.toolbar input[type="text"] { flex: 1; min-width: 180px; }
.toolbar select, .toolbar input[type="date"] { cursor: pointer; }
.spacer { flex: 1; }

.btn {
  border: none; border-radius: 10px; padding: 9px 16px;
  font-size: 0.88rem; font-weight: 600; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-muted); }
.btn-danger { background: var(--critical); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-text { background: none; color: var(--accent); padding: 4px 6px; font-size: 0.82rem; border: none; cursor: pointer; font-family: inherit; }
.btn-text.danger { color: var(--critical); }
.btn-text.good { color: var(--good); }
.btn:disabled { opacity: 0.6; cursor: default; }

/* ---------- Table ---------- */
.table-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: 600; padding: 12px 16px;
  border-bottom: 1px solid var(--gridline); white-space: nowrap;
}
thead th .help { cursor: help; border-bottom: 1px dotted var(--text-muted); }
tbody td { padding: 13px 16px; font-size: 0.88rem; border-bottom: 1px solid var(--gridline); vertical-align: middle; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.nome { font-weight: 600; }
td.muted, .sub { color: var(--text-muted); font-size: 0.8rem; }
td.valor { font-variant-numeric: tabular-nums; font-weight: 600; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px 3px 7px; border-radius: 999px; font-size: 0.76rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-secondary); white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; }
.badge.vencida { color: var(--critical); }

.plano-badge {
  font-size: 0.76rem; color: var(--text-secondary); background: var(--surface-2);
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}

.row-actions { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.row-actions .menu-btn { width: 28px; height: 28px; border-radius: 8px; font-size: 1.3rem; line-height: 0; }

.acoes-header {
  display: flex; align-items: center; gap: 14px;
  padding-bottom: 16px; margin-bottom: 12px;
  border-bottom: 1px solid var(--gridline);
}
.acoes-header h2 { margin: 0; font-size: 1.05rem; }
.acoes-header .sub { margin: 2px 0 0; }
.acoes-avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.15rem; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--trial) 60%, var(--good));
  box-shadow: 0 4px 12px -2px var(--accent-bg);
}

.action-list { display: flex; flex-direction: column; gap: 4px; }
.action-list button {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left; background: none; border: 1px solid transparent;
  padding: 11px; border-radius: 14px; cursor: pointer; font-family: inherit;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}
.action-list button:hover { background: var(--surface-2); border-color: var(--border); }
.action-list button:active { transform: scale(0.98); }
.action-list .action-icon {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; background: var(--accent-bg);
  box-shadow: inset 0 0 0 1px var(--accent-bg);
  transition: transform 0.12s ease;
}
.action-list button:hover .action-icon { transform: scale(1.06); }
.action-list button.danger .action-icon { background: var(--critical-bg); box-shadow: inset 0 0 0 1px var(--critical-bg); }
.action-list .action-texto { min-width: 0; }
.action-list .action-titulo { display: block; font-size: 0.9rem; font-weight: 600; color: var(--text-primary); line-height: 1.3; }
.action-list button.danger .action-titulo { color: var(--critical); }
.action-list .action-desc { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.action-list .divider { border-top: 1px solid var(--gridline); margin: 8px 6px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.empty-state .big { font-size: 2rem; margin-bottom: 8px; }
.empty-state p { margin: 0 0 16px; font-size: 0.9rem; }

/* ---------- Dashboard charts (relatorio) ---------- */
.chart-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.chart-card h3 { margin: 0 0 4px; font-size: 0.95rem; }
.chart-card .chart-sub { margin: 0 0 18px; font-size: 0.78rem; color: var(--text-muted); }

.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 160px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar-col .bar-value { font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-col .bar { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 2px 2px; min-height: 3px; }
.bar-col .bar-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 8px; }

.chart-legenda { display: flex; gap: 16px; margin-bottom: 14px; font-size: 0.78rem; color: var(--text-secondary); }
.chart-legenda span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legenda .ponto { width: 8px; height: 8px; border-radius: 50%; }
.chart-legenda .ponto.faturamento { background: var(--accent); }
.chart-legenda .ponto.custos { background: var(--warning); }

.bar-chart-dupla { display: flex; align-items: flex-end; gap: 10px; height: 180px; }
.bar-mes { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar-par { display: flex; align-items: flex-end; gap: 4px; justify-content: center; width: 100%; height: 100%; }
.bar-par .barra { width: 14px; border-radius: 4px 4px 2px 2px; min-height: 3px; }
.bar-par .barra.faturamento { background: var(--accent); }
.bar-par .barra.custos { background: var(--warning); }
.bar-mes .bar-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 8px; }

/* ---------- KPI tiles (home) ---------- */
.kpi-tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.kpi-tile .kpi-label { font-size: 0.78rem; color: var(--text-muted); display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.kpi-tile .kpi-valor { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; }
.kpi-tile .kpi-sub { font-size: 0.78rem; color: var(--text-secondary); margin-top: 6px; }
.kpi-tile .kpi-sub.up { color: var(--good); }
.kpi-tile .kpi-sub.down { color: var(--critical); }
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .kpi-grid, .kpi-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}

.rank-list { display: flex; flex-direction: column; gap: 10px; }
.rank-row { display: grid; grid-template-columns: 84px 1fr 84px; align-items: center; gap: 10px; font-size: 0.83rem; }
.rank-label { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-bar-track { background: var(--surface-2); border-radius: 5px; height: 10px; overflow: hidden; }
.rank-bar { height: 100%; background: var(--accent); border-radius: 5px; min-width: 3px; }
.rank-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

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

@media (max-width: 720px) {
  .chart-grid { grid-template-columns: 1fr; }
}

/* ---------- Day list (agenda) ---------- */
.day-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 24px;
}
.day-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  min-width: 118px;
  cursor: pointer;
  box-shadow: var(--shadow);
  text-align: left;
  font-family: inherit;
}
.day-card:hover { border-color: var(--text-muted); }
.day-card.selected { border-color: var(--accent); background: var(--surface-2); box-shadow: 0 0 0 1px var(--accent); }
.day-card .dia-semana { font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; letter-spacing: 0.03em; }
.day-card .dia-data { font-size: 1.05rem; font-weight: 700; margin: 2px 0 6px; }
.day-card.hoje .dia-data { color: var(--accent); }
.day-card.atrasado .dia-data { color: var(--critical); }
.day-card .dia-valor { font-size: 0.82rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.day-card .dia-count { font-size: 0.74rem; color: var(--text-secondary); }

/* ---------- Task list (lembretes) ---------- */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow);
}
.task-card .tipo-tag {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  padding: 4px 8px; border-radius: 6px; flex-shrink: 0; white-space: nowrap;
}
.tipo-tag.antecipado { background: var(--trial); color: #fff; }
.tipo-tag.vencimento_dia { background: var(--warning); color: #1a1a19; }
.tipo-tag.atraso { background: var(--critical); color: #fff; }
.task-card .info { flex: 1; min-width: 0; }
.task-card .info .t1 { font-weight: 600; font-size: 0.9rem; }
.task-card .info .t2 { font-size: 0.8rem; color: var(--text-secondary); }
.task-card .valor { font-weight: 700; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.task-card .acoes { flex-shrink: 0; display: flex; gap: 6px; }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(8,8,7,0.55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.overlay.show { display: flex; animation: overlayIn 0.15s ease-out; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 20px;
  width: 100%; max-width: 460px; padding: 26px; box-shadow: 0 24px 60px -20px rgba(0,0,0,0.35), 0 4px 16px rgba(0,0,0,0.08);
  max-height: 90vh; overflow-y: auto;
  animation: modalIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal h2 { margin: 0 0 4px; font-size: 1.15rem; letter-spacing: -0.01em; }
.modal .modal-sub { color: var(--text-secondary); font-size: 0.85rem; margin: 0 0 20px; }
.field { margin-bottom: 16px; }
.field.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.field input, .field select, .field textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 9px; padding: 10px 12px; font-size: 0.9rem; font-family: inherit;
}
.field .hint { font-size: 0.76rem; color: var(--text-muted); margin-top: 5px; }

.input-com-botao { display: flex; }
.input-com-botao input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 9px 0 0 9px; border-right: none; padding: 8px 10px; font-size: 0.82rem; font-family: inherit;
  min-width: 0;
}
.input-com-botao .btn-copiar {
  flex-shrink: 0; border: 1px solid var(--good); border-radius: 0 9px 9px 0;
  background: var(--good); color: #fff; padding: 0 16px; font-size: 0.82rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.input-com-botao .btn-copiar:hover { filter: brightness(1.08); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--surface-1); border: 1px solid var(--border); border-left: 3px solid var(--good);
  border-radius: 10px; padding: 12px 16px; font-size: 0.85rem; box-shadow: var(--shadow); max-width: 320px;
}
.toast.error { border-left-color: var(--critical); }

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); width: 100%; max-width: 380px; padding: 32px;
}
.login-card .brand { display: inline-flex; align-items: center; gap: 10px; font-size: 1.5rem; margin-bottom: 4px; }
.login-card .brand .brand-logo { width: 30px; height: 30px; border-radius: 8px; }
.login-card .sub { color: var(--text-secondary); font-size: 0.88rem; margin: 0 0 24px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card .error-msg { color: var(--critical); font-size: 0.82rem; min-height: 1.2em; }

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .nav-links { display: none; }
}
