:root {
  /* ------------------------------------------------------------------
     Atlas Visual Language — single source of truth.
     Dark-Atlas is the dominant theme; light tokens redefine the same
     semantic names in the light @media block. Components consume only
     the semantic --bg/--fg/--accent/--err etc. — never the raw hex.
     If you tune tokens, tune all four CSS files in the same diff.
     ------------------------------------------------------------------ */
  --atlas-petrol:    #153937;
  --atlas-petrol-2:  #102b29;
  --atlas-teal:      #1F4E4A;
  --atlas-teal-2:    #29605B;
  --atlas-ochre:     #E6A24A;
  --atlas-ochre-2:   #C7873A;
  --atlas-sand:      #F2D6A2;
  --atlas-sand-mute: #C9B385;
  --atlas-sage:      #7FA39A;
  --atlas-sage-2:    #6A8C84;
  --atlas-coral:     #D97A5B;
  --atlas-terracotta:#A63D2F;
  --atlas-burnt:     #C65A2E;
  --atlas-clay:      #8C4A2F;

  --atlas-grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.05 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");

  --bg:           var(--atlas-petrol-2);
  --bg-elev:      var(--atlas-petrol);
  --bg-raised:   var(--atlas-teal);
  --bg-input:    var(--atlas-teal);
  --fg:          var(--atlas-sand);
  --fg-muted:    var(--atlas-sand-mute);
  --accent:      var(--atlas-ochre);
  --accent-hov:  var(--atlas-ochre-2);
  --accent-fade: rgba(230, 162, 74, 0.18);
  --user-bg:     var(--atlas-teal-2);
  --oji-bg:      rgba(31, 78, 74, 0.55);
  --border:      rgba(242, 214, 162, 0.10);
  --border-strong: rgba(242, 214, 162, 0.22);
  --warning:     var(--atlas-coral);
  --error:       var(--atlas-terracotta);
  --error-fg:    #F4C9B8;
  --at-cap:      var(--atlas-burnt);
  --focus-ring:  var(--atlas-ochre);

  --secondary:     var(--atlas-sage);
  --secondary-hov: var(--atlas-sage-2);
  --branch-glow:   rgba(230, 162, 74, 0.30);

  --font-ui: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Helvetica Neue", sans-serif;
  --font-headline: ui-serif, "Playfair Display", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 22px;

  --shadow-1: 0 1px 0 rgba(0, 0, 0, 0.25);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:           #F6EFE2;
    --bg-elev:      #FBF6EC;
    --bg-raised:    #F2D6A2;
    --bg-input:    #FEFCF8;
    --fg:          #153937;
    --fg-muted:    #4A6E69;
    --accent:      #C7873A;
    --accent-hov:  #A86A26;
    --accent-fade: rgba(199, 135, 58, 0.16);
    --user-bg:     #F2D6A2;
    --oji-bg:      #FBF6EC;
    --border:      rgba(21, 57, 55, 0.12);
    --border-strong: rgba(21, 57, 55, 0.25);
    --error-fg:    #6B1C12;
    --secondary:     #7FA39A;
    --secondary-hov: #6A8C84;
    --branch-glow:   rgba(230, 162, 74, 0.22);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Grain overlay — softens flat petrol; pointer-events:none so it never
   intercepts clicks. Applied to body so it covers full viewport. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: var(--atlas-grain);
  background-size: 160px 160px;
  pointer-events: none;
  z-index: 0;
  opacity: 0.9;
}

body {
  display: flex;
  flex-direction: column;
}

/* All app content sits above the grain. header must out-rank main: both are
   positioned siblings, and at equal z-index main (later in the DOM) painted on
   top — which boxed the account dropdown BEHIND the chat surface. A higher
   z-index on header lifts its whole subtree (incl. the overflowing dropdown)
   above main. */
header { position: relative; z-index: 10; }
main { position: relative; z-index: 1; }

/* ------------------ Header ------------------ */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  min-height: 56px;
}

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-name {
  font-family: var(--font-headline);
  font-weight: 600;
  letter-spacing: 0.01em;
  font-size: 1.15rem;
  color: var(--fg);
}
.brand-sep { color: var(--fg-muted); }
.brand-sub {
  font-family: var(--font-headline);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--fg-muted);
  letter-spacing: 0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.surface-nav {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex-wrap: wrap;
}
.surface-link {
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color 120ms ease, background-color 120ms ease;
}
.surface-link:hover { color: var(--fg); background: var(--accent-fade); }
.surface-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.surface-link.is-current {
  color: var(--fg);
  background: var(--accent-fade);
  font-weight: 600;
}

