/* ===================== Tokens ===================== */
:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f7;
  --surface-3: #e8e9f0;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #191919;
  --text-2: #666666;
  --text-3: #8b8b95;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-ink: #ffffff;
  --income-ink: #006c10;
  --danger: #dc3c3d;
  --danger-soft: #fdecec;
  --warning-soft: #fff6e0;
  /* Séries dos gráficos (paleta de referência validada: slot 1 e slot 2) */
  --series-income: #257de0;
  --series-expense: #f47230;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --bubble-user: #4f46e5;
  --bubble-user-ink: #ffffff;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.18);
  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --sidebar: 248px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0b0e;
    --surface: #16161a;
    --surface-2: #1f1f25;
    --surface-3: #2a2a32;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #efefef;
    --text-2: #9c9c9c;
    --text-3: #75757f;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: rgba(129, 140, 248, 0.14);
    --accent-ink: #0b0b0e;
    --income-ink: #53c556;
    --danger: #eb6263;
    --danger-soft: rgba(235, 98, 99, 0.14);
    --warning-soft: rgba(251, 179, 21, 0.12);
    --series-income: #338ced;
    --series-expense: #e76624;
    --grid: #303030;
    --axis: #474747;
    --bubble-user: #4f46e5;
    --bubble-user-ink: #ffffff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0e;
  --surface: #16161a;
  --surface-2: #1f1f25;
  --surface-3: #2a2a32;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #efefef;
  --text-2: #9c9c9c;
  --text-3: #75757f;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.14);
  --accent-ink: #0b0b0e;
  --income-ink: #53c556;
  --danger: #eb6263;
  --danger-soft: rgba(235, 98, 99, 0.14);
  --warning-soft: rgba(251, 179, 21, 0.12);
  --series-income: #338ced;
  --series-expense: #e76624;
  --grid: #303030;
  --axis: #474747;
  --bubble-user: #4f46e5;
  --bubble-user-ink: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ===================== Base ===================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
#app { min-height: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.income { color: var(--income-ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.boot { display: grid; place-items: center; min-height: 100vh; }
.boot-logo {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #4338ca); color: #fff; font-weight: 800; font-size: 28px;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(0.92); opacity: 0.7; } }

/* ===================== Botões e campos ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text); font-weight: 550; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.sm { height: 32px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.btn.icon { width: 40px; padding: 0; }
.btn.icon.sm { width: 32px; }
.btn svg { width: 18px; height: 18px; flex: none; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 550; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--border-strong); background: var(--surface); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.big { height: 56px; font-size: 26px; font-weight: 650; }
.field-error { color: var(--danger); font-size: 13px; }

.segmented { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 12px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; height: 34px; padding: 0 14px; border-radius: 9px; cursor: pointer;
  font-weight: 550; color: var(--text-2);
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented button:disabled { opacity: 0.4; cursor: not-allowed; }
.segmented.full { display: flex; width: 100%; }
.segmented.full button { flex: 1; padding: 0 6px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 550; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }

/* ===================== Layout ===================== */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 6px;
  border-right: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800;
  background: linear-gradient(135deg, #6366f1, #4338ca);
}
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--text-2);
  font-weight: 550; cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item svg { width: 20px; height: 20px; }
