/* Layout: fixed navy rail + scrolling work area; each view is a stack of panels, summary first, detail after. */
:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-2: #f8fafa;
  --line: #e2e8eb;
  --ink: #15293a;
  --muted: #64757f;
  --faint: #93a1a9;
  --rail: #0f2a39;
  --rail-2: #1b3e4f;
  --rail-ink: #c3d4da;
  --accent: #0a7f78;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3f0;
  --good: #1c7f55;
  --good-soft: #e3f4ea;
  --warn: #9a5c0a;
  --warn-soft: #fcf0d9;
  --bad: #b2453f;
  --bad-soft: #fbe9e7;
  --info: #2f5f9a;
  --info-soft: #e7eff9;
  --shadow: 0 1px 2px rgba(15, 42, 57, .05), 0 6px 18px rgba(15, 42, 57, .05);
  --font: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d181e; --surface: #13222a; --surface-2: #172a33; --line: #243b46; --ink: #e3ecef; --muted: #9db0b8; --faint: #6f8590;
    --rail: #0a141a; --rail-2: #183340; --rail-ink: #b5c8cf; --accent: #3cb8ab; --accent-ink: #062320; --accent-soft: #143a38;
    --good: #5fc58f; --good-soft: #15352a; --warn: #e3aa55; --warn-soft: #3a2c14; --bad: #f08a80; --bad-soft: #3d1f1d; --info: #8cb5ea; --info-soft: #1b2c42;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d181e; --surface: #13222a; --surface-2: #172a33; --line: #243b46; --ink: #e3ecef; --muted: #9db0b8; --faint: #6f8590;
  --rail: #0a141a; --rail-2: #183340; --rail-ink: #b5c8cf; --accent: #3cb8ab; --accent-ink: #062320; --accent-soft: #143a38;
  --good: #5fc58f; --good-soft: #15352a; --warn: #e3aa55; --warn-soft: #3a2c14; --bad: #f08a80; --bad-soft: #3d1f1d; --info: #8cb5ea; --info-soft: #1b2c42;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { text-wrap: balance; }
.mono { font-family: var(--mono); font-size: 12px; }

