:root {
  color-scheme: dark;
  --accent: #f56565;
  --carbon: #101514;
  --panel: #171d1c;
  --panel-strong: #202826;
  --line: #34403d;
  --ivory: #f4efe5;
  --muted: #aab4b0;
  --danger: #ff8c73;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--carbon);
  color: var(--ivory);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--carbon); }
button, input, select, textarea { font: inherit; }
button, input, select, textarea { border: 1px solid var(--line); border-radius: 8px; }
button { min-height: 42px; padding: 0 14px; background: var(--panel-strong); color: var(--ivory); cursor: pointer; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.46; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary { border-color: var(--accent); background: var(--accent); color: #101514; font-weight: 800; }

.skip-link { position: fixed; left: 12px; top: -80px; z-index: 10; padding: 10px 14px; background: var(--ivory); color: var(--carbon); }
.skip-link:focus { top: 12px; }
.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; }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: 0.13em; }
.quiet { color: var(--muted); font-size: 13px; line-height: 1.5; }

header { position: sticky; top: 0; z-index: 4; min-height: 64px; padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left)); display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--carbon) 94%, transparent); backdrop-filter: blur(14px); }
.brand { display: inline-flex; align-items: center; }
.brand img { display: block; max-width: 132px; height: auto; }
.brand-light { display: none !important; }
#connection-status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
#connection-status::before { width: 8px; height: 8px; border-radius: 50%; background: #d0a33c; content: ""; }
#connection-status[data-state="online"]::before { background: #52c58a; }
#connection-status[data-state="offline"]::before { background: var(--danger); }
.panic { border-color: #75473d; color: var(--danger); font-weight: 800; }

main { min-height: calc(100vh - 118px); }
.setup { min-height: calc(100vh - 118px); display: grid; place-items: center; padding: 32px 18px; }
.setup-card { width: min(100%, 520px); padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.setup-card h1 { margin: 0; font-size: clamp(30px, 8vw, 46px); line-height: 1.02; }
.setup-card p { line-height: 1.6; }
.setup-card dl, .approval dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.setup-card dt, .approval dt { color: var(--muted); }
.setup-card dd, .approval dd { margin: 0; overflow-wrap: anywhere; }
.setup-card form, .new-session { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
input, select, textarea { width: 100%; padding: 11px 12px; background: var(--carbon); color: var(--ivory); }

.shell { display: grid; grid-template-columns: minmax(270px, 360px) 1fr; min-height: calc(100vh - 118px); }
.session-pane { border-right: 1px solid var(--line); background: var(--panel); }
.signal-count { display: inline-grid; min-width: 20px; height: 20px; place-items: center; margin-left: 5px; padding: 0 5px; border-radius: 999px; background: #f2c14e; color: #101514; font-size: 11px; font-weight: 900; }
.pane-heading, .detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px; border-bottom: 1px solid var(--line); }
.pane-heading h1, .detail-heading h2 { margin: 0; font-size: 20px; }
.pane-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.attention { border-color: #8b6b27; background: #302815; color: #f2c14e; font-weight: 800; }
.usage-strip { display: grid; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.usage-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 10px; font-size: 12px; }
.usage-row .usage-name { font-weight: 700; }
/* One row per window the service described, so several bars line up under one service name. */
.usage-row .usage-meter-row { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, auto) minmax(40px, 1fr) auto; align-items: center; gap: 8px; }
.usage-row .usage-meter-label { max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.usage-row .usage-meter-percent { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.usage-row .usage-meter { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.usage-row .usage-meter > span { display: block; height: 100%; background: var(--accent); }
.usage-row .usage-meter.reached > span { background: var(--danger); }
.usage-row .usage-detail { color: var(--muted); font-size: 11px; white-space: nowrap; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.state-dot.hot, .state-dot.running { background: #52c58a; }
.state-dot.needs-you { background: #f2c14e; box-shadow: 0 0 0 3px color-mix(in srgb, #f2c14e 22%, transparent); }
.state-dot.quota { background: #83908c; }
.state-dot.blocked, .state-dot.failed { background: var(--danger); }
.state-dot.paused, .state-dot.integrating { background: #d0a33c; }
.new-session { margin: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; }
.new-session h2 { margin: 0; font-size: 15px; }
.new-session p { margin: 0; }

.session-detail { min-width: 0; display: grid; grid-template-rows: auto minmax(280px, 1fr); }
/* One pane for the note and the screen, so a hidden note never leaves an empty grid track behind. */
.terminal-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.terminal { flex: 1 1 auto; min-height: 0; min-width: 0; padding: 6px; background: #000; overscroll-behavior: contain; }
.terminal .xterm { height: 100%; }
.terminal-note { padding: 10px 18px; color: var(--muted); border-bottom: 1px solid var(--line); }
.path { max-width: 70vw; margin: 6px 0 0; color: var(--muted); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
.detail-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.back { display: none; }
.output { min-height: 0; overflow: auto; padding: 18px; overscroll-behavior: contain; }
.event { width: fit-content; max-width: min(780px, 92%); margin: 0 0 12px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px; white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; line-height: 1.55; }
.event.mine { margin-left: auto; border-color: #78513e; background: #2d211d; }
.event.theirs { background: var(--panel); }
.event.thought, .event.meta { color: var(--muted); }
.event.warning { color: var(--danger); }
.approval { width: min(780px, 100%); padding: 16px; border-color: #7b5b2d; background: #211d16; font-family: inherit; }
.approval.high { border-color: #8b493a; }
.approval pre { max-height: 42vh; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--carbon); color: var(--ivory); white-space: pre-wrap; overflow-wrap: anywhere; }
.approval-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.composer { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { min-height: 52px; max-height: 180px; resize: vertical; }

footer { min-height: 54px; padding: 8px max(14px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
footer button { min-height: 36px; font-size: 11px; }
.footer-actions { display: flex; align-items: center; gap: 8px; }

@media (max-width: 760px) {
  header { grid-template-columns: 1fr auto; }
  #connection-status { grid-column: 1 / -1; grid-row: 2; }
  .shell { display: block; }
  .session-pane { border-right: 0; }
  .session-detail:not([hidden]) { position: fixed; inset: 0; z-index: 5; background: var(--carbon); padding-top: env(safe-area-inset-top); }
  .detail-heading { padding-top: 14px; flex-wrap: wrap; row-gap: 10px; }
  /* A phone is too narrow for a title beside its buttons: the title takes the row, the buttons the next one. */
  .detail-heading > div:first-of-type { flex-basis: 100%; }
  .detail-heading .detail-actions { justify-content: flex-start; }
  /* The fixed detail is the screen; a definite height is what lets the terminal row reach the bottom. */
  .session-detail:not([hidden]) { height: 100dvh; grid-template-rows: auto minmax(0, 1fr); }
  .pane-heading { align-items: center; }
  .pane-actions { max-width: 56%; }
  .back { display: inline-flex; align-items: center; min-height: 34px; padding: 0 9px; color: var(--accent); }
  .path { max-width: 88vw; }
}

@media (prefers-color-scheme: light) {
  :root { color-scheme: light; --carbon: #f4efe5; --panel: #fffaf0; --panel-strong: #ece5d9; --line: #cbc4b8; --ivory: #18201e; --muted: #65706d; --danger: #a93119; }
  .brand-dark { display: none !important; }
  .brand-light { display: block !important; }
  .event.mine { background: #f4d9cb; }
  .approval { background: #fff3d9; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
