/* ApertureLab Studio: dark neutral theme, high contrast. No external fonts.
   Mobile-first (audit 2026-09-05): the base layout is one pane at a time
   under a tab strip (Chat | Preview | Result | YAML | Jobs | Models); at
   >= 900px it becomes the two-column desktop layout with the strip above
   the right column. */

:root {
  color-scheme: dark;
  --bg: #15171b;
  --bg-panel: #1c1f25;
  --bg-raised: #23272f;
  --bg-input: #0f1114;
  --border: #30353f;
  --text: #e8eaed;
  --text-dim: #9aa1ad;
  --text-faint: #6b7280;
  --accent: #6cb4ff;
  --accent-dim: #2b4a6d;
  --user: #2a3b52;
  --ok: #57c48a;
  --warn: #e0b153;
  --err: #ff6b6b;
  --err-bg: #3a1f22;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* fluid type: 15px on phones, 16px on wide screens; small text never
     drops below 12px */
  --fs-body: clamp(15px, 0.9rem + 0.25vw, 16px);
  --fs-small: clamp(12px, 0.78rem + 0.15vw, 13.5px);
  --fs-tiny: clamp(12px, 0.72rem + 0.15vw, 12.5px);
  --pad-x: clamp(0.8rem, 2.5vw, 1.1rem);
  --tap: 44px;
  --t-fast: 100ms;
  --t-std: 200ms;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-body)/1.45 var(--sans);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;          /* the real viewport under a collapsing address bar */
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }

.mono, pre, code, textarea { font-family: var(--mono); }

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

img { max-width: 100%; display: block; }

[hidden] { display: none !important; }

button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- header --------------------------------------------------------------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 1rem;
  padding: 0.55rem var(--pad-x);
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.brand { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; min-width: 0; }
.brand h1 { margin: 0; font-size: 1.15rem; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap; }
.subtitle { margin: 0; color: var(--text-dim); font-size: var(--fs-small); }

.session {
  display: flex; align-items: center; gap: 0.45rem;
  color: var(--text-dim); font-size: var(--fs-small); white-space: nowrap; min-width: 0;
}
.session code { color: var(--text); font-size: var(--fs-small); }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--err); display: inline-block; flex: none; }
.conn.on { background: var(--ok); }

/* The subtitle and the "session" label are decoration on a phone; the id
   and the button are the content. */
.subtitle, .session-label { display: none; }

/* ---- panes (mobile-first: one pane under the tab strip) ------------------ */

.columns {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "tabs" "pane";
}

.tabs { grid-area: tabs; }
.chat, .panel {
  grid-area: pane;
  min-width: 0;            /* never widen the page (the Jobs tab used to) */
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* one pane at a time */
.columns[data-pane="chat"] .panel { display: none; }
.columns:not([data-pane="chat"]) .chat { display: none; }

/* ---- chat ----------------------------------------------------------------- */

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1rem var(--pad-x);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.msg {
  max-width: 88%;
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg.user {
  align-self: flex-end;
  background: var(--user);
  border-bottom-right-radius: 3px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bg-raised);
  border-bottom-left-radius: 3px;
}

.line { font-size: var(--fs-small); padding: 0 0.2rem; }
.line.status { color: var(--text-dim); }
.line.meta { color: var(--text-faint); font-size: var(--fs-tiny); }
.line.error { color: var(--err); }

.chip {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-panel);
  font-size: var(--fs-small);
  color: var(--text-dim);
  cursor: default;
}
.chip-name { font-family: var(--mono); color: var(--text); }

.tool-result {
  align-self: stretch;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-panel);
  font-size: var(--fs-small);
}
.tool-result summary {
  padding: 0.5rem 0.6rem;
  min-height: var(--tap);
  display: flex; align-items: center;
  cursor: pointer;
  color: var(--text-dim);
  font-family: var(--mono);
  user-select: none;
}
.tool-result[open] summary { border-bottom: 1px solid var(--border); }
.tool-result pre { padding: 0.5rem 0.6rem; max-height: 22rem; overflow: auto; color: var(--text); }
.tool-result.is-error { border-color: var(--err); background: var(--err-bg); }
.tool-result.is-error summary { color: var(--err); }

