:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --sidebar: #f3f3f1;
  --border: #e3e3de;
  --text: #1c1c1a;
  --muted: #66665f;
  --accent: #3b4cca;
  --accent-hover: #2f3ea8;
  --accent-contrast: #ffffff;
  --accent-tint: #eef0fc;
  --error-bg: #fdecec;
  --error-text: #a1261f;
  --code-bg: #f1f1ee;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.06), 0 4px 16px rgba(20, 20, 20, 0.05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151517;
    --surface: #1d1d20;
    --sidebar: #19191b;
    --border: #2c2c31;
    --text: #ececea;
    --muted: #a0a09a;
    --accent: #8b97f5;
    --accent-hover: #a3adf8;
    --accent-contrast: #14142b;
    --accent-tint: #262a45;
    --error-bg: #3a1d1d;
    --error-text: #ff9f98;
    --code-bg: #26262a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #151517;
  --surface: #1d1d20;
  --sidebar: #19191b;
  --border: #2c2c31;
  --text: #ececea;
  --muted: #a0a09a;
  --accent: #8b97f5;
  --accent-hover: #a3adf8;
  --accent-contrast: #14142b;
  --accent-tint: #262a45;
  --error-bg: #3a1d1d;
  --error-text: #ff9f98;
  --code-bg: #26262a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }
