/*
 * Roommate GPT Relay v2.0.2
 * Design language reconstructed from the supplied OpenCode-inspired guide.
 * Berkeley Mono is proprietary and is NOT bundled. The stack falls through
 * to open/system monospace alternatives, with CJK mono faces preferred.
 */

:root {
  color-scheme: light;
  --canvas: #fdfcfc;
  --ink: #201d1d;
  --ink-deep: #0f0000;
  --charcoal: #302c2c;
  --body: #424245;
  --mute: #646262;
  --stone: #6e6e73;
  --ash: #9a9898;
  --surface-soft: #f8f7f7;
  --surface-card: #f1eeee;
  --surface-dark: #201d1d;
  --surface-dark-elevated: #302c2c;
  --hairline: rgba(15, 0, 0, .12);
  --hairline-strong: #646262;
  --accent: #007aff;
  --accent-hover: #0056b3;
  --accent-active: #004085;
  --danger: #ff3b30;
  --danger-hover: #d70015;
  --danger-active: #a50011;
  --warning: #ff9f0a;
  --success: #30d158;
  --on-dark: #fdfcfc;
  --radius: 4px;
  --sidebar-width: 272px;
  --content-width: 960px;
  --chat-width: 800px;
  --section-gap: 96px;
  --font-mono: "Berkeley Mono", "JetBrains Mono", "IBM Plex Mono", "Geist Mono", "Sarasa Mono SC", "Maple Mono SC NF", "Noto Sans Mono CJK SC", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); color: var(--ink); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--body);
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1.5;
  font-weight: 400;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-variant-ligatures: none;
}
button, input, textarea, select { font: inherit; }
button, input, textarea, select, a { -webkit-tap-highlight-color: transparent; }
button { border: 0; }
a { color: inherit; text-decoration: none; }
p, h1, h2, h3, h4, pre { margin-top: 0; }
h1, h2, h3, h4, strong { color: var(--ink); }
[hidden] { display: none !important; }
::selection { color: var(--canvas); background: var(--ink); }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ---------- Shared identity ---------- */
.brand,
.sidebar-brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  color: var(--ink);
  font-weight: 700;
}
.brand-mark,
.gpt-knot,
.home-hero-mark {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid currentColor;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font-weight: 700;
  box-shadow: none;
}
.brand-mark {
  width: 44px;
  height: 44px;
  font-size: 0;
}
.brand-mark::before { content: "[R]"; font-size: 14px; }
.brand-mark.small { width: 32px; height: 32px; }
.brand-mark.small::before { font-size: 12px; }
.ascii-wordmark {
  margin: 0;
  color: inherit;
  font: 700 clamp(12px, 1.55vw, 18px)/1.1 var(--font-mono);
  white-space: pre;
  letter-spacing: 0;
  overflow: hidden;
}
.ascii-logo-inline {
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}
.ascii-logo-inline::before { content: "[ GPT/RELAY ]"; }

.muted { color: var(--mute); }
.ok { color: #16883b; }
.bad, .error-text, .danger { color: var(--danger-active); }

/* ---------- Top navigation ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 max(24px, calc((100vw - 1120px) / 2));
  border-bottom: 1px solid var(--hairline);
  background: rgba(253, 252, 252, .96);
  backdrop-filter: blur(12px);
}
.top-actions { display: flex; align-items: center; gap: 20px; }
.username, .text-link { color: var(--mute); font-size: 14px; line-height: 2; }
.text-link { text-decoration: underline; text-underline-offset: 3px; }
.text-link:active { color: var(--ink); }

/* ---------- Buttons ---------- */
button, .primary, .ghost, .inline-button {
  cursor: pointer;
  border-radius: var(--radius);
  transition: background-color .08s linear, color .08s linear, border-color .08s linear, opacity .08s linear;
}
button:disabled { cursor: not-allowed; opacity: .48; }
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 4px 20px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--canvas);
  font-weight: 500;
  line-height: 2;
}
.primary:active:not(:disabled) { background: var(--ink-deep); }
.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 4px 14px;
  border: 1px solid var(--hairline-strong);
  background: var(--canvas);
  color: var(--ink);
  line-height: 2;
}
.ghost:active:not(:disabled) { background: var(--surface-card); }
.ghost.danger { border-color: var(--danger); color: var(--danger-active); }
.ghost.danger:active:not(:disabled) { color: var(--canvas); background: var(--danger-active); }
.full { width: 100%; }
.inline-button { width: fit-content; margin-top: 16px; }
.align-end { align-self: end; }

