:root {
  --ui-font-scale: 1;
  --ui-font: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
  --ui-mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  --control-height: 38px;
  --ui-space-1: 4px;
  --ui-space-2: 8px;
  --ui-space-3: 12px;
  --ui-space-4: 16px;
  --ui-space-5: 24px;
  --ui-radius-sm: 7px;
  --ui-radius: 11px;
  --ui-radius-lg: 16px;
  --ui-shadow: 0 18px 48px rgba(0, 0, 0, .28);
  --surface-soft: rgba(10, 15, 26, .55);
  --surface-raised: rgba(17, 26, 46, .96);
  --accent-rgb: 111, 149, 255;
  --accent-ink: #071126;
  --danger-ink: #fff;
}

html[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #07101d;
  --panel: #101c2d;
  --border: #263a55;
  --muted: #a6b6cc;
  --text: #f3f7ff;
  --accent2: #223b62;
  --danger: #c92f50;
  --ok: #62e6a5;
  --warn: #f4c96b;
  --err: #ff9aae;
  --surface-soft: rgba(7, 16, 29, .68);
  --surface-raised: rgba(16, 28, 45, .97);
}

html[data-theme="graphite"] {
  color-scheme: dark;
  --bg: #111315;
  --panel: #1b1f22;
  --border: #3b4248;
  --muted: #b2bac1;
  --text: #f6f7f8;
  --accent2: #303b46;
  --danger: #c73651;
  --ok: #72dea9;
  --warn: #eac66f;
  --err: #ff9bae;
  --surface-soft: rgba(11, 13, 15, .68);
  --surface-raised: rgba(27, 31, 34, .97);
}

html[data-theme="daylight"] {
  color-scheme: light;
  --bg: #eef3f8;
  --panel: #ffffff;
  --border: #c5d0dd;
  --muted: #536579;
  --text: #132238;
  --accent2: #d9e5f6;
  --danger: #b42340;
  --ok: #08774b;
  --warn: #8c5b00;
  --err: #b42340;
  --surface-soft: rgba(230, 237, 245, .78);
  --surface-raised: rgba(255, 255, 255, .98);
  --ui-shadow: 0 18px 48px rgba(24, 43, 67, .16);
}

html[data-theme="contrast"] {
  color-scheme: dark;
  --bg: #000;
  --panel: #090909;
  --border: #9aa4b2;
  --muted: #d5dbe3;
  --text: #fff;
  --accent2: #152848;
  --danger: #e54865;
  --ok: #71f6b3;
  --warn: #ffe08a;
  --err: #ffadc0;
  --surface-soft: #050505;
  --surface-raised: #090909;
  --ui-shadow: 0 0 0 2px #fff;
}

