/* ── Fonts (UX-BRAND-07) ──────────────────────────────────────────────── */
@font-face {
  font-family: 'Chronicle Display';
  src: url('/fonts/ChronicleDisplay-Roman.otf') format('opentype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Chronicle Display';
  src: url('/fonts/ChronicleDisplay-Semibold.otf') format('opentype');
  font-weight: 600; font-style: normal; font-display: swap;
}

/* ── Design tokens ────────────────────────────────────────────────────── */
:root {
  /* Brand palette */
  --as-marine:    #075156;
  --as-green:     #2C8248;
  --as-citrus:    #ABDD65;
  --as-navy:      #17232D;
  --as-pale-blue: #E5EEEF;

  /* Font stacks */
  --font-display: 'Chronicle Display', Georgia, 'Times New Roman', serif;
  --font-body:    'Montserrat', 'Helvetica Neue', Arial, sans-serif;
  --font-mono:    'JetBrains Mono', Consolas, 'Courier New', monospace;

  /* Surfaces */
  --bg:   #17232D;
  --bg-2: #1d2b36;
  --bg-3: #253340;
  --bg-4: #2e3e4d;
  --line: #304050;

  /* Text */
  --text:      #E5EEEF;
  --text-dim:  #8fa8b4;
  --text-muted:#5c7582;

  /* Semantic */
  --primary:       #2a7278;
  --primary-hover: #327e84;
  --on-primary:    #FFFFFF;
  --accent:        #ABDD65;
  --on-accent:     #0d1a0a;
  --danger:        #f07680;
  --danger-dim:    rgba(240,118,128,0.15);
  --success:       #4cca70;
  --success-dim:   rgba(76,202,112,0.12);
  --warning:       #f0b429;

  /* Message role colours */
  --msg-user:        #E5EEEF;
  --msg-assistant:   #ABDD65;
  --msg-tool-call:   #cfe6a3;
  --msg-tool-result: #b8b0ff;
  --msg-error:       #f07680;

  /* Radius / spacing */
  --radius-sm: 6px;
  --radius:    8px;
  --radius-lg: 12px;

  /* Focus ring */
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

/* ── Reset ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* ── Base ─────────────────────────────────────────────────────────────── */
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-4); }

/* ── Shared button base ───────────────────────────────────────────────── */
button { font-family: var(--font-body); cursor: pointer; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ── Header ───────────────────────────────────────────────────────────── */
/* Visually-hidden but screen-reader-available (UX-AX-08 / UX-AX-09). */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link (UX-AX-02): off-screen until focused, then anchored top-left. */
.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 200;
  background: var(--accent);
  color: var(--on-accent, #17232D);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: var(--radius);
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 8px;
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top, 8px));
  padding-left:  max(16px, env(safe-area-inset-left,  16px));
  padding-right: max(16px, env(safe-area-inset-right, 16px));
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  position: relative;
  z-index: 10;
  min-height: 52px;
  flex-shrink: 0;
}

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand .logo { height: 26px; width: auto; display: block; }
.brand .product {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.2px;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.brand .product .v {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
}
.grow { flex: 1; }

/* ── Status cluster ───────────────────────────────────────────────────── */
.status-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
}
.env-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(171,221,101,0.12);
  color: var(--accent);
}
.status-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-family: var(--font-body);
  background: var(--bg-3);
  color: var(--text-dim);
  border: 1px solid transparent;
  min-height: 44px;  /* UX-AX-04: 44px tap target (was 32px) */
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.status-trigger:hover,
.status-trigger[aria-expanded="true"] {
  background: var(--bg-4);
  color: var(--text);
  border-color: var(--line);
}
.status-trigger .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-trigger.ok  .dot { background: var(--success); }
.status-trigger.bad .dot { background: var(--danger); }

.status-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 300px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  z-index: 100;
  flex-direction: column;
  overflow: hidden;
}
.status-trigger[aria-expanded="true"] + .status-panel { display: flex; }
.status-panel .p-sect {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.status-panel .p-sect:last-child { border-bottom: none; }
.status-panel h4 {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}
.status-panel .p-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  margin-bottom: 5px;
}
.status-panel .p-row:last-child { margin-bottom: 0; }
.status-panel .p-lbl { color: var(--text-dim); }
.status-panel .p-val { font-family: var(--font-mono); font-size: 12px; }
.status-panel .p-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}
.status-panel .p-link:hover { text-decoration: underline; }