/* ---------- Form controls ---------- */
.stack { display: grid; gap: 16px; }
.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid label,
.stack label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--body);
  font-size: 14px;
}
.form-grid label::before,
.stack label::before { color: var(--mute); }
.span-2 { grid-column: 1 / -1; }
input, textarea, select {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  outline: 0;
  background: var(--surface-soft);
  color: var(--ink);
  caret-color: var(--ink);
}
textarea { min-height: 92px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--ash); }
input:focus, textarea:focus, select:focus {
  border-color: var(--ink);
  background: var(--canvas);
  box-shadow: none;
}
input[readonly], textarea[readonly] { background: var(--surface-card); color: var(--mute); }
label small { color: var(--mute); font-size: 12px; line-height: 1.5; }
select {
  appearance: auto;
  padding-right: 12px;
}

/* ---------- Notices and state ---------- */
.alert {
  padding: 12px 0;
  border: 0;
  border-top: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  border-radius: 0;
  background: transparent;
  font-size: 14px;
}
.alert::before { margin-right: 8px; font-weight: 700; }
.alert.error { color: var(--danger-active); }
.alert.error::before { content: "[x]"; }
.alert.success { color: #167a38; }
.alert.success::before { content: "[+]"; }
.client-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 2px 8px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: var(--mute);
  font-size: 12px;
}
.dot,
.header-client-state i,
.pulse-dot,
.mini-running,
.upload-progress i {
  width: auto;
  height: auto;
  border: 0;
  border-radius: 0;
  background: transparent !important;
  box-shadow: none !important;
  animation: none;
  font-style: normal;
}
.dot::before, .header-client-state i::before { content: "[-]"; }
.client-pill.online .dot::before, .header-client-state.online i::before { content: "[+]"; color: #16883b; }
.header-client-state.busy i::before { content: "[*]"; color: var(--warning); }
.pulse-dot::before { content: "[*]"; color: var(--warning); }
.pulse-dot.stopped::before { content: "[-]"; color: var(--mute); }
.pulse-dot.stopped.failed::before { content: "[x]"; color: var(--danger-active); }
.mini-running::before { content: "[*]"; color: var(--warning); }
.upload-progress i::before { content: "[>]"; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px;
  background: var(--canvas);
}
.login-shell {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(340px, .92fr);
  border: 1px solid var(--hairline);
  background: var(--canvas);
}
.login-terminal {
  min-height: 590px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(32px, 6vw, 64px);
  background: var(--surface-dark);
  color: var(--on-dark);
}
.login-terminal .ascii-wordmark { color: var(--on-dark); }
.login-terminal-copy { max-width: 520px; }
.login-terminal-copy h2 {
  margin-bottom: 20px;
  color: var(--on-dark);
  font-size: clamp(28px, 3vw, 38px);
  line-height: 1.5;
}
.login-terminal-copy p { color: #c7c3c3; }
.terminal-prompt {
  margin-top: 32px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface-dark-elevated);
  color: var(--on-dark);
  overflow-wrap: anywhere;
}
.terminal-prompt::before { content: "> "; color: var(--success); }
.terminal-hints { color: var(--ash); font-size: 14px; line-height: 2; }
.login-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(32px, 6vw, 64px);
  border: 0;
  border-radius: 0;
  background: var(--canvas);
  box-shadow: none;
}
.login-card .brand-mark { display: none; }
.login-card h1 { margin-bottom: 8px; font-size: 28px; line-height: 1.5; }
.login-card .stack { margin-top: 32px; }
.login-meta { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--hairline); color: var(--mute); font-size: 12px; }