html[data-accent="cobalt"] { --accent: #6f95ff; --accent-rgb: 111, 149, 255; --accent-ink: #071126; }
html[data-accent="teal"] { --accent: #52d6c5; --accent-rgb: 82, 214, 197; --accent-ink: #041c19; }
html[data-accent="amber"] { --accent: #efc15c; --accent-rgb: 239, 193, 92; --accent-ink: #211604; }
html[data-accent="rose"] { --accent: #f58ba8; --accent-rgb: 245, 139, 168; --accent-ink: #260913; }

html[data-density="compact"] {
  --control-height: 32px;
  --ui-space-2: 6px;
  --ui-space-3: 9px;
  --ui-space-4: 12px;
  --ui-space-5: 18px;
}

html[data-density="spacious"] {
  --control-height: 44px;
  --ui-space-2: 10px;
  --ui-space-3: 16px;
  --ui-space-4: 22px;
  --ui-space-5: 30px;
}

html, body { max-width: 100%; }
body {
  font-family: var(--ui-font) !important;
  font-size: calc(14px * var(--ui-font-scale)) !important;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}
.mono, code, pre { font-family: var(--ui-mono) !important; }

button, input, select, textarea { font: inherit; }
button, .graph-btn, .back-link, .btn, a.btn {
  min-height: var(--control-height);
  border-radius: var(--ui-radius-sm);
  font-size: calc(13px * var(--ui-font-scale));
}
button {
  height: auto;
  padding: 7px 13px;
  background: var(--accent);
  color: var(--accent-ink);
}
button.sec { background: var(--accent2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); color: var(--danger-ink); }
button.ghost, .btn-ghost {
  min-height: 32px;
  height: auto;
  padding: 5px 10px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: calc(12px * var(--ui-font-scale));
}
button:not(:disabled):hover, .graph-btn:hover, .back-link:hover, .btn:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
button:disabled, .btn:disabled { opacity: .5; }
input, select, textarea {
  min-width: 0;
  min-height: var(--control-height);
  padding: 8px 10px;
  border-radius: var(--ui-radius-sm);
  border-color: var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-family: var(--ui-mono);
  font-size: calc(13px * var(--ui-font-scale));
}
textarea { line-height: 1.5; }
input[type="checkbox"], input[type="radio"] {
  width: 24px;
  height: 24px;
  min-height: 24px;
  accent-color: var(--accent);
}
label, .ctx-field label, .engine-controls label, .context-options label {
  font-size: calc(12px * var(--ui-font-scale));
  line-height: 1.35;
}
a { color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
a:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--warn) !important;
  outline-offset: 2px;
}

header {
  background: color-mix(in srgb, var(--bg) 88%, transparent) !important;
  border-color: var(--border) !important;
}
.brand, header h1 {
  font-size: calc(18px * var(--ui-font-scale)) !important;
  letter-spacing: -.2px;
}
.top { gap: var(--ui-space-3); }
.row { gap: var(--ui-space-2); }
.pill {
  min-height: 28px;
  height: auto;
  padding: 4px 9px;
  font-size: calc(12px * var(--ui-font-scale));
  background: var(--surface-soft);
}
.pill.featured { min-height: 32px; font-size: calc(13px * var(--ui-font-scale)); }
.shared-banner { font-size: calc(12px * var(--ui-font-scale)); }

.metrics {
  gap: var(--ui-space-2);
  margin-top: var(--ui-space-3);
  align-items: stretch;
}
.m {
  min-width: 105px;
  padding: 8px 12px;
  border-radius: var(--ui-radius-sm);
  background: var(--panel);
}
.m .lbl, .m .sub, .stat-label {
  font-size: calc(12px * var(--ui-font-scale));
  line-height: 1.3;
}
.m .val { font-size: calc(20px * var(--ui-font-scale)); }
.m.featured .val { font-size: calc(24px * var(--ui-font-scale)); }

.graph-btn, .back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid rgba(var(--accent-rgb), .48);
  background: rgba(var(--accent-rgb), .1);
  color: var(--accent);
  text-decoration: none;
  font-weight: 750;
  letter-spacing: 0;
}
.graph-btn:hover, .back-link:hover {
  background: rgba(var(--accent-rgb), .19);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: none;
}

.pane, .card, .ctx-panel, .model-card, .engine-panel, .prompt-adjust-panel,
.live-ctx-panel, .vod-panel, .sv-panel, .learn-panel {
  background: var(--panel) !important;
  border-color: var(--border) !important;
  border-radius: var(--ui-radius) !important;
}
.pane-h {
  position: relative;
  min-height: 50px;
  padding: 10px 13px;
  gap: var(--ui-space-2);
  font-size: calc(14px * var(--ui-font-scale));
  border-color: var(--border);
  flex-wrap: nowrap;
  overflow: hidden;
}
body[data-ui-page="dashboard"] .pane:not(.is-collapsed) > .pane-h {
  align-content: center;
  flex-wrap: wrap;
  overflow: visible;
}
body[data-ui-page="dashboard"] .pane:not(.is-collapsed) > .pane-h > * {
  min-width: 0;
  max-width: 100%;
}
body[data-ui-page="dashboard"] .pane:not(.is-collapsed) > .pane-h .pane-title strong {
  overflow-wrap: anywhere;
}
body[data-ui-page="dashboard"] .pane:not(.is-collapsed) > .pane-h .pane-actions {
  margin-left: auto;
}
body[data-ui-page="dashboard"] .pane:not(.is-collapsed) > .pane-h .pill {
  overflow: hidden;
  text-overflow: ellipsis;
}
.pane-body { padding: var(--ui-space-3); }
.pane-title {
  display: flex;
  min-width: 0;
  flex: 1 1 120px;
  flex-direction: column;
  gap: 1px;
  line-height: 1.2;
}
.drag-handle {
  min-width: 26px;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 17px;
  opacity: .68;
  padding: 0;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
}
.drag-handle:hover { background: var(--accent2); opacity: 1; }
.pane-actions {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 5px;
  margin-left: 0;
}
.pane-action {
  position: relative;
  width: 32px;
  min-width: 32px;
  min-height: 30px !important;
  overflow: hidden;
  padding: 0 !important;
  color: transparent !important;
  font-size: 12px !important;
  white-space: nowrap;
}
.pane-action::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
}
.pane-action[data-pane-collapse]::after { content: "−"; }
.pane-action[data-pane-collapse][aria-expanded="false"]::after { content: "+"; }
.pane-action[data-pane-focus]::after { content: "⛶"; font-size: 14px; }
.pane-action[data-pane-focus][aria-pressed="true"]::after { content: "↙"; }
.pane-action[data-pane-hide]::after { content: "×"; }
.pane.is-collapsed { min-height: 52px !important; max-height: 52px !important; resize: none !important; }
.pane.is-collapsed > .pane-body { display: none !important; }
.pane.is-collapsed > .pane-h { min-height: 50px; flex-wrap: nowrap; padding-right: 118px; }
.pane.is-collapsed > .pane-h > :not(.drag-handle):not(.pane-actions):not(.pane-title) { display: none !important; }
.pane.is-collapsed .pane-actions {
  position: absolute;
  top: 9px;
  right: 10px;
  z-index: 3;
  display: inline-flex !important;
}
.pane.is-collapsed .pane-title { overflow: hidden; white-space: nowrap; }
body.pane-focus-mode .top-row { display: flex !important; }
body.pane-focus-mode .pane-top:not(.is-focused) { display: none !important; }
body.pane-focus-mode .pane-top.is-focused {
  width: 100% !important;
  flex-basis: 100% !important;
  min-height: 70vh !important;
  max-height: none !important;
  resize: none !important;
}

.account-picker, .thread-sender-picker, .reply-sender-picker, .follower-section {
  gap: var(--ui-space-2);
}
.account-picker-hint, .thread-live-status, .thread-event-action, .thread-parent-context,
.reply-meta, #reply_sender_hint, .reply-send-status, .follower-hint, .follower-full-link,
.follower-history-table, .history-table, .follower-history-table th, .history-table th,
.reply-event-item, .thread-filter, .thread-unread-badge, .reply-unread-badge,
.thread-toggle-badge, .reply-toggle-badge, .toast-ts, .shared-banner {
  font-size: calc(12px * var(--ui-font-scale)) !important;
}
.thread-sender-picker, .reply-sender-picker, .follower-section {
  padding: 11px;
  background: var(--surface-soft);
  border-color: var(--border);
  border-radius: var(--ui-radius-sm);
}
.thread-sender-picker input, .thread-sender-picker select,
.reply-sender-picker input, .reply-sender-picker select {
  min-height: var(--control-height);
  height: auto;
  padding: 8px 10px;
  font-size: calc(13px * var(--ui-font-scale));
}
.thread-event-list {
  gap: var(--ui-space-2);
  padding-left: 9px;
}
.thread-event-item {
  min-height: 88px;
  padding: 11px 12px;
  gap: 5px;
  border-radius: var(--ui-radius-sm);
}
.thread-event-head, .thread-event-message, .reply-source-message, .reply-sender,
.reply-empty, .thread-empty, .logbox, .pool-list, .excl-list {
  font-size: calc(13px * var(--ui-font-scale));
}
.thread-event-action { color: var(--accent); }
.reply-event-list {
  display: flex;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: none;
  flex: 1 1 120px;
  flex-direction: column;
  gap: 6px;
  overflow-x: hidden;
  overflow-y: auto;
}
.reply-event-item {
  width: 100%;
  max-width: 100%;
  min-height: 38px;
  height: auto;
  padding: 8px 10px;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.reply-compose {
  gap: var(--ui-space-2);
  padding-top: var(--ui-space-3);
}
.reply-source-message { padding: 10px; }
.logbox { padding: 9px; line-height: 1.5; }

.workspace-tools {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(210px, auto) minmax(0, 1fr);
  gap: var(--ui-space-3);
  align-items: start;
  margin-top: var(--ui-space-2);
}
.workspace-quick-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2);
  align-items: end;
}
.workspace-quick-controls label { margin: 0; }
.shared-layout-controls {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-2);
  align-items: end;
}
.shared-layout-controls label { min-width: 140px; margin: 0; }
.shared-layout-controls select { min-width: 170px; }
.shared-layout-controls input { width: 170px; }
.shared-layout-status { flex: 1 1 100%; min-height: 14px; font-size: 10px; }
.workspace-manager {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius-sm);
  background: var(--surface-soft);
}
.workspace-manager > summary {
  min-height: var(--control-height);
  display: flex;
  align-items: center;
  padding: 7px 12px;
  color: var(--text);
  font-size: calc(13px * var(--ui-font-scale));
}
.workspace-manager-body {
  display: grid;
  gap: var(--ui-space-3);
  padding: 12px;
  border-top: 1px solid var(--border);
}
.module-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 8px;
}
.module-option {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius-sm);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.module-option span { display: grid; gap: 2px; }
.workspace-local-note { color: var(--muted); font-size: calc(12px * var(--ui-font-scale)); }
.layout-resizable-control {
  box-sizing: border-box !important;
  resize: none !important;
  background-image:
    linear-gradient(135deg, transparent 52%, color-mix(in srgb, var(--muted) 72%, transparent) 54% 61%, transparent 63%),
    linear-gradient(135deg, transparent 68%, color-mix(in srgb, var(--muted) 72%, transparent) 70% 77%, transparent 79%);
  background-position: right 2px bottom 2px;
  background-repeat: no-repeat;
  background-size: 12px 12px;
}
.layout-resizable-control.layout-user-sized {
  min-width: 0 !important;
  min-height: 0 !important;
  max-height: none !important;
}
.layout-resizable-control.layout-user-sized:not([data-layout-user-axis="vertical"]) {
  width: var(--layout-user-width) !important;
  max-width: var(--layout-control-max-width, calc(100vw - 24px)) !important;
}
.layout-resizable-control.layout-user-sized:not([data-layout-user-axis="horizontal"]) {
  height: var(--layout-user-height) !important;
}
.layout-resizable-control[data-layout-cross-width-locked="1"] {
  width: var(--layout-user-width) !important;
}
.layout-resizable-control[data-layout-cross-height-locked="1"] {
  height: var(--layout-user-height) !important;
}
.layout-responsive-row {
  min-width: 0;
  flex-wrap: wrap !important;
  align-content: flex-start;
}
.layout-responsive-host.layout-host-user-sized-horizontal {
  min-width: min-content !important;
}
.layout-responsive-host.layout-host-user-sized-vertical {
  min-height: min-content !important;
}
.modal-card.layout-responsive-surface { max-width: calc(100vw - 40px); overflow: auto; }
.emoji-picker.layout-responsive-surface { max-width: calc(100vw - 8px); }
.ui-preferences-panel.layout-responsive-surface { max-width: calc(100vw - 36px); }
.ui-preferences-panel.layout-responsive-surface .ui-preferences-body {
  grid-template-columns: minmax(0, 1fr);
}
.pane:not(.is-collapsed) > .pane-h.layout-responsive-row {
  overflow: visible;
}
.layout-resizable-control.layout-resizing {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
  user-select: none;
}
.header-channel { margin: 0; }
.header-channel input { width: 140px; }
.signout-link { display: inline-flex; min-height: var(--control-height); align-items: center; padding: 0 7px; }
.connection-tuning-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--ui-space-2);
  margin-top: var(--ui-space-2);
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius-sm);
  background: var(--surface-soft);
}
.connection-tuning-row > strong { align-self: center; margin-right: 3px; white-space: nowrap; }
.connection-tuning-row > div { min-width: 0; }
.connection-tuning-row label { margin: 0 0 3px; }
.connection-tuning-row button { align-self: end; }
#ratio_pct, #hard_override { width: 95px; }
.grow-field { flex: 1 1 260px; }
.grow-field input { width: 100%; }