/* ── Account / user menu ──────────────────────────────────────────────── */
.account { position: relative; display: flex; align-items: center; }
.user-menu { position: relative; }

.btn-signin {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: var(--radius);
  padding: 7px 14px;
  min-height: 44px; /* UX-AX-04: 44px shipping minimum tap target */
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-signin:hover  { background: var(--primary-hover); }

.user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px 3px 3px;
  color: var(--text);
  font-size: 13px;
  min-height: 36px;
  transition: border-color 0.15s;
}
.user-trigger:hover,
.user-trigger[aria-expanded="true"] { border-color: var(--text-dim); }

.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--as-citrus);
  color: var(--as-navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.user-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  z-index: 120;
  padding: 12px;
  flex-direction: column;
  gap: 10px;
}
.user-trigger[aria-expanded="true"] + .user-panel { display: flex; }

.u-ident .u-name  { font-weight: 600; font-size: 14px; }
.u-ident .u-email { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.adv { border-top: 1px solid var(--line); padding-top: 10px; }
.adv summary { cursor: pointer; color: var(--text-dim); font-size: 12px; list-style: none; }
.adv summary::before { content: '▸ '; }
.adv[open] summary::before { content: '▾ '; }
.adv-hint { font-size: 11px; color: var(--text-muted); margin: 6px 0; }
.adv input[type=text] {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.adv input[type=text]:focus { outline: none; box-shadow: var(--focus-ring); }

/* ── Admin gear button ────────────────────────────────────────────────── */
.admin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 16px;
  min-width: 44px;  /* UX-AX-04: 44px tap target */
  min-height: 44px;
  padding: 0 8px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.admin-btn:hover { color: var(--text); border-color: var(--accent); background: var(--bg-3); }

/* ── Shared button styles ─────────────────────────────────────────────── */
.btn-primary {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  background: var(--primary);
  color: var(--on-primary);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 16px;
  min-height: 36px;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled)  { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  min-height: 36px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2, rgba(127,127,127,0.08)); border-color: var(--primary); }
.btn-secondary:disabled { opacity: 0.45; cursor: not-allowed; }

.admin-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.kv-secret {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border, var(--line));
  border-radius: var(--radius);
  background: var(--bg-3);
}
.kv-secret-head { font-size: 13px; font-weight: 600; color: var(--text); }
.kv-secret input { width: 100%; }

.btn-ghost {
  font-family: var(--font-body);
  font-size: 13px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 14px;
  min-height: 36px;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--bg-3); }

.btn-sm { font-size: 12px; padding: 4px 10px; min-height: 30px; }

.btn-danger {
  font-family: var(--font-body);
  font-size: 12px;
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  min-height: 30px;
  transition: background 0.15s;
}
.btn-danger:hover { background: rgba(240,118,128,0.25); }

/* ── Main layout ──────────────────────────────────────────────────────── */
main {
  display: grid;
  grid-template-columns: 268px 1fr;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
aside {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar-head-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.sidebar-head-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-3);
  padding: 1px 7px;
  border-radius: 10px;
}

.sidebar-ctrls {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-ctrls-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-ctrls select {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  min-height: 38px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238fa8b4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.sidebar-ctrls select:focus { outline: none; box-shadow: var(--focus-ring); border-color: transparent; }

.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius);
  padding: 9px 12px;
  min-height: 40px;
  transition: filter 0.15s;
}
.btn-new-chat:hover:not(:disabled)  { filter: brightness(1.08); }
.btn-new-chat:disabled { opacity: 0.45; cursor: not-allowed; }

/* Sessions list */
#sessions {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.sessions-empty {
  padding: 20px 12px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  line-height: 1.6;
}

.session {
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 2px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 44px;
  transition: background 0.12s;
}
.session:hover { background: var(--bg-3); }
.session.active {
  background: var(--bg-3);
  border-left: 3px solid var(--accent);
  padding-left: 8px;
}

.session-body { flex: 1; min-width: 0; }
.session-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.session.active .session-title { color: var(--accent); }
.session-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.template-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(171,221,101,0.12);
  color: var(--accent);
  margin-left: 5px;
  font-weight: 600;
  vertical-align: middle;
}