/* ---------- Installation ---------- */
.install-page { min-height: 100dvh; padding: 48px 24px 80px; background: var(--canvas); }
.install-shell { width: min(960px, 100%); margin: 0 auto; }
.install-header {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: start;
  gap: 24px;
  margin-bottom: 64px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--hairline);
}
.install-header h1 { margin: 0 0 8px; font-size: 38px; line-height: 1.5; }
.install-header p { margin: 0; color: var(--mute); }
.install-form, .admin-grid { display: grid; gap: 0; }
.install-form .admin-card { border-top: 1px solid var(--hairline); }
.install-form .admin-card:first-child { border-top: 0; }
.install-submit { justify-self: end; margin-top: 32px; }
.success-card { padding-top: 32px !important; border-top: 1px solid var(--hairline); }
.success-card h2::before { content: "[+] "; color: #16883b; }

/* ---------- Admin ---------- */
.admin-layout {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  padding: 64px 0 96px;
}
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.admin-heading {
  margin-bottom: 48px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--hairline);
}
.admin-heading h1 { margin: 0; font-size: 38px; line-height: 1.5; }
.admin-heading p { margin: 4px 0 0; color: var(--mute); }
.health-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 64px;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}
.health-item {
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 16px;
  border-right: 1px solid var(--hairline);
}
.health-item:last-child { border-right: 0; }
.health-item span { color: var(--mute); font-size: 12px; }
.health-item strong { overflow-wrap: anywhere; font-size: 14px; font-weight: 500; }
.health-item strong.ok::before { content: "[+] "; }
.health-item strong.bad::before { content: "[x] "; }
.admin-card {
  margin: 0;
  padding: 40px 0;
  border: 0;
  border-top: 1px solid var(--hairline);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.admin-card:last-child { border-bottom: 1px solid var(--hairline); }
.admin-card h2 { margin: 0 0 5px; font-size: 16px; line-height: 1.5; }
.admin-card h2::before { content: "[+] "; }
.admin-card p { margin: 0; color: var(--body); }
.admin-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}
.copy-box { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; margin-top: 20px; }
.copy-box textarea { min-height: 110px; font-size: 13px; }
.inline-form { display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; }
.user-create-row { grid-template-columns: 1fr 1fr 1.1fr auto; align-items: end; }
.password-row { grid-template-columns: 1fr 1fr 1fr auto; align-items: end; }
.user-table-wrap { margin-top: 24px; overflow-x: auto; border-top: 1px solid var(--hairline); }
.user-table { width: 100%; min-width: 760px; border-collapse: collapse; color: var(--body); font-size: 14px; }
.user-table th, .user-table td { padding: 14px 12px; border-bottom: 1px solid var(--hairline); text-align: left; vertical-align: middle; }
.user-table th { color: var(--mute); font-size: 12px; font-weight: 400; }
.user-table td strong, .user-table td small { display: block; }
.user-table td small { margin-top: 3px; color: var(--mute); }
.actions-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions-cell .inline-form { margin: 0; }
.actions-cell input { width: 160px; }
.admin-ajax-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 500;
  max-width: min(560px, calc(100% - 32px));
  padding: 10px 14px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--canvas);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity .12s linear, transform .12s linear;
}
.admin-ajax-toast::before { content: "[+] "; }
.admin-ajax-toast.show { opacity: 1; transform: translate(-50%, 0); }
.admin-ajax-toast.error { border-color: var(--danger-active); background: var(--danger-active); color: #fff; }
.admin-ajax-toast.error::before { content: "[x] "; }

/* ---------- Chat application ---------- */
.chat-page {
  margin: 0;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--canvas);
  color: var(--body);
  line-height: 1.5;
  overscroll-behavior: none;
}
.chat-app,
.chat-workspace {
  height: var(--relay-viewport-height, 100dvh);
  min-height: 0;
}
.chat-app { display: flex; width: 100%; background: var(--canvas); }
.chat-sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 12px 12px;
  border-right: 1px solid var(--hairline);
  background: var(--canvas);
  z-index: 120;
}
.sidebar-head {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 4px 12px;
  border-bottom: 1px solid var(--hairline);
}
.sidebar-brand { font-size: 14px; }
.sidebar-brand > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gpt-knot {
  width: 30px;
  height: 30px;
  color: var(--ink);
  font-size: 0;
}
.gpt-knot::before { content: "[R]"; font-size: 11px; }
.icon-button {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
}
.icon-button:active { border-color: var(--hairline-strong); background: var(--surface-card); }
.sidebar-close { display: none; font-size: 0; }
.sidebar-close::before { content: "[x]"; font-size: 14px; }
.new-chat-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 20px;
  padding: 6px 10px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--ink);
  text-align: left;
  font-weight: 500;
}
.new-chat-button:active { background: var(--surface-card); }
.new-chat-icon { width: auto; height: auto; border: 0; border-radius: 0; font-size: 0; }
.new-chat-icon::before { content: "[+]"; font-size: 14px; }
.sidebar-section-title {
  padding: 0 8px 8px;
  color: var(--mute);
  font-size: 12px;
  font-weight: 400;
}
.sidebar-section-title::before { content: "[ chat ]"; }
.sidebar-section-title { font-size: 0; }
.sidebar-section-title::before { font-size: 12px; }
.sidebar-history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline-strong) transparent;
}
.sidebar-empty { padding: 10px 8px; color: var(--ash); font-size: 12px; }
.sidebar-empty::before { content: "[-] "; }
.sidebar-chat-row {
  position: relative;
  display: flex;
  align-items: center;
  border-bottom: 1px solid transparent;
}
.sidebar-chat-row.active { border-bottom-color: var(--ink); }
.sidebar-chat-row:active { background: var(--surface-soft); }
.sidebar-chat-item {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 34px 8px 8px;
  border-radius: 0;
  background: transparent;
  color: var(--body);
  text-align: left;
  font-size: 13px;
}
.sidebar-chat-item::before { content: "[-]"; flex: 0 0 auto; color: var(--ash); }
.sidebar-chat-row.active .sidebar-chat-item::before { content: "[+]"; color: var(--ink); }
.sidebar-chat-item span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-delete {
  position: absolute;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: transparent;
  color: var(--mute);
  opacity: 0;
  font-size: 0;
}
.sidebar-delete::before { content: "[x]"; font-size: 12px; }
.sidebar-delete:active { color: #fff; background: var(--danger-active); }
.sidebar-chat-row:hover .sidebar-delete,
.sidebar-chat-row.active .sidebar-delete,
.sidebar-delete:focus-visible { opacity: 1; }
.sidebar-footer { padding: 12px 4px 0; border-top: 1px solid var(--hairline); }
.profile-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.profile-avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: grid;
  place-items: center;
  border-radius: 9999px;
  background: var(--ink);
  color: var(--canvas);
  font-size: 13px;
  font-weight: 700;
}
.profile-copy { display: grid; min-width: 0; line-height: 1.25; }
.profile-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.profile-copy small { margin-top: 3px; color: var(--mute); font-size: 11px; }
.sidebar-links { display: flex; flex-wrap: wrap; gap: 14px; padding: 8px 4px 2px; color: var(--mute); font-size: 12px; }
.sidebar-links a { text-decoration: underline; text-underline-offset: 3px; }
.sidebar-scrim { display: none; }