body[data-ui-page="dashboard"] {
  min-height: 100%;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
}
body[data-ui-page="dashboard"] > header { position: sticky; top: 0; }
body[data-ui-page="dashboard"] .workspace {
  flex: none;
  display: flex !important;
  flex-direction: column;
  gap: var(--ui-space-4);
  min-height: 0;
  padding: var(--ui-space-4);
  overflow: visible !important;
}
body[data-ui-page="dashboard"] .top-row {
  display: flex !important;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: flex-start;
  gap: var(--ui-space-4) !important;
  overflow: visible !important;
}
body[data-ui-page="dashboard"] .pane-top {
  flex: 0 0 auto;
  min-width: 280px;
  min-height: 220px;
  max-width: 100%;
  resize: none;
}
body[data-ui-page="dashboard"] #pane-logs {
  width: 100%;
  min-height: 140px;
  max-width: 100%;
  resize: none;
}
.pane.layout-resizing { outline: 1px solid var(--accent); outline-offset: 1px; }
body[data-ui-page="dashboard"] .pane[data-layout-pane-resize-ready="1"] { position: relative; }
body[data-ui-page="dashboard"] .pane-resize-handle {
  position: absolute;
  z-index: 320;
  display: block;
  touch-action: none;
  user-select: none;
}
body[data-ui-page="dashboard"] .pane-resize-handle--horizontal {
  top: 46px;
  right: 0;
  bottom: 16px;
  width: 7px;
  cursor: ew-resize;
}
body[data-ui-page="dashboard"] .pane-resize-handle--vertical {
  right: 16px;
  bottom: 0;
  left: 0;
  height: 7px;
  cursor: ns-resize;
}
body[data-ui-page="dashboard"] .pane-resize-handle--both {
  right: 2px;
  bottom: 2px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 56%, color-mix(in srgb, var(--muted) 75%, transparent) 58% 66%, transparent 68%, transparent 76%, color-mix(in srgb, var(--muted) 75%, transparent) 78% 86%, transparent 88%);
}
body[data-ui-page="dashboard"] .pane.is-collapsed > .pane-resize-handle,
body[data-ui-page="dashboard"] .pane.is-focused > .pane-resize-handle,
body[data-ui-page="dashboard"] #pane-logs.logs-collapsed > .pane-resize-handle { display: none; }
.workspace #pane-logs.logs-collapsed {
  height: 52px !important;
  min-height: 52px !important;
  max-height: 52px !important;
  resize: none !important;
}
.workspace #pane-logs.logs-collapsed > .pane-body { display: none; }
body[data-ui-page="dashboard"] #bgt_cards,
body[data-ui-page="dashboard"] #bgt_cards label,
body[data-ui-page="dashboard"] #bgt_cards input,
body[data-ui-page="dashboard"] #bgt_cards button,
body[data-ui-page="dashboard"] #bgt_cards select,
body[data-ui-page="dashboard"] #bgt_cards summary,
body[data-ui-page="dashboard"] #bgt_cards small,
body[data-ui-page="dashboard"] #bgt_cards span,
body[data-ui-page="dashboard"] #bgt_cards div,
body[data-ui-page="dashboard"] #bgt_cards b {
  font-size: calc(12px * var(--ui-font-scale)) !important;
}
body[data-ui-page="dashboard"] #bgt_cards input,
body[data-ui-page="dashboard"] #bgt_cards button,
body[data-ui-page="dashboard"] #bgt_cards select { min-height: 32px; }
body[data-ui-page="dashboard"] .pane b,
body[data-ui-page="dashboard"] .pane summary,
body[data-ui-page="dashboard"] .pane label,
body[data-ui-page="dashboard"] .pane .muted,
body[data-ui-page="dashboard"] .pane code,
body[data-ui-page="dashboard"] .pane a {
  font-size: calc(12px * var(--ui-font-scale)) !important;
}
body[data-ui-page="dashboard"] .pane textarea { font-size: calc(13px * var(--ui-font-scale)) !important; }