.session-del {
  opacity: 0;
  color: var(--text-muted);
  font-size: 16px;
  background: none;
  border: none;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
  align-self: center;
  transition: color 0.12s, opacity 0.12s;
}
.session:hover .session-del { opacity: 1; }
.session-del:hover { color: var(--danger); }

/* ── Workspace ────────────────────────────────────────────────────────── */
section.workspace {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* Empty / welcome state */
.workspace-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 32px;
  gap: 16px;
}
.workspace-empty .empty-headline {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 600;
  color: var(--text-dim);
  line-height: 1.2;
  margin: 0;
}
.workspace-empty .empty-sub {
  font-size: 15px;
  /* UX-AX-05: --text-muted is ~3.3:1 on the navy bg (fails AA for body text);
     --text-dim is ~6.4:1. This is real content, so use the compliant token. */
  color: var(--text-dim);
  max-width: 380px;
  line-height: 1.6;
}
.workspace-empty .empty-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 11px 22px;
  cursor: pointer;
  margin-top: 8px;
  transition: filter 0.15s;
}
.workspace-empty .empty-cta:hover { filter: brightness(1.08); }

/* Message trail */
#trail {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Message bubbles */
.msg {
  padding: 10px 14px;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
  line-height: 1.6;
  font-size: 15px;
  max-width: 820px;
}
.msg + .msg { margin-top: 4px; }

.msg .role {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 5px;
  opacity: 0.75;
}
.msg .body { white-space: pre-wrap; word-break: break-word; }

.msg.user {
  background: rgba(229,238,239,0.04);
  border-left-color: var(--msg-user);
}
.msg.user .role { color: var(--msg-user); }

.msg.assistant {
  background: rgba(171,221,101,0.05);
  border-left-color: var(--msg-assistant);
}
.msg.assistant .role { color: var(--msg-assistant); }

.msg.tool-call {
  background: rgba(207,230,163,0.04);
  border-left-color: var(--msg-tool-call);
}
.msg.tool-call .role { color: var(--msg-tool-call); }
.msg.tool-call .body {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
}

.msg.tool-result {
  background: rgba(184,176,255,0.04);
  border-left-color: var(--msg-tool-result);
}
.msg.tool-result .role { color: var(--msg-tool-result); }
.msg.tool-result .body {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
}

