/* Chat page — "Calm terminal in your pocket" (look-and-feel.md).
   Same tokens, fonts and 8px/6-12-20 radius grid as Living City, self-hosted fonts (§2, M-R24). */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("./fonts/inter-variable-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("./fonts/space-grotesk-variable-latin.woff2") format("woff2");
}

:root {
  --font-ui: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --header-h: 52px;
  --chip-row-h: 40px;
  --input-min-h: 56px;

  --bg: #FBF3E3;
  --surface: #FFFFFF;
  --ink: #262A36;
  --ink-2: #555B6B;
  --ink-3: rgba(38, 42, 54, .70);   /* was 3.5:1 vs --bg, now 5.17:1 */
  --line: rgba(38, 42, 54, .09);
  --accent: #2E3A87;
  --accent-ink: #FFFFFF;
  --cos: #F0E4C6;
  --cos-ink: #262A36;
  --pass: #3FAE5A;
  --pass-strong: #2E7F42;          /* new — Allow button fill, 4.96:1 with white text */
  --fail: #C52121;                 /* was 4.0:1 vs card surface, now 5.81:1 (5.27:1 vs --bg) */
  --warn: #F0A93D;
  --warn-ink: #6E4700;             /* new — warn-coloured TEXT, e.g. eyebrow. 8.19:1 on white */
  --glass: rgba(255, 255, 255, .7);
  --hover: rgba(38, 42, 54, .06);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0B1030;
  --surface: #151A3A;
  --ink: #E9EBF7;
  --ink-2: #AAB0CB;
  --ink-3: rgba(233, 235, 247, .55);
  --line: rgba(255, 255, 255, .08);
  --accent: #FFD166;
  --accent-ink: #1B1F3D;
  --cos: #1E2444;
  --cos-ink: #E9EBF7;
  --fail: #E45D5D;      /* dark-mode fail: was 4.28:1 vs dark surface, now 4.86:1 (5.34:1 vs dark --bg) */
  --warn-ink: #F7C979;  /* dark-mode warn-ink: already-used tone-warn colour, 10.95:1 on dark surface */
  --glass: rgba(15, 18, 40, .7);
  --hover: rgba(255, 255, 255, .06);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1030; --surface: #151A3A; --ink: #E9EBF7; --ink-2: #AAB0CB;
    --ink-3: rgba(233, 235, 247, .55); --line: rgba(255, 255, 255, .08);
    --accent: #FFD166; --accent-ink: #1B1F3D; --cos: #1E2444; --cos-ink: #E9EBF7;
    --fail: #E45D5D; --warn-ink: #F7C979;
    --glass: rgba(15, 18, 40, .7); --hover: rgba(255, 255, 255, .06);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

/* ------------------------------------------------------------ brand mark (shared with the city) */
.brand-mark {
  width: 22px; height: 22px; flex: none;
  background:
    conic-gradient(from 225deg at 50% 44%, #F0E4C6 0 90deg, transparent 0) top / 100% 60% no-repeat,
    linear-gradient(90deg, #E2762D 50%, #2E3A87 50%) bottom / 100% 62% no-repeat;
  clip-path: polygon(50% 0, 100% 27%, 100% 73%, 50% 100%, 0 73%, 0 27%);
}
.brand-mark.lg { width: 44px; height: 44px; }
.brand-mark.sm { width: 18px; height: 18px; } /* was an inline style, which the page's CSP blocks */

/* ================================================================ LOGIN SCREEN */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: var(--bg);
}
.login-card { width: 100%; max-width: 360px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 28px; }
.login-brand .brand-mark { width: 44px; height: 44px; }
.login-brand .wordmark { font: 700 20px/1.2 var(--font-ui); letter-spacing: -0.01em; }
.login-field { margin-bottom: 14px; }
.login-field label { display: block; font: 600 13px var(--font-ui); margin-bottom: 6px; color: var(--ink-2); }
.login-field input {
  width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); padding: 0 16px; font-size: 16px;
}
.login-field input:focus-visible { outline-offset: 0; }
.login-field.has-error input { border-color: var(--fail); border-width: 1.5px; }
.login-error { color: var(--fail); font-size: 13px; margin: 8px 0 0; }
.login-submit {
  width: 100%; height: 48px; border-radius: 12px; border: 0; background: var(--accent);
  color: var(--accent-ink); font: 600 15px var(--font-ui); cursor: pointer; margin-top: 6px;
  transition: filter .15s var(--ease), transform .1s var(--ease);
}
.login-submit:hover { filter: brightness(1.06); }
.login-submit:active { transform: scale(.99); }
.login-submit:disabled { opacity: .6; cursor: default; }

/* ================================================================ CHAT SCREEN */
.chat-app[hidden], .login-screen[hidden] { display: none; }
.chat-app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

/* header */
.chat-header {
  flex: none; height: var(--header-h);
  padding-top: env(safe-area-inset-top);
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 5;
}
@media (max-width: 420px) {
  .chat-header { gap: 6px; padding-right: max(4px, env(safe-area-inset-right)); }
}
.chat-header .brand-name {
  font: 600 15px var(--font-ui); letter-spacing: -0.01em;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto;
}
.dev-badge {
  font: 700 10px var(--font-ui); letter-spacing: .06em; text-transform: uppercase;
  background: var(--warn); color: #4A3300; padding: 3px 7px; border-radius: 6px; flex: none;
  white-space: nowrap;
}
:root[data-theme="dark"] .dev-badge { color: #2A1D00; }
/* Phone widths: the badge shrinks to "DEV" so "Chief of Staff" stays whole at 390px. In
   production there is no badge at all; the title only ellipsizes on very narrow screens. */
@media (max-width: 480px) {
  .dev-badge .dev-long { display: none; }
}
@media (max-width: 340px) {
  .dev-badge { font-size: 0; padding: 5px; width: 8px; height: 8px; border-radius: 50%; }
}
.chat-header .spacer { flex: 1 1 auto; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--pass); transition: background .2s var(--ease); }
.conn-dot[data-state="connecting"] { background: var(--warn); }
.conn-dot[data-state="offline"] { background: var(--fail); }
.header-menu-btn {
  width: 44px; height: 44px; margin: -4px 0; border: 0; background: transparent; cursor: pointer;
  display: grid; place-items: center; border-radius: 10px; font-size: 18px; letter-spacing: 1px; color: var(--ink-2);
}
.header-menu-btn:hover { background: var(--hover); }
.city-tab-btn {
  width: 44px; height: 44px; margin: -4px 0; border: 0; background: transparent; cursor: pointer;
  display: grid; place-items: center; border-radius: 10px; opacity: .45;
}

.header-menu {
  position: absolute; top: calc(var(--header-h) + env(safe-area-inset-top) + 4px); right: max(8px, env(safe-area-inset-right));
  z-index: 30; width: 220px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); box-shadow: 0 10px 30px rgba(20,20,30,.16);
  list-style: none; margin: 0; padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.header-menu[hidden] { display: none; }
.header-menu button {
  width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px;
  border-radius: 9px; cursor: pointer; font-size: 14px; display: flex; justify-content: space-between; gap: 8px;
}
.header-menu button:hover, .header-menu button:focus-visible { background: var(--hover); }
.header-menu .value { color: var(--ink-3); font-size: 12px; }

/* reconnecting / back online banner */
.status-banner {
  flex: none; height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center;
  gap: 8px; font: 600 13px var(--font-ui); color: #4A3300; background: var(--warn); /* 5.9:1 (was 3.8:1) */
  transition: height .25s var(--ease), background-color .3s var(--ease), color .3s var(--ease);
}
.status-banner.show { height: 32px; }
.status-banner.pass { background: var(--pass); color: #103A1B; }
.status-banner .shimmer {
  position: relative; overflow: hidden; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.status-banner.show:not(.pass) .shimmer::after {
  content: ""; position: absolute; inset: 0; width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { transform: translateX(-120%); } to { transform: translateX(340%); } }

/* health banner (M-R29): persistent while the problem lasts — offline company, usage limit,
   Claude sign-in expiring/expired, idle-stop risk. Same bar as "Reconnecting…", but it wraps. */
.health-banner {
  flex: none; padding: 6px max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
  min-height: 32px; display: flex; align-items: center; justify-content: center; text-align: center;
  font: 600 13px/1.35 var(--font-ui); color: #4A3300; background: var(--warn);
}
.health-banner[hidden] { display: none; }

/* message list */
.message-list {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.msg-row { display: flex; flex-direction: column; max-width: 78%; }
.msg-row.from-ceo { align-self: flex-end; align-items: flex-end; }
.msg-row.from-cos { align-self: flex-start; align-items: flex-start; }
.msg-row + .msg-row.burst-start { margin-top: 8px; }
.msg-row.same-burst { margin-top: 0; }

.bubble {
  border-radius: 18px; padding: 10px 14px; font-size: 15px; line-height: 1.4;
  overflow-wrap: anywhere; white-space: pre-wrap;
}
.from-ceo .bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.from-cos .bubble { background: var(--cos); color: var(--cos-ink); border-bottom-left-radius: 4px; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble a { color: inherit; text-decoration: underline; }
.bubble strong { font-weight: 700; }

.msg-time {
  font: 500 11px var(--font-ui); color: var(--ink-3); margin-top: 4px; padding: 0 2px;
}
.msg-row.from-ceo .msg-time { text-align: right; }

.msg-status { display: flex; align-items: center; gap: 6px; margin-top: 3px; padding: 0 2px; }
.msg-status .tick { color: var(--pass); font-size: 12px; line-height: 1; }
.msg-status .queued { color: var(--ink-2); font: 600 11px var(--font-ui); letter-spacing: .02em; }
.msg-status .sending { color: var(--ink-3); font: 500 11px var(--font-ui); }
.msg-status .retry-link {
  border: 0; background: transparent; color: var(--fail); font: 600 13px var(--font-ui); padding: 0; cursor: pointer;
}
.msg-row.failed .bubble { border: 1.5px solid var(--fail); }

/* working bubble */
.working-bubble .bubble { background: color-mix(in srgb, var(--cos) 60%, transparent); }
.working-head { display: flex; align-items: center; gap: 8px; }
/* Stop (M-R12): quiet outline pill inside the working bubble; 44px tap target via hit-slop. */
.stop-btn {
  position: relative; margin-left: 12px; flex: none;
  border: 1px solid var(--fail); background: transparent; color: var(--ink);
  border-radius: 999px; padding: 3px 12px; font: 600 12px var(--font-ui); cursor: pointer;
}
.stop-btn::before { content: ""; position: absolute; inset: -10px -8px; } /* hit-slop to >=44px */
.stop-btn:hover { background: var(--hover); }
.stop-btn:disabled { opacity: .6; cursor: default; }
.working-label { font: 600 13px var(--font-ui); color: var(--ink-2); }
.dots { display: inline-flex; gap: 3px; }
.dots i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--ink-2);
  animation: pulse 1.4s var(--ease) infinite;
}
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes pulse { 0%, 60%, 100% { opacity: .25; transform: scale(.8); } 30% { opacity: 1; transform: scale(1); } }
.progress-lines { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.progress-line { display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: var(--ink); animation: line-in .3s var(--ease); }
.progress-line time { font: 500 11px var(--font-ui); color: var(--ink-3); flex: none; }
@keyframes line-in { from { opacity: 0; transform: translateY(-4px); } }

/* approval card */
.approval-card {
  align-self: stretch; max-width: 100%; width: 100%;
  background: var(--surface); border-left: 2px solid var(--warn); border-radius: 14px;
  padding: 16px; margin: 4px 0;
}
.approval-eyebrow { font: 700 11px var(--font-ui); text-transform: uppercase; letter-spacing: .08em; color: var(--warn-ink); margin: 0 0 8px; }
.approval-text { margin: 0 0 14px; font-size: 15px; line-height: 1.45; }
.approval-details {
  margin: 0 0 14px; font: 500 12px/1.5 ui-monospace, "SF Mono", Menlo, monospace; color: var(--ink-2);
  background: var(--hover); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere;
}
.approval-actions { display: flex; gap: 8px; }
.approval-actions button {
  flex: 1 1 0; height: 44px; border-radius: 12px; font: 600 14px var(--font-ui); cursor: pointer;
}
.btn-allow { border: 0; background: var(--pass-strong); color: #fff; }
.btn-deny { border: 1px solid var(--fail); background: var(--surface); color: var(--fail); }
.approval-actions button:disabled { opacity: .55; cursor: default; }
.approval-receipt { font: 500 13px var(--font-ui); color: var(--ink-3); padding: 4px 2px; }
.approval-receipt.allowed::before { content: "\2713  "; color: var(--pass); }
.approval-receipt.denied::before { content: "\2715  "; color: var(--fail); }
.approval-receipt.expired::before { content: "\231B  "; color: var(--warn); }

/* system notices (login expiring / usage limit / unknown command) */
.notice-row { align-self: center; max-width: 92%; }
.notice-row .bubble {
  background: transparent; border: 1px dashed var(--line); color: var(--ink-2);
  font-size: 13px; text-align: center; border-radius: 12px;
}
.notice-row.tone-warn .bubble { border-color: var(--warn); color: #6E4700; }
.notice-actions { margin-top: 6px; }
.resend-link {
  position: relative; border: 0; background: transparent; padding: 0; cursor: pointer;
  color: var(--accent); font: 600 13px var(--font-ui); text-decoration: underline; text-underline-offset: 2px;
}
.resend-link::before { content: ""; position: absolute; inset: -14px -10px; } /* hit-slop to >=44px */
.resend-link:disabled { color: var(--ink-3); text-decoration: none; cursor: default; }
.bubble code { font: 500 .9em ui-monospace, "SF Mono", Menlo, monospace; background: var(--hover); border-radius: 5px; padding: 1px 4px; }
.bubble .code-block {
  margin: 4px 0 8px; font: 500 12px/1.5 ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--hover); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; overflow-wrap: anywhere;
}
:root[data-theme="dark"] .notice-row.tone-warn .bubble { color: #F7C979; }

.empty-state { margin: auto; text-align: center; color: var(--ink-3); padding: 32px; font-size: 14px; }

/* command chip row */
.chip-row-wrap { flex: none; }
.chip-row {
  height: var(--chip-row-h); display: flex; align-items: center; gap: 8px;
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-left));
  overflow-x: auto; scrollbar-width: none; white-space: nowrap;
}
.chip-row::-webkit-scrollbar { display: none; }
.cmd-chip {
  flex: none; border: 1px solid var(--ink-3); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font: 600 13px var(--font-ui); cursor: pointer; color: var(--ink);
  /* no colour transition: a theme switch must never show a half-faded (washed-out) chip */
  transition: transform .1s var(--ease);
  position: relative;
}
.cmd-chip::before { content: ""; position: absolute; inset: -4px 0; } /* 40px row -> 44px tap target */
/* Both themes: --line is too transparent for a visible chip outline (was 1.2:1 light,
   1.2:1 dark against --bg). --ink-3 gives 5.17:1 light / 5.3:1 dark (WCAG 1.4.11 needs
   3:1); label ink stays 14:1+ both themes. */
.cmd-chip:hover { background: var(--hover); }
.cmd-chip:active { transform: scale(.97); }

/* input bar */
.input-bar {
  flex: none; min-height: var(--input-min-h);
  padding: 8px max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex; align-items: flex-end; gap: 8px;
  border-top: 1px solid var(--line);
}
.compose {
  flex: 1 1 auto; min-height: 40px; max-height: 120px; overflow-y: auto;
  border-radius: 18px; border: 1px solid var(--line); background: var(--surface);
  padding: 10px 14px; font-size: 15px; line-height: 1.35; resize: none; color: var(--ink);
}
.compose:focus-visible { outline-offset: 0; }
.send-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent);
  color: var(--accent-ink); cursor: pointer; display: grid; place-items: center;
  transition: filter .15s var(--ease), transform .1s var(--ease);
}
.send-btn:hover { filter: brightness(1.06); }
.send-btn:active { transform: scale(.95); }
.send-btn:disabled { opacity: .45; cursor: default; }
.send-btn svg { width: 18px; height: 18px; }

/* City tab placeholder */
.city-placeholder {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center; padding: 24px;
}
.city-placeholder[hidden] { display: none; }
.city-placeholder .brand-mark { width: 40px; height: 40px; opacity: .5; }
.city-placeholder h2 { font: 600 17px var(--font-ui); margin: 0; }
.city-placeholder p { color: var(--ink-2); font-size: 14px; margin: 0; max-width: 32ch; }
.city-placeholder button {
  margin-top: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 10px 18px; font: 600 13px var(--font-ui); cursor: pointer;
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--input-min-h) + var(--chip-row-h) + 24px);
  transform: translateX(-50%); z-index: 50; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 10px 18px; font: 600 13px var(--font-ui); box-shadow: 0 8px 24px rgba(20,20,30,.18);
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.toast[hidden] { display: none; opacity: 0; }

/* keyboard-open (visualViewport shrink applied via JS setting --kb-inset) */
.chat-app[data-kb-open="true"] .message-list { scroll-padding-bottom: 12px; }

/* laptop layout: same column, centred, generous side space (no dashboard chrome) */
@media (min-width: 720px) {
  .chat-app { align-items: center; }
  .chat-header, .status-banner, .message-list, .chip-row-wrap, .input-bar { width: 100%; max-width: 640px; }
  .chat-header { padding-left: 20px; padding-right: 16px; }
  .message-list { padding-left: 20px; padding-right: 20px; }
  .chip-row { padding-left: 20px; padding-right: 20px; }
  .input-bar { padding-left: 20px; padding-right: 16px; }
}

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