.dot {
  width: 12px;
  height: 12px;
  background: var(--accent);
  display: inline-block;
  /* Atlas sun medallion — filled geometric, no outline */
  clip-path: polygon(50% 0%, 65% 35%, 100% 50%, 65% 65%, 50% 100%, 35% 65%, 0% 50%, 35% 35%);
}

/* Identity chip in header (replaces standalone signout button) */
.account { display: flex; align-items: center; gap: 0.5rem; }

.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-raised);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.25rem 0.6rem 0.25rem 0.3rem;
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 240px;
  min-height: 36px;
}
.account-chip:hover { border-color: var(--accent); }
.account-chip:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.account-chip .avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--atlas-ochre);
  color: var(--atlas-petrol);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.account-chip .email-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-muted);
}
.account-chip .caret {
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--fg-muted);
  margin-right: 2px;
}

.account-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  min-width: 220px;
  padding: 0.4rem;
  z-index: 20;
}
.account-wrap { position: relative; }
.account-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--fg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  min-height: 36px;
}
.account-menu button:hover { background: var(--accent-fade); }
.account-menu button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.account-menu .menu-section {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.account-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.3rem 0;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ------------------ Sign-in screen ------------------ */
.signin-wrap {
  margin: auto;
  text-align: center;
  padding: 2rem 1.25rem;
  max-width: 420px;
  width: 100%;
}
.signin-medallion {
  width: 88px;
  height: 88px;
  margin: 0 auto 1.5rem;
  color: var(--accent);
  filter: drop-shadow(0 1px 0 rgba(0,0,0,0.2));
}
.signin-headline {
  font-family: var(--font-headline);
  font-size: 1.75rem;
  color: var(--fg);
  margin: 0 0 0.5rem;
  letter-spacing: 0.005em;
}
.signin-prose {
  color: var(--fg-muted);
  margin: 0 0 1.75rem;
  font-size: 0.95rem;
}
.signin-prose strong { color: var(--fg); font-weight: 600; }
.signin-error {
  margin-top: 1.25rem;
  color: var(--error-fg);
  background: rgba(166, 61, 47, 0.18);
  border: 1px solid var(--error);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
}

/* ------------------ Wrong-workspace full-screen ------------------ */
.access-denied {
  margin: auto;
  text-align: center;
  padding: 2.5rem 1.5rem;
  max-width: 460px;
}
.access-denied .medallion {
  width: 72px; height: 72px;
  margin: 0 auto 1.25rem;
  color: var(--at-cap);
}
.access-denied h2 {
  font-family: var(--font-headline);
  color: var(--fg);
  margin: 0 0 0.5rem;
  font-size: 1.4rem;
}
.access-denied p {
  color: var(--fg-muted);
  margin: 0 0 1.5rem;
}
.access-denied .email-shown {
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.9rem;
}
.access-denied button {
  background: var(--accent);
  color: var(--atlas-petrol);
  border: none;
  border-radius: var(--radius-md);
  padding: 0.65rem 1.2rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.access-denied button:hover { background: var(--accent-hov); }
.access-denied button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ------------------ Chat wrap ------------------ */
#chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Soft fade-in on sign-in -> chat transition. */
  opacity: 1;
  transition: opacity 220ms ease;
}
#chat-wrap.fade-in { animation: oji-fade-in 220ms ease both; }
@keyframes oji-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ------------------ Messages ------------------ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-width: thin;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.message {
  display: flex;
  max-width: 90%;
}
.message-bubble {
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius-lg);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  line-height: 1.55;
  box-shadow: var(--shadow-1);
}

.message.user {
  align-self: flex-end;
}
.message.user .message-bubble {
  background: var(--user-bg);
  color: var(--fg);
  border-top-right-radius: 4px;
}

.message.oji .message-bubble {
  background: var(--oji-bg);
  color: var(--fg);
  border-top-left-radius: 4px;
  border: 1px solid var(--border);
}

.message-bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.message-bubble a:hover { color: var(--accent-hov); }

.message-error .message-bubble {
  background: rgba(166, 61, 47, 0.15);
  color: var(--error-fg);
  border: 1px solid var(--error);
}