/* Collapsible, content-aware tool result (F4 + rich rendering). */
.tool-result-bar { display: flex; gap: 6px; margin-top: 6px; align-items: stretch; }
.tool-result-summary {
  flex: 1;
  text-align: left;
  padding: 4px 8px;
  background: rgba(184,176,255,0.06);
  border: 1px solid rgba(184,176,255,0.18);
  border-radius: 6px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.tool-result-summary:hover { background: rgba(184,176,255,0.12); }
.tool-result-summary::before { content: '▸ '; color: var(--msg-tool-result); }
.msg.tool-result.expanded .tool-result-summary::before { content: '▾ '; }
.tool-result-open {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid rgba(184,176,255,0.25);
  border-radius: 6px;
  color: var(--msg-tool-result);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.tool-result-open:hover { background: rgba(184,176,255,0.12); }
.tool-result-body {
  margin: 6px 0 0;
  padding: 8px;
  max-height: 420px;
  overflow: auto;
  background: rgba(0,0,0,0.18);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}
.tool-result-body.md { font-family: inherit; }
.msg.tool-result.collapsed .tool-result-body { display: none; }
.tool-result-text { margin: 0; white-space: pre-wrap; word-break: break-word; }
.tool-result-html-note { font-style: italic; color: var(--text-muted); }

/* ── Markdown rendering (assistant + tool/markdown) ───────────────────────── */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md .md-h { margin: 14px 0 6px; line-height: 1.3; font-weight: 600; color: var(--text); }
.md h1.md-h { font-size: 1.35em; } .md h2.md-h { font-size: 1.2em; } .md h3.md-h { font-size: 1.08em; }
.md h4.md-h, .md h5.md-h, .md h6.md-h { font-size: 1em; }
.md .md-p { margin: 8px 0; line-height: 1.55; }
.md .md-ul, .md .md-ol { margin: 8px 0; padding-left: 22px; line-height: 1.5; }
.md .md-ul li, .md .md-ol li { margin: 3px 0; }
.md .md-hr { border: 0; border-top: 1px solid var(--border, #2e3e4d); margin: 14px 0; }
.md code {
  font-family: var(--font-mono); font-size: 0.9em;
  background: rgba(0,0,0,0.28); padding: 1px 5px; border-radius: 4px; color: var(--accent);
}
.md .md-code {
  margin: 10px 0; padding: 10px 12px; overflow: auto;
  background: rgba(0,0,0,0.32); border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px; font-family: var(--font-mono); font-size: 12px; color: var(--text-dim);
}
.md .md-code code { background: none; padding: 0; color: inherit; }
.md a { color: var(--accent); text-decoration: underline; }
.md .md-table, .data-table {
  border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 12px;
}
.md .md-table th, .md .md-table td, .data-table th, .data-table td {
  border: 1px solid rgba(255,255,255,0.10); padding: 5px 9px; text-align: left; vertical-align: top;
}
.md .md-table th, .data-table th {
  background: rgba(255,255,255,0.05); color: var(--text); font-weight: 600; position: sticky; top: 0;
}
.data-table-wrap { overflow: auto; max-height: 380px; }
.data-table tbody tr:nth-child(even), .data-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.02); }

/* ── JSON pretty view ─────────────────────────────────────────────────────── */
.json-view {
  margin: 0; white-space: pre; overflow: auto;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.5; color: var(--text-dim);
}
.json-view .j-key { color: #9ad0ff; }
.json-view .j-str { color: var(--accent); }
.json-view .j-num { color: #ffcf7a; }
.json-view .j-bool { color: #ff9ecf; }

.inline-open {
  margin-top: 8px; padding: 4px 10px; background: transparent;
  border: 1px solid var(--accent); border-radius: 6px; color: var(--accent);
  font-size: 12px; cursor: pointer;
}
.inline-open:hover { background: rgba(171,221,101,0.12); }

/* ── Inspector side panel ─────────────────────────────────────────────────── */
.inspector-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  z-index: 90; opacity: 1;
}
.inspector {
  position: fixed; top: 0; right: 0; height: 100vh;
  width: min(640px, 92vw);
  background: var(--bg-2); border-left: 1px solid var(--bg-4);
  box-shadow: -8px 0 30px rgba(0,0,0,0.4);
  z-index: 91; display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.2s ease;
}
.inspector.open { transform: translateX(0); }
.inspector-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--bg-4); flex: 0 0 auto;
}
.inspector-title {
  font-weight: 600; color: var(--text); font-size: 14px;
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inspector-tabs { display: flex; gap: 4px; }
.inspector-tab {
  padding: 4px 10px; background: transparent; border: 1px solid var(--bg-4);
  border-radius: 6px; color: var(--text-dim); font-size: 12px; cursor: pointer;
}
.inspector-tab.active { background: var(--bg-4); color: var(--text); }
.inspector-body { flex: 1 1 auto; overflow: auto; padding: 14px; min-height: 0; }
.inspector-frame { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.inspector-rich { color: var(--text-dim); }
.inspector-raw {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font-family: var(--font-mono); font-size: 12px; color: var(--text-dim);
}
@media (max-width: 640px) { .inspector { width: 100vw; } }

.msg .footnote {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.msg .template-foot {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* Approval cards (human-in-the-loop) */
.approval-card {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 8px;
  max-width: 820px;
}
.approval-card .approval-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--warning);
  margin-bottom: 6px;
}
.approval-card .approval-tool {
  font-family: var(--font-mono);
  font-size: 13px;
  margin-bottom: 10px;
  color: var(--text-dim);
}
.approval-card .approval-btns,
.approval-card .approval-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.approval-card .approval-reason { font-size: 13px; margin: 4px 0; }
.approval-card .approval-target {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Tenant / environment chip — shows which external system a tool affects. */
.tenant-chip {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  vertical-align: middle;
  white-space: nowrap;
}
.tenant-chip-safe {
  background: color-mix(in srgb, var(--ok, #2e7d32) 16%, transparent);
  color: var(--ok, #2e7d32);
  border: 1px solid color-mix(in srgb, var(--ok, #2e7d32) 35%, transparent);
}
.tenant-chip-gated {
  background: color-mix(in srgb, var(--warning, #c62828) 16%, transparent);
  color: var(--warning, #c62828);
  border: 1px solid color-mix(in srgb, var(--warning, #c62828) 40%, transparent);
}

/* Thinking indicator */
.thinking {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
}
.thinking span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 100% { opacity: 0.25; }
  50%       { opacity: 1; }
}

/* ── Composer ─────────────────────────────────────────────────────────── */
.composer {
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  padding-left:  max(20px, env(safe-area-inset-left,  20px));
  padding-right: max(20px, env(safe-area-inset-right, 20px));
  flex-shrink: 0;
}

.composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  min-height: 44px;
  max-height: 180px;
  overflow-y: auto;
  transition: border-color 0.15s;
  field-sizing: content; /* auto-resize where supported */
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.composer textarea:disabled { opacity: 0.5; }
.composer textarea::placeholder { color: var(--text-muted); }

.composer-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: var(--radius);
  padding: 0 18px;
  height: 44px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: filter 0.15s, opacity 0.15s;
}
.composer-send:hover:not(:disabled)  { filter: brightness(1.08); }
.composer-send:disabled { opacity: 0.4; cursor: not-allowed; }

.composer-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

/* Signed-out state */
body.signed-out .composer { opacity: 0.5; pointer-events: none; }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 16px));
  right:  max(16px, calc(env(safe-area-inset-right, 0px) + 16px));
  background: var(--bg-4);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 300;
  max-width: min(360px, calc(100vw - 32px));
}
.toast.error { background: var(--danger-dim); border-color: var(--danger); color: var(--danger); }

/* ── Admin drawer ─────────────────────────────────────────────────────── */
.admin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  backdrop-filter: blur(2px);
}
.admin-overlay[hidden] { display: none; }

.admin-drawer {
  width: min(520px, 100vw);
  height: 100%;
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 40px rgba(0,0,0,0.45);
  overflow: hidden;
}
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top, 16px));
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.admin-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.admin-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  min-width: 36px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.admin-close:hover { color: var(--text); background: var(--bg-3); }

.admin-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.admin-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 11px 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-tab-panel {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.admin-tab-panel[hidden] { display: none; }

.admin-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.admin-hint {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.55;
}

.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.admin-row-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.admin-row-name { font-weight: 600; font-size: 13px; flex-shrink: 0; }
.admin-row-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.admin-row-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }

/* ── Connected accounts ───────────────────────────────────────────────── */
.admin-section-title { font-weight: 700; color: var(--text); letter-spacing: 0.2px; }

/* Legend explaining the three account states. */
.conn-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 11px;
  color: var(--text-dim);
  margin: 0 0 14px;
}
.conn-legend > span { display: inline-flex; align-items: center; gap: 6px; }

/* Status / live dots. Hidden until `.on`; the live dot pulses while active. */
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
  background: var(--text-muted);
}
.conn-legend .conn-dot { opacity: 1; }
.admin-row .conn-dot { opacity: 0; width: 8px; }
.admin-row .conn-dot.on { opacity: 1; }
.conn-dot-ok { background: var(--ok, #2e7d32); }
.conn-dot-off { background: var(--text-muted); }
.conn-dot-toggle { background: var(--accent); }
.conn-dot-live { background: var(--accent); }
.admin-row .conn-dot-live { display: none; }
.admin-row .conn-dot-live.on { display: inline-block; opacity: 1; animation: conn-pulse 1.2s ease-in-out infinite; }
@keyframes conn-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); }
  70%  { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); }
}

/* Enable/disable switch. */
.conn-toggle { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; flex-shrink: 0; }
.conn-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.conn-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  transition: background 0.15s, border-color 0.15s;
}
.conn-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s, background 0.15s;
}
.conn-toggle input:checked + .conn-slider {
  background: color-mix(in srgb, var(--accent) 40%, transparent);
  border-color: var(--accent);
}
.conn-toggle input:checked + .conn-slider::before { transform: translateX(16px); background: var(--accent); }
.conn-toggle input:focus-visible + .conn-slider { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Disabled account: muted, but the controls stay live. */
.conn-row.conn-disabled .admin-row-name,
.conn-row.conn-disabled .admin-row-meta { opacity: 0.5; }

/* ── Multi-instance MCP groups (source: catalog-group) ─────────────────── */
.conn-group {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px 12px;
}
.conn-group-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.conn-group-chip {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--text-dim) 14%, transparent);
  color: var(--text-dim);
  flex-shrink: 0;
}
.conn-group-instances { display: flex; flex-direction: column; gap: 6px; margin-left: 14px; }
.conn-group-instances .conn-row { background: var(--bg-2); }

