/* SECAP AI Control Centre — one stylesheet, no inline styles (strict CSP). */

:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --accent: #0d766e;
  --accent-ink: #064e48;
  --accent-soft: #e6f4f1;
  --link: #0d766e;
  --blue: #2563eb;
  --green: #15803d;
  --green-soft: #e8f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --warn-line: #f0c78a;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --danger-line: #f3c3bf;
  --ok-bg: #e8f6ec;
  --ok-line: #b9e2c5;
  --ok-ink: #14532d;
  --bad-bg: #fdeceb;
  --bad-line: #f3c3bf;
  --bad-ink: #7a1c14;
  --warn-bg: #fdf3e3;
  --warn-ink: #7c4a06;
  --chip: #eef2f6;
  --chip-ink: #475569;
  --track: #eef2f6;
  --line-soft: #f1f5f9;
  --line-mid: #e6ebf0;
  --input-bg: #ffffff;
  --code-bg: #f1f5f9;
  --code-block-bg: #0f172a;
  --code-block-ink: #e2e8f0;
  --rail: #0c1418;
  --rail-2: #101b21;
  --rail-ink: #e6edf1;
  --rail-muted: #8ca0ab;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -18px rgba(15, 23, 42, 0.35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.55rem; font-weight: 650; }
h2 { font-size: 1.02rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 650; }

p { margin: 0.35rem 0; }
small { font-size: 0.78rem; color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: 0.84em; }

.app { min-height: 100vh; }
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns 0.2s ease; }
.shell > *, .main > *, .grid > *, .card { min-width: 0; }

/* ------------------------------------------------------------------ rail --- */

.rail {
  min-width: 0;
  width: 248px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 14px 16px;
  background: linear-gradient(180deg, var(--rail) 0%, var(--rail-2) 100%);
  color: var(--rail-ink);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--rail-ink); padding: 4px 8px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(140deg, #14b8a6, #0d766e);
  color: #fff; flex: none;
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-mark.large { width: 52px; height: 52px; border-radius: 16px; }
.brand-mark.large svg { width: 28px; height: 28px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 0.98rem; letter-spacing: 0.08em; }
.brand-text small { color: var(--rail-muted); font-size: 0.68rem; letter-spacing: 0.04em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px;
  color: var(--rail-muted); font-size: 0.88rem; font-weight: 500;
}
.nav-item svg { width: 17px; height: 17px; flex: none; }
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: var(--rail-ink); text-decoration: none; }
.nav-item.is-active { background: rgba(20, 184, 166, 0.14); color: #d7fbf4; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 0.68rem; line-height: 1;
  padding: 4px 6px; font-weight: 700;
}