.muted { color: var(--muted); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; background: transparent; color: var(--text);
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-quiet { color: var(--muted); font-weight: 500; }
.btn-quiet:hover { background: var(--border); color: var(--text); }
.btn-icon { width: 40px; padding: 0; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }
.form-error { color: var(--error-text); background: var(--error-bg); padding: 8px 12px; border-radius: 8px; margin-top: 12px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-large { font-size: 22px; margin-bottom: 8px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-contrast); font-size: 16px; font-weight: 800;
}

/* Sign-in */
.signin { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.signin-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px;
}
.signin-card label { margin-top: 20px; }
.signin-card .btn { margin-top: 16px; }

/* App shell */
.app { display: flex; height: 100%; }
.sidebar {
  width: 288px; flex: none; display: flex; flex-direction: column;
  background: var(--sidebar); border-right: 1px solid var(--border);
}
.sidebar-head { padding: 16px; display: grid; gap: 14px; }
.conversations { flex: 1; overflow-y: auto; padding: 4px 8px 8px; border-bottom: 1px solid var(--border); }
.conv {
  display: flex; align-items: center; gap: 4px; border-radius: 10px; margin-bottom: 2px;
}
.conv:hover, .conv.active { background: var(--border); }
.conv-open {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; color: var(--text);
  font: inherit; padding: 9px 10px; cursor: pointer; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; border-radius: 10px;
}
.conv.active .conv-open { font-weight: 600; }
.conv-delete {
  flex: none; width: 32px; height: 32px; margin-right: 4px; border: 0; border-radius: 8px;
  background: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1;
  opacity: 0;
}
.conv:hover .conv-delete, .conv:focus-within .conv-delete, .conv.active .conv-delete { opacity: 1; }
.conv-delete:hover { color: var(--error-text); }
.empty-list { color: var(--muted); padding: 10px 12px; font-size: 14px; }
.sidebar-nav { display: grid; gap: 2px; padding: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  color: var(--muted); font-size: 14px; font-weight: 500; text-decoration: none;
}
.nav-item svg { flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: var(--border); color: var(--text); }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav-item .count {
  margin-left: auto; min-width: 20px; padding: 1px 7px; border-radius: 999px; text-align: center;
  background: var(--accent); color: var(--accent-contrast); font-size: 12px; font-weight: 700;
}
.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 8px 10px 18px; border-top: 1px solid var(--border);
}
.user-email {
  color: var(--muted); font: inherit; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0; background: none; border: 0; padding: 4px 0; text-align: left; cursor: pointer;
}
.user-email:hover { color: var(--text); text-decoration: underline; }
.sidebar-foot .btn { flex: none; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.menu-button { display: none; }
.chat-title { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tools { position: relative; }
.tools summary {
  list-style: none; cursor: pointer; color: var(--muted); font-size: 13px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 999px; user-select: none;
}
.tools summary::-webkit-details-marker { display: none; }
.tools[open] summary { color: var(--text); }
.tools-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 5; width: min(380px, 86vw);
  /* Never taller than the window: the list scrolls inside the panel, not the page. */
  max-height: min(70vh, 560px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 12px 14px 0; overflow: hidden;
}
.tools-head { flex: none; padding-bottom: 10px; }
.tools-panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 8px; }
.tools-filter {
  width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
.tools-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 12px; }
.tools-group { margin: 0 0 4px; padding: 10px 0 4px; font-size: 12px; font-weight: 700; color: var(--muted); }
.tools-group span { font-weight: 500; }
.tools-panel ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.tools-panel .tool-name { font-weight: 600; font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.tools-panel .tool-desc {
  color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.tools-empty { color: var(--muted); font-size: 14px; padding: 8px 0 12px; }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.thread { max-width: 760px; margin: 0 auto; display: grid; gap: 18px; }
.msg { display: grid; gap: 6px; max-width: 100%; }
.msg.user { justify-items: end; }
.bubble { padding: 10px 14px; border-radius: var(--radius); max-width: 100%; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent-tint); white-space: pre-wrap; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { padding: 2px 0; }
.msg.error .bubble { background: var(--error-bg); color: var(--error-text); padding: 10px 14px; }
.meta { color: var(--muted); font-size: 12px; }

.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose pre, .prose table { margin: 0 0 10px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose code { font-family: var(--mono); font-size: 0.9em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.prose pre { background: var(--code-bg); padding: 12px; border-radius: 10px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose th { background: var(--code-bg); }
.prose a { color: var(--accent); }
.plain { white-space: pre-wrap; }

/* How an answer was reached: a quiet one-line summary that opens into a short timeline */
.steps { font-size: 13px; }
.steps > summary {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; cursor: pointer; list-style: none;
  color: var(--muted); padding: 4px 10px 4px 8px; border-radius: 999px;
}
.steps > summary:hover { background: var(--border); color: var(--text); }
.steps > summary::-webkit-details-marker { display: none; }
.steps > summary::before { content: "▸"; display: inline-block; font-size: 11px; transition: transform 0.15s; }
.steps[open] > summary::before { transform: rotate(90deg); }
.steps.has-failure > summary { color: var(--error-text); }
.timeline { list-style: none; margin: 6px 0 4px 14px; padding: 0 0 0 14px; border-left: 2px solid var(--border); display: grid; gap: 12px; }
.timeline-step { color: var(--text); }
.timeline-title { display: flex; flex-wrap: wrap; gap: 0 6px; align-items: baseline; font-weight: 600; overflow-wrap: anywhere; }
.timeline-mark { color: var(--accent); font-weight: 700; }
.timeline-step.failed .timeline-mark, .timeline-step.failed .timeline-title { color: var(--error-text); }
.timeline-time { color: var(--muted); font-weight: 400; }
.timeline-detail { color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.timeline-items { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 2px; }
.timeline-items li { overflow-wrap: anywhere; }
.timeline-items li::before { content: "·"; margin-right: 6px; color: var(--muted); }
.timeline-items a { color: var(--accent); }
.item-note { color: var(--muted); font-size: 12px; }
.raw { margin-top: 6px; }
.raw > summary { cursor: pointer; color: var(--muted); font-size: 12px; list-style: none; }
.raw > summary::-webkit-details-marker { display: none; }
.raw > summary::before { content: "▸ "; }
.raw[open] > summary::before { content: "▾ "; }
.step-label { color: var(--muted); font-size: 12px; margin: 6px 0 2px; }
.raw pre {
  margin: 0; font: 12px/1.45 var(--mono); background: var(--code-bg); padding: 8px 10px;
  border-radius: 8px; overflow-x: auto; max-height: 220px; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* What PS Alpha is doing right now */
.live-status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; padding: 6px 0; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.35; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1); } }

.actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0;
  background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-tint); }
.feedback-form { display: flex; gap: 8px; align-items: center; width: 100%; max-width: 460px; }
.feedback-form input { padding: 7px 10px; }
.feedback-thanks { color: var(--muted); font-size: 13px; }

.empty { max-width: 560px; margin: 8vh auto 0; text-align: center; padding: 0 8px; }
.empty h2 { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.suggestions { display: grid; gap: 10px; margin-top: 24px; }
.suggestion {
  text-align: left; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.suggestion:hover { border-color: var(--accent); }

.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: 0.5; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .typing span { animation: none; opacity: 0.6; }
  .live-dot { animation: none; opacity: 0.8; }
  .steps > summary::before { transition: none; }
}

/* Composer */
.composer {
  max-width: 760px; width: calc(100% - 32px); margin: 8px auto 0; display: flex; align-items: flex-end;
  gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 8px; box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  border: 0; background: transparent; resize: none; max-height: 200px; padding: 8px 8px; outline: none;
}
.composer .btn { flex: none; width: 40px; padding: 0; border-radius: 12px; }
.composer-note { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 12px; }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 9; }

@media (max-width: 800px) {
  .sidebar {
    position: fixed; z-index: 10; inset: 0 auto 0 0; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .menu-button { display: inline-flex; }
  .messages { padding: 16px 16px 8px; }
  @media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
}

/* Administration */
.admin-body { height: auto; min-height: 100%; }
.admin-top {
  display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 2;
}
.admin-title { flex: 1; font-weight: 600; color: var(--muted); }
.admin-top { flex-wrap: wrap; row-gap: 8px; }
.admin-tabs { flex-basis: 100%; display: flex; gap: 4px; overflow-x: auto; margin: 0 -8px -12px; padding: 0 8px; }
.admin-tabs a {
  padding: 10px 14px; color: var(--muted); font-weight: 600; text-decoration: none; white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.admin-tabs a:hover { color: var(--text); }
.admin-tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.admin-tabs a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px; }
.admin-tabs[hidden] { display: none; }
.detail-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 24px; margin-bottom: 4px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-width: 0; }
.crumb-sep { color: var(--muted); }
.crumb-title { font-size: 20px; font-weight: 700; margin: 0; }
.detail-server { display: flex; align-items: center; gap: 12px; }
.hint.tight { margin: 4px 0 12px; max-width: 120ch; }
.tool-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.tool-toolbar input, .tool-toolbar select { padding: 6px 10px; border-radius: 8px; }
.toolbar-search { flex: 0 1 320px; min-width: 200px; }
.tool-toolbar select { width: auto; }
.toolbar-summary { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; }
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.bulk-bar .muted { font-size: 13px; margin-right: 2px; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; font-weight: 500; border-color: var(--border); background: var(--surface); }
.btn-sm:hover:not(:disabled) { background: var(--border); }
.segmented.compact .seg { min-height: 26px; padding: 0 11px; font-size: 13px; }
.segmented.compact { border-radius: 8px; }
.badge-off { background: var(--border); color: var(--muted); }
.tools-scroll { max-height: max(300px, calc(100vh - 250px)); margin-top: 10px; }
.admin-table.tool-table td { padding: 4px 12px; }
.admin-table.tool-table th { padding: 8px 12px; white-space: nowrap; }
.tool-table tbody tr:hover { background: var(--accent-tint); }
.tool-table .tool-name { white-space: nowrap; font-size: 13px; }
.tool-table td.tool-desc { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.tool-table td.tool-fit { white-space: nowrap; width: 1%; }
.tool-table .badge { font-size: 11px; padding: 1px 8px; }
.tool-table .inherited { color: var(--muted); font-size: 12px; margin-left: 6px; }
.admin-main { max-width: 1280px; margin: 0 auto; padding: 24px 20px 64px; display: block; }
.admin-main section { margin-bottom: 40px; }
.admin-h { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.server-list { display: grid; gap: 14px; margin-top: 16px; grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr)); }
.server-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; align-content: start; }
.server-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.server-title { font-size: 16px; font-weight: 700; margin: 0; }
.server-id { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.server-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.server-tools summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.server-tools ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; display: grid; gap: 4px; }
.tool-name { font-family: var(--mono); font-weight: 600; }
.tool-desc { color: var(--muted); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--accent-tint); color: var(--accent); }
.badge-bad { background: var(--error-bg); color: var(--error-text); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg { min-height: 36px; padding: 0 14px; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.seg + .seg { border-left: 1px solid var(--border); }
.seg:hover { background: var(--border); color: var(--text); }
.seg.active { background: var(--accent); color: var(--accent-contrast); }
.table-wrap { overflow-x: auto; margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.admin-table tr:last-child td { border-bottom: 0; }
.rule-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 16px; margin-top: 14px; align-items: start; }
/* A table with its own scroll area (the page keeps scrolling too); the header stays in view. */
.table-scroll { max-height: min(65vh, 640px); overflow: auto; overscroll-behavior: contain; }
.table-scroll.scroll-short { max-height: min(40vh, 360px); }
.table-scroll .admin-table th {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  border-bottom: 0; box-shadow: inset 0 -1px 0 var(--border);
}
.field label { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.field .hint { margin-top: 4px; }
select { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.field-action { align-self: end; }
.form-ok { color: var(--accent); background: var(--accent-tint); padding: 8px 12px; border-radius: 8px; margin-top: 12px; }

/* Model picker and usage meter */
.model-select { width: auto; max-width: 220px; padding: 6px 10px; font-size: 13px; border-radius: 999px; }
.model-note { color: var(--muted); font-size: 13px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; white-space: nowrap; }
.usage { padding: 10px 16px 6px; }
.usage-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.usage-bar { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.usage-bar > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; }
.usage-bar > span.high { background: #d98a1f; }
.usage-bar > span.full { background: var(--error-text); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.month-pick { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.month-pick input { width: auto; }
.stat { font-size: 13px; color: var(--muted); }

/* Tasks */
textarea { resize: vertical; }
.field.wide { grid-column: 1 / -1; }
.task-list { display: grid; gap: 14px; margin-top: 16px; }
.task-card { grid-template-columns: 1fr; }
.task-prompt { margin: 0; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.task-meta { display: flex; gap: 20px; flex-wrap: wrap; font-size: 13px; }
.task-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.runs { margin-top: 4px; }

.admin-main section p + p { margin-top: 12px; }

/* Models: available list, update review, prices */
.admin-sub { font-size: 16px; margin: 28px 0 6px; }
.offer-tools { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end; margin: 12px 0; }
.offer-tools .field { min-width: 200px; }
.manual-add { margin-top: 20px; }
.manual-add summary { cursor: pointer; color: var(--muted); font-weight: 500; padding: 6px 0; }
.manual-add[open] summary { color: var(--text); }
dialog {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; width: min(720px, 94vw); max-height: 86vh;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog .admin-sub { margin-top: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.change-list { max-height: 50vh; overflow-y: auto; margin-top: 12px; }
.change-group { margin-bottom: 16px; }
.change-head { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 6px; }
.change-head h4 { margin: 0; font-size: 14px; }
.change { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; }
.change input[type="checkbox"], .change-head input[type="checkbox"] { width: auto; margin-top: 4px; flex: none; }
.change label { flex: 1; min-width: 0; font-weight: 400; cursor: pointer; overflow-wrap: anywhere; }
.change-name { font-weight: 600; }

/* Sidebar: search, projects, recent */
.search-box input {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
.search-box input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.conversations { padding: 0 8px 8px; }
.section-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 4px; }
.section-title { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.group-label { margin: 10px 8px 2px; font-size: 12px; font-weight: 600; color: var(--muted); }
.icon-btn {
  flex: none; width: 28px; height: 28px; border: 0; border-radius: 8px; background: none;
  color: var(--muted); cursor: pointer; font: inherit; font-size: 18px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.proj-row { display: flex; align-items: center; gap: 2px; border-radius: 10px; }
.proj-row:hover { background: var(--border); }
.proj-row .icon-btn { opacity: 0; }
.proj-row:hover .icon-btn, .proj-row:focus-within .icon-btn { opacity: 1; }
.proj-toggle {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: none; border: 0;
  color: var(--text); font: inherit; font-weight: 600; padding: 8px 8px; cursor: pointer; text-align: left;
}
.proj-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 10px; }
.chev { display: inline-block; width: 12px; color: var(--muted); font-size: 11px; transition: transform 0.15s ease; }
.chev.open { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }
.proj-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-count { flex: none; color: var(--muted); font-size: 12px; font-weight: 500; }
.proj-chats { margin: 0 0 4px 14px; border-left: 1px solid var(--border); padding-left: 4px; }
.empty-list.small { font-size: 13px; padding: 4px 12px 8px; }
.conv .conv-menu { opacity: 0; margin-right: 4px; }
.conv:hover .conv-menu, .conv:focus-within .conv-menu, .conv.active .conv-menu { opacity: 1; }
.conv-project { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.more-btn {
  display: block; width: calc(100% - 16px); margin: 6px 8px; padding: 8px; border: 0; border-radius: 10px;
  background: none; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer;
}
.more-btn:hover { background: var(--border); color: var(--text); }
.results { padding-top: 6px; }
.result {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; background: none;
  border: 0; border-radius: 10px; padding: 9px 10px; color: var(--text); font: inherit; cursor: pointer;
}
.result:hover, .result:focus-visible { background: var(--border); }
.result-title { font-weight: 600; overflow-wrap: anywhere; }
.result-snippet { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.result-project { font-size: 11px; color: var(--accent); font-weight: 600; }
mark { background: var(--accent-tint); color: var(--accent); border-radius: 3px; padding: 0 1px; }
.menu {
  position: fixed; z-index: 30; min-width: 190px; padding: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.menu-heading { padding: 6px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.menu-item {
  display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 8px;
  padding: 8px 10px; color: var(--text); font: inherit; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--border); outline: none; }
.menu-item.danger { color: var(--error-text); }
.dialog-h { margin: 0 0 12px; font-size: 18px; }
#account-dialog { max-width: min(520px, calc(100vw - 32px)); }
.kv { display: flex; gap: 12px; align-items: baseline; }
.kv .k, .group-block .k { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; min-width: 64px; }
.role { font-weight: 600; }
.role.admin { color: var(--accent); }
.group-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.group-list li { display: flex; align-items: center; gap: 8px; }
.group-list code { font: 12px var(--mono); background: var(--code-bg); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }
.copy-id { padding: 2px 8px; font-size: 12px; }
.stack { display: grid; gap: 14px; }
dialog textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; resize: vertical;
}

/* Who can use a server, tool or model: summary, editor, and the "who can use what" check */
.badge-warn { background: transparent; color: var(--text); border: 1px solid var(--accent); }
.access-cell { display: flex; align-items: center; gap: 8px; }
.access-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 34ch; min-height: 26px; font: inherit; font-size: 12px; font-weight: 600; white-space: nowrap; cursor: pointer; border: 1px solid transparent; }
.access-chip.badge-warn { border-color: var(--accent); }
.access-chip:hover { filter: brightness(0.96); text-decoration: underline; }
.access-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.access-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip-icon { flex: none; opacity: 0.7; }
.access-dialog { width: min(640px, 94vw); }
.access-modes { border: 0; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.mode-option { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.mode-option:hover { background: var(--accent-tint); }
.mode-option input { width: auto; flex: none; margin: 3px 0 0; }
.mode-option > span { flex: 1; min-width: 0; text-align: left; }
.mode-option[hidden] { display: none; }
.mode-help { display: block; color: var(--muted); font-size: 13px; }
.access-members-label { font-weight: 600; margin: 16px 0 6px; }
.member-list { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; display: grid; gap: 4px; }
.member-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.member-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.member-add { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; margin-top: 10px; }
.member-add .field { min-width: 160px; flex: 1 1 160px; }
.check-who { font-weight: 600; margin: 16px 0 6px; }
.check-notes { color: var(--muted); font-size: 13px; margin: 0 0 8px; padding-left: 18px; }
.check-list { display: grid; gap: 8px; }
.check-server { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.check-summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; cursor: pointer; }
.check-name { font-weight: 600; }
.check-reason { margin: 8px 0 6px; }
.access-dialog .dialog-actions { position: sticky; bottom: -20px; background: var(--surface); padding: 12px 0 0; margin-top: 12px; }

/* An info icon with a tooltip, shown on hover or keyboard focus */
.title-row { position: relative; display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.title-row .admin-h { margin: 0; }
.info { display: inline-flex; }
.info-btn { width: 22px; height: 22px; padding: 0; display: inline-grid; place-items: center; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: help; }
.info-btn:hover, .info-btn:focus-visible { color: var(--accent); border-color: var(--accent); }
.info-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.info-tip { display: none; position: absolute; left: 0; top: calc(100% + 8px); z-index: 30; width: min(420px, 100%); box-sizing: border-box; padding: 10px 12px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; font-weight: 400; line-height: 1.45; }
.info-tip::before { content: ""; position: absolute; left: 0; right: 0; top: -16px; height: 16px; }
.info:hover .info-tip, .info:focus-within .info-tip { display: block; }

/* A section title with its controls on the same line */
.section-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 28px 0 10px; }
.section-row .admin-sub { margin: 0; }
.section-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.section-controls input[type="search"] { width: 260px; max-width: 100%; padding: 7px 12px; }
.section-controls select { width: auto; padding: 7px 12px; }
@media (max-width: 640px) {
  .section-controls { justify-content: flex-start; width: 100%; }
  .section-controls input[type="search"] { flex: 1 1 100%; width: 100%; }
}

/* Tabs inside a page section (the page's own sections use .admin-tabs) */
.section-row.page-title { margin-top: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 4px 0 14px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px; }

.page-title input[type="month"] { width: auto; padding: 7px 12px; }
@media (max-width: 640px) {
  .page-title .section-controls { width: auto; justify-content: flex-end; }
}

/* Models and Teams: the page fits the window. The page does not scroll; each table scrolls in its own box. */
.admin-main:has(.fit-panel:not([hidden])) { padding-bottom: 24px; }
.fit-panel:not([hidden]) { display: flex; flex-direction: column; height: calc(100dvh - var(--admin-top, 110px) - 48px); min-height: 420px; margin-bottom: 0; }
.fit-panel > * { flex: none; }
.fit-panel .section-row { margin: 10px 0 0; }
.fit-panel .table-wrap { margin-top: 8px; }
.fit-panel .fit-top { flex: 0 1 auto; min-height: 0; max-height: 36%; }
.fit-panel .fit-rest { flex: 1 1 0; min-height: 140px; max-height: none; }
@media (max-width: 640px) {
  .fit-panel:not([hidden]) { display: block; height: auto; min-height: 0; }
  .fit-panel .fit-top { max-height: 40vh; }
  .fit-panel .fit-rest { max-height: 60vh; }
}

/* Application access row, teams page */
.app-row { margin-top: 0; gap: 10px; }
.app-row-label { color: var(--muted); font-weight: 600; }
.check-app { margin: 0 0 6px; color: var(--muted); }
.fit-panel > .teams-layout { flex: 1 1 0; min-height: 0; display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; margin-top: 8px; }
.team-list { list-style: none; margin: 0; padding: 0; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.team-link { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none; }
.team-link:hover { background: var(--accent-tint); }
.team-link.active { background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.team-link-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-link-count { flex: none; font-size: 12px; color: var(--muted); }
.team-none { padding: 12px 14px; }
.team-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
#team-body { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
#team-body[hidden] { display: none; }
#team-body > * { flex: none; }
#team-body > .fit-rest { flex: 1 1 0; min-height: 120px; }
.team-add { display: flex; gap: 8px; align-items: flex-start; margin-top: 4px; }
.team-add textarea { flex: 1; min-height: 44px; }
#team-add-result { margin-top: 6px; font-size: 13px; }
@media (max-width: 640px) {
  .fit-panel > .teams-layout { display: block; }
  .team-list { max-height: 30vh; margin-bottom: 12px; }
  .team-add { flex-direction: column; align-items: stretch; }
  .team-pane, #team-body:not([hidden]) { display: block; }
  #team-body > .fit-rest { max-height: 50vh; }
}