/* Admin kill-switch: locked rows are dimmed and their toggle is inert. */
.conn-lock-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--danger-dim);
  color: var(--danger);
  flex-shrink: 0;
}
.conn-row.conn-locked .admin-row-name,
.conn-row.conn-locked .admin-row-meta { opacity: 0.5; }
.conn-toggle-locked { cursor: not-allowed; opacity: 0.45; }
.conn-toggle-locked input { pointer-events: none; }
.conn-row-wrap { flex-wrap: wrap; }
.conn-hint {
  flex-basis: 100%;
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Tools page ──────────────────────────────────────────────────────────── */
.tools-source { border: 1px solid var(--border, #2a2a35); border-radius: 8px; margin-bottom: 8px; overflow: hidden; }
.tools-source.conn-disabled .admin-row-name,
.tools-source.conn-disabled .admin-row-meta { opacity: 0.5; }
.tools-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 7px; border-radius: 999px; margin-left: 8px; vertical-align: middle;
}
.tools-badge-admin { background: rgba(99, 102, 241, 0.18); color: #a5b4fc; }
.tools-badge-user  { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
.tools-detail { border-top: 1px solid var(--border, #2a2a35); padding: 6px 14px 10px; }
.tools-detail > summary { cursor: pointer; font-size: 12px; color: var(--text-dim, #9aa0ac); padding: 4px 0; user-select: none; }
.tools-detail > summary:hover { color: var(--text, #e6e6ea); }
.tools-tool-list { list-style: none; margin: 6px 0 0; padding: 0; }
.tools-tool-list li { display: flex; flex-direction: column; gap: 1px; padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.04); }
.tools-tool-list li:last-child { border-bottom: none; }
/* Per-tool row: name/description column on the left, on/off toggle on the right. */
.tools-tool-list li.tools-tool { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.tools-tool-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tools-tool-disabled .tools-tool-info { opacity: 0.5; }
.conn-toggle-sm { transform: scale(0.85); }
.tools-tool-name { font-family: var(--mono, monospace); font-size: 12px; color: #c4b5fd; }
.tools-tool-desc { font-size: 11px; color: var(--text-dim, #9aa0ac); }

.admin-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 20px;
}
.admin-badge.active   { background: var(--success-dim); color: var(--success); }
.admin-badge.disabled,
.admin-badge.inactive { background: rgba(255,255,255,0.06); color: var(--text-muted); }

/* Inactive (kill-switched) MCP servers in the admin list: dimmed like other
   disabled rows, but Edit/Delete stay live so they can be re-enabled. */
.admin-row.mcp-row-inactive .admin-row-name,
.admin-row.mcp-row-inactive .admin-row-meta { opacity: 0.5; }

/* Admin form */
.admin-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.admin-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.2px;
}
/* Inline checkbox rows (MCP recipe toggles) — checkbox beside its label text. */
.admin-form label.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.admin-form label.checkbox-row input { width: auto; }
.admin-form input[type=text],
.admin-form input[type=url],
.admin-form input[type=number],
.admin-form select,
.admin-form textarea {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  resize: vertical;
  min-height: 38px;
  transition: border-color 0.15s;
}
.admin-form input:focus,
.admin-form select:focus,
.admin-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ── Friendly schedule builder ────────────────────────────────────────── */
#sched-time { width: auto; align-self: flex-start; }
.sched-preview {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  line-height: 1.45;
}
.sched-preview.err { border-left-color: var(--warn, #e0a070); color: var(--warn, #e0a070); }
.sched-dow { display: flex; flex-wrap: wrap; gap: 6px; border: 0; padding: 0; margin: 0; }
.sched-dow legend { font-size: 12px; font-weight: 600; color: var(--text-dim); padding: 0; margin-bottom: 6px; }
.dow-chip {
  flex-direction: row;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  cursor: pointer;
}
.dow-chip input { width: auto; min-height: 0; margin: 0; accent-color: var(--accent); }
.dow-chip:has(input:checked) { color: var(--text); border-color: var(--accent); }
/* Restore the [hidden] contract for flex-display elements (UA [hidden] is
   overridden by the explicit display rules above) — matches this file's
   per-component pattern (.admin-overlay[hidden], .schedules-panel[hidden], …). */
.admin-form[hidden],
.admin-form label[hidden],
.sched-dow[hidden] { display: none; }

/* ── PWA / Mobile toggle button ───────────────────────────────────────── */
.sidebar-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.sidebar-toggle-btn:hover { background: var(--bg-3); }

/* Sidebar backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 140;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.open { display: block; }

/* ── Mobile ≤768px ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { font-size: 15px; }

  .sidebar-toggle-btn { display: inline-flex; }

  /* Collapse header. UX-AX-14: wrap instead of overflowing at narrow widths —
     the two sign-in buttons used to push the header past the viewport (h-scroll).
     Dropping the flex spacer lets items pack and wrap onto extra rows. */
  header { gap: 8px; min-height: 48px; flex-wrap: wrap; row-gap: 8px; }
  header .grow { display: none; }
  header .brand .product { display: none; }
  header .brand .logo { height: 22px; }
  .env-badge { display: none; }
  .health-lbl-text { display: none; }
  .user-name { display: none; }
  .btn-signin { font-size: 12px; padding: 8px 10px; }
  .admin-btn { min-width: 44px; min-height: 44px; }

  /* Stack to single column — workspace fills screen */
  main { grid-template-columns: 1fr; }

  /* Sidebar becomes full-height overlay from the left */
  aside {
    position: fixed;
    inset: 0;
    width: min(88vw, 300px);
    right: auto;
    z-index: 145;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  aside.sidebar-open {
    transform: translateX(0);
    box-shadow: 6px 0 32px rgba(0,0,0,0.65);
  }

  /* Push sidebar content below the Dynamic Island */
  .sidebar-head {
    padding-top: max(12px, env(safe-area-inset-top, 12px));
  }

  /* Full-width new chat button */
  .btn-new-chat { min-height: 44px; font-size: 14px; }

  /* Larger touch targets */
  .session { min-height: 52px; padding: 12px 10px; }
  .session-del {
    opacity: 1;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Message trail */
  #trail { padding: 14px; }
  .msg { max-width: 100%; font-size: 15px; }
  .workspace-empty { padding: 32px 24px; }
  .workspace-empty .empty-headline { font-size: 26px; }

  /* Status / user panels — keep in viewport */
  .status-panel { width: min(280px, calc(100vw - 16px)); }
  .user-panel   { width: min(260px, calc(100vw - 16px)); }

  /* Composer */
  .composer { padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom, 10px)); }
  .composer textarea { font-size: 16px; min-height: 44px; max-height: 120px; }
  .composer-hint { display: none; }

  /* Admin drawer full-width */
  .admin-drawer {
    width: 100vw;
    border-left: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* Toast */
  .toast { max-width: calc(100vw - 32px); }
}

/* ── Very small (≤ 390px) ─────────────────────────────────────────────── */
@media (max-width: 390px) {
  .status-trigger { padding: 4px 8px; }
  .admin-btn { padding: 0 6px; }
}

/* ── Landscape on short-screen phones ────────────────────────────────── */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 430px) {
  header { padding-top: 4px; padding-bottom: 4px; min-height: 40px; }
  .composer { padding-top: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom, 6px)); }
  .composer textarea { min-height: 36px; max-height: 70px; }
  #trail { padding: 8px 12px; }
}

/* ── Activity drawer (agent runs — ADR-009) ──────────────────────────── */
.activity-drawer { width: min(680px, 100vw); }

.activity-head-ctrls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.activity-auto {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.activity-auto input { accent-color: var(--primary); }

.runs-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
/* Tab switching: the [hidden] attr must win over display:flex above, else the
   runs list bleeds into the Scheduled/Logs tabs (matches .schedules-panel[hidden]). */
.runs-list[hidden] { display: none; }
.runs-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 32px 12px;
}

.logs-panel {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
/* Without this the Logs filter form shows under every other tab (it has a
   display:flex above, which overrides the UA [hidden] rule). */
.logs-panel[hidden] { display: none; }

.logs-filter {
  margin-bottom: 0;
}

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

.logs-filter-grid label {
  margin: 0;
}

.logs-filter-grid input,
.logs-filter-grid select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text);
  padding: 8px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.logs-filter-grid input:focus,
.logs-filter-grid select:focus {
  border-color: var(--primary);
}

.logs-from-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  margin: 0;
}

.logs-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.logs-output {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  flex: 1;
  overflow-y: auto;
}

.log-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.log-row:last-child {
  border-bottom: none;
}

.log-row-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.log-level-chip {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.log-level-debug { background: rgba(255,255,255,0.08); color: var(--text-muted); }
.log-level-info { background: rgba(42,114,120,0.22); color: #6fd3da; }
.log-level-warn { background: rgba(240,180,41,0.16); color: var(--warning); }
.log-level-error { background: rgba(240,118,128,0.16); color: var(--danger); }

.log-row-ts {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.log-row-meta {
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-row-msg {
  font-size: 12px;
  color: var(--text);
}

.log-row-body {
  margin: 0;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.run-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.run-row-running   { border-left: 3px solid var(--primary); }
.run-row-suspended { border-left: 3px solid var(--warning); }
.run-row-failed    { border-left: 3px solid var(--danger); }
.run-row-cancelled { border-left: 3px solid var(--text-muted); }
.run-row-succeeded { border-left: 3px solid var(--success); }
.run-row-queued    { border-left: 3px solid var(--text-dim); }

.run-main { flex: 1; min-width: 0; }
.run-title-line { display: flex; align-items: center; gap: 8px; }
.run-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.run-meta {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.run-chip {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.run-chip-running   { background: rgba(42,114,120,0.22); color: #6fd3da; }
.run-chip-queued    { background: rgba(255,255,255,0.07); color: var(--text-dim); }
.run-chip-suspended { background: rgba(240,180,41,0.16); color: var(--warning); }
.run-chip-succeeded { background: rgba(76,202,112,0.16); color: var(--success); }
.run-chip-failed    { background: rgba(240,118,128,0.16); color: var(--danger); }
.run-chip-cancelled { background: rgba(255,255,255,0.06); color: var(--text-muted); }

.run-actions { display: flex; gap: 6px; flex-shrink: 0; }
.run-cancel { color: var(--danger); }
.run-cancel:hover { background: rgba(240,118,128,0.12); }

.run-watch {
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  flex-shrink: 0;
  max-height: 40%;
  display: flex;
  flex-direction: column;
}
.run-watch[hidden] { display: none; }
.run-watch-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-dim);
}
.run-watch-log {
  margin: 0;
  padding: 0 14px 14px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 560px) {
  .run-row { flex-wrap: wrap; }
  .run-actions { width: 100%; justify-content: flex-end; }
  .logs-filter-grid { grid-template-columns: 1fr; }
}

/* ── Scheduled agents (Activity drawer) ──────────────────────────────── */
.schedules-panel { flex: 1; overflow-y: auto; padding: 8px 14px 16px; }
.schedules-panel[hidden] { display: none; }
.sched-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
}
.sched-main { flex: 1; min-width: 0; }
.sched-name-line { display: flex; align-items: center; gap: 8px; }
.sched-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Benchmark (admin) ───────────────────────────────────────────────── */
.admin-subhead { font-size: 13px; font-weight: 700; color: var(--text); }
.bm-primary-row { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); margin: 6px 0; cursor: pointer; }
.bm-primary-row input { accent-color: var(--primary); }
#bm-models { width: 100%; font-family: 'JetBrains Mono', monospace; font-size: 12px; }

.bm-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 11.5px;
}
.bm-table th, .bm-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}
.bm-table th {
  background: var(--bg-3);
  font-weight: 700;
  font-size: 11px;
  white-space: nowrap;
}
.bm-rowlabel { font-weight: 600; color: var(--text); white-space: nowrap; }
.bm-cell { font-family: 'JetBrains Mono', monospace; white-space: nowrap; }
.bm-ok { color: var(--text-dim); }
.bm-fail { color: var(--danger); }
.bm-summary td { background: var(--bg-2); font-weight: 600; }

.bm-output { margin-top: 12px; }
.bm-output-head { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.bm-output-body {
  margin: 0;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  max-height: 280px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Reduced motion (UX-AX-10) ────────────────────────────────────────────
   Respect prefers-reduced-motion: neutralise animations and transitions
   (thinking blink, the connected-account "in use" pulse, hover/slide
   transitions) for users who request reduced motion. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
