/* =====================================================================
   Enterprise Agent Platform — design system
   Aesthetic: warm, editorial, calm — in the spirit of Anthropic / Claude.
   Warm paper surfaces, hazy slate-blue (#7080A0) brand with light-blue
   support, serif display type for Latin (clean sans for CJK), monospace
   reserved for genuine machine data. Dual theme via CSS light-dark().
   ===================================================================== */

:root {
  color-scheme: light dark;

  /* ---- Brand: hazy slate-blue #7080A0 + light-blue support ---- */
  --brand:         light-dark(hsl(220 22% 53%), hsl(222 30% 67%));
  --accent:        light-dark(hsl(222 24% 41%), hsl(223 40% 77%));
  --accent-hover:  light-dark(hsl(223 27% 34%), hsl(223 48% 84%));
  --accent-solid:  light-dark(hsl(222 23% 45%), hsl(222 27% 66%));
  --accent-solid-h:light-dark(hsl(223 26% 38%), hsl(222 32% 72%));
  --on-accent:     light-dark(hsl(44 42% 97%), hsl(35 16% 11%));
  --accent-soft:   light-dark(hsl(220 40% 92%), hsl(223 19% 21%));
  --accent-soft-ink: light-dark(hsl(223 29% 35%), hsl(223 44% 83%));
  --accent-line:   light-dark(hsl(221 31% 82%), hsl(223 19% 33%));
  --sky:           light-dark(hsl(208 56% 50%), hsl(206 68% 69%));

  /* ---- Surfaces (warm paper / espresso) ---- */
  --bg:        light-dark(hsl(40 30% 92.5%),  hsl(36 9% 9.5%));
  --surface:   light-dark(hsl(44 48% 97.5%),  hsl(36 10% 12.5%));
  --surface-2: light-dark(hsl(42 36% 94.5%),  hsl(35 11% 15.5%));
  --surface-3: light-dark(hsl(40 27% 89%),    hsl(36 12% 19%));
  --sidebar:   light-dark(hsl(41 28% 90%),    hsl(34 13% 8.5%));
  --overlay:   light-dark(hsl(35 25% 20% / 0.4), hsl(34 30% 2% / 0.62));

  /* ---- Lines (warm hairlines) ---- */
  --line:        light-dark(hsl(40 26% 84%), hsl(34 12% 19%));
  --line-strong: light-dark(hsl(40 21% 76%), hsl(35 12% 27%));
  --hairline:    light-dark(hsl(40 28% 86% / 0.7), hsl(34 14% 24% / 0.7));

  /* ---- Text (warm) ---- */
  --ink:    light-dark(hsl(38 9% 13%),  hsl(43 28% 89%));
  --muted:  light-dark(hsl(36 9% 39%),  hsl(40 12% 62%));
  /* Darkened (light) / lightened (dark) to clear WCAG AA 4.5:1 on the
     surfaces it sits on (--bg, --surface, --accent-soft) for readable text
     such as placeholders, timestamps, hints and labels. */
  --faint:  light-dark(hsl(36 10% 39%), hsl(40 11% 72%));

  /* ---- Status: ok (sage) ---- */
  --ok:       light-dark(hsl(150 30% 31%), hsl(150 40% 62%));
  --ok-soft:  light-dark(hsl(146 33% 90%), hsl(150 28% 14%));
  --ok-line:  light-dark(hsl(148 27% 76%), hsl(150 22% 28%));
  --dot:      light-dark(hsl(150 38% 42%), hsl(150 46% 55%));
  /* ---- Status: warn (ochre) ---- */
  --warn:      light-dark(hsl(33 64% 33%), hsl(38 76% 62%));
  --warn-soft: light-dark(hsl(38 66% 89%), hsl(34 46% 14%));
  --warn-line: light-dark(hsl(36 52% 76%), hsl(34 40% 28%));
  /* ---- Status: danger (brick) ---- */
  --danger:      light-dark(hsl(10 55% 42%), hsl(8 72% 71%));
  --danger-soft: light-dark(hsl(12 58% 92%), hsl(8 42% 17%));
  --danger-line: light-dark(hsl(11 46% 80%), hsl(8 38% 32%));

  /* ---- Elevation (warm, soft) ---- */
  --shadow-1: light-dark(0 1px 2px hsl(34 30% 24% / 0.07), 0 1px 2px hsl(0 0% 0% / 0.4));
  --shadow-2: light-dark(0 6px 18px -6px hsl(34 35% 22% / 0.16), 0 8px 22px -6px hsl(0 0% 0% / 0.55));
  --shadow-3: light-dark(0 20px 50px -14px hsl(34 35% 20% / 0.24), 0 26px 60px -16px hsl(0 0% 0% / 0.66));
  --ring: 0 0 0 3px color-mix(in srgb, var(--brand) 35%, transparent);

  /* ---- Geometry ---- */
  --r-xs: 7px;
  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
  --r-pill: 999px;

  /* ---- Type: serif display for Latin, clean sans for CJK ---- */
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
    Georgia, "Source Serif 4", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "PingFang SC",
    "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Hiragino Sans GB", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", "Roboto Mono",
    Menlo, Consolas, "Liberation Mono", monospace;

  --t-fast: 110ms cubic-bezier(0.4, 0, 0.2, 1);
  --t: 170ms cubic-bezier(0.4, 0, 0.2, 1);

  --sidebar-w: 264px;

  font-family: var(--font-sans);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.006em;
}