.rail-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 10px 8px 0; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(20, 184, 166, 0.18); color: #9ff0e5;
  font-size: 0.75rem; font-weight: 700;
}
.who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.who-text strong { font-size: 0.82rem; color: var(--rail-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-text small { color: var(--rail-muted); font-size: 0.68rem; text-transform: capitalize; }
.logout-form { margin-left: auto; }
.icon-button {
  background: transparent; border: 1px solid rgba(255, 255, 255, 0.14); color: var(--rail-muted);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-button svg { width: 15px; height: 15px; }
.icon-button:hover { color: #fff; border-color: rgba(255, 255, 255, 0.3); }

/* ------------------------------------------------------------------ main --- */

.main { padding: 26px 30px 40px; max-width: 1320px; width: 100%; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 0.85rem; margin-top: 3px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.button:hover { border-color: var(--ink-2); color: var(--ink); text-decoration: none; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }
.button.small { height: 28px; padding: 0 10px; font-size: 0.78rem; border-radius: 7px; }
.button.block { width: 100%; height: 40px; margin-top: 6px; }
.button.disabled { opacity: 0.45; pointer-events: none; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 18px 16px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 0.98rem; }
.card-head .muted { font-size: 0.78rem; }
.sub-head { margin-top: 20px; }
.note { color: var(--muted); font-size: 0.78rem; line-height: 1.5; margin-top: 12px; }
.muted { color: var(--muted); }
.strong-link { color: var(--ink); font-weight: 600; }
.strong-link:hover { color: var(--link); }
.danger-text { color: var(--danger); }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.link { font-size: 0.8rem; font-weight: 600; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 8px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 15px; display: flex; flex-direction: column; gap: 2px;
  box-shadow: var(--shadow); min-width: 0;
}
.tile-label { color: var(--muted); font-size: 0.74rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.tile-value { font-size: 1.62rem; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile-hint { color: var(--muted); font-size: 0.72rem; }
.tile-accent { background: linear-gradient(160deg, #0d766e, #0b5f59); border-color: transparent; }
.tile-accent .tile-label, .tile-accent .tile-hint { color: rgba(255, 255, 255, 0.72); }
.tile-accent .tile-value { color: #fff; }
.tile-green .tile-value { color: var(--green); }
.tile-warn { border-color: var(--warn-line); background: var(--warn-soft); }
.tile-warn .tile-value { color: var(--warn); }

/* ------------------------------------------------------------- components --- */

.pill {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px;
  border-radius: 999px; font-size: 0.71rem; font-weight: 650; letter-spacing: 0.01em;
  background: var(--chip); color: var(--chip-ink); white-space: nowrap;
}
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-sky { background: #e8f1fd; color: #1d4ed8; }
.pill-violet { background: #f1ebfd; color: #6d28d9; }
.pill-teal { background: #e2f6f4; color: #0f766e; }
.pill-indigo { background: #e9ebfd; color: #4338ca; }
.pill-orange { background: #fdeee1; color: #c2410c; }
.pill-ink { background: #e9edf1; color: #1e293b; }
.pill-grey { background: var(--chip); color: var(--chip-ink); }

.banner { border-radius: 10px; padding: 11px 14px; font-size: 0.84rem; margin-bottom: 16px; border: 1px solid transparent; }
.banner.ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-ink); }
.banner.danger { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad-ink); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }
.banner.inline { margin: 14px 0 0; }

.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.bars li { display: grid; grid-template-columns: minmax(110px, 150px) 1fr 44px; align-items: center; gap: 10px; }
.bar-label { font-size: 0.8rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; background: #94a3b8; }
.bar-fill.tone-accent { background: linear-gradient(90deg, #14b8a6, #0d766e); }
.bar-fill.tone-green { background: linear-gradient(90deg, #34c26b, #15803d); }
.bar-fill.tone-ink { background: #64748b; }
.bar-value { text-align: right; font-size: 0.8rem; font-variant-numeric: tabular-nums; color: var(--ink-2); }

.w-0 { width: 0; } .w-10 { width: 10%; } .w-20 { width: 20%; } .w-30 { width: 30%; }
.w-40 { width: 40%; } .w-50 { width: 50%; } .w-60 { width: 60%; } .w-70 { width: 70%; }
.w-80 { width: 80%; } .w-90 { width: 90%; } .w-100 { width: 100%; }

.h-0 { height: 2px; } .h-5 { height: 5%; } .h-10 { height: 10%; } .h-15 { height: 15%; }
.h-20 { height: 20%; } .h-25 { height: 25%; } .h-30 { height: 30%; } .h-35 { height: 35%; }
.h-40 { height: 40%; } .h-45 { height: 45%; } .h-50 { height: 50%; } .h-55 { height: 55%; }
.h-60 { height: 60%; } .h-65 { height: 65%; } .h-70 { height: 70%; } .h-75 { height: 75%; }
.h-80 { height: 80%; } .h-85 { height: 85%; } .h-90 { height: 90%; } .h-95 { height: 95%; }
.h-100 { height: 100%; }

.table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .right { text-align: right; }
.table.compact td, .table.compact th { padding: 7px 9px; }
.table-card { padding: 6px 6px 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 0.75rem; }
.detail-cell code { font-size: 0.72rem; color: var(--ink-2); word-break: break-all; }

.mini-track { display: block; height: 4px; border-radius: 999px; background: var(--track); margin-top: 4px; overflow: hidden; }
.mini-fill { display: block; height: 100%; background: linear-gradient(90deg, #14b8a6, #0d766e); }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.list li:last-child { border-bottom: none; }
.list.tight li { padding: 6px 2px; }
.list-meta { display: flex; align-items: center; gap: 8px; font-size: 0.76rem; color: var(--muted); flex-wrap: wrap; }

.health { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.health li { display: flex; align-items: center; gap: 10px; }
.health li > div { flex: 1; display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.health li small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.health-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-2); flex: none; }
.health-dot.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16); }
.health-dot.bad { background: #dc2626; box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.14); }
.health-dot.idle { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.14); }

.empty { text-align: center; padding: 26px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--ink-2); margin-bottom: 4px; }
.empty p { font-size: 0.82rem; }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; margin: 0; }
.facts.tight { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 14px; }
.facts > div { min-width: 0; }
.facts dt { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.facts dd { margin: 1px 0 0; font-size: 0.88rem; word-break: break-word; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 6px; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line-mid); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline-dot { position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px #e6f4f1; }
.timeline strong { font-size: 0.85rem; display: block; }
.timeline small { color: var(--muted); font-size: 0.76rem; }

.notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.notes li { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 0.86rem; }
.note-head { font-size: 0.73rem; color: var(--muted); margin-bottom: 3px; font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.field > span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }
.field.grow { flex: 1; min-width: 220px; }
.field.inline-field { flex-direction: row; align-items: center; gap: 8px; min-width: 0; }
.field.inline-field > span { text-transform: none; letter-spacing: 0; font-size: 0.78rem; }
input, select, textarea {
  font: inherit; font-size: 0.85rem; color: var(--ink);
  background: var(--input-bg); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 6px 9px; height: 34px; min-width: 0;
}
textarea { height: auto; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(13, 118, 110, 0.25); outline-offset: 1px; border-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 0.82rem; color: var(--ink-2); padding-bottom: 8px; }
.check input { height: 16px; width: 16px; }
.filter-actions { display: flex; gap: 8px; padding-bottom: 1px; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.form-grid { display: flex; flex-direction: column; gap: 12px; }
.form-grid h3 { margin-bottom: 2px; }
.propose { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.propose:first-of-type { border-top: none; }

.pager { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; font-size: 0.78rem; color: var(--muted); gap: 10px; flex-wrap: wrap; }
.pager > div { display: flex; gap: 6px; }

.segmented { display: inline-flex; border: 1px solid var(--line-2); border-radius: 9px; overflow: hidden; background: var(--input-bg); }
.segment { padding: 6px 12px; font-size: 0.8rem; color: var(--ink-2); font-weight: 600; }
.segment:hover { background: var(--surface-2); text-decoration: none; }
.segment.is-active { background: var(--accent); color: #fff; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; min-width: 0; }
.chart-bars { display: flex; align-items: flex-end; gap: 2px; width: 100%; height: 100%; justify-content: center; }
.chart-bar { width: 7px; border-radius: 3px 3px 0 0; display: block; min-height: 2px; }
.tone-accent { background: linear-gradient(180deg, #14b8a6, #0d766e); }
.tone-green { background: linear-gradient(180deg, #34c26b, #15803d); }
.chart-day { font-size: 0.66rem; color: var(--muted); }
.legend { display: flex; align-items: center; gap: 6px; font-size: 0.74rem; color: var(--muted); margin-top: 8px; }
.legend-key { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 8px; }
.legend-key:first-child { margin-left: 0; }

.ask .quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.quick {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--ink-2); font-size: 0.84rem;
  text-align: left; font-family: inherit; cursor: pointer; width: 100%;
}
.quick:hover { border-color: var(--accent); color: var(--ink); background: var(--accent-soft); text-decoration: none; }
.quick-arrow { color: var(--link); font-weight: 700; }

.foot { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 0.74rem; margin-top: 22px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ chat --- */

.chat-page .main { padding: 0; max-width: none; height: 100vh; display: flex; }
.chat-shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); width: 100%; min-height: 0; }

.chat-list { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.chat-list-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 10px; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.conversations { overflow-y: auto; padding: 0 8px 10px; flex: 1; }
.conversation { display: flex; flex-direction: column; padding: 9px 10px; border-radius: 9px; color: var(--ink-2); }
.conversation:hover { background: var(--surface-2); text-decoration: none; }
.conversation.is-active { background: var(--accent-soft); color: var(--accent-ink); }
.conversation-title { font-size: 0.84rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-meta { font-size: 0.7rem; color: var(--muted); }
.chat-list-foot { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-top: 1px solid var(--line); font-size: 0.74rem; color: var(--muted); }

.chat-main { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 26px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, 0.75); backdrop-filter: blur(8px); }
.chat-head h1 { font-size: 1.12rem; }
.chat-head .sub { font-size: 0.76rem; }
.chat-head-actions { display: flex; gap: 10px; align-items: center; }

.thread { flex: 1; overflow-y: auto; padding: 26px 26px 10px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 10px; max-width: 860px; width: 100%; }
.msg-user { align-self: flex-end; justify-content: flex-end; }
.msg-user .msg-body { background: var(--accent); color: #fff; border-radius: 14px 14px 4px 14px; padding: 10px 14px; white-space: pre-wrap; font-size: 0.9rem; max-width: 640px; }
.msg-ai { align-self: flex-start; }
.msg-avatar { width: 28px; height: 28px; border-radius: 9px; background: linear-gradient(140deg, #14b8a6, #0d766e); color: #fff; font-size: 0.66rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; margin-top: 2px; }
.msg-ai .msg-body { background: var(--surface); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 12px 16px; font-size: 0.9rem; box-shadow: var(--shadow); min-width: 0; }
.msg-body p { margin: 0.4rem 0; }
.msg-body h3, .msg-body h4, .msg-body h5 { margin: 0.9rem 0 0.3rem; font-size: 0.95rem; }
.msg-body ul { margin: 0.4rem 0; padding-left: 1.2rem; }
.msg-body li { margin: 0.15rem 0; }
.msg-body code { background: var(--code-bg); border-radius: 4px; padding: 1px 4px; }
.msg-body pre { background: var(--code-block-bg); color: var(--code-block-ink); border-radius: 10px; padding: 12px 14px; overflow-x: auto; font-size: 0.78rem; }
.msg-body pre code { background: transparent; padding: 0; color: inherit; }
.msg-body a { color: var(--link); text-decoration: underline; }
.msg-body .table-row { font-family: var(--mono); font-size: 0.76rem; color: var(--ink-2); white-space: pre-wrap; }

.msg-text > *:first-child { margin-top: 0; }
.msg-extras:empty { display: none; }
.msg-extras .quick { margin-top: 10px; }
.tool-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tool-chip { font-family: var(--mono); font-size: 0.68rem; background: var(--chip); color: var(--chip-ink); border-radius: 6px; padding: 2px 6px; }
.tool-note { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; margin-left: 38px; font-size: 0.72rem; color: var(--muted); background: var(--chip); border-radius: 999px; padding: 3px 10px; }
.tool-note.tool-error { background: var(--danger-soft); color: var(--danger); }
.tool-note.tool-pending_approval { background: var(--warn-soft); color: var(--warn); }
.tool-name { font-family: var(--mono); font-weight: 600; }
.tool-status { text-transform: capitalize; }
.tool-note::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.7; }

.composer { display: flex; flex-direction: column; gap: 8px; padding: 12px 26px 18px; border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea {
  width: 100%; min-height: 44px; max-height: 200px; resize: none;
  border-radius: 12px; padding: 11px 13px; font-size: 0.9rem; line-height: 1.45;
}
.composer-actions { display: flex; align-items: center; gap: 8px; }
.composer-hint { margin-right: auto; font-size: 0.74rem; color: var(--muted); }

.hero-chat { margin: auto; max-width: 680px; text-align: center; padding: 30px 10px; }
.hero-mark { width: 52px; height: 52px; border-radius: 16px; margin: 0 auto 14px; background: linear-gradient(140deg, #14b8a6, #0d766e); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; letter-spacing: 0.04em; }
.hero-chat h2 { font-size: 1.2rem; margin-bottom: 6px; }
.hero-chat p { color: var(--muted); font-size: 0.86rem; max-width: 520px; margin: 0 auto 18px; }
.hero-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

/* -------------------------------------------------------------- approvals --- */

.approval-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.approval-summary { font-size: 0.92rem; font-weight: 600; margin: 4px 0 10px; }
.approval-actions { display: flex; gap: 8px; margin-top: 12px; }
.args { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 0.74rem; overflow-x: auto; max-height: 180px; }

/* --------------------------------------------------------------- settings --- */

.inpage-nav { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.inpage-nav a { font-size: 0.8rem; font-weight: 600; color: var(--ink-2); padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.inpage-nav a:hover { border-color: var(--accent); color: var(--link); text-decoration: none; }
.section { margin-bottom: 34px; scroll-margin-top: 20px; }
.section-title { font-size: 1.15rem; margin-bottom: 3px; }
.section-sub { color: var(--muted); font-size: 0.82rem; margin-bottom: 14px; }
.scopes { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; align-items: center; }
.scope { font-family: var(--mono); font-size: 0.68rem; background: var(--chip); color: var(--chip-ink); border-radius: 5px; padding: 2px 6px; }
.tools { margin-top: 10px; font-size: 0.8rem; }
.tools summary { cursor: pointer; color: var(--link); font-weight: 600; }
.tools ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.tools li { display: flex; flex-direction: column; border-bottom: 1px solid var(--line-soft); padding-bottom: 5px; }
.tools small { color: var(--muted); font-size: 0.72rem; }
.steps { margin-top: 8px; }
.steps h3 { margin-bottom: 6px; }
.steps ol { margin: 0; padding-left: 1.2rem; font-size: 0.84rem; color: var(--ink-2); }
.steps li { margin: 6px 0; }
.ticks { margin: 8px 0 0; padding-left: 1.1rem; font-size: 0.84rem; color: var(--ink-2); }
.ticks li { margin: 6px 0; }

/* ------------------------------------------------------------------ auth --- */

.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 20% -10%, #10313a 0%, #0c1418 55%, #0a1114 100%); padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 18px; padding: 32px 30px 26px; box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.55); }
.auth-brand { margin-bottom: 16px; }
.auth-card h1 { font-size: 1.3rem; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 16px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.auth-form .field { min-width: 0; }
.auth-form input { height: 40px; }
.auth-foot { margin-top: 16px; color: var(--muted); font-size: 0.73rem; text-align: center; }

/* -------------------------------------------------------------- responsive --- */


/* ------------------------------------------------------------ rail tools --- */

.rail { overflow-y: auto; scrollbar-width: thin; }
.rail-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.rail-actions form { margin: 0; }
.theme-icon { display: none; }
.theme-icon svg { width: 15px; height: 15px; }
html[data-theme="light"] .theme-icon-moon { display: inline-flex; }
html[data-theme="dark"] .theme-icon-sun { display: inline-flex; }

.rail-toggle {
  position: fixed; top: 14px; left: 14px; z-index: 60;
  width: 38px; height: 38px; padding: 0;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: var(--rail); color: var(--rail-ink);
  border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 10px;
  box-shadow: 0 8px 20px -12px rgba(0, 0, 0, 0.7); cursor: pointer;
}
.rail-toggle span { display: block; width: 16px; height: 2px; border-radius: 2px; background: currentColor; }
.rail-toggle:hover { border-color: rgba(255, 255, 255, 0.35); }
.rail-toggle:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.rail-scrim { display: none; }

@media (min-width: 981px) {
  .rail-toggle {
    left: 198px; background: transparent; border-color: transparent; box-shadow: none; color: var(--rail-muted);
  }
  .rail-toggle:hover { background: rgba(255, 255, 255, 0.06); color: var(--rail-ink); border-color: transparent; }
  html.rail-collapsed .rail-toggle {
    left: 14px; background: var(--rail); color: var(--rail-ink);
    border-color: rgba(255, 255, 255, 0.16); box-shadow: 0 8px 20px -12px rgba(0, 0, 0, 0.7);
  }
  html.rail-collapsed .shell { grid-template-columns: 0 minmax(0, 1fr); }
  html.rail-collapsed .rail { transform: translateX(-248px); visibility: hidden; }
  html.rail-collapsed .main { padding-top: 68px; }
  html.rail-collapsed .chat-page .main { padding-top: 0; }
  html.rail-collapsed .chat-page .chat-head { padding-left: 72px; }
}

/* ----------------------------------------------------------------- theme --- */

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a1013;
  --surface: #111a1f;
  --surface-2: #162127;
  --ink: #e9eff2;
  --ink-2: #c3cfd7;
  --muted: #93a4af;
  --line: #22303a;
  --line-2: #33454f;
  --line-soft: #1b262d;
  --line-mid: #24323b;
  --accent: #0f766e;
  --accent-ink: #0b5f59;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --link: #5eead4;
  --green: #4ade80;
  --green-soft: rgba(34, 197, 94, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(245, 158, 11, 0.12);
  --warn-line: rgba(245, 158, 11, 0.4);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --danger-line: rgba(248, 113, 113, 0.4);
  --ok-bg: rgba(34, 197, 94, 0.12);
  --ok-line: rgba(34, 197, 94, 0.38);
  --ok-ink: #86efac;
  --bad-bg: rgba(248, 113, 113, 0.12);
  --bad-line: rgba(248, 113, 113, 0.38);
  --bad-ink: #fca5a5;
  --warn-bg: rgba(245, 158, 11, 0.12);
  --warn-ink: #fcd34d;
  --chip: #1b262d;
  --chip-ink: #c3cfd7;
  --track: #1b262d;
  --input-bg: #0d161b;
  --code-bg: #1b262d;
  --code-block-bg: #060b0e;
  --code-block-ink: #d8e3e9;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 12px 32px -22px rgba(0, 0, 0, 0.9);
}
html[data-theme="dark"] .button { background: var(--surface-2); color: var(--ink); }
html[data-theme="dark"] .button:hover { border-color: var(--muted); color: var(--ink); }
html[data-theme="dark"] .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
html[data-theme="dark"] .button.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
html[data-theme="dark"] .table tbody tr:hover { background: #162127; }
html[data-theme="dark"] .chat-head { background: rgba(17, 26, 31, 0.82); }
html[data-theme="dark"] .msg-body pre { border: 1px solid var(--line); }
html[data-theme="dark"] .auth-card { border: 1px solid var(--line); }
html[data-theme="dark"] .tile-accent { background: linear-gradient(160deg, #0f766e, #0b5f59); }
html[data-theme="dark"] .pill-green { background: rgba(34, 197, 94, 0.16); color: #6ee7a0; }
html[data-theme="dark"] .pill-warn { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
html[data-theme="dark"] .pill-danger { background: rgba(248, 113, 113, 0.18); color: #fca5a5; }
html[data-theme="dark"] .pill-sky { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
html[data-theme="dark"] .pill-violet { background: rgba(139, 92, 246, 0.2); color: #c4b5fd; }
html[data-theme="dark"] .pill-teal { background: rgba(20, 184, 166, 0.2); color: #5eead4; }
html[data-theme="dark"] .pill-indigo { background: rgba(99, 102, 241, 0.2); color: #a5b4fc; }
html[data-theme="dark"] .pill-orange { background: rgba(249, 115, 22, 0.2); color: #fdba74; }
html[data-theme="dark"] .pill-ink { background: rgba(148, 163, 184, 0.16); color: #cbd5e1; }
html[data-theme="dark"] .pill-grey { background: rgba(148, 163, 184, 0.14); color: #c3cfd7; }

/* ----------------------------------------------------------- responsive --- */

@media (max-width: 1180px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  /* The rail becomes an off-canvas drawer, opened by the floating button. */
  .rail {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 55;
    width: 278px; max-width: 86vw; height: 100dvh;
    transform: translateX(-104%);
    transition: transform 0.22s ease;
    box-shadow: 30px 0 60px -30px rgba(0, 0, 0, 0.65);
  }
  html.rail-open .rail { transform: none; }
  html.rail-open { overflow: hidden; }
  .rail-scrim {
    position: fixed; inset: 0; z-index: 54;
    background: rgba(4, 8, 10, 0.55);
  }
  html.rail-open .rail-scrim { display: block; }
  .rail-toggle { left: 12px; top: 12px; }

  .main { padding: 66px 16px 34px; min-width: 0; }
  .grid, .grid.two { grid-template-columns: minmax(0, 1fr); }
  .approval-grid { grid-template-columns: 1fr; }
  .ask .quick-grid { grid-template-columns: 1fr; }

  .chat-page .main { height: 100dvh; padding-top: 58px; }
  .chat-shell { grid-template-columns: 1fr; min-height: 0; }
  .chat-list { display: none; }
  .thread { padding: 18px 14px 6px; }
  .chat-head, .composer { padding-left: 14px; padding-right: 14px; }
  .chat-head { padding-left: 62px; flex-wrap: wrap; }

  .rail-foot { flex-direction: column; align-items: stretch; gap: 10px; }
  .who-text { display: flex; }
  .rail-actions { margin-left: 0; }
  .icon-button { width: 34px; height: 34px; }
}

@media (max-width: 620px) {
  .main { padding: 62px 12px 28px; }
  .chat-page .main { padding-top: 54px; }
  .tiles, .tiles.three, .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px; }
  .tile-value { font-size: 1.4rem; }
  h1 { font-size: 1.25rem; }
  .card { padding: 14px 12px 12px; }
  .facts, .facts.tight { grid-template-columns: 1fr; }
  .hero-grid { grid-template-columns: 1fr; }
  .hero-chat { padding: 20px 4px; }
  .filters .field, .propose .field { min-width: 100%; }
  .filter-actions { width: 100%; }
  .filter-actions .button { flex: 1; }
  .page-head { flex-direction: column; align-items: stretch; }
  .head-actions { width: 100%; }
  .head-actions .button { flex: 1; }
  .segmented { width: 100%; }
  .segment { flex: 1; text-align: center; }
  .chart-bar { width: 5px; }
  .bars li { grid-template-columns: minmax(86px, 120px) 1fr 38px; gap: 8px; }
  .table { min-width: 620px; }
  .table.compact { min-width: 520px; }
  .inline-form { flex-wrap: wrap; }
  .inline-form input, .inline-form select { flex: 1 1 120px; }
  .propose .button { width: 100%; }
  .propose .field.grow { min-width: 0; }
  .chat-head .field.inline-field { width: 100%; }
  .chat-head .field.inline-field select { flex: 1; max-width: none; }
  .approval-actions .button { flex: 1; }
  .msg-body { font-size: 0.88rem; }
  .msg-body pre { font-size: 0.74rem; }
  .foot { flex-direction: column; gap: 4px; }
  .auth-card { padding: 26px 20px 22px; }
  .auth { padding: 16px; }
  .inpage-nav { gap: 4px; }
  .inpage-nav a { font-size: 0.76rem; padding: 5px 9px; }
}

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