body[data-ui-page="follower"] {
  min-height: 100%;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
}
.follower-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: var(--ui-space-4);
  display: grid;
  gap: var(--ui-space-4);
}
.follower-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: var(--ui-space-4);
}
.follower-grid .wide { grid-column: 1 / -1; }
.follower-grid .pane { min-height: 0; overflow: visible; }
.follower-grid .pane-body {
  flex: 0 0 auto;
  min-height: 110px;
  overflow: visible;
}
.follower-grid .wide .pane-body { overflow-x: auto; }
.follower-grid .wide, .follower-grid .wide .pane-body,
.follower-pane-body, .follower-history-section, .follower-history-scroll { min-width: 0; max-width: 100%; }
.control-stack { display: grid; gap: var(--ui-space-3); }
.control-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--ui-space-2); align-items: end; }
.status-grid { display: grid; grid-template-columns: repeat(4, minmax(115px, 1fr)); gap: var(--ui-space-2); }
.account-select { width: 100%; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.history-table .ok, .follower-history-table .ok { color: var(--ok); }
.history-table .bad, .follower-history-table .bad { color: var(--err); }
.history-more { width: 100%; margin-top: 12px; }
.error-box[hidden], .follower-error-box[hidden] { display: none; }
.follower-transaction {
  padding: 11px 12px;
  border: 1px solid rgba(var(--accent-rgb), .4);
  border-radius: var(--ui-radius-sm);
  background: rgba(var(--accent-rgb), .09);
  color: var(--muted);
}
.follower-transaction strong { color: var(--text); }
.toast.toast-reply { border-left-color: var(--warn); }
.error-box, .follower-error-box {
  border: 1px solid color-mix(in srgb, var(--err) 55%, var(--border));
  background: color-mix(in srgb, var(--err) 8%, var(--panel));
  color: var(--err);
}

body[data-ui-page="tester"] { overflow-x: hidden; }
body[data-ui-page="tester"] header {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-3);
  padding: 12px 18px;
}
body[data-ui-page="tester"] .content {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: var(--ui-space-4);
  gap: var(--ui-space-4);
}
body[data-ui-page="tester"] .header-actions { flex-wrap: wrap; }
body[data-ui-page="tester"] .model-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
}
body[data-ui-page="tester"] .ctx-field { min-width: min(100%, 200px); }
body[data-ui-page="tester"] .ctx-field label,
body[data-ui-page="tester"] .prompt-adjust-input label,
body[data-ui-page="tester"] .prompt-adjust-preview label,
body[data-ui-page="tester"] .engine-controls label,
body[data-ui-page="tester"] .status-badge,
body[data-ui-page="tester"] .pending-source,
body[data-ui-page="tester"] .pending-mode,
body[data-ui-page="tester"] .sv-vibe,
body[data-ui-page="tester"] .sv-dedup,
body[data-ui-page="tester"] .learn-item .learn-tag {
  font-size: calc(12px * var(--ui-font-scale));
}
body[data-ui-page="tester"] textarea,
body[data-ui-page="tester"] input,
body[data-ui-page="tester"] select,
body[data-ui-page="tester"] .ctx-info,
body[data-ui-page="tester"] .engine-state,
body[data-ui-page="tester"] .engine-reason,
body[data-ui-page="tester"] .engine-wave,
body[data-ui-page="tester"] .model-card .top-row input,
body[data-ui-page="tester"] .msg-list,
body[data-ui-page="tester"] .pending-list,
body[data-ui-page="tester"] .gen-history-list,
body[data-ui-page="tester"] .live-col .live-list,
body[data-ui-page="tester"] .vod-list,
body[data-ui-page="tester"] .sv-detail,
body[data-ui-page="tester"] .sv-ctx-box,
body[data-ui-page="tester"] .learn-list {
  font-size: calc(13px * var(--ui-font-scale));
}
body[data-ui-page="tester"] .vod-controls input[type="text"] { min-width: min(100%, 240px); }
body[data-ui-page="tester"] .metric,
body[data-ui-page="tester"] .metric .label,
body[data-ui-page="tester"] .metric .value,
body[data-ui-page="tester"] .arrow,
body[data-ui-page="tester"] .msg-empty,
body[data-ui-page="tester"] .metrics-row,
body[data-ui-page="tester"] .prompt-adjust-summary,
body[data-ui-page="tester"] h3,
body[data-ui-page="tester"] label {
  font-size: calc(12px * var(--ui-font-scale)) !important;
}
body[data-ui-page="tester"] input { font-size: calc(13px * var(--ui-font-scale)) !important; }