::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

/* Custom scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 34%, transparent);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: var(--r-pill);
}
*::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--muted) 52%, transparent); background-clip: padding-box; }

:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--r-xs);
}

h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre, .mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  background: var(--surface-2);
  color: var(--muted);
}

/* =====================================================================
   Form controls
   ===================================================================== */
button, input, textarea, select { font: inherit; color: inherit; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 9px 11px;
  color: var(--ink);
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, textarea:hover, select:hover { border-color: var(--accent-line); }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
textarea { resize: vertical; min-height: 88px; line-height: 1.55; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) center, calc(100% - 12px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

/* Buttons */
.btn {
  --bg: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--ink);
  font-weight: 550;
  font-size: 13.5px;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast),
    box-shadow var(--t-fast), transform var(--t-fast);
}
.btn:hover { background: var(--surface-3); border-color: var(--line-strong); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn--primary {
  background: var(--accent-solid);
  border-color: transparent;
  color: var(--on-accent);
  box-shadow: var(--shadow-1), inset 0 1px 0 hsl(0 0% 100% / 0.14);
}
.btn--primary:hover { background: var(--accent-solid-h); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn--ghost:hover { background: var(--surface-3); color: var(--ink); }

.btn--danger { color: var(--danger); border-color: var(--danger-line); background: transparent; }
.btn--danger:hover { background: var(--danger-soft); }

.btn--lg { min-height: 44px; padding: 0 18px; font-size: 14.5px; }
.btn--block { width: 100%; }
.btn--sm { min-height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: var(--r-xs); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

.btn svg, .nav__item svg, .channel svg { width: 17px; height: 17px; flex: 0 0 auto; }

/* Spinner */
.spin { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
   Auth / login
   ===================================================================== */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}
.auth__aside {
  position: relative;
  overflow: hidden;
  padding: 52px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: hsl(42 30% 90%);
  background:
    radial-gradient(70% 55% at 88% 92%, hsl(208 46% 56% / 0.18), transparent 70%),
    radial-gradient(80% 60% at 4% 0%, hsl(34 46% 62% / 0.14), transparent 65%),
    linear-gradient(158deg, hsl(222 25% 31%), hsl(224 28% 18%));
}
.auth__aside::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(36% 28% at 80% 16%, hsl(42 42% 82% / 0.08), transparent 72%);
  pointer-events: none;
}
.auth__aside > * { position: relative; }
.auth__logo { height: 44px; width: auto; filter: brightness(0) invert(1); opacity: 0.96; }

.auth__main { display: grid; place-items: center; padding: 28px; background: var(--bg); }
.auth__card {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
}
.auth__card h1 { font-family: var(--font-display); font-size: 29px; font-weight: 500; letter-spacing: -0.01em; }
.auth__card form { display: grid; gap: 13px; }
/* ---- Aside already shows the logo on wide screens; avoid a duplicate in the card ---- */
.auth__card .brand__logo { display: none; }
.auth__card .brand__eyebrow { font-size: 11.5px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 550; color: var(--muted); }
.field--inline { grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.field-stack { display: grid; gap: 5px; min-width: 0; }
.field-help { min-height: 16px; color: var(--muted); font-size: 12px; line-height: 1.35; }

.error {
  display: none;
  color: var(--danger);
  font-size: 13px;
}
.error:not(:empty) {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 9px 11px;
  background: var(--danger-soft);
  border: 1px solid var(--danger-line);
  border-radius: var(--r-sm);
}

/* =====================================================================
   App shell
   ===================================================================== */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  position: relative;
  z-index: 30;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar__head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 16px 16px 14px;
}
.brand { display: grid; gap: 5px; justify-items: start; min-width: 0; }
.brand__logo { height: 20px; width: auto; display: block; }
.brand__eyebrow { font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--faint); }

.sidebar__scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 12px 12px; display: flex; flex-direction: column; gap: 18px; }

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 6px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.nav { display: grid; gap: 2px; }
.nav__item, .channel {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
  position: relative;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav__item:hover, .channel:hover { background: var(--surface-3); color: var(--ink); }
.nav__item svg { color: var(--faint); transition: color var(--t-fast); }
.nav__item:hover svg { color: var(--muted); }
.nav__item.is-active, .channel.is-active {
  background: var(--accent-soft);
  color: var(--accent-soft-ink);
  font-weight: 600;
}
.nav__item.is-active svg { color: var(--accent); }
.nav__item.is-active::before, .channel.is-active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.nav__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav__badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  background: var(--surface-3);
  padding: 0 7px;
  border-radius: var(--r-pill);
  min-width: 20px;
  text-align: center;
}

