:root {
  --bg: #111111;
  --side: #161616;
  --panel: #191919;
  --panel-2: #212121;
  --hover: #1f1f1f;
  --line: #262626;
  --line-2: #333333;
  --text: #ececec;
  --muted: #9b9b9b;
  --faint: #6c6c6c;
  --accent: #4cc38a;
  --accent-dim: rgba(76, 195, 138, 0.13);
  --warn: #e0a84a;
  --warn-dim: rgba(224, 168, 74, 0.13);
  --bad: #e06c5a;
  --bad-dim: rgba(224, 108, 90, 0.13);
  --radius: 8px;
  --side-w: 216px;
  --chat-w: 400px;
  --top-h: 52px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 21px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; font-weight: 600; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.block { display: block; }
.pad { padding: 12px 14px; margin: 0; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.value { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.push { margin-left: auto; }
.i { flex: none; display: block; }
[hidden] { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 7px; border: 1px solid var(--line-2);
  background: var(--panel-2); cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: #474747; background: #262626; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--text); color: #111; border-color: var(--text); font-weight: 600; }
.btn-primary:hover { background: #fff; border-color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); border-color: transparent; }
.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn-good:hover { border-color: var(--accent); color: var(--accent); }
.btn-bad:hover { border-color: var(--bad); color: var(--bad); }
.link-btn { border: 0; background: none; color: var(--faint); cursor: pointer; padding: 0; margin-left: 10px; font-size: 12px; }
.link-btn:hover { color: var(--bad); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.pill.ok::before { background: var(--accent); }
.pill.warn::before { background: var(--warn); }
.pill.bad::before { background: var(--bad); }

.tag {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 5px; font-size: 12px; vertical-align: middle;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; text-decoration: none;
}
a.tag:hover { color: var(--text); border-color: var(--line-2); }
.tag.green { color: var(--accent); background: var(--accent-dim); border-color: transparent; }
.tag.amber { color: var(--warn); background: var(--warn-dim); border-color: transparent; }
.tag.red { color: var(--bad); background: var(--bad-dim); border-color: transparent; }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; user-select: none; font-size: 13px; white-space: nowrap; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { position: relative; width: 28px; height: 16px; border-radius: 999px; background: var(--line-2); transition: background 0.15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #bbb; transition: transform 0.15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(12px); background: #fff; }
.switch input:focus-visible + .track { outline: 2px solid #666; outline-offset: 2px; }

/* App layout */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr) var(--chat-w); height: 100vh; }
body.chat-hidden .app { grid-template-columns: var(--side-w) minmax(0, 1fr); }
body.chat-hidden .chat { display: none; }

.sidebar { display: flex; flex-direction: column; background: var(--side); border-right: 1px solid var(--line); padding: 12px 10px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; text-decoration: none; white-space: nowrap; padding: 6px 8px 16px; }
.brand-lg { font-size: 19px; gap: 12px; justify-content: center; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; text-decoration: none; color: var(--muted); }
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: var(--panel-2); color: var(--text); }
.user-menu { position: relative; margin-top: auto; }
.user-button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0; border-radius: 7px; background: none; cursor: pointer; color: var(--muted); text-align: left; }
.user-button:hover { background: var(--hover); color: var(--text); }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line-2); display: grid; place-items: center; font-size: 11px; font-weight: 600; color: var(--text); flex: none; }
.menu { position: absolute; left: 0; bottom: 44px; background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 4px; min-width: 170px; z-index: 40; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); }
.menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--panel-2); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { height: var(--top-h); flex: none; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.global-search { position: relative; flex: 1; max-width: 460px; display: flex; align-items: center; }
.search-icon { position: absolute; left: 10px; color: var(--faint); pointer-events: none; }
.global-search input { width: 100%; height: 34px; padding: 0 34px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--panel); outline: none; }
.global-search input:focus { border-color: #555; }
.global-search kbd { position: absolute; right: 8px; font: 11px/1 ui-monospace, Menlo, monospace; color: var(--faint); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 5px; pointer-events: none; }
.search-results {
  position: absolute; top: 40px; left: 0; right: 0; max-height: 60vh; overflow: auto; z-index: 30;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); padding: 6px;
}
.search-results .group { padding: 8px 8px 4px; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }
.search-results a { display: block; padding: 7px 8px; border-radius: 6px; text-decoration: none; }
.search-results a:hover { background: var(--panel-2); }
.search-results .empty { padding: 12px 8px; color: var(--muted); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.view { flex: 1; overflow: auto; padding: 24px 28px 64px; outline: none; }
.view-inner { max-width: 1120px; margin: 0 auto; }
.view-inner.wide { max-width: none; }

.map-wrap { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; }
.map-style { position: absolute; top: 12px; left: 12px; z-index: 2; }
.map-legend {
  position: absolute; left: 14px; bottom: 14px; background: rgba(20, 20, 20, 0.92); border: 1px solid var(--line-2);
  border-radius: var(--radius); padding: 10px 12px; font-size: 12px; display: grid; gap: 5px;
}
.map-legend span { display: inline-flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.maplibregl-popup-content { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 12px 14px; font-size: 13px; }
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 16px; padding: 2px 6px; }
.maplibregl-ctrl-attrib { background: rgba(18, 18, 18, 0.7) !important; color: var(--faint); }
.maplibregl-ctrl-attrib a { color: var(--muted); }

/* Page parts */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 3px 0 0; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.crumbs { display: flex; gap: 6px; margin-bottom: 8px; font-size: 13px; color: var(--faint); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"] { height: 30px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--panel); min-width: 220px; outline: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 28px; padding: 0 11px; border-radius: 999px; border: 1px solid var(--line-2); background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--text); color: #111; border-color: var(--text); }
.chip .c { opacity: 0.6; margin-left: 5px; }
.segmented { display: inline-flex; padding: 2px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); }
.segmented button { height: 26px; padding: 0 12px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.segmented button.active { background: var(--panel-2); color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; }
.stat:hover { border-color: var(--line-2); }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .big { font-size: 21px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }

.brief { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.brief .lead { font-size: 15px; font-weight: 550; margin: 4px 0 0; }
.brief .meta { font-size: 12px; color: var(--faint); }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); min-height: 42px; }
.panel-head a { text-decoration: none; }
.panel .table-wrap { border: 0; border-radius: 0; }
.panel .empty-state { border: 0; }
.panels { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.panels .panel { margin-bottom: 0; }

.list-plain a { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; padding: 10px 14px; border-bottom: 1px solid var(--line); text-decoration: none; }
.list-plain a:last-child { border-bottom: 0; }
.list-plain a:hover { background: var(--hover); }

/* Fields */
.fields { display: grid; }
.field { display: grid; grid-template-columns: 42% 1fr; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); min-height: 38px; align-items: center; }
.field:last-child { border-bottom: 0; }
.field-label { color: var(--muted); font-size: 13px; padding: 9px 0; }
.field-value { padding: 6px 8px; margin: 3px -8px; border-radius: 6px; min-height: 30px; word-break: break-word; cursor: text; }
.field:not(.static) .field-value:hover { background: var(--panel-2); }
.field:not(.static) .field-value:focus { outline: 1px solid #555; }
.field.static .field-value { cursor: default; }
.field-value.long { white-space: pre-wrap; }
.field-value a { color: var(--accent); text-decoration: none; }
.field-value a:hover { text-decoration: underline; }
.editor { padding: 4px 0; }
.editor input, .editor select, .editor textarea, .form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; padding: 6px 9px; border-radius: 6px; border: 1px solid #555; background: var(--bg); outline: none;
}
.editor input, .editor select, .form-grid input, .form-grid select { height: 32px; }
.editor textarea, .form-grid textarea { resize: vertical; line-height: 1.45; }
.editor-hint { font-size: 11px; color: var(--faint); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 12px 14px; }
.form-grid label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { border-color: var(--line-2); color: var(--text); font-size: 14px; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { border-color: #666; }

/* Record page */
.record-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.record-sub { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 16px; }
.kpi { padding: 10px 14px; border-right: 1px solid var(--line); min-width: 0; }
.kpi:last-child { border-right: 0; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 15px; font-weight: 600; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rtabs { display: flex; align-items: center; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.rtabs a { padding: 9px 12px 8px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.rtabs a:hover { color: var(--text); }
.rtabs a.active { color: var(--text); border-bottom-color: var(--text); }
.rtabs .c { color: var(--faint); margin-left: 6px; font-size: 12px; }
.rtabs .switch { padding-left: 12px; }
.tab-actions { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 10px; }
.tasks .task { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tasks .task:last-child { border-bottom: 0; }
.tasks .task:hover { background: var(--hover); }
.tasks .task input { margin-top: 3px; accent-color: #4cc38a; cursor: pointer; }
.task-main { flex: 1; min-width: 0; }
.tasks .task-row { align-items: center; }
.kpi-sub { font-size: 12px; font-weight: 400; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-main .sub, .note .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.note.activity { cursor: pointer; }
.note.activity:hover { border-color: var(--line-2); }
.notes + .panel, .panel + .notes { margin-top: 12px; }
.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* Tables */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--panel); }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; font-weight: 500; color: var(--faint); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; background: var(--panel); position: sticky; top: 0; }
table.list th[data-sort-key] { cursor: pointer; }
table.list th[data-sort-key]:hover, table.list th.sorted { color: var(--text); }
table.list th .arrow { margin-left: 4px; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.row[data-href], table.list tr.row[data-drawer] { cursor: pointer; }
table.list tr.row:hover td { background: var(--hover); }
table.list td.r, table.list th.r { text-align: right; }
table.list .sub { color: var(--muted); font-size: 12px; }
table.list a { text-decoration: none; }
table.list tr.row:hover a, table.list a:hover { text-decoration: underline; text-underline-offset: 3px; }
table.list td.clip { max-width: 280px; }
table.list td.clip .sub { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.w-strength { width: 34px; }

.strength { display: inline-flex; gap: 2px; vertical-align: middle; }
.strength i { width: 5px; height: 12px; border-radius: 1px; background: var(--line-2); }
.strength i.on { background: var(--warn); }

/* Pipeline */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.board-col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; min-height: 140px; }
.board-col.over { border-color: #666; background: var(--panel-2); }
.board-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; padding: 2px 4px; }
.board-sum { padding: 0 4px 6px; min-height: 22px; }
.board-card { display: block; background: var(--bg); border: 1px solid var(--line-2); border-radius: 7px; padding: 9px 10px; margin-top: 6px; text-decoration: none; cursor: grab; }
.board-card:hover { border-color: #4a4a4a; }
.board-title { font-weight: 550; font-size: 13px; line-height: 1.35; }
.board-meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin: 6px 0 2px; font-size: 13px; }
.board-card .sub { font-size: 12px; color: var(--muted); }

/* Notes and history */
.notes { display: grid; gap: 8px; }
.note { padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.note-text { white-space: pre-wrap; }
.note .meta { font-size: 12px; color: var(--faint); margin-top: 4px; }
.note-form { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 6px; }
.note-form textarea { flex: 1; min-height: 40px; resize: vertical; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--panel); outline: none; }
.note-form textarea:focus { border-color: #555; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline li { padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.t-head { font-size: 13px; }
.t-body { margin-top: 4px; font-size: 13px; color: #cfcfcf; display: grid; gap: 2px; word-break: break-word; }

.empty-state { padding: 26px 18px; text-align: center; color: var(--muted); border: 1px dashed var(--line-2); border-radius: var(--radius); }
.source-link { color: var(--muted); word-break: break-all; }
pre.log { white-space: pre-wrap; font: 12px/1.5 ui-monospace, Menlo, monospace; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; max-height: 280px; overflow: auto; margin: 8px 0 0; }
details.run { padding: 6px 0; border-bottom: 1px solid var(--line); }
details.run:last-child { border-bottom: 0; }
details summary { cursor: pointer; }

/* Drawer */
.drawer { position: fixed; inset: 0; z-index: 60; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); border-left: 1px solid var(--line-2); display: flex; flex-direction: column; box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; min-height: 0; overflow: auto; padding: 16px 18px; display: grid; gap: 14px; align-content: start; grid-auto-rows: max-content; }
.drawer-body .panels { grid-template-columns: 1fr; }
.drawer-body .panel { margin-bottom: 0; }
.drawer-foot { display: flex; justify-content: space-between; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

/* Chat */
.chat { display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--side); min-height: 0; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: var(--top-h); flex: none; padding: 0 10px 0 16px; border-bottom: 1px solid var(--line); }
.chat-head-actions { display: flex; align-items: center; gap: 4px; }
.chat-head-actions .switch { margin-right: 6px; font-size: 12px; }
.chat-log { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 100%; }
.msg.user { align-self: flex-end; max-width: 88%; background: var(--panel-2); border: 1px solid var(--line-2); padding: 8px 12px; border-radius: 12px 12px 3px 12px; white-space: pre-wrap; }
.msg.assistant { line-height: 1.55; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px; padding-left: 20px; }
.msg.assistant li { margin: 2px 0; }
.msg.assistant a { color: var(--accent); word-break: break-word; }
.msg.assistant code { background: var(--panel-2); padding: 1px 4px; border-radius: 4px; font-size: 12.5px; }
.msg.error { color: var(--warn); background: var(--warn-dim); padding: 8px 12px; border-radius: 8px; }
.msg-steps { margin-top: 6px; font-size: 12px; color: var(--faint); }
.msg-steps summary { list-style: none; }
.msg-steps summary::-webkit-details-marker { display: none; }
.msg-steps summary::before { content: "▸ "; }
.msg-steps[open] summary::before { content: "▾ "; }
.msg-steps ol { margin: 4px 0 0; padding-left: 18px; }
.msg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chat-status { display: flex; align-items: center; gap: 8px; padding: 8px 16px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--text); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.chat-form { padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.chat-context { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); padding: 0 2px 6px; }
.chat-context span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-context button { border: 0; background: none; color: var(--faint); cursor: pointer; }
.chat-input { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--bg); padding: 6px 6px 6px 10px; }
.chat-input:focus-within { border-color: #555; }
.chat-input textarea { flex: 1; resize: none; max-height: 200px; padding: 5px 0; border: 0; background: none; outline: none; line-height: 1.45; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 80;
  background: var(--text); color: #111; padding: 9px 16px; border-radius: 8px; font-weight: 550; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.chat-form[hidden], .auto-notes[hidden] { display: none; }

.auto-notes {
  position: fixed; right: 18px; bottom: 18px; z-index: 81; width: min(380px, calc(100vw - 36px));
  background: var(--panel); border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: var(--radius);
  padding: 10px 14px; display: grid; gap: 5px; font-size: 13px; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
}
.auto-head { display: flex; align-items: center; gap: 6px; color: var(--accent); font-weight: 600; font-size: 12px; }
.auto-line { line-height: 1.4; }

.modal {
  width: min(480px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line-2); border-radius: 12px;
  background: var(--panel); color: var(--text); box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); }
.modal-body { display: grid; gap: 10px; padding: 20px 20px 16px; }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-head p { margin: 4px 0 0; }
.modal textarea { width: 100%; resize: vertical; min-height: 70px; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); outline: none; font: inherit; line-height: 1.45; }
.modal textarea:focus { border-color: #555; }
.modal .field-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.modal p.faint { margin: 0; }
.reason-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.reason-chips .chip.active { background: var(--bad-dim); color: var(--bad); border-color: var(--bad); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.btn-bad-solid { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.btn-bad-solid:hover { background: #ea7c6b; border-color: #ea7c6b; }

.chat-empty { margin: auto 0; text-align: center; color: var(--faint); font-size: 13px; padding: 24px 12px; line-height: 1.5; }
.conv-list { display: grid; gap: 6px; }
.conv { display: grid; gap: 3px; text-align: left; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; font: inherit; }
.conv:hover { border-color: var(--line-2); background: var(--panel-2); }
.conv-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conv-sum { color: var(--muted); font-size: 12.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.conv-banner { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel); }
.conv-banner .conv-sum { -webkit-line-clamp: unset; display: block; }
.conv-banner .btn { justify-self: start; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px 26px; }
.login-card form { display: grid; gap: 14px; margin-top: 18px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { height: 38px; padding: 0 12px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--bg); outline: none; }
.login-card input:focus { border-color: #555; }
.btn-block { width: 100%; }
.form-error { margin: 0; color: var(--bad); font-size: 13px; }

/* Responsive */
.chat-toggle span { margin-left: 2px; }
@media (max-width: 1360px) { :root { --chat-w: 360px; } .grid-3 { grid-template-columns: 1fr 1fr; } table.list .hide-md { display: none; } }
@media (max-width: 1180px) {
  :root { --side-w: 60px; }
  .sidebar { padding: 12px 8px; align-items: center; }
  .brand span, .nav a span, .user-name { display: none; }
  .brand { padding: 6px 0 16px; }
  .nav a { justify-content: center; padding: 9px; }
  .user-button { justify-content: center; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 920px) {
  .app, body.chat-hidden .app { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .chat { position: fixed; inset: 0; z-index: 50; display: none; border-left: 0; }
  body.chat-open .chat { display: flex; }
  body.chat-hidden .chat { display: none; }
  body.chat-hidden.chat-open .chat { display: flex; }
  .view { padding: 18px 16px 64px; }
  .field { grid-template-columns: 1fr; gap: 0; padding-top: 6px; }
  .field-label { padding: 0; font-size: 12px; }
  .field-value { margin-top: 0; }
  table.list .hide-sm { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .panels { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .app, body.chat-hidden .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .sidebar { order: 2; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 4px; }
  .brand { display: none; }
  .nav { display: flex; flex: 1; justify-content: space-around; }
  .user-menu { margin-top: 0; }
  .menu { left: auto; right: 0; }
  .topbar { padding: 0 10px; gap: 8px; }
  #ai-pill, .global-search kbd { display: none; }
  .main { min-height: 0; }
}
