/* ============ Design tokens ============ */
:root, html[data-theme="dark"] {
  --bg: #0b0e14;
  --surface: #121722;
  --surface-2: #171d2a;
  --elevated: #1e2533;
  --border: #242c3b;
  --border-soft: #1d2532;
  --text: #e8edf5;
  --text-dim: #aab4c5;
  --muted: #79839a;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --accent-soft: rgba(59,130,246,.15);
  --green: #34d399; --green-soft: rgba(52,211,153,.14);
  --red: #f87171;   --red-soft: rgba(248,113,113,.14);
  --amber: #fbbf24; --amber-soft: rgba(251,191,36,.14);
  --violet: #a78bfa; --violet-soft: rgba(167,139,250,.14);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 32px -12px rgba(0,0,0,.55);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.25);
  --r-xs: 8px; --r-sm: 11px; --r: 16px; --r-lg: 22px;
  --sidebar-w: 248px; --chat-w: 372px;
}
html[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f7f9fd;
  --elevated: #ffffff;
  --border: #e4e9f1;
  --border-soft: #eef1f6;
  --text: #131a2a;
  --text-dim: #44506a;
  --muted: #76829a;
  --accent: #2563eb; --accent-strong: #1d4ed8;
  --accent-soft: rgba(37,99,235,.1);
  --green: #16a34a; --green-soft: rgba(22,163,74,.1);
  --red: #dc2626;   --red-soft: rgba(220,38,38,.1);
  --amber: #d97706; --amber-soft: rgba(217,119,6,.12);
  --violet: #7c3aed; --violet-soft: rgba(124,58,237,.1);
  --shadow: 0 1px 2px rgba(20,30,60,.06), 0 14px 34px -16px rgba(20,30,60,.22);
  --shadow-sm: 0 1px 2px rgba(20,30,60,.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; letter-spacing: -0.01em;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* ============ App shell ============ */
.app { display: grid; height: 100vh; }
/* Modo dashboard: nav · conteúdo · chat dock */
.app.mode-dash { grid-template-columns: var(--sidebar-w) 1fr var(--chat-w); }
.app.mode-dash.chat-hidden { grid-template-columns: var(--sidebar-w) 1fr 0; }
/* Modo chat (tela inicial): só o chat, em tela cheia */
.app.mode-chat { grid-template-columns: 1fr; }
.app.mode-chat .sidebar, .app.mode-chat .main, .app.mode-chat #scrim { display: none !important; }

/* ============ Sidebar ============ */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 18px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff; font-weight: 800; font-size: 20px; box-shadow: 0 6px 16px -4px var(--accent-soft);
}
.brand-name { font-size: 21px; font-weight: 800; letter-spacing: -0.03em; }
.brand-name span { color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border: none; border-radius: var(--r-sm); cursor: pointer;
  background: transparent; color: var(--muted); font-size: 14.5px; font-weight: 500;
  font-family: inherit; text-align: left; transition: all .15s ease; position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.ic { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sidebar-foot { border-top: 1px solid var(--border-soft); padding-top: 8px; }
.ghost-item { color: var(--text-dim); }

/* ============ Main ============ */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 16px 26px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.head-titles { flex: 1; min-width: 0; }
.head-titles h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.head-titles p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.head-actions { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong)); color: #fff; font-weight: 700; font-size: 15px;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-dim); cursor: pointer; display: grid; place-items: center; transition: all .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.sm svg { width: 15px; height: 15px; }
.menu-btn { display: none; }

.content { flex: 1; overflow-y: auto; padding: 24px 26px; }
.view { display: none; flex-direction: column; gap: 18px; animation: fade .25s ease; }
.view.active { display: flex; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============ KPIs ============ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 16px; display: flex; align-items: center; gap: 13px; box-shadow: var(--shadow-sm);
}
.kpi-ic { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; }
.kpi-ic svg { width: 21px; height: 21px; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.kpi-ic.blue { background: var(--accent-soft); color: var(--accent); stroke: var(--accent); }
.kpi-ic.green { background: var(--green-soft); color: var(--green); stroke: var(--green); }
.kpi-ic.red { background: var(--red-soft); color: var(--red); stroke: var(--red); }
.kpi-ic.violet { background: var(--violet-soft); color: var(--violet); stroke: var(--violet); }
.kpi-ic.amber { background: var(--amber-soft); color: var(--amber); stroke: var(--amber); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; display: block; }
.kpi-val { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; display: block; }
.pos { color: var(--green); } .neg { color: var(--red); } .accent { color: var(--accent); }

/* ============ Panels ============ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.panel.highlight { background: linear-gradient(135deg, var(--surface), var(--surface-2)); border-color: var(--accent-soft); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 10px; }
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.empty { color: var(--muted); font-size: 13px; text-align: center; margin: 14px 0 2px; }
.muted-line { color: var(--text-dim); font-size: 13.5px; margin: 0 0 10px; }

/* ============ Forms & buttons ============ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .span2 { grid-column: span 2; }
.form-row, .filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; }
.filters input, .filters select { flex: 1; min-width: 120px; }
input, select {
  padding: 11px 13px; border-radius: var(--r-xs); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: var(--r-xs); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 13.5px; font-weight: 600;
  font-family: inherit; cursor: pointer; text-decoration: none; transition: all .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn.sm { padding: 7px 12px; font-size: 12.5px; }
.io-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ============ Listas de transações ============ */
.tx-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tx-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 13px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--r-xs); transition: border-color .15s;
}
.tx-item:hover { border-color: var(--border); }
.tx-item .info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.tx-item .cat { font-size: 14px; font-weight: 500; text-transform: capitalize; }
.tx-item .meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-item .amt { font-weight: 700; font-size: 14px; white-space: nowrap; }
.tx-item .amt.income { color: var(--green); } .tx-item .amt.expense { color: var(--red); }
.tx-item .acts { display: flex; gap: 2px; }
.tx-item .acts button { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 3px 5px; border-radius: 6px; }
.tx-item .acts button:hover { color: var(--accent); background: var(--accent-soft); }
.tx-item .acts button.del:hover { color: var(--red); background: var(--red-soft); }

/* ============ Progresso (orçamentos/metas) ============ */
.prog-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 13px; }
.prog-item { background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--r-xs); padding: 13px 14px; position: relative; }
.prog-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.prog-top .cat { text-transform: capitalize; font-weight: 600; font-size: 14px; }
.prog-top .vals { color: var(--muted); font-size: 12.5px; }
.bar { height: 8px; border-radius: 6px; background: var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 6px; background: var(--accent); transition: width .4s ease; }
.bar.ok > span { background: var(--green); }
.bar.alerta > span { background: var(--amber); }
.bar.estourado > span { background: var(--red); }
.prog-item .del { position: absolute; top: 11px; right: 12px; background: transparent; border: none; color: var(--muted); cursor: pointer; }
.prog-item .del:hover { color: var(--red); }
.prog-item .add-btn { margin-top: 10px; }