.chat-workspace {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--canvas);
}
.chat-header {
  flex: 0 0 calc(56px + var(--safe-top));
  min-height: calc(56px + var(--safe-top));
  display: flex;
  align-items: center;
  gap: 14px;
  padding: var(--safe-top) max(20px, var(--safe-right)) 0 max(20px, var(--safe-left));
  border-bottom: 1px solid var(--hairline);
  background: rgba(253, 252, 252, .96);
  backdrop-filter: blur(10px);
  z-index: 60;
}
.mobile-menu { display: none; }
.mobile-menu span { display: none; }
.mobile-menu::before { content: "[=]"; font-size: 14px; }
.model-heading { display: flex; align-items: baseline; gap: 9px; }
.model-heading strong { font-size: 16px; }
.model-heading strong::before { content: "[ GPT ]"; }
.model-heading strong { font-size: 0; }
.model-heading strong::before { font-size: 16px; }
.model-heading span { color: var(--mute); font-size: 12px; }
.header-client-state {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--mute);
  font-size: 12px;
}
.header-client-state.online { color: var(--body); }

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-bottom: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline-strong) transparent;
}
.home-hero {
  width: min(var(--content-width), calc(100% - 48px));
  margin: clamp(32px, 8vh, 88px) auto 64px;
  padding: clamp(40px, 7vw, 72px) clamp(24px, 5vw, 48px);
  background: var(--surface-dark);
  color: var(--on-dark);
}
.home-hero-mark {
  width: auto;
  height: auto;
  border: 0;
  border-radius: 0;
  color: var(--on-dark);
  font-size: 0;
  place-items: start;
}
.home-hero-mark::before {
  content: "█▀█ █▀▀ █   █▀█ █ █\A█▀▄ ██▄ █▄▄ █▀█  █";
  white-space: pre;
  font: 700 clamp(22px, 4vw, 38px)/1.1 var(--font-mono);
}
.home-hero h1 {
  max-width: 760px;
  margin: 42px 0 18px;
  color: var(--on-dark);
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1.5;
}
.home-hero p { max-width: 720px; margin: 0; color: #c8c4c4; }
.home-hero::after {
  content: "tab 选择附件    enter 发送    ctrl-v 粘贴";
  display: block;
  margin-top: 40px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-dark-elevated);
  color: var(--ash);
  font-size: 13px;
}
.chat-thread { width: min(var(--chat-width), calc(100% - 48px)); margin: 0 auto; padding: 48px 0 72px; }
.ajax-chat-page .home-hero { flex: 0 0 auto; }
.ajax-thread { flex: 0 0 auto; padding-bottom: 52px; }
.chat-turn { display: flex; width: 100%; margin: 0 0 40px; }
.user-turn { justify-content: flex-end; }
.turn-body { min-width: 0; overflow-wrap: anywhere; }
.user-bubble {
  max-width: min(78%, 640px);
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 15px;
}
.user-bubble::before { content: "[you] "; color: var(--mute); font-size: 12px; }
.user-bubble .plain-text { display: inline; }
.attachment-list, .selected-files { display: flex; flex-wrap: wrap; gap: 8px; }
.user-bubble .attachment-list { margin-top: 10px; }
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--body);
  font-size: 12px;
}
.attachment-chip::before { content: "[file]"; color: var(--mute); }
.attachment-chip small { color: var(--mute); }
.assistant-turn { align-items: flex-start; gap: 14px; }
.assistant-avatar {
  width: 42px;
  height: 28px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  margin-top: 0;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--canvas);
  font-size: 0;
  font-weight: 700;
}
.assistant-avatar::before { content: "[AI]"; font-size: 11px; }
.assistant-body { width: calc(100% - 56px); max-width: 100%; }
.live-status {
  min-height: 28px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--mute);
  font-size: 12px;
}
.live-status[data-status="failed"],
.live-status[data-status="canceled"] { color: var(--danger-active); }
.inline-cancel {
  min-height: 28px;
  margin-left: 4px;
  padding: 1px 8px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--mute);
  font-size: 12px;
}
.inline-cancel::before { content: "[x] "; }
.thinking-panel { margin: 4px 0 18px; color: var(--mute); }
.thinking-panel summary {
  width: fit-content;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 12px;
}
.thinking-panel summary::-webkit-details-marker { display: none; }
.thinking-panel summary::before { content: "[+] "; }
.thinking-panel[open] summary::before { content: "[-] "; }
.thinking-chevron { display: none; }
.thinking-output { margin: 12px 0 0; padding: 12px 0 12px 16px; border-left: 1px solid var(--hairline-strong); color: var(--mute); font-size: 13px; }
.assistant-output { color: var(--body); font-size: 15.5px; line-height: 1.72; }
.assistant-output > :first-child { margin-top: 0; }
.assistant-output h1 { margin: 1.6em 0 .6em; font-size: 1.55em; line-height: 1.35; }
.assistant-output h2 { margin: 1.5em 0 .55em; padding-bottom: 6px; border-bottom: 1px solid var(--hairline); font-size: 1.3em; line-height: 1.4; }
.assistant-output h2::before { content: "[+] "; }
.assistant-output h3 { margin: 1.3em 0 .45em; font-size: 1.1em; }
.assistant-output h3::before { content: "[-] "; color: var(--mute); }
.markdown-output { overflow-wrap: anywhere; }
.markdown-output p { margin: 0 0 1em; }
.markdown-output p:last-child { margin-bottom: 0; }
.markdown-output ul, .markdown-output ol { margin: .6em 0 1em; padding-left: 0; list-style: none; }
.markdown-output li { position: relative; margin: .36em 0; padding-left: 3.4em; }
.markdown-output ul > li::before { content: "[+]"; position: absolute; left: 0; color: var(--mute); }
.markdown-output ol { counter-reset: relay-list; }
.markdown-output ol > li { counter-increment: relay-list; }
.markdown-output ol > li::before { content: "[" counter(relay-list) "]"; position: absolute; left: 0; color: var(--mute); }
.markdown-output hr { height: 1px; margin: 1.7em 0; border: 0; background: var(--hairline); }
.markdown-output a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.markdown-output strong { color: var(--ink); font-weight: 700; }
.markdown-output em { font-style: normal; text-decoration: underline; text-underline-offset: 3px; }
.markdown-output img { max-width: 100%; height: auto; border: 1px solid var(--hairline); border-radius: 0; }
.markdown-output blockquote {
  margin: 16px 0;
  padding: 10px 0 10px 18px;
  border-left: 1px solid var(--hairline-strong);
  background: transparent;
  color: var(--mute);
}
.inline-code, .assistant-output .inline-code {
  padding: 2px 5px;
  border-radius: var(--radius);
  background: var(--surface-card);
  color: var(--ink);
  font-size: .92em;
}
.code-block {
  margin: 18px 0;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--surface-dark);
}
.code-head {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  border-bottom: 1px solid rgba(255,255,255,.14);
  background: var(--surface-dark-elevated);
  color: var(--ash);
  font-size: 12px;
}
.code-head span::before { content: "[ "; }
.code-head span::after { content: " ]"; }
.code-copy { min-height: 30px; padding: 2px 8px; border: 1px solid #646262; border-radius: var(--radius); background: transparent; color: #dad6d6; font-size: 12px; }
.code-block pre { margin: 0; padding: 16px; overflow: auto; border: 0; border-radius: 0; background: var(--surface-dark); color: var(--on-dark); line-height: 1.6; }
.code-block code { white-space: pre; font-family: var(--font-mono); font-size: 13px; }
.table-scroll { margin: 16px 0; overflow-x: auto; border-top: 1px solid var(--hairline); }
.markdown-output table { width: 100%; min-width: 480px; border-collapse: collapse; background: transparent; font-size: 13px; }
.markdown-output th, .markdown-output td { padding: 10px 12px; border-right: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline); text-align: left; vertical-align: top; }
.markdown-output th { background: var(--surface-soft); color: var(--ink); font-weight: 700; }
.markdown-output th:last-child, .markdown-output td:last-child { border-right: 0; }
.markdown-output .katex-display { max-width: 100%; margin: 1.1em 0; overflow-x: auto; overflow-y: hidden; padding: 5px 0; }
.markdown-output .katex { color: var(--ink); font-size: 1.06em; }
.katex-error.latex-source-fallback {
  display: inline-block;
  padding: 3px 6px;
  border: 1px dashed var(--warning);
  border-radius: var(--radius);
  background: #fff9ed;
  color: var(--ink) !important;
  font-family: var(--font-mono);
  white-space: pre-wrap;
}
.typing-placeholder, .conversation-loading { display: inline-flex; align-items: center; gap: 8px; }
.typing-placeholder i, .conversation-loading i { width: auto; height: auto; border: 0; border-radius: 0; background: transparent; animation: relay-blink 1.2s infinite; }
.typing-placeholder i::before, .conversation-loading i::before { content: "."; color: var(--mute); }
.typing-placeholder i:nth-child(2), .conversation-loading i:nth-child(2) { animation-delay: .15s; }
.typing-placeholder i:nth-child(3), .conversation-loading i:nth-child(3) { animation-delay: .3s; }
@keyframes relay-blink { 0%, 45%, 100% { opacity: .25; } 20% { opacity: 1; } }
.answer-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.answer-action {
  min-height: 32px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--mute);
  font-size: 12px;
}
.answer-action::before { content: "[copy] "; }
.answer-action:active { border-color: var(--hairline-strong); color: var(--ink); }
.integrity-badge { color: #167a38; font-size: 11px; }
.integrity-badge::before { content: "[+] "; }
.chat-error { margin-top: 12px; padding: 10px 0; border-top: 1px solid var(--danger); border-bottom: 1px solid var(--danger); border-radius: 0; background: transparent; color: var(--danger-active); font-size: 13px; }
.chat-error::before { content: "[x] "; }
.markdown-output a.generated-file-link,
.answer-content a.generated-file-link,
.assistant-output a.generated-file-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  padding: 8px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
}
.markdown-output a.generated-file-link::before,
.answer-content a.generated-file-link::before,
.assistant-output a.generated-file-link::before { content: "[download]"; color: var(--mute); }