/* Cortex relay — an Oji follow-up that cortex posted back into the
   conversation. The "via Cortex" badge sits OUTSIDE the bubble; attribution
   is structural (driven by the server `source` field in chat.js), never from
   the message text (Sophia F-5). Marked with the ochre geometric token so a
   relayed finding never reads as Oji's own composed answer. */
.message.message-cortex {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
}
.cortex-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.12rem 0.6rem 0.12rem 0.45rem;
}
.cortex-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--accent);
  transform: rotate(45deg);
  flex-shrink: 0;
}
.message.oji.message-cortex .message-bubble {
  border-left: 3px solid var(--accent);
}
.message.message-cortex.is-arriving { animation: oji-relay-in 280ms ease both; }
@keyframes oji-relay-in {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Retry bubble — transient network/5xx error with action button. */
.message-retry {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-self: stretch;
  max-width: 90%;
}
.message-retry .retry-text {
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius-lg);
  background: rgba(198, 90, 46, 0.15);
  color: var(--error-fg);
  border: 1px solid var(--at-cap);
  font-size: 0.92rem;
}
.message-retry .retry-btn {
  align-self: flex-start;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.85rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  min-height: 32px;
}
.message-retry .retry-btn:hover { background: var(--accent-fade); }
.message-retry .retry-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ------------------ Empty state ------------------ */
.empty-state {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  text-align: center;
  padding: 2rem 1rem;
  color: var(--fg-muted);
}
.empty-state .medallion {
  width: 64px;
  height: 64px;
  color: var(--accent);
  opacity: 0.85;
}
.empty-state .empty-headline {
  font-family: var(--font-headline);
  font-size: 1.2rem;
  color: var(--fg);
  margin: 0;
}
.empty-state .empty-prose {
  font-size: 0.95rem;
  max-width: 32ch;
  margin: 0;
}

/* ------------------ Session-expired inline banner ------------------ */
.session-banner {
  background: rgba(217, 122, 91, 0.15);
  border: 1px solid var(--warning);
  color: var(--fg);
  padding: 0.6rem 1rem;
  margin: 0.75rem auto 0;
  max-width: 820px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
}
.session-banner button {
  background: var(--accent);
  color: var(--atlas-petrol);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.8rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 32px;
}
.session-banner button:hover { background: var(--accent-hov); }

/* ------------------ Composer ------------------ */
.composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  align-items: flex-end;
  position: relative;
}

.composer-input {
  flex: 1;
  resize: none;
  background: var(--bg-input);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 0.7rem 0.95rem;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.45;
  outline: none;
  max-height: 200px; /* ~6 lines at 1.45 line-height */
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.composer-input::placeholder { color: var(--fg-muted); }
.composer-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-fade);
}

.send-btn {
  background: var(--accent);
  color: var(--atlas-petrol);
  border: none;
  border-radius: var(--radius-lg);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  align-self: flex-end;
  flex-shrink: 0;
  transition: background-color 120ms ease, opacity 120ms ease;
}
.send-btn:hover { background: var(--accent-hov); }
.send-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.send-btn:disabled {
  background: var(--bg-raised);
  color: var(--fg-muted);
  cursor: not-allowed;
}

/* Char counter pill — sits above the composer when nearing the 8000 limit. */
.char-counter {
  position: absolute;
  right: 1rem;
  top: -1.6rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  opacity: 0;
  transition: opacity 140ms ease, color 140ms ease, border-color 140ms ease;
  pointer-events: none;
}
.char-counter.is-visible { opacity: 1; }
.char-counter.is-warn { color: var(--atlas-coral); border-color: var(--atlas-coral); }
.char-counter.is-cap { color: var(--at-cap); border-color: var(--at-cap); }

/* Paste-truncated transient notice (sibling of char-counter) */
.paste-notice {
  position: absolute;
  left: 1rem;
  top: -1.6rem;
  font-size: 0.75rem;
  color: var(--atlas-coral);
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}
.paste-notice.is-visible { opacity: 1; }

.hidden { display: none !important; }

/* ------------------ Universal focus ring (Atlas Ochre) ------------------ */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------
   Thinking strip — Pass 1. Same shape vocabulary will later anchor
   Logicus / Dreamer / Criticus when brain-v3 ships trace[] (Pass 2:
   sub-agent ribbon, currently deferred).
   ------------------------------------------------------------------ */