/* ============ Patrimônio / carteira ============ */
.nw-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.nw-grid strong { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; display: block; margin-top: 3px; }
.alloc { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 16px; }
.pill { background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: 12px; text-transform: capitalize; color: var(--text-dim); }

/* ============ Saúde / score ============ */
.score-row { display: flex; gap: 20px; align-items: center; }
.gauge {
  width: 96px; height: 96px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p,0) * 1%), var(--border) 0);
}
.gauge .score {
  width: 78px; height: 78px; border-radius: 50%; background: var(--surface); display: grid; place-items: center;
  font-size: 30px; font-weight: 800; color: var(--accent);
}
.factors { list-style: none; margin: 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; gap: 6px; flex: 1; color: var(--text-dim); }
.factors b { color: var(--text); }
.factors .meta { color: var(--muted); font-size: 12px; }
#hs-rating { text-transform: capitalize; }

/* ============ Chips / badges / insights ============ */
.chip { background: var(--surface-2); border: 1px solid var(--border); color: var(--accent); border-radius: 10px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.badges { display: flex; flex-wrap: wrap; gap: 7px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 5px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.badge.on { border-color: var(--green); color: var(--text); }
.badge.off { opacity: .45; }
.insight-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ins { padding: 11px 13px; border-radius: var(--r-xs); font-size: 13.5px; background: var(--surface-2); border-left: 3px solid var(--muted); }
.ins.alta { border-left-color: var(--red); }
.ins.média { border-left-color: var(--amber); }
.ins.baixa, .ins.info { border-left-color: var(--accent); }
.review { font-size: 14px; line-height: 1.6; margin-top: 12px; color: var(--text-dim); }

/* ============ Chat dock ============ */
.chatdock {
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0; transition: transform .25s ease;
}
.app.mode-dash.chat-hidden .chatdock { transform: translateX(100%); }
.chatdock-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.cd-title { font-weight: 700; font-size: 15px; }
.cd-title small { color: var(--muted); font-weight: 400; font-size: 12px; }
.cd-title .spark { color: var(--accent); }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 11px; }
.msg { max-width: 88%; padding: 11px 14px; border-radius: 15px; line-height: 1.5; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg.bot.typing { color: var(--muted); font-style: italic; }
.msg .action-tag { display: inline-block; margin-top: 7px; font-size: 11.5px; color: var(--accent); background: var(--accent-soft); border-radius: 7px; padding: 2px 8px; }
.chips { display: flex; gap: 7px; padding: 0 16px 8px; flex-wrap: wrap; }
.chips .chip { cursor: pointer; background: var(--surface-2); transition: all .15s; }
.chips .chip:hover { border-color: var(--accent); }
.composer { display: flex; gap: 9px; padding: 14px 16px; border-top: 1px solid var(--border); }
.composer input { flex: 1; border-radius: 22px; padding: 11px 16px; }
.icon-btn.send { background: var(--accent); border-color: var(--accent); color: #fff; border-radius: 50%; }
.icon-btn.send:hover { background: var(--accent-strong); color: #fff; }

/* ============ Chat em tela cheia (home) ============ */
.app.mode-chat .chatdock { position: static; width: auto; transform: none !important; border-left: none; background: var(--bg); box-shadow: none; }
.app.mode-chat .chatdock-head { justify-content: center; border-bottom: 1px solid var(--border-soft); padding: 20px; }
.app.mode-chat .cd-title { font-size: 18px; }
.app.mode-chat #chat-close { display: none; }
.app.mode-chat .messages { max-width: 768px; width: 100%; margin: 0 auto; padding: 26px 24px; gap: 14px; }
.app.mode-chat .msg { max-width: 84%; font-size: 15px; padding: 13px 16px; }
.app.mode-chat .chips { max-width: 768px; width: 100%; margin: 0 auto; justify-content: center; padding: 0 24px 10px; }
.app.mode-chat .composer { max-width: 768px; width: 100%; margin: 0 auto; border-top: none; padding: 8px 24px 28px; }
.app.mode-chat .composer input { background: var(--surface); border-radius: 26px; padding: 14px 20px; font-size: 15px; box-shadow: var(--shadow-sm); }
.app.mode-chat .icon-btn.send { width: 48px; height: 48px; }

/* ============ Botão flutuante (FAB) ============ */
.fab {
  position: fixed; bottom: 22px; right: 22px; z-index: 60;
  display: inline-flex; align-items: center; gap: 9px; padding: 13px 20px;
  border: none; border-radius: 999px; background: var(--accent); color: #fff;
  font-family: inherit; font-size: 14px; font-weight: 650; cursor: pointer;
  box-shadow: 0 10px 26px -8px rgba(0,0,0,.55); transition: background .15s, transform .15s;
}
.fab:hover { background: var(--accent-strong); transform: translateY(-2px); }
.fab svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* No dashboard com o dock aberto (desktop), posiciona o FAB à esquerda do dock */
@media (min-width: 1181px) { .app.mode-dash:not(.chat-hidden) .fab { right: calc(var(--chat-w) + 22px); } }

/* ============ Responsivo ============ */
.scrim { display: none; }
@media (max-width: 1180px) {
  .app.mode-dash, .app.mode-dash.chat-hidden { grid-template-columns: var(--sidebar-w) 1fr; }
  .app.mode-dash .chatdock { position: fixed; right: 0; top: 0; bottom: 0; width: min(var(--chat-w), 92vw); z-index: 40; box-shadow: var(--shadow); transform: translateX(100%); }
  .app.mode-dash:not(.chat-hidden) .chatdock { transform: none; }
}
@media (max-width: 820px) {
  .app.mode-dash, .app.mode-dash.chat-hidden { grid-template-columns: 1fr; }
  .app.mode-dash .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); z-index: 50; transform: translateX(-100%); transition: transform .25s; }
  .app.mode-dash.nav-open .sidebar { transform: none; }
  .app.mode-dash.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 45; }
  .menu-btn { display: grid; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 18px 16px; }
  .fab { bottom: 16px; right: 16px; }
}