.channels { display: grid; gap: 2px; }
.channel__hash { color: var(--faint); font-family: var(--font-mono); font-size: 14px; }
.channel.is-active .channel__hash { color: var(--accent); }
.channel__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.channel-create { display: flex; gap: 6px; margin-top: 6px; padding: 0 2px; }
.channel-create input { height: 32px; padding: 0 10px; font-size: 13px; }

.sidebar__foot {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.avatar {
  width: 32px; height: 32px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--on-accent);
  background: linear-gradient(150deg, var(--brand), color-mix(in srgb, var(--brand) 68%, hsl(206 55% 46%)));
}
.user__meta { display: grid; line-height: 1.25; min-width: 0; }
.user__name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user__role { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }

/* =====================================================================
   Main column
   ===================================================================== */
.main { min-width: 0; display: grid; grid-template-rows: auto 1fr; height: 100vh; height: 100dvh; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 60px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__title-wrap { min-width: 0; flex: 1; }
.topbar__title { display: flex; align-items: center; gap: 9px; font-family: var(--font-display); font-size: 17px; font-weight: 500; letter-spacing: -0.01em; }
.topbar__title .hash { color: var(--faint); font-family: var(--font-mono); }
.topbar__sub { font-size: 12px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__actions { display: flex; align-items: center; gap: 4px; }

.menu-btn { display: none; }
/* Rendered as a <button> so keyboard users can dismiss the mobile drawer;
   strip default button chrome and hide entirely on desktop. */
.scrim { display: none; appearance: none; border: 0; margin: 0; padding: 0; font: inherit; cursor: pointer; }

.content { min-height: 0; overflow: hidden; position: relative; display: grid; }

/* Entrance animation, applied only when the view changes */
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-enter { animation: view-in 0.24s cubic-bezier(0.22, 1, 0.36, 1) both; }

/* =====================================================================
   Chat
   ===================================================================== */
.chat { display: grid; grid-template-rows: 1fr auto; min-height: 0; height: 100%; }
.messages {
  overflow-y: auto;
  padding: 22px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.messages__inner { width: min(860px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

.msg { display: flex; gap: 12px; align-items: flex-start; max-width: 88%; }
.msg--user { flex-direction: row-reverse; align-self: flex-end; }
.msg__avatar {
  width: 32px; height: 32px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 650;
}
.msg--agent .msg__avatar { background: var(--accent-soft); color: var(--accent-soft-ink); }
.msg--agent .msg__avatar svg { width: 18px; height: 18px; }
.msg--user .msg__avatar { background: var(--surface-3); color: var(--muted); }

.msg__bubble {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 11px 14px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.msg--agent .msg__bubble { background: transparent; border: none; box-shadow: none; padding: 1px 0 0; }
.msg--user .msg__bubble {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.msg__meta { display: flex; align-items: baseline; gap: 9px; margin-bottom: 5px; }
.msg__name { font-weight: 650; font-size: 12.5px; }
.msg__time { font-family: var(--font-mono); font-size: 10.5px; color: var(--faint); }
.msg__pending { font-size: 11px; color: var(--muted); }
.msg--pending { opacity: 0.72; }
.msg__body { white-space: pre-wrap; word-break: break-word; line-height: 1.66; font-size: 14.5px; }
.msg--streaming .msg__body::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.15em;
  margin-left: 3px;
  vertical-align: -0.18em;
  border-radius: 2px;
  background: var(--accent-solid);
  animation: blink 1s infinite both;
}

.msg-attachments {
  display: grid;
  gap: 8px;
  margin-top: 9px;
}
.msg-attachment {
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.msg-attachment--image {
  width: min(360px, 100%);
  display: grid;
  gap: 5px;
}
.msg-attachment--image img {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.msg-attachment__caption,
.msg-attachment__meta span {
  color: var(--muted);
  font-size: 11.5px;
}
.msg-attachment--file {
  width: min(420px, 100%);
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
}
.msg-attachment__fileicon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: var(--accent);
  background: var(--accent-soft);
}
.msg-attachment__meta { min-width: 0; display: grid; gap: 1px; }
.msg-attachment__meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}

.msg__suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--accent-line);
  color: var(--accent-soft-ink);
  background: var(--surface);
  border-radius: var(--r-pill);
  padding: 3px 9px 3px 7px;
  font-size: 11.5px;
}
.chip__id { font-family: var(--font-mono); font-size: 10px; color: var(--on-accent); background: var(--accent-solid); padding: 1px 5px; border-radius: var(--r-pill); }

/* Typing indicator */
.typing { display: flex; gap: 12px; align-items: center; }
.typing__dots { display: inline-flex; gap: 5px; align-items: center; padding: 8px 0; }
.typing__dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite both; }
.typing__dots i:nth-child(2) { animation-delay: 0.2s; }
.typing__dots i:nth-child(3) { animation-delay: 0.4s; }
.msg--activity { max-width: 100%; }
.msg__suggest + .agent-work,
.msg__body + .agent-work {
  margin-top: 10px;
}
.agent-work {
  width: min(680px, 100%);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-solid);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.agent-work--active { background: color-mix(in srgb, var(--accent-soft) 54%, var(--surface)); border-color: var(--accent-line); border-left-color: var(--accent-solid); }
.agent-work--complete {
  background: var(--surface);
  border-color: var(--line);
  border-left-color: var(--line-strong);
  color: var(--ink);
}
.agent-work__summary {
  min-height: 42px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}
.agent-work__summary::-webkit-details-marker { display: none; }
.agent-work__done {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--accent);
}
.agent-work__main { min-width: 0; flex: 1; display: grid; gap: 2px; }
.agent-work__title { font-size: 12.5px; font-weight: 650; }
.agent-work__step {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-work__log {
  border-top: 1px solid var(--line);
  padding: 8px 10px 10px;
  display: grid;
  gap: 5px;
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
}
.agent-work__line { white-space: pre-wrap; word-break: break-word; color: var(--muted); }
.agent-work__line:last-child { color: var(--ink); }
.agent-status {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  min-height: 32px;
}
.agent-status__queue { color: var(--faint); font-size: 12px; }
.typing-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
  padding-left: 44px;
}
.typing-line .typing__dots { padding: 0; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

/* Composer */
.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 14px 20px calc(16px + env(safe-area-inset-bottom)); }
.composer__wrap { width: min(860px, 100%); margin: 0 auto; }
.composer__field {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: 7px 7px 7px 15px;
  transition: border-color var(--t), box-shadow var(--t);
}
.composer__field:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.composer__field textarea {
  border: 0;
  background: transparent;
  height: 35px;
  padding: 7px 0;
  min-height: 24px;
  max-height: 200px;
  overflow-y: hidden;
  resize: none;
  line-height: 1.5;
  transition: height var(--t), background var(--t);
}
.composer__field textarea.is-scrollable { overflow-y: auto; }
.composer__field textarea:focus-visible { box-shadow: none; }
.composer__file-input { display: none; }
.composer__attach {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  color: var(--muted);
}
.composer__send { width: 36px; height: 36px; border-radius: var(--r-pill); padding: 0; }
.composer__hint { display: flex; gap: 8px; align-items: center; margin-top: 9px; font-size: 11.5px; color: var(--faint); padding-left: 2px; }
.composer-files {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}
.composer-file {
  max-width: 260px;
  min-height: 32px;
  display: inline-grid;
  grid-template-columns: 18px minmax(0, 1fr) auto 24px;
  align-items: center;
  gap: 7px;
  padding: 5px 5px 5px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.composer-file__icon { color: var(--accent); }
.composer-file__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}
.composer-file__size { color: var(--faint); font-size: 11px; }
.composer-file__remove { width: 24px; height: 24px; }
.mention-menu {
  position: absolute;
  left: 12px;
  right: 52px;
  bottom: calc(100% + 8px);
  z-index: 10;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}
.mention-menu[hidden] { display: none; }
.mention-option {
  width: 100%;
  min-height: 44px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.mention-option.is-active,
.mention-option:hover {
  background: var(--surface-2);
}
.mention-option__avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.mention-option__avatar--agent {
  background: var(--accent-soft);
  color: var(--accent-soft-ink);
}
.mention-option__main { min-width: 0; display: grid; gap: 1px; }
.mention-option__label {
  font-weight: 650;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mention-option__meta {
  color: var(--muted);
  font-size: 11.5px;
  font-family: var(--font-mono);
}
.mention-option__desc {
  max-width: 180px;
  color: var(--faint);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =====================================================================
   Panels (knowledge / settings)
   ===================================================================== */
.panel { height: 100%; overflow-y: auto; padding: 22px 20px 40px; }
.panel__inner { width: min(1080px, 100%); margin: 0 auto; display: grid; gap: 16px; }
.panel__header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 2px; }
.panel__header h2 { font-family: var(--font-display); font-size: 18px; font-weight: 500; }

/* Admin paging */
.admin-panel { gap: 14px; }
.admin-pager {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  box-shadow: var(--shadow-1);
}
.admin-pager__item {
  min-width: 0;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.admin-pager__item:hover { background: var(--surface-2); color: var(--ink); }
.admin-pager__item.is-active {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-soft-ink);
}
.admin-pager__item svg { width: 16px; height: 16px; flex: 0 0 auto; }
.admin-pager__item > span:not(.admin-pager__badge) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-pager__badge {
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 11px;
}
.admin-page { display: grid; gap: 14px; min-width: 0; }
.admin-page__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 2px 2px 0;
}
.admin-page__head h2 {
  margin-top: 2px;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 500;
}
.admin-page__head p {
  max-width: 660px;
  color: var(--muted);
  font-size: 12.5px;
}
.admin-page__content { display: grid; gap: 16px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  display: grid;
  gap: 14px;
  box-shadow: var(--shadow-1);
}
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card__title { display: flex; align-items: center; gap: 9px; font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.card__title svg { width: 17px; height: 17px; color: var(--muted); }
.card__desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.card form { display: grid; gap: 12px; }

.list { display: grid; gap: 9px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 2px 0; }

/* Knowledge */
.kb-grid { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 16px; align-items: start; }
.kb-grid--single { grid-template-columns: 1fr; }
.search-field { position: relative; display: flex; align-items: center; }
.search-field > svg { position: absolute; left: 11px; width: 16px; height: 16px; color: var(--faint); pointer-events: none; }
.search-field input { padding-left: 34px; width: 100%; }
.search-field__clear { position: absolute; right: 6px; width: 28px; height: 28px; color: var(--muted); }
.list__note { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); margin: 4px 0 2px; }
.doc-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 13px;
  background: var(--surface-2);
  display: grid;
  gap: 5px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.doc-card:hover { border-color: var(--accent-line); box-shadow: var(--shadow-1); }
.doc-card__title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px; }
.doc-card__title svg { width: 15px; height: 15px; color: var(--accent); flex: 0 0 auto; }
.doc-card__summary { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card__actions { display: flex; gap: 8px; margin-top: 4px; }
.doc-viewer {
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.doc-viewer__bar { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.doc-viewer__bar .eyebrow { color: var(--muted); }
.doc-viewer pre { margin: 0; padding: 14px; font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; color: var(--ink); }

/* Settings rows */
.account-admin { gap: 16px; }
.account-create {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px;
  background: var(--surface-2);
}
.account-create__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.account-list { display: grid; gap: 10px; }
.account-row {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px;
  background: var(--surface-2);
}
.account-row__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.account-row__identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.account-row__identity > div:last-child {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}
.account-row__identity strong {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-row__identity span {
  color: var(--muted);
  font-size: 12px;
}
.account-row__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.account-row__active { min-height: 100%; margin: 0; }

/* Token usage */
.token-usage {
  min-width: 0;
  display: grid;
  gap: 16px;
}
.token-usage__overview { min-width: 0; }
.token-usage__filters {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.token-usage__filters .field {
  width: 130px;
}
.token-usage__columns {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
}
.metric-tile {
  min-width: 0;
  display: grid;
  gap: 3px;
  align-content: center;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
  background: var(--surface-2);
}
.metric-tile span {
  color: var(--muted);
  font-size: 12px;
}
.metric-tile strong {
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 21px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.metric-tile small {
  color: var(--faint);
  font-size: 11.5px;
}
.usage-card { min-width: 0; }
.usage-table {
  min-width: 0;
  display: grid;
  gap: 1px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--line);
}
.usage-table__row {
  min-width: max(720px, 100%);
  display: grid;
  grid-template-columns: repeat(var(--usage-cols), minmax(96px, 1fr));
  gap: 1px;
  background: var(--line);
}
.usage-table__row > * {
  min-width: 0;
  padding: 10px 11px;
  background: var(--surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.usage-table__head > * {
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 650;
}
.usage-table strong {
  font-family: var(--font-mono);
  font-weight: 700;
}
.usage-user {
  display: grid;
  line-height: 1.25;
}
.usage-user strong,
.usage-user small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.usage-user small {
  color: var(--muted);
  font-size: 11.5px;
}

/* Message audit */
.audit-grid { display: grid; gap: 16px; }
.audit-card { min-width: 0; }
.audit-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.audit-tool {
  min-width: 0;
  display: grid;
  gap: 9px;
  align-content: end;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
  background: var(--surface-2);
}
.audit-tool--compact .field { margin: 0; }
.audit-list {
  min-width: 0;
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  padding-right: 2px;
}
.audit-message {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 11px 12px;
  background: var(--surface-2);
}
.audit-message__meta {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--faint);
  font-size: 11.5px;
}
.audit-message__meta strong { color: var(--ink); font-size: 12.5px; }
.audit-message__body {
  grid-column: 1 / 2;
  min-width: 0;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.58;
}
.audit-message__actions {
  grid-column: 2 / 3;
  grid-row: 1 / span 2;
  display: flex;
  align-items: center;
}
.audit-message__actions .icon-btn { color: var(--danger); }
.audit-private {
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr;
  gap: 14px;
  min-width: 0;
}
.audit-conversations {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 7px;
  max-height: 560px;
  overflow: auto;
}
.audit-conversation {
  min-width: 0;
  width: 100%;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 9px;
  text-align: left;
  cursor: pointer;
}
.audit-conversation:hover { border-color: var(--accent-line); background: var(--surface-3); }
.audit-conversation.is-active {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-soft-ink);
}
.audit-conversation .avatar { width: 30px; height: 30px; border-radius: 8px; }
.audit-conversation__main {
  min-width: 0;
  display: grid;
  line-height: 1.25;
}
.audit-conversation__main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.audit-conversation__main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 11.5px;
}
.audit-private__messages { min-width: 0; display: grid; gap: 10px; align-content: start; }
.audit-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.audit-subhead > div { min-width: 0; display: grid; line-height: 1.25; }
.audit-subhead strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-subhead span:not(.status) { color: var(--muted); font-size: 12px; }

.secret-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 11px 13px;
  background: var(--surface-2);
}
.secret-row__key { display: flex; align-items: center; gap: 9px; min-width: 0; }
.secret-row__key svg { width: 15px; height: 15px; color: var(--faint); flex: 0 0 auto; }
.secret-row__name { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; overflow-wrap: anywhere; }
.secret-row__val { font-family: var(--font-mono); font-size: 11.5px; color: var(--faint); }
.secret-row form { display: flex; gap: 7px; grid-column: 1 / -1; }
.secret-row form input { height: 32px; }

.runtime-row {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 13px;
  background: var(--surface-2);
}
.runtime-row__main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.runtime-row__title { display: flex; align-items: center; gap: 9px; }
.runtime-row__name { font-weight: 600; font-size: 13.5px; }
.runtime-row__detail { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); overflow-wrap: anywhere; }
.runtime-row__actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }

/* Status badge + dot */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px 0 8px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: var(--surface);
  text-transform: lowercase;
}
.status .dot { width: 7px; height: 7px; }
.status--ok { color: var(--ok); border-color: var(--ok-line); background: var(--ok-soft); }
.status--warn { color: var(--warn); border-color: var(--warn-line); background: var(--warn-soft); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); flex: 0 0 auto; position: relative; }
.dot--warn { background: var(--warn); }
.dot--off { background: var(--faint); }
.dot--pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: inherit;
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(1); opacity: 0.6; } 100% { transform: scale(3.2); opacity: 0; } }