.sidebar-footer { margin-top: auto; display: grid; gap: 6px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: var(--surface-2); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; object-fit: cover; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.user-card .info { min-width: 0; }
.user-card .info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; padding: 28px 32px 48px; }
.page { max-width: 1180px; margin: 0 auto; display: grid; gap: 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.bottom-nav { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px 16px calc(96px + var(--safe-bottom)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 6px 6px calc(6px + var(--safe-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px); border-top: 1px solid var(--border);
  }
  .bottom-nav button {
    border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 6px 0; border-radius: 12px;
    color: var(--text-3); font-size: 11px; font-weight: 550; cursor: pointer;
  }
  .bottom-nav button svg { width: 22px; height: 22px; }
  .bottom-nav button.active { color: var(--accent); }
  .bottom-nav .chat-btn span.ico {
    width: 44px; height: 32px; border-radius: 12px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink);
  }
  h1 { font-size: 21px; }
}

/* ===================== Cards ===================== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.card-sub { color: var(--text-2); font-size: 13px; }
.grid { display: grid; gap: 20px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.span-main { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 1100px) { .grid.span-main { grid-template-columns: 1fr; } }
@media (max-width: 900px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } .grid { gap: 14px; } .card { padding: 16px; } }

/* Hero + tiles do dashboard */
.summary { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
@media (max-width: 900px) { .summary { grid-template-columns: 1fr 1fr; gap: 12px; } .summary .hero { grid-column: 1 / -1; } }
.stat-label { color: var(--text-2); font-size: 13px; font-weight: 550; display: flex; align-items: center; gap: 8px; }
.stat-value { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; margin-top: 6px; white-space: nowrap; }
.hero .stat-value { font-size: clamp(30px, 3.6vw, 48px); line-height: 1.1; }
@media (max-width: 900px) { .hero .stat-value { font-size: 40px; } .stat-value { font-size: 20px; } }
.delta { font-size: 12px; font-weight: 600; margin-top: 6px; display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); }
.delta.good { color: var(--income-ink); }
.delta.bad { color: var(--danger); }
.summary.card-summary { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
@media (max-width: 900px) { .summary.card-summary { grid-template-columns: 1fr; } }
.card-invoice .btn { width: 100%; justify-content: center; }
.card-strip { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.card-strip .tx-icon { flex: none; }
.card-strip .grow { flex: 1; min-width: 160px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }

.month-picker { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.month-picker .label { min-width: 150px; text-align: center; font-weight: 600; }

/* ===================== Listas de lançamentos ===================== */
.tx-list { display: grid; }
.tx-day { font-size: 12px; font-weight: 650; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; padding: 14px 4px 6px; }
.tx-row {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 8px;
  border-radius: 12px; cursor: pointer; border: 0; background: none; text-align: left; width: 100%;
}
.tx-row:hover { background: var(--surface-2); }
.tx-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; background: var(--surface-2); position: relative; }
.tx-icon .dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface); }
.tx-main { min-width: 0; }
.tx-desc { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { color: var(--text-2); font-size: 13px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tx-who { max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-row.deleted .tx-desc, .tx-row.deleted .tx-amount { text-decoration: line-through; color: var(--text-3); }

.empty { text-align: center; padding: 40px 16px; color: var(--text-2); display: grid; gap: 12px; justify-items: center; }
.empty .big { font-size: 40px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar .input, .toolbar .select { width: auto; min-width: 160px; height: 38px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.totals-row { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; }
.totals-row b { font-variant-numeric: tabular-nums; }

.fab {
  position: fixed; right: 18px; bottom: calc(86px + var(--safe-bottom)); z-index: 15; width: 56px; height: 56px; border-radius: 18px;
  border: 0; background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-lg); display: none; place-items: center; cursor: pointer;
}
.fab svg { width: 26px; height: 26px; }
@media (max-width: 900px) { .fab { display: grid; } }

/* ===================== Tabelas ===================== */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table td.r, .table th.r { text-align: right; }
.table tr:last-child td { border-bottom: 0; }

/* ===================== Auditoria ===================== */
.audit-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.audit-item:last-child { border-bottom: 0; }
.audit-badge { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 16px; background: var(--surface-2); }
.audit-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 550; }
.audit-diff { margin-top: 8px; display: grid; gap: 4px; font-size: 13px; }
.audit-diff .row { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 8px; }
.audit-diff .old { color: var(--danger); text-decoration: line-through; word-break: break-word; }
.audit-diff .new { color: var(--income-ink); word-break: break-word; }
.audit-diff .key { color: var(--text-2); }
pre.json { margin: 8px 0 0; padding: 10px; border-radius: 10px; background: var(--surface-2); font-size: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }

/* ===================== Modal / toast ===================== */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 16px;
  animation: fade 0.15s ease;
}
.modal {
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 20px;
  box-shadow: var(--shadow-lg); padding: 22px; display: grid; gap: 16px; animation: rise 0.18s ease;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
@media (max-width: 600px) {
  .overlay { place-items: end stretch; padding: 0; }
  .modal { width: 100%; border-radius: 22px 22px 0 0; max-height: 92vh; padding-bottom: calc(22px + var(--safe-bottom)); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + var(--safe-bottom)); z-index: 60; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); }
@media (min-width: 901px) { .toasts { bottom: 24px; } }
.toast {
  background: #1f1f25; color: #f3f3f3; border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 12px; animation: rise 0.18s ease; font-size: 14px;
}
.toast.error { background: #7f1d1d; }
.toast button { margin-left: auto; background: none; border: 0; color: #a5b4fc; font-weight: 650; cursor: pointer; }

.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-pad { display: grid; place-items: center; padding: 48px; }

/* ===================== Gráficos ===================== */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .value-label { fill: var(--text); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .hover-band, .chart .hover-band.on { fill: var(--surface-2); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); border-radius: 10px; padding: 8px 10px; font-size: 12px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.tooltip .t-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }

.hbars { display: grid; gap: 4px; }
.hbar {
  display: grid; grid-template-columns: minmax(110px, 34%) minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 6px 6px; border-radius: 10px; border: 0; background: none; text-align: left; cursor: pointer; width: 100%;
}
.hbar:hover { background: var(--surface-2); }
.hbar .name { display: flex; gap: 8px; align-items: center; min-width: 0; font-size: 14px; }
.hbar .name span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .track { height: 12px; position: relative; }
.hbar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--series-expense); min-width: 2px; }
.hbar .fill.income { background: var(--series-income); }
.hbar .val { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; min-width: 92px; }
.hbar .val small { display: block; color: var(--text-2); font-weight: 500; font-size: 11px; }

/* ===================== Login ===================== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: min(400px, 100%); display: grid; gap: 22px; text-align: center; padding: 36px 28px; }
.login-card .brand-mark { width: 64px; height: 64px; border-radius: 20px; font-size: 32px; margin: 0 auto; }
.google-btn { height: 48px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border-strong); font-weight: 600; width: 100%; }
.google-btn:hover { background: var(--surface-2); }
.alert { padding: 10px 12px; border-radius: 12px; font-size: 14px; text-align: left; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warning-soft); }
.alert.info { background: var(--surface-2); color: var(--text-2); }
/* Seletor de ícone da categoria (com o "+" para outros ícones) */
.icon-picker { display: grid; gap: 10px; }
.icon-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-more { border-style: dashed; color: var(--text-2); }
.icon-more.active { border-style: solid; color: var(--accent); }
.icon-more-panel { display: grid; gap: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2); max-height: 320px; overflow-y: auto; }
.icon-group { display: grid; gap: 6px; }
.icon-more-panel .btn.icon.sm:not(.primary) { background: var(--surface); }

.check-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); cursor: pointer; }
.check-row input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

