/*
 * Zeron web client styling.
 *
 * iPad/Safari rules baked in here (not in the markup, so they cannot be
 * forgotten when a new control is added):
 *
 * - `env(safe-area-inset-*)` on the shell so the composer clears the home
 *   indicator and the header clears the status bar in standalone/fullscreen.
 * - `-webkit-text-size-adjust: 100%` stops Safari from inflating text in
 *   landscape; every input is ≥16px so focusing it never zooms the viewport.
 * - `touch-action: manipulation` kills the double-tap zoom delay on buttons.
 * - `:active`, never `:hover`, for feedback — a touch device leaves `:hover`
 *   stuck on the last-tapped element.
 * - `overscroll-behavior: contain` on the scrolling panes so a scroll at the
 *   end of the transcript does not rubber-band the whole page.
 * - `dvh` units so the composer tracks the collapsing Safari toolbar.
 * - `prefers-reduced-motion` honored for the one animation there is.
 * - Light and dark via `prefers-color-scheme`, plus an explicit
 *   `color-scheme` so form controls match.
 */

:root {
  /* T3 Code's light palette, verbatim (packages/shared/src/themePalettes.ts).
     Light only, deliberately: this is used on an iPad in a bright room and a
     dark theme that follows the system was doing the user no favours. */
  color-scheme: light;
  --bg: #fcfcfc;              /* canvas */
  --bg-raised: #ffffff;       /* surface */
  --bg-sunken: #fafafa;       /* sidebar / muted */
  --surface-hover: #f4f4f5;   /* accentSurface */
  --border: #e4e4e7;
  --input: #d4d4d8;
  --placeholder: #71717b;
  --sidebar-row-hover: #fcfcfc;
  --text: #27272a;
  --text-muted: #71717b;
  --accent: #1b4ed8;
  --accent-hover: #3160db;
  --accent-text: #ffffff;
  --accent-surface: #f4f4f5;
  --danger: #fb2c36;
  --danger-text: #c10007;
  --danger-surface: #fcebec;
  --warn: #fe9a00;
  --warn-text: #bb4d00;
  --warn-surface: #fcf4e8;
  --ok: #16a34a;
  --message-surface: #f4f4f5;
  --message-text: #27272a;
  --code-bg: #ffffff;
  --code-text: #27272a;
  --radius: 8px;
  --radius-lg: 12px;
  --tap: 44px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

/* `hidden` must win over any layout rule below. Without this, an element with a
   `display` declaration in the stylesheet stays visible when `hidden` is set. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#app {
  min-height: 100dvh;
}

/* ---------------------------------------------------------------- shell -- */

/* Flex, not `grid-template-rows: auto auto 1fr`: the banner is present in the
   DOM but hidden most of the time, and a fixed three-row template would leave
   the empty `1fr` row occupying half the viewport. Flex only sizes children
   that are actually displayed. */
.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.shell__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--tap);
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.shell__brand {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.shell__spacer,
.composer__spacer {
  flex: 1 1 auto;
}

.shell__status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: lowercase;
}
/* A small filled dot reads faster than a coloured pill and does not compete
   with the transcript for attention. */
.shell__status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}
.shell__status--online {
  color: var(--ok);
}
.shell__status--idle {
  color: var(--text-muted);
}
.shell__status--host_offline,
.shell__status--reconnecting {
  color: var(--warn);
}
.shell__status--unauthorized,
.shell__status--closed {
  color: var(--danger);
}

.shell__device {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 13px;
  color: var(--text-muted);
}

.shell__select {
  min-height: 36px;
  font-size: 16px; /* ≥16px: below this iOS zooms on focus */
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  max-width: 46vw;
}

.shell__banner {
  flex: 0 0 auto;
  padding: 0.55rem 0.75rem;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.shell__banner--info {
  background: color-mix(in srgb, var(--warn) 14%, var(--bg));
}
.shell__banner--error {
  background: color-mix(in srgb, var(--danger) 14%, var(--bg));
}

.shell__body {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  min-height: 0;
}

/* Split view / narrow iPad: one pane at a time, driven by .shell--chat. */
@media (max-width: 900px) {
  .shell__body {
    grid-template-columns: 1fr;
  }
  .shell--chat .sidebar {
    display: none;
  }
  .shell:not(.shell--chat) .pane {
    display: none;
  }
}

/* -------------------------------------------------------------- sidebar -- */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-sunken);
}

