/* ═══════════════════════════════════════════════════════════════════════════
   Åkre AI — Nordic Hovudbok Design System
   Substitution note: Commit Mono → Spline Sans Mono (OFL-1.1 variable woff2,
   directly downloadable). Same anonymous tabular quality, not code-aesthetic-heavy.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Self-hosted @font-face ────────────────────────────────────────────────── */

@font-face {
  font-family: 'Source Serif 4';
  src: url('/static/fonts/SourceSerif4Variable-Roman.woff2') format('woff2-variations');
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Source Serif 4';
  src: url('/static/fonts/SourceSerif4Variable-Italic.woff2') format('woff2-variations');
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('/static/fonts/PlusJakartaSans[wght].woff2') format('woff2-variations');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Plus Jakarta Sans';
  src: url('/static/fonts/PlusJakartaSans-Italic[wght].woff2') format('woff2-variations');
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}

/* Spline Sans Mono substitutes for Commit Mono (same OFL-1.1, variable, tabular, not code-heavy) */
@font-face {
  font-family: 'Commit Mono';
  src: url('/static/fonts/SplineSansMono[wght].woff2') format('woff2-variations');
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Commit Mono';
  src: url('/static/fonts/SplineSansMono-Italic[wght].woff2') format('woff2-variations');
  font-weight: 300 700;
  font-style: italic;
  font-display: swap;
}

/* ── Full token set ────────────────────────────────────────────────────────── */

:root {
  /* ── Colour ────────────────────────────────────────────────────── */
  --ink-900:    #1A2B1F;
  --ink-800:    #243829;
  --ink-700:    #2F4D38;
  --ink-500:    #5C7A64;
  --ink-300:    #A8BFB0;
  --ink-100:    #D6E5DA;
  --ground-50:  #F7F4EF;
  --ground-0:   #FDFCF9;
  --brass-500:  #B8922A;
  --brass-400:  #CBA543;
  --brass-100:  #F2E9D0;
  --brass-50:   #FAF5E8;
  --green-700:  #1C4A2A;
  --green-600:  #245932;
  --green-500:  #2D6B3D;
  --green-100:  #D4EDDA;
  --green-50:   #EAF5EE;
  --red-600:    #C0392B;
  --red-50:     #FDF0EE;
  --amber-500:  #E07A00;
  --amber-50:   #FEF3E2;

  /* ── Typography ────────────────────────────────────────────────── */
  --font-display: 'Source Serif 4', Georgia, serif;
  --font-body:    'Plus Jakarta Sans', system-ui, sans-serif;
  --font-mono:    'Commit Mono', 'SFMono-Regular', Consolas, monospace;
  --font-features-numeric: "tnum" 1, "lnum" 1;

  /* ── Type scale (major third ×1.25) ────────────────────────────── */
  --text-xs:    0.75rem;
  --text-sm:    0.825rem;
  --text-base:  0.9375rem;
  --text-md:    1.0625rem;
  --text-lg:    1.25rem;
  --text-xl:    1.5625rem;
  --text-2xl:   1.953rem;
  --text-3xl:   2.441rem;

  /* ── Font weights ───────────────────────────────────────────────── */
  --fw-light:    300;
  --fw-regular:  400;
  --fw-medium:   500;
  --fw-semibold: 600;
  --fw-bold:     700;

  /* ── Line heights ───────────────────────────────────────────────── */
  --lh-tight:  1.2;
  --lh-snug:   1.35;
  --lh-normal: 1.55;
  --lh-loose:  1.7;

  /* ── Letter spacing ─────────────────────────────────────────────── */
  --ls-tight:  -0.02em;
  --ls-normal:  0;
  --ls-wide:    0.04em;
  --ls-wider:   0.08em;

  /* ── Spacing (4px base grid) ────────────────────────────────────── */
  --s-1:   0.25rem;
  --s-2:   0.5rem;
  --s-3:   0.75rem;
  --s-4:   1rem;
  --s-5:   1.25rem;
  --s-6:   1.5rem;
  --s-8:   2rem;
  --s-10:  2.5rem;
  --s-12:  3rem;
  --s-16:  4rem;

  /* ── Radii ──────────────────────────────────────────────────────── */
  --r-none:   0;
  --r-sm:     3px;
  --r-md:     6px;
  --r-lg:     10px;
  --r-full:   9999px;

  /* ── Hairlines & borders ────────────────────────────────────────── */
  --border-hairline: 1px solid var(--ink-100);
  --border-rule:     0.5px solid var(--ink-100);
  --border-medium:   1.5px solid var(--ink-300);
  --border-strong:   2px solid var(--ink-500);

  /* ── Shadows ────────────────────────────────────────────────────── */
  --shadow-sm:  0 1px 4px rgba(26,43,31,.06);
  --shadow-md:  0 2px 12px rgba(26,43,31,.08);
  --shadow-lg:  0 4px 24px rgba(26,43,31,.12);

  /* ── Semantic aliases ───────────────────────────────────────────── */
  --bg:          var(--ground-50);
  --surface:     var(--ground-0);
  --text:        var(--ink-800);
  --text-muted:  var(--ink-500);
  --primary:     var(--green-600);
  --primary-h:   var(--green-700);
  --accent:      var(--brass-500);
  --accent-h:    var(--brass-400);

  /* ── Motion ─────────────────────────────────────────────────────── */
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1);
  --dur-fast:    120ms;
  --dur-base:    200ms;
  --dur-slow:    350ms;

  /* ── Layout ─────────────────────────────────────────────────────── */
  --topbar-h:   52px;
  --thread-max: 840px;
}

