/* Personal agent — Graphite & Ember. Tokens mirror the hub. One flat ember accent. */

:root {
  --ember: #c2410c;
  --ember-2: #e2622e;
  --ember-rgb: 194, 65, 12;
  --font-heading: "Bricolage Grotesque", "Space Grotesk", system-ui, sans-serif;
  --font-body: "Hanken Grotesk", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --radius-sm: 6px;
  --radius: 10px;
  --fast: 0.16s cubic-bezier(0.4, 0, 0.2, 1);
  --topbar-h: 59px;
  --side-w: 360px;
}

:root, [data-theme="dark"] {
  --bg: #0e0e11;
  --surface: #141418;
  --surface-2: #1b1b20;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text: #c9c9c4;
  --text-strong: #e8e8e4;
  --muted: #8a8a85;
  --accent-text: #e2622e;
  --ok: #5aa877;
  --ok-soft: rgba(90, 168, 119, 0.12);
  --danger: #d0533f;
  --user-bg: #1b1b20;
  --agent-bg: rgba(194, 65, 12, 0.1);
}

[data-theme="light"] {
  --ember: #b23a0a;
  --ember-2: #c2410c;
  --ember-rgb: 178, 58, 10;
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f3f1eb;
  --border: rgba(23, 23, 26, 0.1);
  --border-strong: rgba(23, 23, 26, 0.2);
  --text: #3d3a34;
  --text-strong: #17171a;
  --muted: #6b675e;
  --accent-text: #b23a0a;
  --ok: #2f7d4f;
  --ok-soft: rgba(47, 125, 79, 0.1);
  --danger: #b43d2b;
  --user-bg: #f3f1eb;
  --agent-bg: rgba(178, 58, 10, 0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
h1, h2, h3 { font-family: var(--font-heading); color: var(--text-strong); letter-spacing: -0.02em; line-height: 1.15; }
a { color: var(--text-strong); text-decoration: none; }
a:hover { color: var(--accent-text); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
.icon { width: 18px; height: 18px; display: block; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45em;
  height: 34px; padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  color: var(--text-strong);
  font-weight: 600; font-size: 13px; white-space: nowrap;
}
.btn:hover { border-color: rgba(var(--ember-rgb), 0.6); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--ember); border-color: var(--ember); color: #fff; }
.btn-primary:hover { background: var(--ember-2); border-color: var(--ember-2); }
.btn-ghost { border-color: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-icon { width: 34px; padding: 0; }
.eyebrow { font: 600 11px/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); min-height: 1.2em; }
.hint[data-tone="error"] { color: var(--danger); }
.hint[data-tone="ok"] { color: var(--ok); }
.lede, .field-label { font-size: 13px; color: var(--muted); }
.field-label { display: block; margin: 8px 0 4px; }

.topbar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px;
  height: var(--topbar-h); padding: 0 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--accent-text); font: 600 13px/1 var(--font-body); }
.brand span { color: var(--text); }
.brand__mark { display: block; color: var(--accent-text); }
.topbar__title { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.topbar__title h1 { font-size: 20px; font-weight: 700; white-space: nowrap; }
.topbar__title p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__actions { display: flex; align-items: center; gap: 6px; }

.strip {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text);
  background: var(--surface);
}
.strip__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
#strip-text { flex: 1; }

.gate {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
#turnstile { flex: 1 1 auto; min-width: min(100%, 300px); max-width: 100%; }
#gate-hint { flex: 1 1 100%; }
#gate-hint:empty { display: none; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr var(--side-w);
  min-height: 0;
}
.chat, .side { min-width: 0; min-height: 0; }
.chat {
  display: flex; flex-direction: column;
  padding: 16px 20px 12px;
  gap: 12px;
}
.thread { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.messages { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.empty { margin: auto; color: var(--muted); font-size: 14px; max-width: 42ch; text-align: center; }
.message {
  max-width: 68ch;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.message[data-role="user"] { background: var(--user-bg); align-self: flex-end; }
.message[data-role="assistant"] { background: var(--agent-bg); align-self: flex-start; }
.message p { white-space: pre-wrap; color: var(--text-strong); overflow-wrap: anywhere; }
.recalls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.recall {
  font-family: var(--font-mono); font-size: 11px;
  border-radius: 999px; padding: 3px 8px;
  background: rgba(var(--ember-rgb), 0.12);
  color: var(--accent-text);
  border: 1px solid rgba(var(--ember-rgb), 0.35);
}
.composer, .note-form, #research-form { display: grid; gap: 8px; }
textarea, input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  resize: vertical;
}
.composer__row, .panel-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-actions .hint { flex: 1; min-width: 0; }

.side {
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow: auto;
  display: flex; flex-direction: column;
}
.panel { padding: 14px 14px 18px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.panel__head { display: flex; align-items: center; gap: 8px; }
.panel__head h2 { font-size: 16px; }
.count {
  font-family: var(--font-mono); font-size: 12px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; height: 22px;
  display: inline-flex; align-items: center;
}
.note-list { list-style: none; display: grid; gap: 4px; }
.note {
  width: 100%; text-align: left; padding: 8px 10px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  color: var(--text-strong); font-weight: 600; font-size: 14px;
}
.note:hover, .note.is-on { border-color: rgba(var(--ember-rgb), 0.6); background: var(--agent-bg); }
.viewer { display: grid; gap: 8px; }
.viewer__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.viewer h3 { font-size: 15px; }
.viewer pre {
  white-space: pre-wrap; font-family: var(--font-body); font-size: 14px;
  background: var(--bg); border-radius: var(--radius-sm); padding: 10px;
  border: 1px solid var(--border); color: var(--text);
  overflow-wrap: anywhere;
}
.report { display: grid; gap: 8px; }
#report-summary { white-space: pre-wrap; color: var(--text-strong); overflow-wrap: anywhere; }
#report-cites { list-style: none; display: grid; gap: 4px; font-size: 13px; }
#report-cites a { word-break: break-all; }
.cite-bad { color: var(--danger); overflow-wrap: anywhere; }

.foot {
  border-top: 1px solid var(--border);
  padding: 12px 20px 16px;
  font-size: 13px; color: var(--muted);
}

@media (min-width: 901px) {
  html, body { height: 100%; }
  body { height: 100dvh; overflow: hidden; }
  .layout { min-height: 0; overflow: hidden; }
  .side { overflow: auto; }
}

@media (max-width: 900px) {
  .topbar {
    position: static;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    height: auto;
    padding: 8px 14px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    gap: 8px;
  }
  .brand span { display: none; }
  .topbar__title { flex: 1; min-width: 0; }
  .topbar__title h1 { font-size: 16px; }
  .topbar__title p { display: none; }
  .topbar__actions { flex-shrink: 0; }
  .layout { grid-template-columns: 1fr; }
  .side { border-left: 0; border-top: 1px solid var(--border); }
  .chat { min-height: 70dvh; }
  .strip { flex-wrap: wrap; }
  .composer { position: static; padding-bottom: 0; }
  html { scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .message { scroll-margin-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .layout { order: 3; }
  .gate {
    order: 4;
    position: sticky;
    bottom: 0;
    z-index: 4;
    border-bottom: 0;
    border-top: 1px solid var(--border);
    padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  }
  .foot { order: 5; }
  .chat,
  .side { padding-bottom: 96px; }
}

/* Phone layout. Graphite and Ember stay; controls grow to a finger and fields stay at 16px so iOS does not zoom. */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
textarea,
select {
  font-size: 16px;
}
@media (max-width: 900px) {
  .btn,
  a.btn,
  .btn-primary,
  .btn-ghost,
  .note {
    min-height: 44px;
  }
  .btn-icon {
    min-width: 44px;
    width: 44px;
    height: 44px;
  }
  .topbar__actions { justify-content: flex-end; max-width: 100%; }
  .composer input { min-width: 0; max-width: 100%; }
}
@media (max-height: 520px) {
  .chat { min-height: 0; }
  .composer { position: static; }
  .layout { order: 4; }
  .gate { position: static; order: 3; }
  .chat,
  .side { padding-bottom: 12px; }
}

.shows {
  margin: 0 0 0.85rem;
  font-size: 0.875rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.shows--bar {
  margin: 0;
  padding: 0.7rem 1rem;
  background: rgba(194, 65, 12, 0.08);
  border-bottom: 1px solid rgba(194, 65, 12, 0.28);
}
.shows__k {
  margin-right: 0.45rem;
  font-family: "JetBrains Mono", ui-monospace, Menlo, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #c2410c;
}