.chat-image {
  align-self: flex-start;
  margin: 0.2rem 0;
  max-width: 88%;
}
.chat-image img { border: 1px solid var(--border); border-radius: 6px; cursor: zoom-in; }
.chat-image figcaption { margin-top: 0.3rem; font-size: var(--fs-small); color: var(--text-dim); overflow-wrap: anywhere; }

.composer {
  display: flex;
  gap: 0.6rem;
  padding: 0.6rem var(--pad-x) 0.2rem;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  resize: vertical;
  min-height: 3.2rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;         /* < 16px makes iOS Safari zoom the page on focus */
  line-height: 1.4;
  transition: border-color var(--t-fast) ease-out;
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer textarea:disabled { opacity: 0.6; }

.composer button {
  align-self: flex-end;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  background: var(--accent-dim);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--t-fast) ease-out, transform var(--t-fast) ease-out;
}
.composer button:active:not(:disabled) { transform: scale(0.97); background: var(--accent); color: #0b0d10; }
.composer button:disabled { opacity: 0.5; cursor: progress; }

.hint {
  margin: 0;
  padding: 0.25rem var(--pad-x) calc(0.5rem + env(safe-area-inset-bottom));
  background: var(--bg-panel);
  color: var(--text-faint);
  font-size: var(--fs-tiny);
}

/* ---- tab strip ------------------------------------------------------------ */

.tabs {
  display: flex;
  gap: 0.2rem;
  padding: 0.4rem var(--pad-x) 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  overflow-x: auto;                 /* six tabs on a 360px phone */
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 1 0 auto;
  min-height: var(--tap);
  padding: 0.45rem 0.9rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--text-dim);
  font-size: var(--fs-small);
  cursor: pointer;
  scroll-snap-align: start;
  transition: color var(--t-fast) ease-out, background-color var(--t-fast) ease-out;
}
.tab:active { color: var(--text); background: var(--bg-raised); }
.tab:focus-visible { outline-offset: -2px; }
.tab.active {
  color: var(--text);
  background: var(--bg);
  border-color: var(--border);
  margin-bottom: -1px;
}

.tab-panel {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1rem var(--pad-x) calc(1rem + env(safe-area-inset-bottom));
}

.empty { color: var(--text-faint); margin: 0 0 1rem; }
.note { color: var(--text-faint); font-size: var(--fs-small); margin: 0.8rem 0 0; }
.section-title { margin: 1rem 0 0.4rem; font-size: var(--fs-small); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }

.figure { margin: 0; min-width: 0; }
.figure img { border: 1px solid var(--border); border-radius: 6px; background: #000; cursor: zoom-in; }
.figure figcaption { margin-top: 0.4rem; font-size: var(--fs-small); color: var(--text-dim); overflow-wrap: anywhere; }

.links { list-style: none; margin: 0; padding: 0; font-size: var(--fs-small); }
.links li { padding: 0.15rem 0; font-family: var(--mono); word-break: break-all; }
.links a { display: inline-block; min-height: calc(var(--tap) - 12px); padding: 6px 0; }

.toolbar { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.7rem; font-size: var(--fs-small); color: var(--text-dim); }
.toolbar select {
  min-height: var(--tap);
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--mono);
  font-size: 16px;
}

.code {
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  font-size: var(--fs-small);
  line-height: 1.5;
  tab-size: 2;
}

/* ---- jobs ----------------------------------------------------------------- */

.jobs { display: flex; flex-direction: column; gap: 0.8rem; min-width: 0; }

.job {
  min-width: 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  font-size: var(--fs-small);
  overflow-wrap: anywhere;
}

.job-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; }
.job-id { color: var(--text); word-break: break-all; }
.job-meta { color: var(--text-dim); margin: 0.2rem 0 0.5rem; min-height: 1em; }