.sidebar__top {
  flex: 0 0 auto;
  padding: 0.5rem;
}

.sidebar__search {
  width: 100%;
  min-height: 38px;
  font-size: 16px;
  padding: 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
}
.sidebar__search::placeholder {
  color: var(--placeholder);
}

.sidebar__list {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 0.4rem 0.6rem;
}

.row {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 0.5rem 0.6rem;
  margin: 0 0 0.1rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.row:active {
  background: var(--sidebar-row-hover);
}
/* T3's selected row is a white card against the muted sidebar, not a tinted
   accent wash — quieter, and it leaves the accent for real actions. */
.row--active {
  background: var(--bg-raised);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.06);
}

.row__head {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.row__title {
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row__time,
.row__preview {
  color: var(--text-muted);
  font-size: 13px;
}

.row__meta {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.15rem;
}

.row__preview {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.dot--working {
  background: var(--accent);
}
.dot--awaitingInput {
  background: var(--warn);
}
.dot--errored {
  background: var(--danger);
}
.dot--completed {
  background: var(--ok);
}

/* ----------------------------------------------------------------- pane -- */

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.pane__bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--tap);
  padding: 0.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.pane__back {
  display: none;
  min-height: var(--tap);
  padding: 0 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  touch-action: manipulation;
}
@media (max-width: 900px) {
  .pane__back {
    display: inline-block;
  }
}

.pane__title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ----------------------------------------------------------- transcript -- */

.transcript {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 1.25rem 1rem 2rem;
  min-height: 0;
  background: var(--bg);
}

.entry {
  margin: 0 auto 1.75rem;
  max-width: 42rem;
}

/* T3 labels the speaker inline and quietly; the transcript is the content, not
   the chrome. */
.entry__head {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
}

.entry__role {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.entry__time {
  font-size: 11px;
  color: var(--text-muted);
}

/* The user's own words sit in a filled bubble (T3's `messageSurface`); the
   assistant's are plain prose on the canvas. That asymmetry is what makes a
   long transcript scannable. */
.entry--user .part--text {
  background: var(--message-surface);
  border-radius: var(--radius-lg);
  padding: 0.65rem 0.85rem;
}

.entry--assistant .part--text {
  font-size: 15px;
  line-height: 1.65;
}

.part {
  margin: 0 0 0.6rem;
}
.part:last-child {
  margin-bottom: 0;
}

.part--text p:first-child,
.part--text h1:first-child,
.part--text h2:first-child {
  margin-top: 0;
}

.part--text pre,
.tool__output {
  margin: 0.6rem 0;
  padding: 0.7rem 0.8rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-text);
  font: 12.5px/1.6 var(--mono);
}

.part--text code {
  font: 12.5px/1.5 var(--mono);
  background: var(--bg-sunken);
  padding: 0.1rem 0.32rem;
  border-radius: 5px;
}

.part--text pre code {
  background: none;
  padding: 0;
}

.part--text blockquote {
  margin: 0.5rem 0;
  padding-left: 0.7rem;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.part--text a {
  color: var(--accent);
}

/* Thinking and tool calls are a *work log*, not content: no box, no fill, just a
   quiet row with a chevron. Boxing each one turned a busy transcript into a
   wall of cards (and T3 does the same — flat rows on the canvas). */
.part--reasoning,
.part--tool {
  border-radius: var(--radius);
  background: transparent;
  padding: 0;
}

.part--reasoning > summary,
.part--tool > summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  min-height: 32px;
  padding: 0.1rem 0;
  font-size: 13px;
  color: var(--text-muted);
  touch-action: manipulation;
  list-style: none;
  user-select: none;
}
.part--reasoning > summary::-webkit-details-marker,
.part--tool > summary::-webkit-details-marker {
  display: none;
}
/* The chevron is the only affordance, and it rotates — on touch there is no
   hover to reveal that the row is expandable. */
.part--reasoning > summary::before,
.part--tool > summary::before {
  content: "›";
  flex: 0 0 auto;
  font-size: 15px;
  line-height: 1;
  transition: transform 120ms ease;
}
.part--reasoning[open] > summary::before,
.part--tool[open] > summary::before {
  transform: rotate(90deg);
}
.part--reasoning > summary:hover,
.part--tool > summary:hover {
  color: var(--text);
}

.part--tool > summary {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
}

/* The expanded body is indented under the row it belongs to. */
.part--reasoning > div,
.part--tool > pre,
.part--tool > ul,
.part--tool > p {
  margin-left: 1.05rem;
}

.tool__diff {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
  font: 12px/1.6 var(--mono);
  color: var(--text-muted);
}

.tool__tail {
  margin: 0.4rem 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.part--error {
  border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border));
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  background: var(--danger-surface);
  color: var(--danger-text);
  font-size: 13.5px;
}

.part--fork,
.part--image {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.streaming {
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink {
  to {
    visibility: hidden;
  }
}
@media (prefers-reduced-motion: reduce) {
  .streaming {
    animation: none;
  }
}

/* --------------------------------------------------------------- input -- */

.part--input {
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--warn) 10%, var(--bg));
  padding: 0.7rem 0.8rem;
}

.part--input-resolved {
  border-color: var(--border);
  background: var(--bg-raised);
}

.input__header {
  margin: 0 0 0.5rem;
  font-size: 14px;
}

.input__question {
  margin: 0.5rem 0 0.4rem;
  font-weight: 550;
}

.input__option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: var(--tap);
  padding: 0 0.2rem;
  cursor: pointer;
}