/* ── Dark theme ─────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --ground-50:   #141A15;
  --ground-0:    #1C2620;
  --ink-900:     #EAE6DD;
  --ink-800:     #D4D0C8;
  --ink-700:     #A8A49C;
  --ink-500:     #787470;
  --ink-300:     #4A4744;
  --ink-100:     #2E3530;
  --brass-500:   #CBA543;
  --brass-400:   #DDB95A;
  --brass-100:   #2A2415;
  --brass-50:    #1E1B0F;
  --green-700:   #2D7040;
  --green-600:   #38874F;
  --green-500:   #459E60;
  --green-100:   #163324;
  --green-50:    #0F2119;
  --red-600:     #E05A4A;
  --red-50:      #2A1512;
  --amber-500:   #E8942A;
  --amber-50:    #2A1E08;
}

/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Utility ────────────────────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.amount  { font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums; }

/* ── Ledger background texture (min-width: 600px) ───────────────────────────── */
@media (min-width: 600px) {
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image: repeating-linear-gradient(
      0deg,
      transparent,
      transparent 31px,
      var(--ink-100) 31px,
      var(--ink-100) 32px
    );
    opacity: 0.35;
  }
}

/* ── Theme toggle button ────────────────────────────────────────────────────── */
.theme-toggle {
  background: transparent;
  border: 1px solid rgba(253,252,249,.20);
  color: var(--ground-0);
  border-radius: var(--r-sm);
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
  flex-shrink: 0;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}
.theme-toggle:hover { background: rgba(253,252,249,.15); border-color: rgba(253,252,249,.35); }

/* ═══════════════════════════════════════════════════════════════════════════
   LOGIN SCREEN
   ════════════════════════════════════════════════════════════════════════════ */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--s-4);
  position: relative;
  z-index: 1;
}

.login-card {
  background: var(--surface);
  border: var(--border-hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: var(--s-10) var(--s-8);
  width: 100%;
  max-width: 400px;
  animation: card-appear var(--dur-slow) var(--ease-out) both;
}

@keyframes card-appear {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}

.login-brand {
  text-align: center;
  margin-bottom: var(--s-8);
}

.login-brand-rule-brass {
  display: block;
  width: 100%;
  height: 0;
  border: none;
  border-top: 1px solid var(--brass-500);
  margin-bottom: var(--s-4);
  opacity: 0.7;
}

.login-brand h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: var(--fw-bold);
  color: var(--ink-900);
  letter-spacing: var(--ls-tight);
  line-height: var(--lh-tight);
  margin-bottom: var(--s-1);
}

.login-brand p {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink-500);
  line-height: var(--lh-normal);
  margin-top: var(--s-1);
}

.login-brand-rule-ink {
  display: block;
  width: 100%;
  height: 0;
  border: none;
  border-top: 0.5px solid var(--ink-100);
  margin-top: var(--s-4);
}

.login-error {
  border-left: 3px solid var(--red-600);
  background: var(--red-50);
  color: var(--red-600);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: var(--s-2) var(--s-3);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  margin-bottom: var(--s-4);
  line-height: var(--lh-normal);
}

.form-group {
  margin-bottom: var(--s-4);
}

.form-group label {
  display: block;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--ink-500);
  letter-spacing: var(--ls-wider);
  text-transform: uppercase;
  margin-bottom: var(--s-1);
}