/* OAuth */
.oauth-transfer { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.oauth-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.oauth-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px;
  background: var(--surface-2);
  display: grid;
  gap: 12px;
  min-width: 0;
}
.oauth-card.is-active { border-color: var(--accent-line); box-shadow: 0 0 0 1px var(--accent-line); }
.oauth-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.oauth-card__id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.oauth-card__logo { width: 34px; height: 34px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 9px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.oauth-card__logo svg { width: 18px; height: 18px; }
.oauth-card__label { font-weight: 600; font-size: 13.5px; }
.oauth-card__model { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.oauth-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 4px; }
.oauth-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.oauth-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--danger-line);
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.oauth-error svg { flex: 0 0 auto; margin-top: 1px; }
.oauth-guide {
  border: 1px solid var(--accent-line);
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  padding: 12px;
  display: grid;
  gap: 10px;
  min-width: 0;
}
.oauth-guide.complete { border-color: var(--ok-line); background: var(--ok-soft); color: var(--ok); }
.oauth-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.oauth-line > span { color: var(--muted); font-size: 12.5px; min-width: 64px; }
.oauth-line a, .oauth-line code { overflow-wrap: anywhere; font-size: 12.5px; }
.oauth-code {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  padding: 12px;
  border: 1px dashed var(--accent-line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--accent-soft-ink);
}

