:root {
  --bg: #ece4d8;
  --surface: #ffffff;
  --surface-2: #fbf8f4;
  --line: #ebe4da;
  --line-soft: #f2ece3;
  --ink: #2b2620;
  --ink-2: #5c534a;
  --muted: #8d8478;
  --accent: #9a6b45;
  --accent-ink: #7d5434;
  --accent-soft: #f4ece2;
  --ok: #2e8b57; --ok-bg: #e7f3ec;
  --warn: #9a6a12; --warn-bg: #fbf1dd;
  --err: #b0392f; --err-bg: #fbeae7;
  --info: #2f6f8f; --info-bg: #e7f0f5;
  /* validated 2-series categorical (dataviz six-checks, light mode) */
  --series-1: #95571f;
  --series-2: #d9a441;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(58, 46, 32, .05), 0 2px 8px rgba(58, 46, 32, .06);
  --shadow-lift: 0 2px 4px rgba(58, 46, 32, .06), 0 6px 16px rgba(58, 46, 32, .09);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
svg { display: block; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--err); }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

button, a.btn {
  font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid transparent;
  background: var(--accent); color: #fff; padding: 8px 14px; display: inline-flex;
  align-items: center; gap: 7px; transition: background .12s, border-color .12s;
  text-decoration: none; box-sizing: border-box;
}
button:hover, a.btn:hover { background: var(--accent-ink); }
button.outline { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
button.outline:hover { background: var(--surface-2); border-color: #ddd3c6; }
button.plain { background: none; color: var(--ink-2); padding: 6px 8px; }
button.plain:hover { background: var(--accent-soft); color: var(--accent-ink); }
button.small, a.btn.small { padding: 5px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select {
  font: inherit; padding: 8px 11px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--surface); color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 32px; width: 360px; display: grid; gap: 14px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.login-card h1 span, .brand span { color: var(--accent); font-weight: 500; }
.login-card label { display: grid; gap: 5px; font-size: 13px; color: var(--ink-2); }

/* ---------- shell ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 58px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar-group { display: flex; align-items: center; gap: 9px; }
.topbar-group .label { color: var(--muted); font-size: 13px; }
.vdiv { width: 1px; height: 26px; background: var(--line); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent-ink); display: grid; place-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
}

.shell { display: grid; grid-template-columns: 216px 1fr; align-items: start; }
.sidebar {
  position: sticky; top: 58px; height: calc(100vh - 58px);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 3px;
  border-right: 1px solid var(--line); background: var(--surface);
}
.sidebar button {
  background: none; color: var(--ink-2); justify-content: flex-start;
  padding: 9px 12px; border-radius: 10px; width: 100%; font-size: 13.5px;
}
.sidebar button:hover { background: var(--surface-2); color: var(--ink); }
.sidebar button.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.sidebar button.active svg { stroke: var(--accent); }
.sidebar .sep { height: 1px; background: var(--line); margin: 9px 6px; }
.content { padding: 22px; min-height: calc(100vh - 58px); max-width: 1280px; width: 100%; margin-inline: auto; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
}
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 650; letter-spacing: -.005em; }
.card-head .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.icon-badge {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-ink); flex: none;
}
.icon-badge.g { background: var(--ok-bg); color: var(--ok); }
.icon-badge.r { background: var(--err-bg); color: var(--err); }
.icon-badge.b { background: var(--info-bg); color: var(--info); }
.icon-badge.a { background: var(--warn-bg); color: var(--warn); }

/* client header */
.client-card { padding: 16px; display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.client-card .icon-badge { width: 42px; height: 42px; border-radius: 12px; }
.client-card h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.client-card .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.client-card .spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: 20px; font-size: 11px; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; background: var(--accent-soft); color: var(--accent-ink);
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.conn-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; flex-wrap: wrap; }
.hr { height: 1px; background: var(--line-soft); }
.add-conn-form { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.add-conn-form select { flex: none; }
.add-conn-form input { flex: 1; min-width: 140px; }
.card-body label { display: grid; gap: 5px; }
.card-body label input { width: 100%; }
.pill.connected { background: var(--ok-bg); color: var(--ok); }
.pill.error, .pill.failed, .pill.rejected, .pill.overdue { background: var(--err-bg); color: var(--err); }
.pill.proposed, .pill.open, .pill.approved, .pill.partial { background: var(--warn-bg); color: var(--warn); }
.pill.applied, .pill.paid, .pill.posted, .pill.ok { background: var(--ok-bg); color: var(--ok); }
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 6px;
  font-size: 11.5px; font-weight: 600; background: var(--accent-soft); color: var(--accent-ink);
}
.tag.transaction { background: var(--info-bg); color: var(--info); }
.tag.contact { background: #eae9f5; color: #4c479b; }
.tag.account { background: var(--accent-soft); color: var(--accent-ink); }
.tag.change { background: var(--warn-bg); color: var(--warn); }
.tag.sync { background: var(--ok-bg); color: var(--ok); }
.tag.assistant { background: #e8f1ef; color: #2b6b60; }

/* stat row */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat {
  display: flex; align-items: center; gap: 11px; padding: 13px 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); color: inherit; cursor: pointer;
}
.stat { transition: box-shadow .15s, transform .15s, border-color .15s; }
.stat:hover { border-color: #dccdb9; box-shadow: var(--shadow-lift); transform: translateY(-1px); }
.stat .v { font-size: 18px; font-weight: 680; letter-spacing: -.02em; line-height: 1.2; white-space: nowrap; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 1px; }
.stat .chev { color: var(--muted); flex: none; }
.stat > div:nth-child(2) { flex: 1; min-width: 0; }

/* grid */
.grid { display: grid; grid-template-columns: var(--cols, 1.32fr 1fr); gap: 14px; margin-bottom: 14px; align-items: start; }

/* locked row: both cards share one fixed height; content scrolls inside */
.grid.locked { align-items: stretch; grid-auto-rows: var(--row-h, 470px); }
.grid.locked > .card { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.grid.locked > .card > .card-head { flex: none; }
.grid.locked > .card > .seg { flex: none; }
.grid.locked > .card > .table-wrap { flex: 1; min-height: 0; max-height: none; }
.grid.locked > .card > .qa { flex: 1; min-height: 0; align-content: start; overflow: auto; }
.grid.locked #outBody { flex: 1; min-height: 0; display: flex; }
.grid.locked #outBody > .table-wrap { flex: 1; min-height: 0; max-height: none; }
.grid.locked #outBody > .empty { margin: auto; }
.chart-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chart-body svg { flex: 1; min-height: 0; width: 100%; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted);
  padding: 9px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0;
}
td { padding: 10px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.table-wrap { overflow: auto; max-height: 420px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 13px; }
/* tables inside a locked card: tighter cells so all columns fit the box */
.grid.locked th, .grid.locked td { padding: 9px 10px; }
.grid.locked td.num, .grid.locked th.num { white-space: nowrap; }

/* segmented control */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { background: none; color: var(--ink-2); padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }
.seg button:hover { background: var(--surface); }
.seg button.active { background: var(--accent); color: #fff; font-weight: 600; }

/* chart */
.legend { display: flex; gap: 16px; align-items: center; font-size: 12px; color: var(--ink-2); }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }
.chart-tip {
  position: fixed; pointer-events: none; z-index: 60; background: var(--ink); color: #fff;
  padding: 7px 10px; border-radius: 8px; font-size: 12px; line-height: 1.45;
  box-shadow: 0 4px 14px rgba(0,0,0,.18); opacity: 0; transition: opacity .1s;
}
.chart-tip .k { color: #d9cfc3; }
.bar { cursor: pointer; }
.bar:hover { opacity: .82; }

/* quick actions */
.qa { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.qa button {
  background: var(--surface); border: 1px solid var(--line); color: inherit;
  padding: 13px; border-radius: 11px; display: flex; gap: 11px; align-items: center; text-align: left;
}
.qa button { transition: box-shadow .15s, transform .15s, border-color .15s; }
.qa button:hover { border-color: #dccdb9; box-shadow: var(--shadow-lift); transform: translateY(-1px); }
.qa .t { font-size: 13px; font-weight: 620; }
.qa .d { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.qa .chev { margin-left: auto; color: var(--muted); }

/* detail panel */
.detail { border: 1px solid var(--line); border-radius: 11px; padding: 14px; margin: 14px 16px 16px; background: var(--surface-2); }
.detail h4 { margin: 0 0 3px; font-size: 14px; }
pre { background: var(--accent-soft); padding: 9px 11px; border-radius: 8px; overflow: auto; font-size: 12px; margin: 5px 0; white-space: pre-wrap; word-break: break-word; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(43, 38, 32, .38); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 480px;
  max-height: 85vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lift);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft); flex: none;
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 650; padding-right: 12px; }
.modal-body { padding: 16px; overflow-y: auto; font-size: 13.5px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; font-size: 13px; }
.detail-grid .muted { font-size: 11.5px; text-transform: uppercase; letter-spacing: .02em; display: block; }

/* ---------- assistant ---------- */
.assistant-split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
.card.assistant { display: flex; flex-direction: column; height: 560px; }
.card.assistant .card-head { flex: none; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 18px 16px; }

.workspace-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; }
.workspace-title { margin-bottom: 12px; }
.workspace-title h4 { margin: 0 0 2px; font-size: 14px; }
.workspace-body .table-wrap { max-height: none; }
.workspace-body .stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.workspace-body .stat .v { font-size: 15px; }
.workspace-empty {
  height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; gap: 8px; color: var(--muted);
}
.workspace-empty svg { color: #d8cdbe; margin-bottom: 4px; }
.workspace-empty p { margin: 0; font-size: 13.5px; }
.hero { max-width: 520px; margin: 26px auto 22px; text-align: center; }
.hero .spark {
  width: 62px; height: 62px; border-radius: 50%; margin: 0 auto 16px;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center;
}
.hero h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: -.02em; }
.hero .lede { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.hero p { margin: 0; color: var(--ink-2); font-size: 13.5px; line-height: 1.6; }
.prompts { max-width: 560px; margin: 0 auto; display: grid; gap: 8px; }
.prompts .ph { font-size: 12.5px; font-weight: 650; color: var(--ink-2); margin-bottom: 2px; }
.prompts button {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  padding: 11px 13px; border-radius: 11px; display: flex; gap: 10px; align-items: center;
  font-size: 13px; text-align: left;
}
.prompts button { transition: box-shadow .15s, transform .15s, border-color .15s; }
.prompts button:hover { border-color: var(--accent); box-shadow: var(--shadow-lift); transform: translateY(-1px); }
.prompts .chev { margin-left: auto; color: var(--muted); }
.prompts button:hover .chev { color: var(--accent); }

.msg { max-width: 82%; padding: 10px 13px; border-radius: 13px; font-size: 13.5px; line-height: 1.55; margin-bottom: 11px; word-break: break-word; }
.msg.user { margin-left: auto; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.assistant pre { background: var(--surface); border: 1px solid var(--line); }
.msg ul { margin: 6px 0; padding-left: 18px; }
.msg li { margin: 2px 0; }
.msg .tools { font-size: 11px; color: var(--muted); margin-top: 7px; padding-top: 6px; border-top: 1px solid var(--line); }
.msg .actions { margin-top: 9px; display: flex; gap: 7px; }
.typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bounce 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

.composer { flex: none; padding: 12px 16px 14px; border-top: 1px solid var(--line-soft); }
.composer form { display: flex; gap: 9px; align-items: center; }
.composer input { flex: 1; padding: 11px 14px; border-radius: 11px; }
.composer .send { width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 11px; flex: none; }
.composer .note { display: flex; gap: 6px; align-items: center; font-size: 11.5px; color: var(--muted); margin-top: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 1040px) { .grid { grid-template-columns: 1fr; } .assistant-split { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--line); padding: 9px 12px;
  }
  .sidebar button { width: auto; white-space: nowrap; padding: 8px 11px; }
  .sidebar .sep { display: none; }
  .content { padding: 14px; }
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar .label, .topbar .uname { display: none; }
  .qa { grid-template-columns: 1fr; }
  .grid.locked { grid-auto-rows: auto; }
  .grid.locked > .card { overflow: visible; }
  .grid.locked > .card > .table-wrap,
  .grid.locked #outBody > .table-wrap { max-height: 300px; }
  .chart-body svg { min-height: 180px; }
  .client-card { flex-wrap: wrap; row-gap: 10px; }
  .client-card .spacer { flex-basis: 100%; height: 0; }
  .client-card h2 { font-size: 16px; }
  .card.assistant { height: auto; min-height: 70vh; }
  .msg { max-width: 92%; }
}