.form-group input {
  width: 100%;
  padding: var(--s-2) var(--s-3);
  border: var(--border-hairline);
  border-radius: var(--r-md);
  font-size: var(--text-base);
  font-family: var(--font-body);
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  line-height: var(--lh-normal);
}

.form-group input:focus {
  border-color: var(--green-600);
  border-width: 1.5px;
  box-shadow: 0 0 0 3px rgba(36,89,50,.12);
}

.form-group input::placeholder { color: var(--ink-300); }

.btn-primary {
  width: 100%;
  height: 44px;
  background: var(--green-600);
  color: var(--ground-0);
  border: none;
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
  margin-top: var(--s-2);
}

.btn-primary:hover:not(:disabled) { background: var(--green-700); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

/* ═══════════════════════════════════════════════════════════════════════════
   APP SHELL
   ════════════════════════════════════════════════════════════════════════════ */

#app-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOP BAR
   ════════════════════════════════════════════════════════════════════════════ */

.topbar {
  background: var(--green-700);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 var(--s-5);
  gap: var(--s-3);
  flex-shrink: 0;
  border-bottom: 0.5px solid var(--brass-500);
  z-index: 10;
  position: relative;
}

.topbar-brand {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: var(--fw-semibold);
  color: var(--ground-0);
  letter-spacing: var(--ls-tight);
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar-sep {
  width: 1px;
  height: 24px;
  background: var(--brass-500);
  opacity: 0.45;
  flex-shrink: 0;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-left: auto;
  flex-shrink: 0;
}

.topbar-email {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  color: rgba(253,252,249,.65);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: rgba(253,252,249,.08);
  border: 1px solid rgba(253,252,249,.25);
  color: var(--ground-0);
  border-radius: var(--r-sm);
  padding: 4px 10px;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out);
}

.btn-logout:hover { background: rgba(253,252,249,.18); }

/* ═══════════════════════════════════════════════════════════════════════════
   CLIENT SWITCHER (custom dropdown)
   ════════════════════════════════════════════════════════════════════════════ */

.client-switcher {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 280px;
}

.client-switcher-btn {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  background: rgba(253,252,249,.10);
  border: 1px solid rgba(184,146,42,.35);
  border-radius: var(--r-sm);
  padding: var(--s-1) var(--s-3) var(--s-1) var(--s-2);
  cursor: pointer;
  min-width: 140px;
  max-width: 100%;
  transition: border-color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
  text-align: left;
}

.client-switcher-btn:hover {
  border-color: var(--brass-400);
  background: rgba(253,252,249,.14);
}

.client-prefix {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  color: var(--brass-400);
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  white-space: nowrap;
  flex-shrink: 0;
}

.client-name {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--fw-medium);
  color: var(--ground-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  transition: opacity var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}

.client-chevron {
  flex-shrink: 0;
  color: var(--brass-400);
  width: 14px;
  height: 14px;
  transition: transform var(--dur-base) var(--ease-out);
}

.client-switcher.open .client-chevron {
  transform: rotate(180deg);
}

.client-dropdown {
  position: absolute;
  top: calc(100% + var(--s-1));
  left: 0;
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--ground-0);
  border: var(--border-hairline);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}

.client-switcher.open .client-dropdown {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.client-dropdown-item {
  display: block;
  width: 100%;
  padding: var(--s-2) var(--s-4);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink-800);
  background: none;
  border: none;
  border-left: 2px solid transparent;
  cursor: pointer;
  text-align: left;
  transition: background var(--dur-fast) var(--ease-out),
              border-left-color var(--dur-fast) var(--ease-out);
}

.client-dropdown-item:hover {
  background: var(--brass-50);
  border-left-color: var(--brass-500);
}

.client-dropdown-item.active {
  border-left-color: var(--brass-500);
  background: var(--brass-50);
  font-weight: var(--fw-medium);
}

/* ═══════════════════════════════════════════════════════════════════════════
   CHAT AREA
   ════════════════════════════════════════════════════════════════════════════ */

.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: var(--thread-max);
  width: 100%;
  margin: 0 auto;
}

#thread {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-5) var(--s-4) 0;
  scroll-behavior: smooth;
}

/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY STATE
   ════════════════════════════════════════════════════════════════════════════ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  padding: var(--s-8) var(--s-4);
  gap: var(--s-4);
}

.empty-rule {
  border: none;
  border-top: 1px solid var(--brass-500);
  width: 48px;
  opacity: 0.6;
  margin: 0 auto;
}