.config-form { max-width: 720px; }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.config-grid .field--full { grid-column: 1 / -1; }
.security-config { max-width: 860px; }
.security-status {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 8px;
}
.security-status__row {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.security-status__row > span:first-child {
  color: var(--muted);
  font-size: 12px;
}
.security-status__row .status {
  min-width: 0;
  max-width: 68%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.config-software { max-width: none; }
.config-sections { display: flex; gap: 8px; flex-wrap: wrap; }
.config-fields-form, .raw-config-form { display: grid; gap: 12px; }
.config-groups { display: grid; gap: 10px; }
.config-group {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  overflow: hidden;
}
.config-group summary {
  min-height: 40px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.config-group__body {
  border-top: 1px solid var(--line);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}
.config-field {
  min-width: 0;
  display: grid;
  gap: 6px;
}
.config-field__label {
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.config-field__label strong { font-size: 12.5px; font-weight: 600; }
.config-field__label code {
  color: var(--faint);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.config-field textarea, .raw-config {
  min-height: 88px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
}
.raw-config { min-height: 320px; }
.config-warning {
  padding: 10px 12px;
  border: 1px solid var(--warn-line);
  border-radius: var(--r-sm);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.check-row input { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--accent-solid); }
.check-row__text { display: grid; }
.check-row__text strong { font-size: 13px; font-weight: 600; }
.check-row__text span { font-size: 12px; color: var(--muted); }
.form-actions { display: flex; gap: 9px; flex-wrap: wrap; padding-top: 2px; }

/* Empty state */
.empty {
  margin: auto;
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 12px;
  padding: 48px 24px;
  max-width: 380px;
}
.empty__icon {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--accent);
}
.empty__icon svg { width: 26px; height: 26px; }
.empty h3 { font-family: var(--font-display); font-size: 17px; font-weight: 500; }
.empty p { font-size: 13px; color: var(--muted); }

/* =====================================================================
   Toasts
   ===================================================================== */
.toast-stack {
  position: fixed;
  z-index: 100;
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(380px, calc(100vw - 36px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 12px 13px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-3);
  animation: toast-in 0.26s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.toast.is-leaving { animation: toast-out 0.2s ease forwards; }
.toast__icon { flex: 0 0 auto; margin-top: 1px; }
.toast__icon svg { width: 18px; height: 18px; }
.toast--error { border-left: 3px solid var(--danger); }
.toast--error .toast__icon { color: var(--danger); }
.toast--ok { border-left: 3px solid var(--ok); }
.toast--ok .toast__icon { color: var(--ok); }
.toast__body { font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.toast__title { font-weight: 600; margin-bottom: 1px; }
.toast__msg { color: var(--muted); }
.toast__close { margin: -4px -4px 0 auto; }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 940px) {
  .kb-grid, .config-grid, .account-create__grid, .account-row__grid, .token-usage__columns, .audit-tools, .audit-private { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  .auth { grid-template-columns: 1fr; }
  .auth__aside { display: none; }
  .auth__card .brand__logo { display: block; } /* aside hidden here — restore the card logo */

  .shell { grid-template-columns: 1fr; }
  .menu-btn { display: inline-grid; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, var(--sidebar-w));
    transform: translateX(-102%);
    transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow-3);
    padding-left: env(safe-area-inset-left);
    padding-top: env(safe-area-inset-top);
  }
  .shell.is-open .sidebar { transform: none; }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: var(--overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--t);
  }
  .shell.is-open .scrim { opacity: 1; visibility: visible; }

  .messages, .composer { padding-left: 14px; padding-right: 14px; }
  .panel { padding: 16px 14px 32px; }
  .msg { max-width: 100%; }
  .token-usage__overview .card__head {
    display: grid;
  }
  .token-usage__filters {
    justify-content: flex-start;
  }
  .usage-table__row {
    min-width: max(640px, 100%);
  }
}

/* =====================================================================
   Motion preferences
   ===================================================================== */
@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;
  }
}