body[data-ui-page="graph"], body[data-ui-page="tester-context"] {
  overflow-x: hidden;
  background: var(--bg) !important;
  color: var(--text) !important;
}
body[data-ui-page="graph"] header, body[data-ui-page="tester-context"] header {
  gap: var(--ui-space-3);
  padding: 12px 18px;
  background: var(--panel) !important;
}
body[data-ui-page="graph"] .stat-card, body[data-ui-page="graph"] .legend-item {
  background: var(--surface-soft);
  border-color: var(--border);
}

body[data-ui-page="login"] {
  min-height: 100vh;
  padding: var(--ui-space-4);
  background:
    radial-gradient(circle at 15% 15%, rgba(var(--accent-rgb), .13), transparent 35%),
    var(--bg) !important;
}
.auth-shell {
  min-height: calc(100vh - (var(--ui-space-4) * 2));
  display: grid;
  place-items: center;
}
.auth-card {
  width: min(440px, 100%);
  margin: 0;
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius-lg);
  background: var(--panel);
  box-shadow: var(--ui-shadow);
}
.auth-form {
  display: grid;
  gap: 14px;
}
.auth-form label {
  display: block;
  margin: 0;
  color: var(--muted);
}
.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 16%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--danger) 42%, var(--border));
  color: color-mix(in srgb, var(--danger) 70%, var(--text));
}
body[data-ui-page="login"] h1 { font-size: calc(26px * var(--ui-font-scale)); }
body[data-ui-page="login"] p { color: var(--muted); }
body[data-ui-page="login"] input, body[data-ui-page="login"] button { width: 100%; }
.suite-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-height);
  padding: 7px 12px;
  border: 1px solid rgba(var(--accent-rgb), .48);
  border-radius: var(--ui-radius-sm);
  background: rgba(var(--accent-rgb), .1);
  color: var(--accent);
  text-decoration: none;
  font-weight: 750;
  letter-spacing: 0;
}
.suite-link:hover {
  background: rgba(var(--accent-rgb), .19);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: none;
}
.suite-link-numberino {
  white-space: nowrap;
}

