/* ============================================================================
   Financial AIdvisor — design system
   Vibrant-fintech look, light + dark themes, left navigation rail.
   All colors flow through CSS variables so both themes share one stylesheet.
   ========================================================================== */

/* ---- Design tokens: light (default) --------------------------------------- */
:root {
  color-scheme: light;

  /* surfaces & background */
  --bg: #eef1f8;
  --bg-grad: radial-gradient(1200px 600px at 110% -10%, #e7e9ff 0%, rgba(231,233,255,0) 55%),
             radial-gradient(900px 500px at -10% 0%, #e3f6f8 0%, rgba(227,246,248,0) 50%),
             #eef1f8;
  --panel: #ffffff;
  --panel-soft: #f3f5fb;
  --panel-strong: #eceffa;
  --rail: rgba(255, 255, 255, 0.72);
  --rail-border: #e4e7f2;

  /* text */
  --text: #0d1322;
  --text-soft: #3a4253;
  --muted: #636b7b;

  /* lines */
  --line: #e6e9f2;
  --line-strong: #d2d7e4;

  /* brand accent (indigo → violet) */
  --accent: #5b5bf0;
  --accent-strong: #4a44d6;
  --accent-soft: #ecebff;
  --accent-contrast: #ffffff;
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --accent-grad-soft: linear-gradient(135deg, rgba(99,102,241,0.14), rgba(139,92,246,0.14));
  --accent2: #0891b2;
  --accent2-soft: #e0f7fb;

  /* semantic */
  --ok: #0a8f5f;
  --ok-soft: #e6f8f0;
  --warn: #b06a00;
  --warn-soft: #fff3e0;
  --danger: #d92d3c;
  --danger-soft: #ffecec;
  --user: #2563eb;
  --user-soft: #eef4ff;

  /* data-viz palette (shared across themes) */
  --c1: #6366f1;
  --c2: #06b6d4;
  --c3: #10b981;
  --c4: #f59e0b;
  --c5: #f43f5e;
  --c6: #8b5cf6;
  --c7: #ec4899;
  --c8: #14b8a6;

  /* shadows */
  --shadow-xs: 0 1px 2px rgba(13, 19, 34, 0.05);
  --shadow-sm: 0 1px 3px rgba(13, 19, 34, 0.07), 0 1px 2px rgba(13, 19, 34, 0.04);
  --shadow-md: 0 6px 18px rgba(13, 19, 34, 0.08), 0 2px 6px rgba(13, 19, 34, 0.04);
  --shadow-lg: 0 24px 50px rgba(13, 19, 34, 0.16);
  --shadow-raised: 0 12px 30px rgba(13, 19, 34, 0.18);
  --accent-shadow: 0 10px 24px rgba(99, 102, 241, 0.30);

  /* radii */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  /* layout */
  --rail-w: 268px;

  --fz-num: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
}

/* ---- Design tokens: dark -------------------------------------------------- */
[data-theme="dark"] {
  color-scheme: dark;

  --bg: #090b11;
  --bg-grad: radial-gradient(1100px 600px at 110% -10%, rgba(124,92,246,0.16) 0%, rgba(124,92,246,0) 55%),
             radial-gradient(900px 500px at -10% 0%, rgba(6,182,212,0.12) 0%, rgba(6,182,212,0) 50%),
             #090b11;
  --panel: #161a24;
  --panel-soft: #1c2130;
  --panel-strong: #272d3d;
  --rail: rgba(18, 21, 29, 0.72);
  --rail-border: #232734;

  --text: #eef1f8;
  --text-soft: #c4cad6;
  --muted: #8b94a6;

  --line: #262b38;
  --line-strong: #38404f;

  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.16);
  --accent-contrast: #0b0d14;
  --accent-grad: linear-gradient(135deg, #6d7bff 0%, #a472ff 100%);
  --accent-grad-soft: linear-gradient(135deg, rgba(129,140,248,0.20), rgba(164,114,255,0.20));
  --accent2: #22d3ee;
  --accent2-soft: rgba(34, 211, 238, 0.15);

  --ok: #34d399;
  --ok-soft: rgba(16, 185, 129, 0.15);
  --warn: #fbbf24;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --danger: #fb7185;
  --danger-soft: rgba(244, 63, 94, 0.16);
  --user: #93b4ff;
  --user-soft: rgba(59, 130, 246, 0.16);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 28px 60px rgba(0, 0, 0, 0.65);
  --shadow-raised: 0 16px 40px rgba(0, 0, 0, 0.6);
  --accent-shadow: 0 12px 28px rgba(99, 102, 241, 0.45);
}

/* ---- Reset & base --------------------------------------------------------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font: 14.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--accent-soft); color: var(--text); }
a { color: var(--accent); }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }

h1, h2, h3, h4 { color: var(--text); }

/* ---- Buttons & inputs (base) ---------------------------------------------- */
button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  min-height: 38px;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.06s ease, box-shadow 0.15s ease;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:disabled:hover { border-color: var(--line); color: var(--text); transform: none; }
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--accent-shadow);
}
button.primary:hover { filter: brightness(1.06); color: #fff; border-color: transparent; }
button.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
button.danger:hover { background: var(--danger-soft); color: var(--danger); }
button.link-button {
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 4px 2px;
  min-height: 0;
  box-shadow: none;
}
button.link-button:hover { color: var(--accent-strong); border-color: transparent; }

input, textarea, select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: var(--panel);
  color: var(--text);
  min-height: 38px;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ============================================================================
   App shell — navigation rail + main column
   ========================================================================== */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---- Navigation rail ------------------------------------------------------ */
.nav-rail {
  flex: 0 0 var(--rail-w);
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--rail);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-right: 1px solid var(--rail-border);
  z-index: 60;
}
.nav-rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 14px 12px;
}
.brand { display: flex; gap: 11px; align-items: center; min-width: 0; }
.brand > div { min-width: 0; }
.logo {
  width: 34px; height: 34px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--accent-shadow);
  flex: 0 0 auto;
}
.logo svg { width: 100%; height: 100%; display: block; border-radius: 11px; }
.brand-name {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-name .brand-accent {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-tag { color: var(--muted); font-size: 11px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* theme toggle */
.theme-toggle {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  min-height: 36px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text-soft);
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* nav scroll area */
.nav-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-group { margin-top: 12px; }
.nav-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: 4px 12px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  border-radius: 11px;
  padding: 9px 12px;
  min-height: 40px;
  font-size: 14px;
  font-weight: 600;
  position: relative;
}
.nav-item .nav-ico {
  flex: 0 0 auto;
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.nav-item .nav-ico svg { width: 18px; height: 18px; display: block; }
.nav-item:hover { background: var(--panel-soft); color: var(--text); border-color: transparent; }
.nav-item:hover .nav-ico { color: var(--text-soft); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.nav-item.active .nav-ico { color: var(--accent); }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -10px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent-grad);
}
.nav-item .nav-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: var(--panel-strong);
  border-radius: 99px;
  padding: 1px 7px;
}

/* primary AI entry */
.nav-item.nav-ai {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: var(--accent-shadow);
  font-weight: 700;
  margin: 2px 2px 4px;
}
.nav-item.nav-ai .nav-ico { color: #fff; }
.nav-item.nav-ai:hover { filter: brightness(1.06); color: #fff; }
.nav-item.nav-ai.active::before { display: none; }

/* rail footer / profile */
.nav-rail-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--rail-border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.account-status {
  color: var(--muted);
  font-size: 12.5px;
  overflow-wrap: anywhere;
  padding: 2px 4px;
}
.account-status.ok { color: var(--ok); }
.account-status.error { color: var(--danger); }
.account-form { display: flex; flex-direction: column; gap: 8px; }
.account-form input { width: 100%; }
.account-form .account-form-row { display: flex; gap: 8px; }
.account-form .account-form-row button { flex: 1 1 auto; }
.account-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.account-actions button {
  flex: 1 1 auto;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12.5px;
  border-radius: 9px;
}
.label-short { display: none; }

/* ---- Main column ---------------------------------------------------------- */
.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* mobile top bar (hidden on desktop) */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--rail);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
}
.icon-btn {
  width: 40px; height: 40px;
  min-height: 40px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  font-size: 18px;
}
.mobile-topbar .brand-mini {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.02em;
  margin-right: auto;
}
.mobile-topbar .brand-mini .brand-accent {
  background: var(--accent-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ---- Panels --------------------------------------------------------------- */
.tab-panel { display: none; flex-direction: column; min-height: 0; }
.tab-panel.active { display: flex; }
.tab-panel:not(#aiPanel) {
  max-width: 1180px;
  width: 100%;
  margin: 22px auto;
  padding: 0 24px;
  flex: 0 0 auto;
  animation: panel-in 0.22s ease;
}
@keyframes panel-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* AI panel fills the content area; chat scrolls internally */
#aiPanel {
  flex: 1 1 auto;
  height: 100%;
  flex-direction: row;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.panel-head h2 {
  font-size: 22px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
}
.panel-subhead {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 22px 0 10px;
}
.panel-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-hint {
  color: var(--muted);
  font-size: 13.5px;
  margin: 0 0 16px;
  line-height: 1.5;
  max-width: 760px;
}

.horizon-picker {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  flex-wrap: wrap;
}
.horizon-picker button {
  min-height: 32px;
  padding: 5px 12px;
  font-size: 12.5px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.horizon-picker button:hover { color: var(--text); background: var(--panel); }
.horizon-picker button.active {
  background: var(--panel);
  color: var(--accent-strong);
  box-shadow: var(--shadow-xs);
}
[data-theme="dark"] .horizon-picker button.active { background: var(--panel-strong); }

.empty { color: var(--muted); font-style: italic; margin: 0; font-size: 13.5px; }
/* When an empty note is the sole content of a panel list, present it as a
   proper centered empty-state card (chat sidebar keeps its compact style). */
[data-tab-panel]:not(#aiPanel) .empty:only-child {
  display: block;
  font-style: normal;
  text-align: center;
  max-width: 460px;
  margin: 8px auto;
  padding: 40px 28px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.card-link {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-soft);
  font-size: 12.5px;
  padding: 5px 12px;
  min-height: 34px;
  border-radius: 9px;
  text-decoration: none;
  font-weight: 600;
}
.card-link:hover { color: var(--accent); border-color: var(--accent); }

/* generic surface card used across sections */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ============================================================================
   AI panel — conversation list + chat
   ========================================================================== */
.chat-sidebar {
  flex: 0 0 256px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel-soft);
  min-height: 0;
}
.chat-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
  gap: 8px;
}
.chat-sidebar-head strong {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 700;
}
.chat-sidebar-head button {
  padding: 6px 12px;
  min-height: 32px;
  font-size: 12.5px;
  font-weight: 700;
  border-radius: 10px;
  background: var(--accent-grad);
  color: #fff;
  border: none;
  box-shadow: var(--accent-shadow);
}
.chat-sidebar-head button:hover { filter: brightness(1.06); color: #fff; border-color: transparent; }
.chat-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px 12px;
  overflow-y: auto;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-list .empty { color: var(--muted); font-size: 12.5px; padding: 12px 8px; }
.chat-list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.chat-list-item:hover { background: var(--panel); border-color: var(--line); }
.chat-list-item.active {
  background: var(--panel);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.chat-list-item .title {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.chat-list-item.active .title { color: var(--accent-strong); }
.chat-list-item .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.chat-list-item .actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.1s ease; }
.chat-list-item:hover .actions,
.chat-list-item.active .actions { opacity: 1; }
.chat-list-item .actions button {
  background: transparent;
  border: none;
  padding: 3px 6px;
  min-height: 26px;
  font-size: 12px;
  color: var(--muted);
  border-radius: 6px;
}
.chat-list-item .actions button:hover { background: var(--panel-strong); color: var(--accent); border-color: transparent; }

.chat-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}
.ai-toolbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
  padding: 12px max(20px, calc((100% - 860px) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.ai-toolbar #toggleSidebarButton {
  display: none;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  min-height: 34px;
  border-radius: 9px;
}
.chat-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
  letter-spacing: -0.01em;
}

.onboarding {
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
  padding: 14px max(20px, calc((100% - 860px) / 2));
}
.onboarding-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.onboarding-head strong { display: block; font-size: 14.5px; }
.onboarding-head span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.onboarding-form {
  display: grid;
  grid-template-columns: minmax(150px, 1.4fr) repeat(4, minmax(92px, 1fr)) auto;
  gap: 8px;
  align-items: end;
}
.onboarding-form label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.onboarding-form span { color: var(--muted); font-size: 12px; font-weight: 600; }
.onboarding-form input { width: 100%; }

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 28px max(24px, calc((100% - 820px) / 2));
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 200px;
}
.chat-message {
  border-radius: var(--radius-lg);
  padding: 2px 0;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.65;
  animation: msg-in 0.24s ease;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.chat-message.system {
  background: var(--accent-grad-soft);
  color: var(--text-soft);
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  align-self: stretch;
}
.chat-message.assistant {
  background: transparent;
  color: var(--text);
  align-self: stretch;
  padding: 2px 0;
}
.chat-message.user {
  background: var(--accent-grad);
  color: #fff;
  align-self: flex-end;
  border: none;
  box-shadow: var(--accent-shadow);
  max-width: 80%;
  padding: 13px 17px;
}
.chat-message.user a { color: #eef0ff; }
.chat-message.error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  align-self: stretch;
  max-width: 100%;
  padding: 14px 18px;
}
.chat-body p { margin: 0; }
.chat-body p + p,
.chat-body p + ul,
.chat-body p + ol,
.chat-body p + pre,
.chat-body p + blockquote,
.chat-body p + .md-table-wrap,
.chat-body ul + p,
.chat-body ol + p,
.chat-body pre + p,
.chat-body .md-table-wrap + p { margin-top: 10px; }
.chat-message code {
  background: var(--panel-strong);
  padding: 1.5px 6px;
  border-radius: 5px;
  font-size: 0.88em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.chat-message.user code { background: rgba(255, 255, 255, 0.20); }
.chat-message pre {
  margin: 0;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13px;
}
.chat-message.user pre { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.25); }
.chat-message pre code { background: transparent; padding: 0; font-size: inherit; }
.chat-message hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.chat-message ul, .chat-message ol { margin: 0; padding-left: 22px; }
.chat-message li + li { margin-top: 4px; }
.chat-message blockquote {
  margin: 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text-soft);
  border-radius: 0 8px 8px 0;
  font-size: 0.96em;
}
.chat-message.user blockquote {
  border-left-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.md-table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); }
.chat-message.user .md-table-wrap { border-color: rgba(255, 255, 255, 0.25); }
.md-table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--panel); }
.chat-message.user .md-table { background: rgba(255, 255, 255, 0.04); color: #fff; }
.md-table th, .md-table td { padding: 9px 13px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.md-table th {
  font-weight: 700;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.chat-message.user .md-table th { background: rgba(255, 255, 255, 0.12); color: #fff; }
.md-table tbody tr:last-child td { border-bottom: none; }
.md-table tbody tr:hover td { background: var(--panel-soft); }
.chat-message.user .md-table tbody tr:hover td { background: rgba(255, 255, 255, 0.06); }

/* markdown: headings, task lists, code blocks, strikethrough */
.chat-body .md-h { margin: 16px 0 7px; line-height: 1.3; font-weight: 800; letter-spacing: -0.01em; }
.chat-body .md-h:first-child { margin-top: 0; }
.chat-body .md-h1 { font-size: 1.28em; }
.chat-body .md-h2 { font-size: 1.14em; }
.chat-body .md-h3 { font-size: 1.02em; color: var(--text-soft); }
.chat-message del { opacity: 0.65; }
.chat-message li.md-task { list-style: none; margin-left: -20px; display: flex; align-items: flex-start; gap: 8px; }
.chat-message li.md-task input { margin: 3px 0 0; accent-color: var(--accent); width: 15px; height: 15px; flex: 0 0 auto; }
.md-code { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel-strong); }
.md-code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 6px 12px;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
}
.md-code-lang { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.md-copy {
  font-size: 11.5px; font-weight: 600; padding: 3px 10px; min-height: 26px;
  border-radius: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--text-soft);
}
.md-copy:hover { color: var(--accent); border-color: var(--accent); }
.md-copy.ok { color: var(--ok); border-color: var(--ok); }
.md-code pre { border: none; border-radius: 0; margin: 0; background: transparent; }
.chat-message.user .md-code { border-color: rgba(255, 255, 255, 0.22); background: rgba(255, 255, 255, 0.10); }
.chat-message.user .md-code-head { background: rgba(255, 255, 255, 0.10); border-color: rgba(255, 255, 255, 0.22); }
.chat-message.user .md-code-lang { color: rgba(255, 255, 255, 0.8); }
.chat-message.user .md-copy { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.25); color: #fff; }

.chat-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px max(20px, calc((100% - 820px) / 2)) 22px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  align-items: end;
}
.quick-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.quick-actions .quick-chip {
  flex: 0 0 auto;
  font-size: 12.5px;
  min-height: 30px;
  padding: 5px 13px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  font-weight: 600;
  color: var(--text-soft);
  border-radius: 99px;
}
.quick-actions .quick-chip:hover { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }
.chat-input textarea {
  resize: none;
  min-height: 52px;
  max-height: 240px;
  padding: 14px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.chat-input textarea:focus { background: var(--panel); border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-input > button[type="submit"] {
  align-self: end;
  padding: 0 20px;
  min-height: 52px;
  border-radius: 16px;
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
  box-shadow: var(--accent-shadow);
}
.chat-input > button[type="submit"]:hover { filter: brightness(1.06); color: #fff; border-color: transparent; }
.chat-input > button[type="submit"]:disabled { background: var(--panel-strong); color: var(--muted); box-shadow: none; }

/* assistant "thinking" indicator */
.chat-thinking { display: inline-flex; align-items: center; gap: 5px; padding: 8px 0; }
.chat-thinking span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: think 1.2s infinite ease-in-out;
}
.chat-thinking span:nth-child(2) { animation-delay: 0.2s; }
.chat-thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes think { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.msg-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.chat-message.user .msg-foot { justify-content: flex-end; }
.msg-time { font-size: 11px; color: var(--muted); }
.chat-message.user .msg-time { color: rgba(255, 255, 255, 0.78); }
.msg-copy {
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; min-height: 26px;
  border-radius: 7px; border: 1px solid var(--line); background: transparent; color: var(--muted);
  opacity: 0; transition: opacity 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.chat-message:hover .msg-copy, .msg-copy:focus-visible { opacity: 1; }
.msg-copy:hover { color: var(--accent); border-color: var(--accent); }
.msg-copy.ok { color: var(--ok); border-color: var(--ok); opacity: 1; }

.tool-trace {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: baseline;
}
.chat-message.user .tool-trace { border-color: rgba(255, 255, 255, 0.3); color: rgba(255, 255, 255, 0.85); }
.tool-trace code { background: var(--panel-soft); padding: 1px 6px; border-radius: 5px; font-size: 11px; }
.chat-message.user .tool-trace code { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* ============================================================================
   Shared rows
   ========================================================================== */
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14.5px;
}
.row:last-child { border-bottom: none; }
.row-main { min-width: 0; }
.row-main strong { font-weight: 600; display: block; overflow-wrap: anywhere; }
.row-main small { color: var(--muted); display: block; }
.row-amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.row-amount.negative { color: var(--warn); }
.row-amount.positive { color: var(--ok); }
.row-amount.neutral { color: var(--muted); }
.source-badge {
  justify-self: end;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 2px 9px;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.row.derived-row .row-main strong { color: var(--text-soft); }
.row-delete, .row-reconcile {
  min-height: 30px; min-width: 30px;
  padding: 0 9px;
  font-weight: 700;
  color: var(--muted);
  border-radius: 99px;
  border-color: transparent;
  background: transparent;
}
.row-delete:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.row-reconcile:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.account-row { grid-template-columns: minmax(0, 1fr) auto auto auto; }
.row.forecast-row { grid-template-columns: 1fr auto; }
.row.forecast-row.warn { color: var(--warn); }
.row.forecast-explain-row {
  margin-top: 8px;
  color: var(--muted);
  background: var(--panel-soft);
  border-radius: 8px;
  padding-left: 10px;
  padding-right: 10px;
}
.row.history-row { grid-template-columns: minmax(0, 1fr) auto; }
.warnings-list { margin-top: 8px; }
.row.forecast-row.warnings-more { color: var(--muted); font-size: 13px; opacity: 0.85; }
.row.forecast-row.warnings-more strong { display: none; }

/* card-style list container */
.list-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 6px 16px;
}

/* ============================================================================
   Dashboard (Обзор) — full charts arrive in a later phase
   ========================================================================== */
.dash {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.dash-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  min-width: 0;
}
.dash-card.span-2 { grid-column: span 2; }
.dash-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.dash-card-head h3 { font-size: 14px; font-weight: 700; margin: 0; }
.dash-card-head .dash-sub { font-size: 12px; color: var(--muted); }
.dash-hero {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  box-shadow: var(--accent-shadow);
}
.dash-hero .dash-hero-label { font-size: 12.5px; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.05em; }
.dash-hero .dash-hero-value { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 6px; }
.dash-hero .dash-hero-sub { font-size: 13px; opacity: 0.9; margin-top: 8px; }
.dash-hero-spark { margin-top: 14px; }
.dash-hero-spark .spark { height: 38px; opacity: 0.9; }

.dash-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-top: 16px; }
.dash-card.full { grid-column: 1 / -1; }

.dash-goals { display: flex; flex-wrap: wrap; gap: 18px; }
.dash-goal { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 92px; }
.dash-goal-name { font-size: 12px; color: var(--text-soft); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.dash-acts { display: flex; flex-direction: column; }
.dash-act { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.dash-act:last-child { border-bottom: none; }
.dash-act-main { min-width: 0; }
.dash-act-main strong { display: block; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-act-main small { color: var(--muted); font-size: 12px; }

/* ---- chart toolkit (charts.js) ---- */
.chart-empty { color: var(--muted); font-style: italic; font-size: 13px; padding: 28px 0; text-align: center; }
.chart-donut { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut-wrap { position: relative; flex: 0 0 auto; }
.donut-wrap svg { width: 100%; height: 100%; display: block; }
.donut-seg { transition: opacity 0.12s ease; }
.chart-donut:hover .donut-seg { opacity: 0.4; }
.chart-donut .donut-seg:hover { opacity: 1; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-center-value { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.donut-center-label { font-size: 11px; color: var(--muted); }
.chart-legend { display: flex; flex-direction: column; gap: 7px; flex: 1 1 150px; min-width: 0; font-size: 12.5px; }
.chart-leg { display: flex; align-items: center; gap: 8px; color: var(--text-soft); }
.chart-leg i { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.chart-leg-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-leg b { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.chart-bars { max-width: 640px; }
.chart-bars svg { width: 100%; height: auto; display: block; }
.chart-bars .bar { transition: opacity 0.12s ease; }
.chart-bars:hover .bar { opacity: 0.5; }
.chart-bars .bar:hover { opacity: 1; }
.chart-bars .chart-axis { fill: var(--muted); font-size: 11px; }
.chart-bars .chart-baseline { stroke: var(--line); stroke-width: 1; }
.chart-bars .chart-legend { flex-direction: row; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.ring { display: block; }
.ring .ring-label { fill: var(--text); font-size: 15px; font-weight: 700; }
.spark { width: 100%; height: 34px; display: block; }
.spark-area { opacity: 0.14; }
.chart-tip {
  position: fixed; z-index: 2000; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 6px 10px; border-radius: 9px; font-size: 12px; font-weight: 600;
  box-shadow: var(--shadow-md); max-width: 240px;
}
.chart-tip b { font-weight: 800; }

/* ---- skeleton loaders ---- */
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skel-list { display: flex; flex-direction: column; gap: 12px; }
.skeleton {
  background: linear-gradient(90deg, var(--panel-soft) 25%, var(--panel-strong) 50%, var(--panel-soft) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.3s linear infinite;
  border-radius: var(--radius);
}
.skel-row { height: 58px; }
.skel-card { height: 120px; border-radius: var(--radius-lg); }

/* ============================================================================
   Dashboard v2 — bento, insight strip, KPI deltas, number typography, motion
   ========================================================================== */

/* number typography — currency mark de-emphasised, tabular figures */
.cur { color: var(--muted); font-weight: 600; font-size: 0.62em; margin-left: 0.14em; }
.dash-hero .cur { color: rgba(255, 255, 255, 0.72); }
.kpi-value, .dash-hero-value, .hsum-cell strong, .donut-center-value, .dash-single-val { font-variant-numeric: tabular-nums; }

/* insight strip */
.dash-insight {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 18px; border-radius: var(--radius-lg);
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.dash-insight-ic { flex: 0 0 auto; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.dash-insight-ic svg { width: 22px; height: 22px; }
.dash-insight-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.dash-insight-hi { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.dash-insight-txt strong { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.dash-insight.tone-ok .dash-insight-ic { background: var(--accent2-soft); color: var(--accent2); }
.dash-insight.tone-warn .dash-insight-ic { background: var(--warn-soft); color: var(--warn); }
.dash-insight.tone-bad .dash-insight-ic { background: var(--danger-soft); color: var(--danger); }

/* bento top: hero + 2x2 KPI grid, equal heights */
.dash-top { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; align-items: stretch; }
.dash-top .dash-hero { display: flex; flex-direction: column; justify-content: center; }
.dash-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dash-kpis .kpi-card { justify-content: center; }
.kpi-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.kpi-delta { font-size: 12px; font-weight: 700; white-space: nowrap; }
.kpi-delta.good { color: var(--ok); }
.kpi-delta.bad { color: var(--danger); }
.kpi-spark { margin-top: 8px; }
.kpi-spark .spark { height: 28px; opacity: 0.85; }

/* spending single-category fallback */
.dash-single { display: flex; flex-direction: column; gap: 12px; padding: 14px 0 6px; }
.dash-single-val { font-size: 28px; font-weight: 800; }
.dash-single-bar { height: 10px; border-radius: 999px; background: var(--panel-strong); overflow: hidden; }
.dash-single-bar span { display: block; height: 100%; width: 100%; background: var(--accent-grad); border-radius: 999px; }
.dash-single-hint { font-size: 13px; color: var(--muted); }

/* card depth & hover-lift */
.dash-card, .budget-card, .goal-card, .kpi-card, .hsum-cell {
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.dash-card:hover, .budget-card:hover, .goal-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.dash-card.full:hover { transform: none; box-shadow: var(--shadow-sm); }

/* settings submit on its own row, left-aligned */
.settings-form button[type="submit"] { grid-column: 1 / -1; justify-self: start; }

/* chart polish: nice gridlines, sparkline area driven by gradient */
.cf-grid { stroke: var(--line); stroke-width: 1; opacity: 0.6; }
.spark-area { opacity: 1; }

/* ---- motion ---- */
@keyframes donut-in { from { opacity: 0; transform: rotate(-14deg) scale(0.9); } to { opacity: 1; transform: none; } }
.donut-svg { animation: donut-in 0.5s ease both; transform-origin: 50% 50%; }
@keyframes bar-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.chart-bars .bar { transform-box: fill-box; transform-origin: bottom; animation: bar-grow 0.55s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes ring-in { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: none; } }
.ring { animation: ring-in 0.4s ease both; }
@keyframes card-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.dash-insight, .dash-top { animation: card-in 0.4s ease both; }
.dash-cards > .dash-card { animation: card-in 0.45s ease both; }
.dash-cards > .dash-card:nth-child(2) { animation-delay: 0.06s; }
.dash-cards > .dash-card:nth-child(3) { animation-delay: 0.12s; }
.dash-cards > .dash-card:nth-child(4) { animation-delay: 0.18s; }
.dash-cards > .dash-card:nth-child(n+5) { animation-delay: 0.22s; }

/* ============================================================================
   Forecast dashboard
   ========================================================================== */
.forecast-mode {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.forecast-mode input[type="checkbox"] { width: 16px; height: 16px; margin-top: 2px; flex: 0 0 auto; accent-color: var(--accent); }

.fc-verdict {
  padding: 14px 16px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 14.5px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.fc-verdict.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.fc-verdict.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.fc-verdict.bad { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-xs);
}
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; letter-spacing: -0.01em; }
.kpi-card.bad .kpi-value { color: var(--danger); }
.kpi-card.warn .kpi-value { color: var(--warn); }
.kpi-card.ok .kpi-value { color: var(--ok); }

.cf-chart { margin-bottom: 10px; }
.cf-chart svg { width: 100%; height: auto; display: block; }
.cf-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.cf-area { fill: var(--accent); opacity: 0.14; }
.cf-zero { stroke: var(--line-strong); stroke-width: 1; }
.cf-reserve { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 4 3; opacity: 0.75; }
.cf-danger { fill: var(--danger); opacity: 0.14; }
.cf-dot { stroke: var(--panel); stroke-width: 1; cursor: pointer; transition: stroke-width 0.1s ease; }
.cf-dot:hover { stroke-width: 2.5; }
.cf-min { cursor: pointer; }
.cf-dot.in { fill: var(--ok); }
.cf-dot.out { fill: var(--danger); }
.cf-min { fill: var(--panel); stroke: var(--accent); stroke-width: 2; }
.cf-min.bad { stroke: var(--danger); }
.cf-minlabel { fill: var(--accent-strong); font-size: 12px; font-weight: 700; paint-order: stroke; stroke: var(--panel); stroke-width: 3.5px; stroke-linejoin: round; }
.cf-minlabel.bad { fill: var(--danger); }
.cf-ylabel, .cf-xlabel { fill: var(--muted); font-size: 11px; }
.cf-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; font-size: 11.5px; color: var(--muted); }
.cf-leg { display: inline-flex; align-items: center; gap: 5px; }
.cf-leg::before { content: ""; width: 10px; height: 10px; border-radius: 50%; }
.cf-leg.line::before { border-radius: 0; width: 14px; height: 0; border-top: 2px solid var(--accent); }
.cf-leg.in::before { background: var(--ok); }
.cf-leg.out::before { background: var(--danger); }
.cf-leg.reserve::before { border-radius: 0; width: 14px; height: 0; border-top: 2px dashed var(--warn); }

.fc-period { font-size: 13.5px; color: var(--text-soft); margin: 12px 0 16px; line-height: 1.5; }
.fc-period .positive { color: var(--ok); }
.fc-period .negative { color: var(--danger); }
.fc-muted { color: var(--muted); }

.fc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.fc-block .panel-subhead { margin-top: 4px; }
.fc-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.fc-row:last-child { border-bottom: none; }
.fc-row-main { min-width: 0; }
.fc-row-main strong { display: block; font-weight: 600; font-size: 13.5px; }
.fc-row-main small { display: block; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.fc-row-amt { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.fc-row-amt.ok, .fc-row-amt.positive { color: var(--ok); }
.fc-row-amt.warn { color: var(--warn); }
.fc-row-amt.bad, .fc-row-amt.negative { color: var(--danger); }

/* ============================================================================
   Budget
   ========================================================================== */
.budget-period { font-weight: 500; color: var(--muted); font-size: 15px; margin-left: 6px; }
#budgetSummary .budget-bar-block.big {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.budget-bar-block { margin: 0; }
.budget-bar-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.budget-bar-head strong { font-size: 15px; }
.budget-pct { font-size: 13px; font-weight: 700; color: var(--ok); }
.budget-pct.warn { color: var(--warn); }
.budget-pct.over { color: var(--danger); }
.budget-pct.none { color: var(--muted); }
.budget-track { position: relative; height: 9px; border-radius: 999px; background: var(--panel-strong); margin: 10px 0 6px; overflow: hidden; }
.budget-fill { height: 100%; border-radius: 999px; background: var(--ok); transition: width 0.4s ease; }
.budget-fill.warn { background: var(--warn); }
.budget-fill.over { background: var(--danger); }
.budget-fill.none { background: var(--line-strong); }
.budget-caption { color: var(--muted); font-size: 13px; }
.budget-caption.over { color: var(--danger); font-weight: 600; }
.budget-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-xs);
}
.budget-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.budget-src { font-size: 11px; font-weight: 600; color: var(--accent-strong); background: var(--accent-soft); border-radius: 999px; padding: 2px 9px; }
.budget-src.manual { color: var(--warn); background: var(--warn-soft); }
.budget-actions .link-button { font-size: 13px; }
.budget-editor { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.budget-input { flex: 0 1 160px; padding: 8px 11px; font-size: 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--panel); }
.budget-editor .primary { padding: 8px 14px; }

.envelope-add { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.envelope-add input[type="text"] { flex: 1 1 160px; min-width: 0; }
.envelope-add input[type="date"] { flex: 0 1 170px; }

.debt-group { margin-bottom: 12px; }
.debt-group:last-child { margin-bottom: 0; }
.debt-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 8px 0 6px;
  border-bottom: 1px solid var(--line-strong);
  margin-bottom: 4px;
}

.row.document-row { grid-template-columns: minmax(0, 1fr) auto; }
.row.document-row button { flex: 0 0 auto; min-height: 34px; padding: 6px 11px; font-size: 12.5px; }

/* ============================================================================
   Settings
   ========================================================================== */
.settings-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  align-items: start;
  margin-bottom: 6px;
}
.settings-form label { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.settings-form label > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.settings-form label > small { color: var(--muted); font-size: 11.5px; }
.settings-form select { min-height: 38px; }
.settings-form button[type="submit"] { align-self: end; justify-self: start; }
.settings-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-bottom: 8px; }
.settings-actions small { color: var(--muted); margin-bottom: 8px; }

/* ============================================================================
   Goals
   ========================================================================== */
.goal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-xs);
}
.goal-row { display: flex; gap: 16px; align-items: center; }
.goal-ring { flex: 0 0 auto; }
.goal-body { flex: 1 1 auto; min-width: 0; }
.goal-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.goal-type-badge { font-size: 11px; font-weight: 600; color: var(--accent-strong); background: var(--accent-soft); border-radius: 999px; padding: 2px 9px; }
.goal-status-badge { font-size: 11px; font-weight: 600; border-radius: 999px; padding: 2px 9px; }
.goal-status-badge.achieved { color: var(--ok); background: var(--ok-soft); }
.goal-status-badge.cancelled { color: var(--muted); background: var(--panel-soft); }
.goal-meta .link-button { font-size: 13px; }

/* ============================================================================
   History
   ========================================================================== */
.history-filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 14px; }
.filter-chip {
  min-height: 32px;
  padding: 5px 15px;
  font-size: 12.5px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 600;
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }

.history-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.hsum-cell {
  display: flex; flex-direction: column; gap: 3px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}
.hsum-cell span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.hsum-cell strong { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hsum-cell strong.positive { color: var(--ok); }
.hsum-cell strong.negative { color: var(--warn); }

.history-day { margin-bottom: 16px; }
.history-day-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 8px 0; border-bottom: 2px solid var(--line-strong); margin-bottom: 2px;
}
.history-day-date { font-size: 12px; font-weight: 700; color: var(--text-soft); }
.history-day-net { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.history-day-net.positive { color: var(--ok); }
.history-day-net.negative { color: var(--warn); }

.plan-month-head {
  font-size: 12px; font-weight: 700; color: var(--accent-strong);
  padding: 14px 0 4px; border-bottom: 1px solid var(--line); margin-bottom: 2px;
}
.plan-month-head:first-child { padding-top: 0; }

/* ============================================================================
   Scenarios (what-if)
   ========================================================================== */
.scenario-layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); gap: 18px; align-items: start; }
.scenario-saved { grid-column: 1; grid-row: 1; min-width: 0; }
.scenario-builder, .scenario-placeholder { grid-column: 2; grid-row: 1; min-width: 0; }
.scenario-builder[hidden], .scenario-placeholder[hidden] { display: none; }
.scenario-saved-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.scenario-saved-head strong { font-size: 14px; }
.scenario-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.scenario-list .empty { font-size: 13px; }
.scenario-item { display: flex; align-items: stretch; gap: 4px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.scenario-item.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft) inset; }
.scenario-open {
  flex: 1 1 auto; text-align: left; border: none; background: transparent;
  padding: 11px 13px; display: flex; flex-direction: column; gap: 2px; cursor: pointer;
}
.scenario-open:hover { background: var(--panel-soft); color: inherit; border-color: transparent; }
.scenario-open strong { font-size: 14px; }
.scenario-open small { color: var(--muted); font-size: 12px; }
.scenario-item .row-delete { border: none; background: transparent; color: var(--muted); padding: 0 10px; }
.scenario-item .row-delete:hover { color: var(--danger); border-color: transparent; }
.scenario-builder {
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--panel); padding: 18px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow-sm);
}
.scenario-placeholder {
  padding: 28px; border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); background: var(--panel-soft);
}
.scenario-builder-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.scenario-name-input { flex: 1 1 200px; font-size: 15px; font-weight: 600; }
.scenario-builder-actions { display: flex; gap: 6px; }
.scenario-compare { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-soft); padding: 16px; }
.scenario-compare-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.scenario-compare-col { display: flex; flex-direction: column; gap: 4px; }
.scenario-compare-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
.scenario-compare-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 13px; }
.scenario-compare-row span { color: var(--muted); }
.scenario-compare-row strong { font-variant-numeric: tabular-nums; }
.scenario-compare-row strong.neg { color: var(--danger); }
.scenario-compare-row.delta-row { border-top: 1px dashed var(--line); padding-top: 4px; margin-top: 2px; }
.scenario-delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.scenario-delta.good { color: var(--ok); }
.scenario-delta.bad { color: var(--danger); }
.scenario-delta.flat { color: var(--muted); }
.scenario-compare-foot { display: block; margin-top: 10px; color: var(--text); font-size: 13px; line-height: 1.45; }
.scenario-chart { margin-top: 12px; }
.scenario-chart svg { width: 100%; height: 120px; display: block; overflow: visible; }
.scenario-chart path { fill: none; stroke-width: 1.8; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.scenario-chart .chart-base { stroke: var(--line-strong); stroke-dasharray: 3 3; }
.scenario-chart .chart-scen.better { stroke: var(--ok); }
.scenario-chart .chart-scen.worse { stroke: var(--danger); }
.scenario-chart .chart-scen.accent { stroke: var(--accent); }
.scenario-chart .chart-zero { stroke: var(--line-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.scenario-chart .chart-reserve { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 2 3; vector-effect: non-scaling-stroke; opacity: 0.7; }
.scenario-chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 6px; font-size: 11.5px; color: var(--muted); }
.scenario-chart-legend .legend { display: inline-flex; align-items: center; gap: 5px; }
.scenario-chart-legend .legend::before { content: ""; width: 14px; height: 0; border-top: 2px solid currentColor; }
.scenario-chart-legend .legend.base { color: var(--line-strong); }
.scenario-chart-legend .legend.scen.better { color: var(--ok); }
.scenario-chart-legend .legend.scen.worse { color: var(--danger); }
.scenario-chart-legend .legend.scen.accent { color: var(--accent); }
.scenario-chart-legend .legend.reserve { color: var(--warn); }
.scenario-sections { display: flex; flex-direction: column; gap: 14px; }
.scenario-section { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.scenario-section-head { display: flex; flex-direction: column; gap: 2px; padding: 11px 14px; background: var(--panel-soft); border-bottom: 1px solid var(--line); }
.scenario-section-head strong { font-size: 14px; }
.scenario-section-head span { color: var(--muted); font-size: 12px; }
.scenario-section-body { padding: 8px 14px; display: flex; flex-direction: column; gap: 4px; }
.scenario-toggle { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.scenario-toggle:last-child { border-bottom: none; }
.scenario-toggle.is-off { opacity: 0.55; }
.scenario-toggle.is-off .scenario-toggle-main strong { text-decoration: line-through; }
.scenario-toggle-main { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; cursor: pointer; margin: 0; }
.scenario-toggle-main input[type="checkbox"] { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--accent); }
.scenario-toggle-main span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.scenario-toggle-main strong { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.scenario-toggle-main small { color: var(--muted); font-size: 12px; }
.scenario-override-input { flex: 0 0 110px; width: 110px; padding: 7px 9px; font-size: 13px; }
.scenario-override-pair { display: flex; gap: 6px; flex: 0 0 auto; }
.scenario-override-pair .scenario-override-input { flex: 0 0 96px; width: 96px; }
.scenario-added-list { display: flex; flex-direction: column; gap: 6px; }
.scenario-added-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 11px; border: 1px solid var(--accent-soft); background: var(--accent-soft); border-radius: 10px; }
.scenario-added-item span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.scenario-added-item strong { font-size: 13px; }
.scenario-added-item small { color: var(--accent-strong); font-size: 12px; }
.scenario-added-item .row-delete { border: none; background: transparent; color: var(--accent-strong); padding: 0 4px; }
.scenario-add-form { margin-top: 8px; }
.scenario-add-title { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.scenario-add-grid { display: grid; grid-template-columns: 1.4fr 0.8fr 0.8fr 0.8fr auto; gap: 6px; }
.scenario-add-grid input, .scenario-add-grid select { font-size: 13px; padding: 8px; min-width: 0; }

/* ============================================================================
   Modal dialogs
   ========================================================================== */
dialog.ui-modal {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0;
  width: min(440px, calc(100vw - 32px));
  background: var(--panel);
  color: var(--text);
}
dialog.ui-modal::backdrop { background: rgba(8, 11, 20, 0.5); backdrop-filter: blur(3px); }
.ui-modal-body { padding: 20px 22px 16px; }
.ui-modal-title { font-size: 16px; font-weight: 700; margin: 0 0 6px; }
.ui-modal-text { margin: 0 0 12px; color: var(--text-soft); font-size: 13.5px; line-height: 1.5; }
.ui-modal-input { width: 100%; margin-bottom: 4px; }
.ui-modal-error { color: var(--danger); font-size: 12.5px; min-height: 16px; margin: 2px 0 0; }
.ui-modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 14px 22px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.ui-modal-actions .spacer { flex: 1 1 auto; }

/* ============================================================================
   Toast
   ========================================================================== */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--text);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow-raised);
  z-index: 1000;
  max-width: 360px;
  font-size: 13.5px;
  font-weight: 600;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }

/* ============================================================================
   Footer
   ========================================================================== */
.app-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 1180px;
  width: 100%;
  margin: 8px auto 0;
  padding: 16px 24px 22px;
  color: var(--muted);
  font-size: 12px;
}
body.ai-active .app-footer { display: none; }
.app-footer nav { display: flex; gap: 14px; flex-wrap: wrap; }
.app-footer a { color: var(--muted); text-decoration: underline; }
.app-footer a:hover { color: var(--accent); }

/* backdrop for mobile drawers */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(8, 11, 20, 0.45); z-index: 70; }

/* ============================================================================
   Responsive
   ========================================================================== */
@media (max-width: 980px) {
  button { min-height: 44px; }
  input, textarea, select { min-height: 44px; }
  button.link-button { min-height: 44px; padding: 8px 2px; }

  .nav-rail {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 84%;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.18);
  }
  .nav-rail.open { transform: translateX(0); }
  .mobile-topbar { display: flex; }
  .main { height: 100dvh; }

  .label-full { display: none; }
  .label-short { display: inline; }

  .tab-panel:not(#aiPanel) { margin: 14px auto; padding: 0 14px; }
  .panel-head h2 { font-size: 20px; }

  /* chat conversation list becomes a drawer too */
  .chat-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 80%;
    max-width: 320px;
    z-index: 80;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.18);
  }
  .chat-sidebar.open { transform: translateX(0); }
  .ai-toolbar #toggleSidebarButton { display: inline-flex; }
  .chat-log { padding: 18px 16px; min-height: 180px; }
  .chat-message { font-size: 14.5px; }
  .chat-message.user { max-width: 92%; }
  .ai-toolbar { padding: 10px 16px; }
  .onboarding { padding: 14px 16px; }
  .onboarding-form { grid-template-columns: 1fr 1fr; }
  .onboarding-form button { grid-column: 1 / -1; }
  .chat-input { padding: 12px 16px 16px; grid-template-columns: 1fr; }
  .chat-input > button[type="submit"] { width: 100%; }
  .quick-actions { flex-wrap: nowrap; overflow-x: auto; }

  .fc-cols { grid-template-columns: 1fr; gap: 8px; }
  .scenario-layout { grid-template-columns: 1fr; }
  .scenario-saved, .scenario-builder, .scenario-placeholder { grid-column: 1; grid-row: auto; }
  .scenario-compare-grid { grid-template-columns: 1fr; gap: 10px; }
  .scenario-add-grid { grid-template-columns: 1fr 1fr; }
  .scenario-toggle { flex-wrap: wrap; }
  .scenario-override-input, .scenario-override-pair .scenario-override-input { flex: 1 1 auto; width: auto; }
  .dash-card.span-2 { grid-column: span 1; }
  .dash-top { grid-template-columns: 1fr; }

  .toast { left: 10px; right: 10px; bottom: calc(16px + env(safe-area-inset-bottom)); max-width: none; }
}

@media (max-width: 560px) {
  .history-summary { grid-template-columns: 1fr; gap: 8px; }
  .hsum-cell { flex-direction: row; justify-content: space-between; align-items: center; }
  .hsum-cell strong { font-size: 16px; }
  .onboarding-form { grid-template-columns: 1fr; }
  .kpi-value { font-size: 18px; }
  .dash-hero .dash-hero-value { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
