:root {
  --bg: #0a0d14;
  --bg-2: #0e121c;
  --panel: rgba(22, 27, 40, 0.72);
  --panel-solid: #141926;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e7ecf5;
  --muted: #8b95a9;
  --faint: #5c6577;
  --accent: #5eead4;
  --accent-2: #818cf8;
  --accent-3: #f472b6;
  --amber: #fbbf24;
  --red: #f87171;
  --green: #34d399;
  --karbon: #6366f1;
  --ghl: #22d3ee;
  --quickbooks: #34d399;
  --stripe: #a78bfa;
  --other: #94a3b8;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 40px -12px rgba(0, 0, 0, 0.6);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Ambient background glow */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(720px circle at 12% -8%, rgba(99, 102, 241, 0.16), transparent 55%),
    radial-gradient(680px circle at 100% 0%, rgba(45, 212, 191, 0.12), transparent 50%),
    radial-gradient(900px circle at 60% 120%, rgba(129, 140, 248, 0.10), transparent 55%);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* ── Login ─────────────────────────────────────────────── */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  position: relative; z-index: 1;
  width: 360px; padding: 40px 32px;
  background: var(--panel); backdrop-filter: blur(20px);
  border: 1px solid var(--border-strong); border-radius: 22px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-badge {
  width: 54px; height: 54px; margin: 0 auto 6px;
  display: grid; place-items: center; font-size: 22px;
  border-radius: 16px; color: #04110d;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 30px -6px rgba(94, 234, 212, 0.5);
}
.login-card h1 { font-size: 22px; font-weight: 700; }
.login-card input, .login-card button {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  font-family: var(--font); font-size: 14px;
}
.login-card input {
  background: rgba(0,0,0,0.3); border: 1px solid var(--border-strong); color: var(--text);
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
  border: none; cursor: pointer; font-weight: 600; color: #04110d;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transition: transform .1s, filter .2s;
}
.login-card button:hover { filter: brightness(1.08); }
.login-card button:active { transform: scale(.98); }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ── App shell ─────────────────────────────────────────── */
.app { position: relative; z-index: 1; display: grid; grid-template-columns: 232px 1fr; height: 100vh; }

.sidebar {
  display: flex; flex-direction: column; padding: 22px 16px;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand-mark {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px;
  font-size: 15px; color: #04110d;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.brand-text { font-weight: 800; letter-spacing: .5px; font-size: 16px; }
.brand-text b { color: var(--accent); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border: none; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer;
  font-family: var(--font); font-size: 13.5px; font-weight: 500; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item i { font-style: normal; width: 18px; text-align: center; font-size: 15px; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active {
  background: rgba(129, 140, 248, 0.14); color: #fff;
  box-shadow: inset 0 0 0 1px rgba(129,140,248,0.25);
}
.nav-item.active i { opacity: 1; }

.sidebar-foot { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; }
.live { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
/* Dot reflects real SSE state: dim when disconnected, green + pulsing when the
   live stream is connected. */
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: none; transition: background .3s ease; }
.live.connected .dot { background: var(--green); box-shadow: 0 0 0 0 rgba(52,211,153,.6); animation: pulse 2s infinite; }
.live.connected { color: var(--green); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,.5);} 70% { box-shadow: 0 0 0 8px rgba(52,211,153,0);} 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0);} }
.ghost-btn { padding: 9px; border: 1px solid var(--border); border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; font-family: var(--font); font-size: 13px; }
.ghost-btn:hover { border-color: var(--border-strong); color: var(--text); }

.main { overflow: hidden; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 28px 16px; border-bottom: 1px solid var(--border);
}
.topbar h2 { font-size: 20px; font-weight: 700; }
.topbar-controls { display: flex; align-items: center; gap: 12px; }
.segmented { display: flex; background: rgba(0,0,0,0.25); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.segmented button {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  padding: 6px 12px; border-radius: 7px; font-family: var(--font); font-size: 12.5px; font-weight: 600;
}
.segmented button.active { background: rgba(255,255,255,0.08); color: #fff; }
.icon-btn { width: 38px; height: 36px; border: 1px solid var(--border); border-radius: 10px; background: rgba(0,0,0,0.2); color: var(--muted); cursor: pointer; font-size: 16px; }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

.view { flex: 1; overflow-y: auto; padding: 24px 28px 60px; }

/* ── Cards & grid ──────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 20px; }
.card {
  background: var(--panel); backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; position: relative; overflow: hidden;
}
.card.pad-lg { padding: 22px 24px; }
.kpi .kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.kpi .kpi-value { font-size: 30px; font-weight: 800; margin-top: 8px; letter-spacing: -1px; }
.kpi .kpi-sub { font-size: 12.5px; color: var(--faint); margin-top: 6px; }
.kpi .kpi-value.small { font-size: 22px; }
.kpi-accent { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.kpi-accent.warn { background: linear-gradient(90deg, var(--amber), var(--red)); }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 26px 2px 12px; }
.two-col { grid-template-columns: 1.6fr 1fr; }
.chart { width: 100%; height: 280px; }
.chart.sm { height: 220px; }

/* ── Flow map ──────────────────────────────────────────── */
.flow-wrap { padding: 8px; }
.flow-svg { width: 100%; height: 460px; display: block; }
/* stroke-width + stroke-opacity are set per-edge inline (volume-weighted), so
   this rule must NOT hardcode them. */
.flow-edge { fill: none; transition: stroke-width .35s ease, stroke-opacity .35s ease; }
.flow-edge.err { filter: drop-shadow(0 0 6px var(--red)); }
.flow-edge-hit { stroke-opacity: 1 !important; }
.flow-flow { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 2 14; animation: dash 1.2s linear infinite; opacity: .7; }
@keyframes dash { to { stroke-dashoffset: -16; } }
.flow-pulse-dot { filter: drop-shadow(0 0 6px rgba(255,255,255,.55)); }
.flow-node rect { filter: drop-shadow(0 8px 22px rgba(0,0,0,.5)); transition: stroke .3s ease; }
.flow-node.has-error rect { stroke: var(--red) !important; filter: drop-shadow(0 0 12px rgba(248,113,113,.55)); }
.flow-node text { font-family: var(--font); }
.flow-badge { font-family: var(--mono); font-size: 11px; }
.flow-ticker { font-family: var(--mono); font-size: 10.5px; opacity: .85; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 14px; padding: 0 6px; }
.legend span { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.legend i { width: 11px; height: 11px; border-radius: 3px; }

/* ── Tables / feeds ────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; padding: 12px 14px; color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel-solid); }
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 380px; overflow: hidden; text-overflow: ellipsis; }
table.data tr:hover td { background: rgba(255,255,255,0.02); }
table.data tr.clickable { cursor: pointer; }
.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .3px; }
.badge.karbon { background: rgba(99,102,241,.16); color: #a5b4fc; }
.badge.ghl { background: rgba(34,211,238,.16); color: #67e8f9; }
.badge.quickbooks { background: rgba(52,211,153,.16); color: #6ee7b7; }
.badge.stripe { background: rgba(167,139,250,.16); color: #c4b5fd; }
.badge.other { background: rgba(148,163,184,.16); color: #cbd5e1; }
.badge.ok { background: rgba(52,211,153,.15); color: #6ee7b7; }
.badge.err { background: rgba(248,113,113,.16); color: #fca5a5; }
.badge.method { background: rgba(255,255,255,.06); color: var(--muted); font-family: var(--mono); }

.chips { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: rgba(0,0,0,.2); color: var(--muted); cursor: pointer; font-size: 12.5px; font-weight: 500; }
.chip.active { border-color: var(--accent); color: var(--text); background: rgba(94,234,212,.08); }

.pipeline-grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stage-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.stage-row:last-child { border-bottom: none; }
.stage-bar { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--accent-2), var(--accent-3)); margin-top: 5px; }
.stage-name { font-size: 13px; }
.stage-count { font-family: var(--mono); font-weight: 600; color: var(--text); }

.empty { text-align: center; color: var(--faint); padding: 60px 20px; font-size: 14px; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Drawer ────────────────────────────────────────────── */
.drawer { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.5); backdrop-filter: blur(2px); display: flex; justify-content: flex-end; }
.drawer-inner { width: min(620px, 92vw); height: 100%; background: var(--panel-solid); border-left: 1px solid var(--border-strong); padding: 22px; overflow-y: auto; box-shadow: -20px 0 60px -20px rgba(0,0,0,.7); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.drawer-head h3 { font-size: 16px; }
.code { font-family: var(--mono); font-size: 12px; line-height: 1.65; color: #c7d2e5; background: #0a0e17; border: 1px solid var(--border); border-radius: 12px; padding: 16px; white-space: pre-wrap; word-break: break-word; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.15); }

/* ── Accounts / Transactions / Settings additions ─────────────────────────── */
.ok-text { color: var(--green); }
.err-text { color: var(--red); }

.acct-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  font-family: var(--font); font-size: 13px; font-weight: 600; color: var(--text);
  background: rgba(255,255,255,0.05); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 14px; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { background: rgba(255,255,255,0.1); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.send { border-color: rgba(94,234,212,0.5); color: var(--accent); }
.btn.send:hover { background: rgba(94,234,212,0.12); }
.btn.ghost { color: var(--muted); background: transparent; }

.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 16px 0; border-top: 1px solid var(--border);
}
.setting-row:first-of-type { border-top: none; }
.setting-label { font-weight: 600; font-size: 15px; margin-bottom: 3px; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer; background: rgba(255,255,255,0.12);
  border-radius: 26px; transition: background .2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }
