:root {
  --page: #f9f9f7;
  --surface: #ffffff;
  --border: #e6e5e0;
  --grid: #ecebe7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --brand: #052361;
  --brand-2: #3e5b63;
  --on-brand: #ffffff;
  --series: #2a78d6;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --border: #2c2c2a;
    --grid: #2a2a28;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #898781;
    --brand: #2f4f9e;
    --series: #3987e5;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
[hidden] { display: none !important; }
a { color: inherit; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.danger { color: var(--critical); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.link { background: none; border: 0; color: var(--text-2); font: inherit; cursor: pointer; padding: 0; }
.link:hover { color: var(--text); text-decoration: underline; }
label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
.error { color: var(--text); margin: 0; }
.error::before { content: '✕ '; color: var(--critical); }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.badge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.ACTIVE::before { background: var(--good); }
.badge.PENDING::before { background: var(--warning); }
.badge.TOKEN_EXPIRED::before { background: var(--critical); }
.badge.DISCONNECTED::before { background: var(--muted); }

.delta { font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta .up { color: var(--good); }
.delta .down { color: var(--critical); }
.delta .flat { color: var(--muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; position: relative; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; }
.login-logo { width: 150px; display: block; margin: 0 auto; }
.login .powered { position: absolute; right: 16px; bottom: 16px; }
.powered { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); opacity: 0.75; }
.powered img { height: 18px; display: block; }

/* Estrutura */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; }
.brand img { height: 40px; display: block; }
.topbar nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; font-weight: 600; color: var(--text-2); }
.topbar nav a.active { color: var(--text); }
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
.footer { display: flex; justify-content: flex-end; padding: 0 24px 16px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }

/* Tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 8px; border-bottom: 1px solid var(--border); }
th.num { text-align: right; }
td { padding: 10px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--page); }
.client-cell { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--grid); flex: none; }
.avatar.lg { width: 64px; height: 64px; }
.thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--grid); display: block; }

/* Detalhe */
.profile { display: flex; gap: 14px; align-items: center; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.info-grid div span { display: block; font-size: 12px; color: var(--muted); }
.notice { border-left: 4px solid var(--warning); }
.period { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 16px 0; }
.chip { border: 1px solid var(--border); background: transparent; color: var(--text-2); border-radius: 16px; padding: 5px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.chip.active { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.period input { width: auto; padding: 5px 8px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile .label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.tile .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; }
.tile .prev { font-size: 12px; color: var(--muted); }
.tile.hero { grid-column: span 2; }
.tile.hero .value { font-size: 34px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; margin-bottom: 16px; }
.chart-box { position: relative; height: 220px; }
.section { margin-bottom: 16px; }

.hbars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: 110px 1fr 44px; gap: 8px; align-items: center; font-size: 13px; }
.hbar .track { height: 12px; }
.hbar .fill { height: 10px; background: var(--series); border-radius: 0 4px 4px 0; min-width: 2px; }

dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(520px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-body { padding: 20px; display: grid; gap: 12px; }
.dialog-body .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--page); padding: 10px 16px; border-radius: 8px; font-weight: 600; z-index: 10;
}

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .tile.hero { grid-column: span 1; }
  .dialog-body .row { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