.empty-state-brand {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--fw-semibold);
  color: var(--ink-900);
  letter-spacing: var(--ls-tight);
  line-height: var(--lh-tight);
  animation: stagger-in var(--dur-slow) var(--ease-out) both;
  animation-delay: 0ms;
}

.empty-state-sub {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink-500);
  max-width: 320px;
  line-height: var(--lh-loose);
  animation: stagger-in var(--dur-slow) var(--ease-out) both;
  animation-delay: 80ms;
}

.example-chips {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  align-items: center;
  animation: stagger-in var(--dur-slow) var(--ease-out) both;
  animation-delay: 160ms;
}

.example-chip {
  background: var(--surface);
  border: var(--border-hairline);
  border-left: 2px solid var(--brass-500);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: var(--s-2) var(--s-4);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              border-left-color var(--dur-fast) var(--ease-out);
  text-align: left;
  min-width: 220px;
  width: 100%;
  max-width: 360px;
}

.example-chip:hover {
  background: var(--brass-50);
  border-left-color: var(--brass-400);
}

@keyframes stagger-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MESSAGE BUBBLES
   ════════════════════════════════════════════════════════════════════════════ */

.msg-row {
  display: flex;
  margin-bottom: var(--s-4);
}

.msg-row.user  { justify-content: flex-end; }
.msg-row.bot   { justify-content: flex-start; }

/* User bubble */
.msg-row.user .bubble {
  background: var(--green-700);
  color: var(--ground-0);
  border-radius: var(--r-lg) var(--r-lg) var(--r-sm) var(--r-lg);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  padding: var(--s-3) var(--s-4);
  max-width: 70%;
  word-break: break-word;
  animation: bubble-in-user var(--dur-base) var(--ease-out) both;
}

@keyframes bubble-in-user {
  from { opacity: 0; transform: translateY(6px) translateX(4px); }
  to   { opacity: 1; transform: none; }
}

/* Assistant bubble */
.msg-row.bot .bubble {
  background: var(--surface);
  color: var(--text);
  border: var(--border-hairline);
  border-left: 2px solid var(--brass-500);
  border-radius: var(--r-sm) var(--r-lg) var(--r-lg) var(--r-lg);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--lh-loose);
  padding: var(--s-3) var(--s-4);
  max-width: 78%;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
  animation: bubble-in-bot var(--dur-base) var(--ease-out) both;
}

@keyframes bubble-in-bot {
  from { opacity: 0; transform: translateY(6px) translateX(-4px); }
  to   { opacity: 1; transform: none; }
}

/* Markdown inside bot bubbles */
.bubble h1, .bubble h2, .bubble h3 {
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  color: var(--ink-900);
  letter-spacing: var(--ls-tight);
  margin: var(--s-4) 0 var(--s-2);
  line-height: var(--lh-snug);
}
.bubble h1 { font-size: var(--text-lg); }
.bubble h2 { font-size: var(--text-md); }
.bubble h3 { font-size: var(--text-base); }

.bubble h1:first-child,
.bubble h2:first-child,
.bubble h3:first-child { margin-top: 0; }

.bubble strong { font-weight: var(--fw-bold); }
.bubble em     { font-style: italic; }
.bubble p      { margin: var(--s-2) 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child  { margin-bottom: 0; }
.bubble ul, .bubble ol { padding-left: 1.5em; margin: var(--s-2) 0; }
.bubble li     { margin-bottom: var(--s-1); line-height: var(--lh-normal); }

.bubble code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--brass-50);
  border: 0.5px solid var(--ink-100);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  font-variant-numeric: tabular-nums lining-nums;
}

.bubble pre {
  background: var(--ground-50);
  border: var(--border-hairline);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  overflow-x: auto;
  margin: var(--s-3) 0;
}

.bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: var(--text-sm);
  font-family: var(--font-mono);
}

.bubble hr {
  border: none;
  border-top: 0.5px solid var(--ink-100);
  margin: var(--s-3) 0;
}

/* Tables */
.bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin: var(--s-3) 0;
}
.bubble th {
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--ls-wider);
  color: var(--ink-700);
  background: var(--brass-50);
  border: 0.5px solid var(--ink-100);
  padding: var(--s-2) var(--s-3);
  text-align: left;
}
.bubble td {
  border: 0.5px solid var(--ink-100);
  padding: var(--s-2) var(--s-3);
  color: var(--ink-800);
}
.bubble td:where([align="right"], .num) {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums lining-nums;
}