/* Composer */
.chat-composer-dock {
  flex: none;
  padding: 10px max(20px, var(--safe-right)) max(14px, var(--safe-bottom)) max(20px, var(--safe-left));
  border-top: 1px solid var(--hairline);
  background: var(--canvas);
}
.gpt-composer {
  position: relative;
  isolation: isolate;
  width: min(var(--chat-width), 100%);
  margin: 0 auto;
  padding: 10px 12px 9px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  box-shadow: none;
}
.gpt-composer:focus-within { border-color: var(--ink); background: var(--canvas); }
.gpt-composer textarea {
  width: 100%;
  min-height: 32px;
  max-height: min(34dvh, 220px);
  resize: none;
  overflow-y: auto;
  padding: 4px 5px 2px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  line-height: 1.5;
}
.gpt-composer textarea:focus { background: transparent; }
.gpt-composer textarea::placeholder { color: var(--ash); }
.composer-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 7px; }
.composer-left-tools { display: flex; align-items: center; min-width: 0; gap: 10px; }
.round-tool, .composer-send {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  padding: 0;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--ink);
}
.round-tool input { display: none; }
.round-tool span { font-size: 0; }
.round-tool span::before { content: "[+]"; font-size: 12px; }
.composer-send { background: var(--ink); color: var(--canvas); font-size: 0; }
.composer-send::before { content: "[>]"; font-size: 12px; }
.composer-send:disabled { background: var(--surface-card); color: var(--ash); border-color: var(--hairline); }
.paste-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--mute); font-size: 11px; }
.composer-files { margin-bottom: 7px; }
.selected-file-chip {
  position: relative;
  max-width: 250px;
  min-height: 50px;
  padding: 5px 34px 5px 6px;
  background: var(--canvas);
}
.selected-file-chip::before { display: none; }
.selected-file-chip > img { width: 40px; height: 40px; flex: 0 0 40px; object-fit: cover; border: 1px solid var(--hairline); border-radius: 0; background: var(--surface-card); }
.selected-file-chip > b { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 38px; color: transparent; font-size: 0; }
.selected-file-chip > b::before { content: "[file]"; color: var(--mute); font-size: 11px; }
.selected-file-chip > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-file-chip small { display: block; line-height: 1.2; }
.remove-file {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 25px;
  height: 25px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--mute);
  font-size: 0;
}
.remove-file::before { content: "[x]"; font-size: 11px; }
.remove-file:active { background: var(--danger-active); color: #fff; }
.drop-overlay {
  position: absolute;
  inset: -1px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--ink);
  border-radius: var(--radius);
  background: rgba(253,252,252,.97);
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: none;
  transition: opacity .08s linear;
}
.drop-overlay.show { opacity: 1; }
.drop-overlay strong::before { content: "[+] "; }
.drop-overlay span { margin-top: 4px; color: var(--mute); font-size: 11px; }
.upload-progress {
  position: relative;
  height: 24px;
  margin: 6px 4px 0;
  color: var(--mute);
  font-size: 11px;
}
.upload-progress::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--hairline);
}
.upload-progress::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--upload-progress, 2%);
  height: 2px;
  background: var(--ink);
  transition: width .12s linear;
}
.composer-message { min-height: 0; margin: 5px 4px 0; color: var(--danger-active); font-size: 11px; }
.composer-disclaimer { width: min(var(--chat-width), 100%); margin: 7px auto 0; color: var(--ash); text-align: center; font-size: 10px; }
.composer-disclaimer::before { content: "[i] "; }
.conversation-loading { justify-content: center; width: 100%; padding: 22vh 0; }
.ajax-thread .chat-turn { content-visibility: auto; contain-intrinsic-size: 1px 180px; }
.ajax-thread .assistant-output { min-height: 0; }
.ajax-thread .attachment-list { margin-bottom: 0; }
.ajax-thread .live-status[hidden] + .thinking-panel[hidden] + .assistant-output:empty { display: none; }
.ajax-composer.composer-busy { opacity: 1; }
.ajax-composer.composer-busy textarea { cursor: text; }
.upload-progress[hidden] { display: none !important; }