.badge {
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: var(--fs-tiny);
  letter-spacing: 0.04em;
  color: var(--text-dim);
  white-space: nowrap;
}
.badge.state-running { color: var(--accent); border-color: var(--accent); }
.badge.state-done { color: var(--ok); border-color: var(--ok); }
.badge.state-failed, .badge.state-error, .badge.state-cancelled { color: var(--err); border-color: var(--err); }
.badge.state-queued, .badge.state-pending { color: var(--warn); border-color: var(--warn); }

.progress {
  height: 7px;
  border-radius: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease-out; }
.progress.indeterminate .bar {
  width: 30%;
  animation: slide 1.4s ease-in-out infinite;
}
@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

.job .job-error { margin: 0.3rem 0; white-space: pre-wrap; }
.job .links { margin: 0.3rem 0; }

.job-log summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; color: var(--text-dim); user-select: none; }
.job-log pre {
  margin-top: 0.4rem;
  padding: 0.5rem 0.6rem;
  max-height: 16rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  font-size: var(--fs-tiny);
  color: var(--text-dim);
}

/* ---- working indicators --------------------------------------------------- */

.msg.assistant.working {
  display: inline-flex; gap: 10px; align-items: center;
  padding: 0.55rem 0.9rem; color: var(--text-dim); font-size: var(--fs-small);
}
.work-label { font-family: var(--mono); }

/* glyph 4: chirp bars (LLM / tool activity) */
.glyph-chirp { display: inline-flex; gap: 3px; align-items: center; height: 16px; }
.glyph-chirp i { width: 3px; height: 100%; background: var(--accent); border-radius: 2px;
  transform-origin: center; animation: studio-bar 1.1s infinite ease-in-out; }
.glyph-chirp i:nth-child(2) { animation-delay: .12s } .glyph-chirp i:nth-child(3) { animation-delay: .24s }
.glyph-chirp i:nth-child(4) { animation-delay: .36s } .glyph-chirp i:nth-child(5) { animation-delay: .48s }
.glyph-chirp i:nth-child(6) { animation-delay: .6s }
@keyframes studio-bar { 0%, 100% { transform: scaleY(.25); opacity: .5 } 50% { transform: scaleY(1); opacity: 1 } }

/* glyph 3: sonar sweep (simulation running) */
.glyph-sweep { display: inline-block; width: 20px; height: 20px; border-radius: 50%; position: relative;
  overflow: hidden; border: 1.5px solid #3a4150; flex: none;
  background: radial-gradient(circle, #1f2a38 0 40%, transparent 41%); vertical-align: middle; }
.glyph-sweep::before { content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(108,180,255,.85) 0deg, rgba(108,180,255,.25) 40deg, transparent 70deg);
  animation: studio-spin 1.6s linear infinite; }
.glyph-sweep::after { content: ""; position: absolute; left: 50%; top: 50%; width: 3px; height: 3px;
  margin: -1.5px; border-radius: 50%; background: var(--accent); }
@keyframes studio-spin { to { transform: rotate(360deg) } }
.job-head .glyph-sweep { margin-right: 6px; }

/* ---- models gallery ------------------------------------------------------- */

.models-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 10px; }
.model-card { min-height: var(--tap); background: var(--bg-raised); border: 1px solid #2c313a; border-radius: 8px; padding: 6px; color: var(--text);
  cursor: pointer; text-align: left; transition: border-color var(--t-fast) ease-out, transform var(--t-fast) ease-out; }
.model-card:active { transform: scale(0.98); border-color: var(--accent); }
.model-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 5px; background: #14171c; display: block; }
.model-name { font-family: var(--mono); font-size: var(--fs-small); margin-top: 6px; }
.model-dims { color: var(--text-dim); font-size: var(--fs-tiny); }
#model-view img { max-width: 100%; border-radius: 8px; }

.btn-secondary { margin-left: 0.6rem; min-height: var(--tap); background: transparent; color: var(--text); border: 1px solid #3a4150; border-radius: 6px;
  padding: 0.3rem 0.8rem; font-size: var(--fs-small); cursor: pointer; white-space: nowrap;
  transition: border-color var(--t-fast) ease-out, color var(--t-fast) ease-out; }