/* Streaming cursor */
.stream-cursor {
  display: inline-block;
  color: var(--brass-400);
  animation: cursor-blink 0.85s step-end infinite;
  margin-left: 1px;
  font-weight: var(--fw-light);
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOOL CHIPS (receipt stamp motif)
   ════════════════════════════════════════════════════════════════════════════ */

.tool-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1);
  margin-top: var(--s-2);
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  background: var(--brass-50);
  border: 1px solid var(--brass-100);
  border-bottom: 1px dashed var(--brass-400);
  border-radius: var(--r-sm);
  padding: 2px var(--s-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-700);
  animation: chip-appear var(--dur-fast) var(--ease-out) both;
}

@keyframes chip-appear {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

/* Spinner ring (::before pseudo) */
.tool-chip::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1.5px solid var(--brass-500);
  border-top-color: transparent;
  animation: chip-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes chip-spin {
  to { transform: rotate(360deg); }
}

.tool-chip.done {
  background: var(--green-50);
  border: 1px solid var(--green-100);
  border-bottom: 1px solid var(--green-100);
  color: var(--green-700);
  transition: background var(--dur-slow) var(--ease-in-out),
              border-color var(--dur-slow) var(--ease-in-out),
              color var(--dur-slow) var(--ease-in-out);
}

.tool-chip.done::before {
  content: none;
}

.tool-chip.done .chip-check {
  display: inline-block;
  width: 7px;
  height: 5px;
  flex-shrink: 0;
}

.tool-chip .chip-check { display: none; }

.tool-chip.error {
  background: var(--red-50);
  border: 1px solid rgba(192,57,43,.25);
  border-bottom: 1px dashed var(--red-600);
  color: var(--red-600);
}

.tool-chip.error::before { content: none; }

.chip-elapsed {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-300);
  margin-left: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   THINKING / STREAMING INDICATOR
   ════════════════════════════════════════════════════════════════════════════ */

.thinking-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) 0 var(--s-4);
  color: var(--ink-500);
  font-family: var(--font-body);
  font-size: var(--text-sm);
}

.thinking-spinner {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--brass-500);
  border-top-color: transparent;
  animation: chip-spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   INPUT BAR
   ════════════════════════════════════════════════════════════════════════════ */

.input-bar {
  padding: var(--s-3) var(--s-4) var(--s-4);
  background: var(--bg);
  border-top: 0.5px solid var(--ink-100);
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
  background: var(--surface);
  border: var(--border-hairline);
  border-radius: var(--r-lg);
  padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

.input-row:focus-within {
  border-color: var(--green-600);
  box-shadow: 0 0 0 3px rgba(36,89,50,.10);
}

#msg-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: var(--text-base);
  font-family: var(--font-body);
  color: var(--text);
  background: transparent;
  resize: none;
  max-height: 160px;
  min-height: 22px;
  line-height: var(--lh-normal);
  padding: 0.15rem 0;
}

#msg-input::placeholder { color: var(--ink-300); }

.btn-send {
  flex-shrink: 0;
  background: var(--green-600);
  color: var(--ground-0);
  border: none;
  border-radius: var(--r-md);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

.btn-send:hover:not(:disabled) { background: var(--green-700); }
.btn-send:active:not(:disabled) { transform: scale(0.92); }
.btn-send:disabled { opacity: 0.4; cursor: default; }

.btn-send svg { width: 16px; height: 16px; fill: currentColor; }

.input-hint {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  color: var(--ink-300);
  margin-top: var(--s-1);
  padding-left: var(--s-1);
}

/* ═══════════════════════════════════════════════════════════════════════════
   ERROR STATES
   ════════════════════════════════════════════════════════════════════════════ */

.error-note {
  border-left: 3px solid var(--red-600);
  background: var(--red-50);
  color: var(--red-600);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: var(--s-2) var(--s-3);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  margin: var(--s-2) 0;
  line-height: var(--lh-normal);
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 600px) {
  .topbar { padding: 0 var(--s-3); gap: var(--s-2); }
  .topbar-email { display: none; }
  .client-switcher { max-width: 180px; }
  .msg-row.user .bubble,
  .msg-row.bot  .bubble { max-width: 88%; }
  #thread { padding: var(--s-3) var(--s-3) 0; }
  .input-bar { padding: var(--s-2) var(--s-3) var(--s-3); }
  .input-hint { display: none; }
  .btn-send { width: 32px; height: 32px; }
  .empty-state { padding: var(--s-6) var(--s-3); }
  .empty-rule { display: none; }
}

@media (max-width: 480px) {
  .login-card { padding: var(--s-8) var(--s-5); }
  .theme-toggle { display: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ════════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