.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.rail { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 22px 14px 16px; background: var(--rail); color: var(--rail-ink); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; color: #fff; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #0b8f86; color: #fff; font-weight: 700; font-size: 17px; }
.brand-name { font-weight: 700; font-size: 15.5px; letter-spacing: -.2px; }
.brand-sub { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: #8fa7b1; }
.nav-group { padding: 14px 10px 6px; font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: #7e97a2; }
.nav { display: grid; gap: 2px; }
.nav button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 7px; background: transparent; color: var(--rail-ink); text-align: left; font-size: 13.5px; }
.nav button:hover { background: var(--rail-2); color: #fff; }
.nav button.active { background: var(--rail-2); color: #fff; box-shadow: inset 2px 0 0 #5fd0c2; }
.nav .ico { width: 18px; text-align: center; color: #7fa2ad; }
.nav button.active .ico { color: #6fd8ca; }
.nav .pill-count { margin-left: auto; min-width: 20px; padding: 1px 6px; border-radius: 99px; background: #e9a23b; color: #2a1a02; font-size: 11px; font-weight: 700; text-align: center; }
.nav .lock { margin-left: auto; font-size: 11px; color: #6f8a95; }
.rail-foot { margin-top: auto; display: grid; gap: 12px; padding-top: 18px; }
.role-box { padding: 12px; border: 1px solid #2c4c5b; border-radius: 9px; background: #14323f; }
.role-box label { display: block; margin-bottom: 6px; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: #8fa7b1; }
.role-box select { width: 100%; padding: 7px 8px; border: 1px solid #36596a; border-radius: 6px; background: #0f2a39; color: #fff; font-size: 13px; }
.who { display: flex; align-items: center; gap: 9px; margin-top: 10px; }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: #bfe6da; color: #134040; font-size: 11px; font-weight: 700; flex: none; }
.who-name { color: #fff; font-size: 12.5px; font-weight: 600; }
.who-role { font-size: 11px; color: #8fa7b1; }
.rail-note { font-size: 11px; line-height: 1.5; color: #8fa7b1; padding: 0 4px; }

.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 4; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 62px; padding: 10px 32px; border-bottom: 1px solid var(--line); background: var(--surface); }
.crumb { color: var(--muted); font-size: 13px; }
.crumb strong { color: var(--ink); }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-right: 4px; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.view { max-width: 1380px; margin: 0 auto; padding: 26px 32px 56px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 600; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.link { padding: 0; border: 0; background: none; color: var(--accent); font-size: 12.5px; font-weight: 600; }
.link:hover { text-decoration: underline; }

.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.head h1 { margin: 0; font-size: clamp(22px, 2.4vw, 28px); letter-spacing: -.6px; line-height: 1.2; }
.head p { margin: 5px 0 0; color: var(--muted); font-size: 13.5px; max-width: 70ch; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--muted); font-size: 12px; white-space: nowrap; }

.notice { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 18px; padding: 10px 14px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; background: var(--surface); color: var(--muted); font-size: 12.5px; }
.notice strong { color: var(--ink); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { padding: 15px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-value { margin-top: 6px; font-size: 26px; font-weight: 700; letter-spacing: -.8px; line-height: 1.1; }
.kpi-foot { margin-top: 6px; font-size: 11.5px; color: var(--faint); }
.up { color: var(--good); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; min-width: 0; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 14.5px; letter-spacing: -.1px; }
.panel-head .sub { margin-top: 2px; font-size: 12px; color: var(--muted); }
.panel-body { padding: 14px 16px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.filters input, .filters select { height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); font-size: 12.5px; }
.filters input { flex: 1 1 200px; min-width: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { padding: 9px 12px; background: var(--surface-2); color: var(--faint); font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; text-align: left; white-space: nowrap; }
td { padding: 11px 12px; border-top: 1px solid var(--line); color: var(--muted); vertical-align: middle; white-space: nowrap; }
td.num, th.num { text-align: right; }
tbody tr:hover td { background: var(--surface-2); }
.cust { display: flex; align-items: center; gap: 9px; }
.cust-av { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-size: 10.5px; font-weight: 700; flex: none; }
.cust-name { color: var(--ink); font-weight: 600; }
.small { font-size: 11.5px; color: var(--faint); }
.amt { color: var(--ink); font-weight: 600; }

.tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.plain::before { display: none; }
.t-high, .t-bad { color: var(--bad); background: var(--bad-soft); }
.t-medium, .t-warn { color: var(--warn); background: var(--warn-soft); }
.t-low, .t-muted { color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); }
.t-good { color: var(--good); background: var(--good-soft); }
.t-accent { color: var(--accent); background: var(--accent-soft); }
.t-info { color: var(--info); background: var(--info-soft); }

.empty { padding: 28px 16px; text-align: center; color: var(--faint); font-size: 13px; }

.brief-item { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.brief-item:first-child { border-top: 0; padding-top: 0; }
.b-ico { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--warn-soft); color: var(--warn); font-size: 13px; flex: none; }
.b-ico.g { background: var(--accent-soft); color: var(--accent); }
.b-title { font-weight: 600; font-size: 13px; }
.b-copy { font-size: 12px; color: var(--muted); }

.feed { display: grid; }
.feed-item { display: grid; grid-template-columns: 62px 1fr; gap: 10px; padding: 9px 16px; border-top: 1px solid var(--line); font-size: 12.5px; }
.feed-item:first-child { border-top: 0; }
.feed-time { color: var(--faint); font-family: var(--mono); font-size: 11px; padding-top: 2px; }
.feed-who { font-weight: 600; color: var(--ink); }
.feed-what { color: var(--muted); }

/* Approvals */
.approvals { display: grid; gap: 12px; }
.ap { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.ap.sensitive { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.ap-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.ap-title { font-weight: 600; }
.ap-meta { font-size: 12px; color: var(--muted); }
.ap-body { display: grid; gap: 8px; padding: 13px 16px; }
.ap-body textarea, .modal textarea { width: 100%; min-height: 96px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); line-height: 1.55; resize: vertical; }
.ap-why { font-size: 12px; color: var(--muted); }
.ap-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 11px 16px; border-top: 1px solid var(--line); background: var(--surface-2); }
.ap-foot .acts { display: flex; gap: 8px; }
.mini-ap { display: flex; gap: 10px; align-items: flex-start; padding: 11px 16px; border-top: 1px solid var(--line); }
.mini-ap:first-child { border-top: 0; }

/* Chat */
.chat { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: min(72vh, 760px); min-height: 460px; }
.chat-log { overflow-y: auto; padding: 16px; display: grid; align-content: start; gap: 12px; background: var(--surface-2); }
.msg { max-width: min(78%, 640px); padding: 10px 13px; border-radius: 12px; font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.user { justify-self: end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.ai { justify-self: start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.sys { justify-self: center; max-width: 92%; padding: 6px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.msg ul { margin: 6px 0; padding-left: 18px; }
.msg p { margin: 0 0 6px; }
.msg p:last-child { margin-bottom: 0; }
.thinking { color: var(--faint); font-style: italic; }
.chat-input { display: grid; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface); }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.suggest { display: flex; gap: 6px; flex-wrap: wrap; }
.suggest button { padding: 5px 10px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--muted); font-size: 12px; }
.suggest button:hover { border-color: var(--accent); color: var(--accent); }

/* Cards grid (automations, integrations) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 14px; }
.card { display: grid; gap: 10px; align-content: start; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.card-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card h3 { margin: 0; font-size: 14.5px; }
.card .desc { font-size: 12.5px; color: var(--muted); }
.steps { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; font-size: 12.5px; }
.steps li { display: flex; gap: 8px; color: var(--muted); }
.steps li b { color: var(--ink); font-weight: 600; min-width: 64px; font-family: var(--mono); font-size: 11.5px; padding-top: 1px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.stat-v { font-weight: 700; font-size: 15px; }
.stat-l { font-size: 11px; color: var(--faint); }
.switch { position: relative; width: 38px; height: 22px; flex: none; border: 0; border-radius: 99px; background: var(--line); transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12.5px; }
.kv dt { color: var(--faint); }
.kv dd { margin: 0; color: var(--ink); text-align: right; }
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12.5px; }
.flow span.node { padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); font-weight: 600; }
.flow span.arrow { color: var(--faint); }

/* Reports */
.chart svg { display: block; width: 100%; height: auto; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 130px minmax(0, 1fr) 70px; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-track { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: inherit; }
.funnel { display: grid; gap: 8px; }
.funnel-row { display: grid; grid-template-columns: 170px minmax(0, 1fr) 60px; gap: 10px; align-items: center; font-size: 12.5px; }
.funnel-bar { height: 22px; border-radius: 5px; background: var(--accent-soft); position: relative; overflow: hidden; }
.funnel-bar i { position: absolute; inset: 0 auto 0 0; background: var(--accent); opacity: .85; border-radius: 5px; }

/* Security */
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.yes { color: var(--good); font-weight: 700; }
.no { color: var(--faint); }
.policy { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--line); }
.policy:first-child { border-top: 0; }
.policy-t { font-weight: 600; font-size: 13px; }
.policy-d { font-size: 12px; color: var(--muted); }

.restricted { display: grid; place-items: center; gap: 8px; padding: 60px 20px; text-align: center; color: var(--muted); }
.restricted .big { font-size: 28px; }

/* Modal + toast */
.backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(8, 22, 30, .5); }
.modal { width: min(100%, 580px); max-height: calc(100vh - 32px); overflow-y: auto; border-radius: 12px; background: var(--surface); box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; }
.modal-head h2 { margin: 0; font-size: 18px; letter-spacing: -.3px; }
.modal-body { display: grid; gap: 14px; padding: 0 20px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
.field label { display: block; margin-bottom: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.field select { height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.x { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); font-size: 16px; line-height: 1; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-size: 12.5px; }
.detail-grid .k { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.detail-grid .v { color: var(--ink); font-weight: 500; overflow-wrap: anywhere; }
.guard { padding: 9px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 12px; }
.toast { position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 30; max-width: min(420px, calc(100% - 40px)); padding: 11px 15px; border-radius: 9px; background: var(--rail); color: #fff; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.25); transform: translateY(12px); opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { transform: none; opacity: 1; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; padding: 12px 16px; }
  .brand { padding: 0 0 10px; }
  .nav-group, .rail-note { display: none; }
  .nav { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
  .nav button { width: auto; flex: none; padding: 7px 10px; font-size: 12.5px; }
  .nav button.active { box-shadow: none; }
  .rail-foot { margin-top: 8px; padding-top: 0; }
  .role-box { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
  .role-box label { margin: 0; white-space: nowrap; }
  .who { display: none; }
  .top { position: static; padding: 10px 16px; }
  .view { padding: 18px 16px 40px; }
  .kpi-value { font-size: 22px; }
  .bar-row { grid-template-columns: 100px minmax(0, 1fr) 60px; }
  .funnel-row { grid-template-columns: 110px minmax(0, 1fr) 44px; }
  .msg { max-width: 90%; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}