[data-ui-preferences-anchor] { display: inline-flex; }
.ui-settings-trigger {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 180;
  min-height: var(--control-height);
  padding: 7px 12px;
  border: 1px solid rgba(var(--accent-rgb), .5);
  background: var(--surface-raised);
  color: var(--accent);
  box-shadow: var(--ui-shadow);
}
[data-ui-preferences-anchor] .ui-settings-trigger {
  position: static;
  box-shadow: none;
}
.ui-preferences-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
}
.ui-preferences-dialog[hidden] { display: none; }
.ui-preferences-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: rgba(0, 0, 0, .68);
  padding: 0;
}
.ui-preferences-panel {
  position: relative;
  width: min(580px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--ui-shadow);
}
.ui-preferences-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  padding: 20px 22px 15px;
  border-bottom: 1px solid var(--border);
}
.ui-preferences-header h2 { margin: 2px 0 0; font-size: 23px; }
.ui-eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.ui-icon-button {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 23px;
}
.ui-preferences-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 20px 22px;
}
.ui-field { display: grid; gap: 7px; margin: 0; color: var(--text); }
.ui-field > span { display: flex; justify-content: space-between; color: var(--text); font-weight: 750; }
.ui-field small, .ui-check small { display: block; color: var(--muted); font-weight: 500; }
.ui-field-wide { grid-column: 1 / -1; }
.ui-field-range input { width: 100%; min-height: 28px; padding: 0; }
.ui-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--ui-radius-sm);
  background: var(--surface-soft);
  color: var(--text);
}
.ui-check strong { display: block; }
.ui-preferences-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 22px 20px;
  border-top: 1px solid var(--border);
}
.ui-button-secondary { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.ui-dialog-open { overflow: hidden !important; }

html[data-motion="reduced"] *, html[data-motion="reduced"] *::before, html[data-motion="reduced"] *::after {
  scroll-behavior: auto !important;
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

@media (max-width: 900px) {
  :root { --control-height: 44px; }
  body { font-size: calc(14px * var(--ui-font-scale)) !important; }
  button, .btn, .graph-btn, .back-link { min-height: 44px; }
  header { position: static !important; padding: 10px 12px !important; }
  .top, body[data-ui-page="tester"] header, body[data-ui-page="graph"] header,
  body[data-ui-page="tester-context"] header {
    align-items: stretch;
  }
  .top > .row, header > .row { width: 100%; }
  body[data-ui-page="dashboard"] .top > .row:first-child { flex-wrap: nowrap; }
  body[data-ui-page="dashboard"] .shared-banner { display: none; }
  body[data-ui-page="dashboard"] .header-actions {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 2px 0 5px;
    scrollbar-width: thin;
  }
  body[data-ui-page="dashboard"] .header-actions > * { flex: 0 0 auto; }
  body[data-ui-page="dashboard"] .header-channel input { width: 105px; }
  body[data-ui-page="dashboard"] .connection-tuning-row > strong { flex: 0 0 100%; }
  body[data-ui-page="dashboard"] .connection-tuning-row .grow-field { flex-basis: 100%; }
  body[data-ui-page="dashboard"] .metrics {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 2px 0 5px;
    scrollbar-width: thin;
  }
  body[data-ui-page="dashboard"] .metrics .m { flex: 0 0 112px; min-width: 112px; }
  body[data-ui-page="dashboard"] .workspace-tools {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }
  body[data-ui-page="dashboard"] .workspace-quick-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }
  body[data-ui-page="dashboard"] .workspace-quick-controls label,
  body[data-ui-page="dashboard"] .workspace-quick-controls select { width: 100%; }
  body[data-ui-page="dashboard"] .shared-layout-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }
  body[data-ui-page="dashboard"] .shared-layout-controls label,
  body[data-ui-page="dashboard"] .shared-layout-controls input,
  body[data-ui-page="dashboard"] .shared-layout-controls select { width: 100%; }
  body[data-ui-page="dashboard"] .shared-layout-status { grid-column: 1 / -1; }
  body[data-ui-page="dashboard"] .workspace-manager > summary { min-height: 44px; }

  body[data-ui-page="dashboard"] {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }
  body[data-ui-page="dashboard"] .workspace {
    display: flex !important;
    padding: 12px;
    overflow: visible !important;
  }
  body[data-ui-page="dashboard"] .top-row {
    display: flex !important;
    flex-wrap: wrap;
    gap: 12px !important;
    overflow: visible !important;
  }
  body[data-ui-page="dashboard"] .pane-top {
    min-width: min(280px, 100%);
    max-width: 100%;
    overflow: hidden;
    resize: none;
  }
  body[data-ui-page="dashboard"] .thread-event-list,
  body[data-ui-page="dashboard"] .logbox { max-height: 360px; overflow: auto; }
  body[data-ui-page="dashboard"] #pane-logs:not(.logs-collapsed) { min-height: 180px; }

  .follower-grid, .status-grid { grid-template-columns: 1fr 1fr; }
  .follower-grid .wide { grid-column: 1 / -1; }
  .follower-shell { padding: 12px; }

  body[data-ui-page="tester"] header h1 { width: 100%; white-space: normal; }
  body[data-ui-page="tester"] .header-actions { width: 100%; margin-left: 0; flex-wrap: nowrap; overflow-x: auto; }
  body[data-ui-page="tester"] .header-actions .btn { flex: 0 0 auto; }
  body[data-ui-page="tester"] .content { padding: 12px; }
  body[data-ui-page="tester"] .prompt-adjust-grid,
  body[data-ui-page="tester"] .live-ctx-body,
  body[data-ui-page="tester"] .vod-body { grid-template-columns: 1fr; }
  body[data-ui-page="tester"] .vod-controls > * { min-width: 0 !important; width: 100%; }
  body[data-ui-page="tester"] .model-card { min-width: 0; padding: 12px; }

  body[data-ui-page="graph"] { min-height: 100vh; height: auto; }
  body[data-ui-page="graph"] header { flex-wrap: wrap; }
  body[data-ui-page="graph"] .stat-cards { width: 100%; margin-left: 0; flex-wrap: nowrap; overflow-x: auto; }
  body[data-ui-page="graph"] .stat-card { flex: 0 0 100px; }
  body[data-ui-page="graph"] .chart-wrap { min-height: 430px; }
  body[data-ui-page="tester-context"] header { flex-wrap: wrap; }
  body[data-ui-page="tester-context"] header .spacer { display: none; }
}