/* ---------- Legacy/general content ---------- */
.layout, .conversation { width: min(var(--content-width), calc(100% - 48px)); margin: 48px auto 96px; }
.composer-panel, .history-panel, .message, .run-status-card {
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--canvas);
  box-shadow: none;
}
.composer-panel { padding: 24px 0; border-left: 0; border-right: 0; }
.history-panel { margin-top: 48px; border-left: 0; border-right: 0; }
.section-heading.compact { padding: 16px 0; margin: 0; }
.task-list { border-top: 1px solid var(--hairline); }
.task-row { display: flex; justify-content: space-between; gap: 18px; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--hairline); }
.task-title { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-meta { color: var(--mute); font-size: 12px; }
.status { padding: 2px 8px; border: 1px solid var(--hairline); border-radius: var(--radius); background: var(--canvas); color: var(--mute); font-size: 12px; }
.status-completed { color: #167a38; }
.status-failed { color: var(--danger-active); }
.status-generating { color: #9a6300; }
.empty { padding: 28px 0; color: var(--mute); }
.message, .run-status-card { padding: 20px 0; border-left: 0; border-right: 0; }
.message-label { color: var(--mute); font-size: 12px; }

/* ---------- Responsive ---------- */
@media (hover: none) {
  .sidebar-delete { opacity: 1; }
}

@media (max-width: 900px) {
  :root { --section-gap: 64px; }
  .chat-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    flex-basis: min(86vw, 320px);
    padding: max(14px, var(--safe-top)) 12px max(12px, var(--safe-bottom));
    transform: translateX(-102%);
    transition: transform .16s ease-out;
  }
  .chat-sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-grid; }
  .sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 110;
    display: block;
    background: rgba(32,29,29,.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .16s linear;
  }
  .sidebar-scrim.show { opacity: 1; pointer-events: auto; }
  .mobile-menu { display: inline-grid; }
  .health-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .health-item:nth-child(2) { border-right: 0; }
  .health-item:nth-child(-n+2) { border-bottom: 1px solid var(--hairline); }
  .user-create-row, .password-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .user-create-row .align-end, .password-row .align-end { align-self: end; }
}

@media (max-width: 768px) {
  .topbar { padding: 0 16px; }
  .topbar .brand > span:last-child { max-width: 48vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .login-page { padding: 0; align-items: stretch; }
  .login-shell { min-height: 100dvh; grid-template-columns: 1fr; border: 0; }
  .login-terminal { min-height: auto; padding: 40px 24px; }
  .login-terminal .ascii-wordmark { display: none; }
  .login-terminal-copy h2 { font-size: 28px; }
  .terminal-prompt, .terminal-hints { display: none; }
  .login-card { padding: 48px 24px; }
  .install-page { padding: 32px 18px 64px; }
  .install-header { grid-template-columns: 48px 1fr; margin-bottom: 40px; }
  .install-header h1 { font-size: 30px; }
  .admin-layout { width: min(100% - 32px, 1120px); padding: 40px 0 72px; }
  .admin-heading h1 { font-size: 30px; }
  .admin-card-head { align-items: stretch; flex-direction: column; }
  .copy-box { grid-template-columns: 1fr; }
  .form-grid.two, .user-create-row, .password-row { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .install-submit { justify-self: stretch; }
  .chat-thread { width: min(100% - 32px, var(--chat-width)); }
  .home-hero { width: calc(100% - 32px); }
}

@media (max-width: 640px) {
  :root { --section-gap: 48px; }
  body { font-size: 15px; }
  .chat-header {
    gap: 8px;
    padding-left: max(8px, var(--safe-left));
    padding-right: max(8px, var(--safe-right));
  }
  .mobile-menu { min-width: 40px; min-height: 40px; }
  .model-heading { min-width: 0; }
  .model-heading span { display: none; }
  .header-client-state { gap: 4px; font-size: 10px; }
  .header-client-state span { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-scroll { -webkit-overflow-scrolling: touch; }
  .home-hero { margin-top: 24px; padding: 36px 20px; }
  .home-hero h1 { margin-top: 32px; font-size: 28px; }
  .home-hero::after { margin-top: 28px; font-size: 11px; }
  .chat-thread { width: calc(100% - 24px); padding: 28px 0 48px; }
  .chat-turn { margin-bottom: 30px; }
  .user-bubble { max-width: 92%; padding: 10px 11px; font-size: 14px; }
  .assistant-turn { display: block; }
  .assistant-avatar { width: 42px; margin-bottom: 10px; }
  .assistant-body { width: 100%; }
  .assistant-output { font-size: 15px; line-height: 1.68; }
  .assistant-output h1 { font-size: 1.36em; }
  .assistant-output h2 { font-size: 1.2em; }
  .assistant-output h3 { font-size: 1.06em; }
  .markdown-output li { padding-left: 3em; }
  .markdown-output table { min-width: 380px; }
  .code-block { margin-left: -2px; margin-right: -2px; }
  .chat-composer-dock {
    padding: 7px max(7px, var(--safe-right)) max(7px, var(--safe-bottom)) max(7px, var(--safe-left));
  }
  .gpt-composer { padding: 8px; }
  .gpt-composer textarea { font-size: 16px; }
  .paste-hint { display: none; }
  .composer-disclaimer { display: none; }
  .composer-files {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  .composer-files::-webkit-scrollbar { display: none; }
  .selected-file-chip { flex: 0 0 auto; max-width: min(78vw, 260px); scroll-snap-align: start; }
  .compact-attachments { max-width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .compact-attachments .attachment-chip { flex: 0 0 auto; }
  .drop-overlay { display: none; }
  .health-grid { grid-template-columns: 1fr; }
  .health-item { border-right: 0; border-bottom: 1px solid var(--hairline); }
  .health-item:last-child { border-bottom: 0; }
  .top-actions { gap: 12px; }
  .text-link { font-size: 12px; }
  .actions-cell { min-width: 300px; }
}

@media (max-width: 380px) {
  .header-client-state span { max-width: 58px; }
  .chat-thread { width: calc(100% - 18px); }
  .home-hero { width: calc(100% - 18px); }
  .user-bubble { max-width: 96%; }
}

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

/* Explicit coverage hooks for runtime-only wrappers. */
.admin-page { background: var(--canvas); }
.ajax-composer-dock { background: var(--canvas); }
.conversation-turn-pair { display: block; }
.file-tool { user-select: none; }

/* ---------- v2.0.2 custom branding ---------- */
.site-logo {
  display: block;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
}
.site-logo-small {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
}
.sidebar-site-logo {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
}
.login-site-logo {
  width: auto;
  max-width: min(240px, 100%);
  height: 52px;
  margin-bottom: 24px;
  object-position: left center;
}
.hero-site-logo {
  width: auto;
  max-width: min(320px, 82%);
  height: 72px;
  margin: 0 auto;
  filter: brightness(0) invert(1);
}
.branding-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 16px 0;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}
.branding-upload {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  min-width: 0;
}
.branding-preview {
  display: grid;
  place-items: center;
  min-height: 96px;
  padding: 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface-soft);
  overflow: hidden;
}
.branding-preview img {
  display: block;
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
}
.branding-preview.icon-preview {
  width: 96px;
  min-height: 96px;
}
.branding-preview.icon-preview img {
  width: 64px;
  height: 64px;
}
.branding-copy {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.branding-copy input[type="file"] {
  padding: 7px;
  min-height: 44px;
  overflow: hidden;
}
.check-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 8px !important;
  color: var(--mute) !important;
  font-size: 12px !important;
}
.check-row input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  height: 16px;
  padding: 0;
  accent-color: var(--ink);
}

@media (max-width: 768px) {
  .branding-settings { grid-template-columns: 1fr; }
  .branding-upload { grid-template-columns: 88px minmax(0, 1fr); }
  .branding-preview, .branding-preview.icon-preview { width: 88px; min-height: 88px; }
  .branding-preview.icon-preview img { width: 56px; height: 56px; }
  .hero-site-logo { height: 56px; }
}

@media (max-width: 480px) {
  .branding-upload { grid-template-columns: 1fr; }
  .branding-preview, .branding-preview.icon-preview { width: 100%; }
  .branding-preview img { max-height: 64px; }
  .login-site-logo { height: 44px; }
}