.thinking-strip {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  opacity: 0;
  transition: height 180ms ease, opacity 180ms ease, padding 180ms ease;
}
.thinking-strip.is-active {
  height: 22px;
  padding: 0.25rem 1.25rem;
  opacity: 1;
}
.thinking-strip .shape {
  width: 8px;
  height: 8px;
  background: var(--atlas-ochre);
  opacity: 0.3;
  animation: oji-thinking-pulse 1.4s ease-in-out infinite;
}
.thinking-strip .shape.s-triangle {
  background: transparent;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid var(--atlas-ochre);
}
.thinking-strip .shape.s-diamond {
  transform: rotate(45deg);
  animation-delay: 0.18s;
}
.thinking-strip .shape.s-circle {
  border-radius: 50%;
  animation-delay: 0.36s;
}
@keyframes oji-thinking-pulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1.0; }
}
@media (prefers-reduced-motion: reduce) {
  .thinking-strip .shape,
  .thinking-strip .shape.s-diamond,
  .thinking-strip .shape.s-circle {
    animation: none;
    opacity: 0.7;
  }
  #chat-wrap.fade-in { animation: none; }
  .message.message-cortex.is-arriving { animation: none; }
}

/* ------------------ Mobile ≤480px ------------------ */
@media (max-width: 480px) {
  header { padding: 0.6rem 0.85rem; padding-top: calc(0.6rem + env(safe-area-inset-top, 0px)); }
  .brand-name { font-size: 1.05rem; }
  .account-chip { max-width: 160px; }
  .account-chip .email-text { font-size: 0.8rem; }
  .messages { padding: 0.85rem 0.65rem; gap: 0.55rem; }
  .message { max-width: 94%; }
  .message-bubble { padding: 0.55rem 0.8rem; font-size: 0.95rem; }
  .composer { padding: 0.6rem 0.65rem 0.85rem; padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px)); }
  .composer-input { font-size: 1rem; /* keep 16px to avoid iOS zoom */ }
  .char-counter { top: -1.5rem; right: 0.65rem; font-size: 0.7rem; }
  .paste-notice { left: 0.65rem; top: -1.5rem; font-size: 0.7rem; }
  .session-banner { margin: 0.6rem 0.65rem 0; flex-direction: column; align-items: flex-start; }
  .signin-headline { font-size: 1.4rem; }
}

/* ====================== Previous-chats drawer ====================== */
.prevchats-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 43, 41, 0.55);
  z-index: 90;
}
.prevchats-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(380px, 88vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
  z-index: 100;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.prevchats-panel.slide-in { animation: oji-drawer-in 200ms ease both; }
@keyframes oji-drawer-in {
  from { transform: translateX(18px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

.prevchats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem 0.75rem;
  padding-top: calc(1rem + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.prevchats-title {
  font-family: var(--font-headline);
  font-size: 1.2rem;
  color: var(--fg);
  margin: 0;
}
.prevchats-close {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
}
.prevchats-close:hover { color: var(--fg); background: var(--accent-fade); }
.prevchats-close:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.prevchats-status {
  padding: 0.75rem 1.1rem;
  color: var(--fg-muted);
  font-size: 0.9rem;
}
.prevchats-status.is-error { color: var(--error-fg); }
.prevchats-status:empty { display: none; }

.prevchats-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem 0.6rem 1rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.prevchats-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0.6rem 0.7rem;
  cursor: pointer;
  color: var(--fg);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 44px;
}
.prevchats-item:hover { background: var(--accent-fade); border-color: var(--border); }
.prevchats-item:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.prevchats-item.is-current { border-color: var(--border-strong); background: var(--accent-fade); }
.prevchats-item-title {
  font-size: 0.95rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.prevchats-item-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--fg-muted);
  font-family: var(--font-mono);
}
.prevchats-channel {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-raised);
  color: var(--fg-muted);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  font-size: 0.68rem;
}
.prevchats-current-badge { color: var(--accent); }

@media (max-width: 480px) {
  header {
    padding: 0.6rem 0.85rem;
    padding-top: calc(0.6rem + env(safe-area-inset-top, 0px));
  }
  .brand-name { font-size: 1.05rem; }
  .account-chip { max-width: 120px; }
  .account-chip .email-text { font-size: 0.8rem; }
  .surface-link { font-size: 0.78rem; padding: 0.25rem 0.4rem; }
  .prevchats-panel { width: 100vw; border-left: none; }
}
@media (prefers-reduced-motion: reduce) {
  .prevchats-panel.slide-in { animation: none; }
}