@media (max-width: 560px) {
  .module-options { grid-template-columns: 1fr; }
  body[data-ui-page="dashboard"] .connection-tuning-row > div,
  body[data-ui-page="dashboard"] .connection-tuning-row input,
  body[data-ui-page="dashboard"] .connection-tuning-row select,
  body[data-ui-page="dashboard"] .connection-tuning-row button { width: 100%; }
  .follower-grid, .status-grid { grid-template-columns: 1fr; }
  .follower-grid .wide { grid-column: auto; }
  .control-row { grid-template-columns: 1fr; }
  body[data-ui-page="follower"] .history-table,
  body[data-ui-page="dashboard"] .follower-history-table,
  body[data-ui-page="follower"] .history-table tbody,
  body[data-ui-page="dashboard"] .follower-history-table tbody {
    display: block;
    width: 100%;
    min-width: 0;
  }
  body[data-ui-page="follower"] .history-table thead,
  body[data-ui-page="dashboard"] .follower-history-table thead { display: none; }
  body[data-ui-page="follower"] .history-table tr,
  body[data-ui-page="dashboard"] .follower-history-table tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    margin-bottom: 10px;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: var(--ui-radius-sm);
    background: var(--surface-soft);
  }
  body[data-ui-page="follower"] .history-table td,
  body[data-ui-page="dashboard"] .follower-history-table td {
    display: grid;
    min-width: 0;
    gap: 2px;
    padding: 0;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  body[data-ui-page="follower"] .history-table td::before,
  body[data-ui-page="dashboard"] .follower-history-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-family: var(--ui-font);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  body[data-ui-page="follower"] .history-table td:last-child,
  body[data-ui-page="dashboard"] .follower-history-table td:last-child { grid-column: 1 / -1; }
  .ui-preferences-body { grid-template-columns: 1fr; padding: 16px; }
  .ui-field-wide { grid-column: auto; }
  .ui-preferences-header, .ui-preferences-actions { padding-left: 16px; padding-right: 16px; }
  .ui-preferences-actions { flex-direction: column-reverse; }
  .ui-preferences-actions button { width: 100%; }
  .toast-box { left: 10px; right: 10px; }
  .toast { min-width: 0; max-width: none; }
}