.btn-secondary:active { border-color: var(--accent); color: var(--accent); }
.btn-secondary:disabled { opacity: 0.5; cursor: default; }

.work-elapsed { color: var(--text-faint); font-family: var(--mono); font-size: var(--fs-tiny); min-width: 2.5em; }

.msg.assistant.partial { opacity: 0.85; }

/* Inline link with a 44 px hit area: the padding expands the target and
   the negative margin keeps the caption's layout exactly where it was. */
.raw-link { color: var(--accent); font-size: var(--fs-small); text-decoration: none;
  display: inline-block; padding: 14px 6px; margin: -14px -6px; }

/* ---- lightbox ------------------------------------------------------------- */

.lightbox {
  border: none; padding: 0; margin: 0;
  width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none;
  background: #000; color: var(--text);
  touch-action: pinch-zoom;         /* native pinch on the image */
}
.lightbox::backdrop { background: #000; }
.lightbox img {
  width: 100%; height: 100%; object-fit: contain; cursor: zoom-out;
}
.lightbox-close {
  position: fixed; top: calc(0.5rem + env(safe-area-inset-top)); right: calc(0.5rem + env(safe-area-inset-right));
  width: var(--tap); height: var(--tap); border-radius: 50%;
  border: 1px solid var(--border); background: rgba(20, 22, 27, 0.8); color: var(--text);
  font-size: 1.4rem; line-height: 1; cursor: pointer;
}

/* ---- hover: only where a pointer can hover ------------------------------- */

@media (hover: hover) {
  a:hover { text-decoration: underline; }
  .tab:hover { color: var(--text); }
  .composer button:hover:not(:disabled) { background: var(--accent); color: #0b0d10; }
  .model-card:hover { border-color: var(--accent); }
  .btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
  .raw-link:hover { text-decoration: underline; }
}

/* ---- touch: bigger targets, no keyboard-only affordances ----------------- */

@media (pointer: coarse) {
  .tab, .composer button, .btn-secondary, .model-card, .toolbar select, .lightbox-close { min-height: 44px; }
  .composer textarea, .toolbar select { font-size: 16px; }
  .hint { display: none; }          /* "Shift+Enter" means nothing on a phone */
}

/* ---- wide screens: two columns, tab strip above the right column --------- */

@media (min-width: 900px) {
  .subtitle, .session-label { display: block; }
  .session-label { display: inline; }
  .columns {
    grid-template-columns: minmax(340px, 1fr) minmax(340px, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "chat tabs" "chat panel";
  }
  .chat { grid-area: chat; border-right: 1px solid var(--border); }
  .panel { grid-area: panel; }
  /* both panes always visible; the Chat tab is a phone-only control */
  .columns[data-pane="chat"] .panel { display: flex; }
  .columns:not([data-pane="chat"]) .chat { display: flex; }
  .tab-chat { display: none; }
  .tabs { overflow-x: visible; padding-top: 0.5rem; }
  .tab { flex: 0 0 auto; min-height: 0; }
}

/* ---- motion preferences --------------------------------------------------- */

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

/* ---- 'Last updated' strip under the header (2026-09-08) -------------------
   Its own full-width row between the header and the panes, so the text
   flows across the page instead of stacking beside the title. */
.whats-new {
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: 0.35rem var(--pad-x);
  font-size: 0.78rem; line-height: 1.35; color: var(--text-dim);
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
}
.whats-new-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.whats-new-text b { color: var(--text); font-weight: 600; }
.whats-new-close {
  flex: none; margin: -0.2rem -0.3rem 0 0; padding: 0 0.4rem;
  background: none; border: 0; color: var(--text-dim); font-size: 1.05rem; line-height: 1.4;
  cursor: pointer; border-radius: 4px;
}
.whats-new-close:hover, .whats-new-close:focus-visible { color: var(--text); background: var(--bg); outline: none; }