/* ===================== Chat ===================== */
.chat { display: flex; flex-direction: column; height: calc(100vh - 76px); max-width: 860px; margin: 0 auto; width: 100%; }
.chat.standalone { height: 100dvh; max-width: none; }
.app-standalone .main { padding: 0; }
@media (max-width: 900px) {
  .chat { height: calc(100dvh - 16px - 78px - var(--safe-bottom)); }
  .chat.standalone { height: 100dvh; }
}
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
}
.chat.standalone .chat-head { border-radius: 0; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
.chat-head .title { flex: 1; min-width: 0; }
.chat-head .title b { display: block; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--text-3); }
.status-dot.ok { background: #0aac23; }
.status-dot.bad { background: #dc3c3d; }
.chat-body {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--surface);
  overscroll-behavior: contain;
}
.chat.standalone .chat-body { background: var(--bg); }
.msg { display: flex; flex-direction: column; max-width: min(82%, 560px); gap: 6px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; }
.bubble { padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.msg.user .bubble { background: var(--bubble-user); color: var(--bubble-user-ink); border-bottom-right-radius: 6px; }
.msg.assistant .bubble { background: var(--surface-2); border-bottom-left-radius: 6px; }
.msg.assistant.error .bubble { background: var(--danger-soft); }
.msg.pending .bubble { opacity: 0.7; }
.msg-time { font-size: 11px; color: var(--text-3); padding: 0 6px; display: flex; gap: 6px; align-items: center; }
.msg-cards { display: grid; gap: 6px; width: 100%; min-width: 260px; }
.msg-card {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 10px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--border); text-align: left; cursor: pointer; width: 100%;
}
.chat:not(.standalone) .msg-card { background: var(--bg); }
.msg-card .tx-icon { width: 34px; height: 34px; font-size: 16px; border-radius: 10px; }
.msg-card.deleted { opacity: 0.55; }
.msg-card.deleted .tx-desc, .msg-card.deleted .tx-amount { text-decoration: line-through; }
.msg-actions { display: flex; gap: 6px; }

/* Relatório no chat */
.msg.has-report { max-width: min(96%, 620px); width: 100%; }
.report { width: 100%; display: grid; gap: 14px; padding: 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); }
.chat:not(.standalone) .report { background: var(--bg); }
.report-head { display: grid; gap: 2px; }
.report-head .tiny { text-transform: none; }
.report-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.report-kpi { display: grid; gap: 4px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.report-kpi b { font-size: 18px; font-variant-numeric: tabular-nums; }
.report-kpi b.big { font-size: 20px; }
.report-note { font-size: 13px; color: var(--text-2); }
.report-sec { display: grid; gap: 6px; }
.report-sec-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; font-weight: 650;
  color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.report-sec-head .legend { text-transform: none; letter-spacing: 0; font-weight: 500; }
.report-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.report-chips .chip { font-weight: 500; font-size: 12.5px; padding: 4px 10px; }
.report-chips .chip b { font-variant-numeric: tabular-nums; color: var(--text); }
.report .hbar { grid-template-columns: minmax(96px, 36%) minmax(0, 1fr) auto; }
.report .tx-row { padding: 8px 4px; grid-template-columns: 34px minmax(0, 1fr) auto; }
.report .tx-row .tx-icon { width: 34px; height: 34px; font-size: 16px; border-radius: 10px; }
/* Painel "Relatório" do chat */
.report-sheet { display: grid; gap: 14px; }
.report-quick { display: flex; flex-wrap: wrap; gap: 6px; }
.report-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.report-dates label { display: grid; gap: 4px; }
.report-sheet-sep { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 12px; }
.report-sheet-sep::before, .report-sheet-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.report-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.chat-empty { margin: auto; text-align: center; display: grid; gap: 14px; justify-items: center; padding: 24px; max-width: 420px; }
.chat-empty .brand-mark { width: 56px; height: 56px; border-radius: 18px; font-size: 26px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.suggestions button {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.suggestions button:hover { border-color: var(--accent); color: var(--accent); }
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--border);
  background: var(--surface); border-radius: 0 0 var(--radius) var(--radius);
}
.chat.standalone .composer { border-radius: 0; }
@media (max-width: 900px) { .chat:not(.standalone) .composer { padding-bottom: 10px; } }
.composer textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 140px; padding: 11px 14px; border-radius: 22px; border: 1px solid var(--border-strong);
  background: var(--bg); outline: none; line-height: 1.4; overflow-y: hidden;
}
.composer textarea:focus { border-color: var(--accent); }
.round-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none; display: grid; place-items: center; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); transition: transform 0.1s, background 0.15s;
}
.round-btn:active { transform: scale(0.94); }
.round-btn:disabled { opacity: 0.5; }
.round-btn.secondary { background: var(--surface-2); color: var(--text); }
.round-btn.rec { background: var(--danger); color: #fff; animation: recpulse 1.4s ease-in-out infinite; }
.round-btn svg { width: 22px; height: 22px; }
@keyframes recpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(220, 60, 61, 0.45); } 50% { box-shadow: 0 0 0 10px rgba(220, 60, 61, 0); } }
.recording-bar { flex: 1; height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border-radius: 22px; background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.recording-bar .level { flex: 1; height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--danger) 20%, transparent); overflow: hidden; }
.mic-chip { border: 0; background: color-mix(in srgb, var(--danger) 12%, transparent); color: inherit; font: inherit; font-size: 11px; font-weight: 600;
  border-radius: 999px; padding: 4px 8px; max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.mic-chip.bt { outline: 1px dashed currentColor; }
.msg-heard { font-size: 11px; color: var(--text-3); padding: 0 6px; max-width: 85%; }
.msg.user .msg-heard { align-self: flex-end; text-align: right; }
.msg-audio { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-3); padding: 0 2px; }
.msg.user .msg-audio { align-self: flex-end; }
.mic-list { display: grid; gap: 8px; }
.mic-option { display: grid; gap: 2px; text-align: left; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 10px 12px; font: inherit; cursor: pointer; }
.mic-option.active { border-color: var(--accent); background: var(--accent-soft); }
.recording-bar .level div { height: 100%; background: var(--danger); border-radius: 3px; transition: width 0.08s; }

/* Chat dentro do sistema: ocupa a altura útil da tela */
.main.chat-route { padding: 20px 32px; }
.main.chat-route .chat { height: calc(100vh - 40px); }
@media (max-width: 900px) {
  .main.chat-route { padding: 0 0 calc(70px + var(--safe-bottom)); }
  .main.chat-route .chat { height: calc(100dvh - 70px - var(--safe-bottom)); }
  .main.chat-route .chat-head, .main.chat-route .composer { border-radius: 0; }
}

/* Separador de dia e histórico do chat */
.day-sep { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 12px; font-weight: 600; margin: 6px 0; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.day-sep span { text-transform: capitalize; }
.history-filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; justify-content: space-between; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.history-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.chip-btn.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.history-dates { display: flex; gap: 8px; }
.history-dates label { display: grid; gap: 2px; }
.history-dates .input { height: 36px; width: 150px; padding: 0 8px; }
@media (max-width: 600px) { .history-dates { width: 100%; } .history-dates label { flex: 1; } .history-dates .input { width: 100%; } }
.undo-btn { height: 26px; padding: 0 8px; }
.undo-btn .num { color: var(--text-3); font-weight: 500; }