.input__option input {
  width: 22px;
  height: 22px;
}

.input__text {
  width: 100%;
  min-height: var(--tap);
  font-size: 16px;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}

.input__submit {
  margin-top: 0.6rem;
}

/* ------------------------------------------------------------ composer -- */

.composer {
  flex: 0 0 auto;
  display: grid;
  gap: 0.4rem;
  padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.composer__row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.composer__row--meta {
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
}

.composer__input {
  flex: 1 1 auto;
  min-height: var(--tap);
  max-height: 12rem;
  font: 16px/1.5 var(--font);
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--input);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  color: var(--text);
  resize: none;
}
.composer__input::placeholder {
  color: var(--placeholder);
}
/* T3's focus ring: the accent at low alpha rather than a hard outline. */
.composer__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.composer__toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: var(--tap);
  cursor: pointer;
}

.composer__toggle input {
  width: 20px;
  height: 20px;
}

.composer__hint {
  font-family: var(--mono);
  font-size: 12px;
}

.composer__send {
  min-width: 84px;
}
.composer__hint {
  color: var(--text-muted);
}
/* The queue is part of the composer, so it is indented and borderless — a
   nested box here read as a second composer. */
.composer__queue {
  display: block;
}

.queue {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.queue__item {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  background: var(--bg-sunken);
}

.queue__text {
  flex: 1 1 auto;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------------- buttons -- */

.button {
  min-height: 38px;
  min-width: 38px;
  padding: 0 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  font: 500 14px/1 var(--font);
  cursor: pointer;
  touch-action: manipulation;
}
/* Touch needs a full-size target even when the visual control is small: the
   Send/Remove buttons keep a 38px box but pad their own hit area. */
.button:active {
  background: var(--surface-hover);
}
.button[disabled] {
  opacity: 0.45;
}
.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.button--primary:active {
  background: var(--accent-hover);
}
.button--danger {
  color: var(--danger-text);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
  background: var(--danger-surface);
}
.button--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.button--ghost:active {
  background: var(--surface-hover);
  color: var(--text);
}

.empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* --------------------------------------------------------------- login -- */

.login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: calc(1.5rem + env(safe-area-inset-top)) 1.25rem
    calc(1.5rem + env(safe-area-inset-bottom));
}

.login__card {
  width: 100%;
  max-width: 24rem;
  display: grid;
  gap: 0.9rem;
  text-align: center;
}

.login__title {
  margin: 0;
  font-size: 1.35rem;
}

.login__body {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.login__field {
  display: grid;
  gap: 0.35rem;
  text-align: left;
}

.login__label {
  font-size: 13px;
  color: var(--text-muted);
}

.login__input {
  min-height: var(--tap);
  font-size: 16px;
  padding: 0 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}

.login__error {
  color: var(--danger);
  font-size: 14px;
  min-height: 1.4em;
}

.login__note {
  font-size: 12px;
  color: var(--text-muted);
}

/* The device-grant user code: the one thing the human has to read off this
   screen and type elsewhere, so it is large, spaced, and selectable. */
.login__code {
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  padding: 0.6rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  user-select: all;
}

.login__status {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 1.4em;
}

/* Stacked and full-width: on a tablet these are the only controls, and a
   thumb-sized target beats a tidy row. */
.login__actions {
  display: grid;
  gap: 0.5rem;
}
