:root {
  --bg: #0b0c0e;
  --s1: #121418;
  --s2: #181b20;
  --s3: #20242b;
  --text: #eceef1;
  --muted: #8b919b;
  --faint: #5b616b;
  --accent: #c8f04a;
  --accent-ink: #11160a;
  --danger: #ff6b5e;
  --warn: #f2b84b;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --top: env(safe-area-inset-top, 0px);
  --bot: env(safe-area-inset-bottom, 0px);
  --kb: 0px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; -webkit-font-smoothing: antialiased; position: fixed; inset: 0; overflow: hidden;
}
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
textarea, input { caret-color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
code, pre, .events, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.num, .usage, time { font-variant-numeric: tabular-nums; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; height: calc(100% - var(--kb)); }

/* header */
.top { padding: calc(var(--top) + 10px) 16px 0; background: var(--bg); flex: none; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.title { font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; transition: background .3s; }
.dot.on { background: var(--accent); }
.dot.busy { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.dot.warn { background: var(--warn); }
@keyframes pulse { 50% { opacity: .35; } }
.right { display: flex; align-items: center; gap: 4px; }
.usage { display: flex; gap: 10px; font-size: 12px; color: var(--muted); padding: 4px 4px; }
.usage b { color: var(--text); font-weight: 600; }
.usage .hot b { color: var(--warn); }
.usage .crit b { color: var(--danger); }
.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:active { background: var(--s2); }
.tabs { display: flex; gap: 4px; margin-top: 8px; padding: 3px; background: var(--s1); border-radius: 12px; }
.tabs button { flex: 1; border: 0; background: none; color: var(--muted); padding: 8px 0; border-radius: 9px; font-weight: 560; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.tabs button[aria-selected="true"] { background: var(--s3); color: var(--text); }
.badge { background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; border-radius: 9px; padding: 1px 6px; }

/* views */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.thread { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 8px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: auto; }
.msg { max-width: 86%; animation: arrive .5s var(--ease) both; }
@keyframes arrive { from { opacity: 0; transform: translateY(8px); } }
.msg.user { align-self: flex-end; background: var(--s3); padding: 9px 13px; border-radius: 18px 18px 6px 18px; }
.msg.assistant { align-self: flex-start; max-width: 94%; padding: 2px 2px; }
.msg.event { align-self: center; color: var(--muted); font-size: 13px; max-width: 92%; text-align: center; }
.msg .body { overflow-wrap: anywhere; white-space: pre-wrap; max-width: 68ch; }
.msg .body p { margin: 0 0 8px; } .msg .body p:last-child { margin-bottom: 0; }
.msg .body ul, .msg .body ol { margin: 4px 0 8px; padding-left: 20px; white-space: normal; }
.msg .body code { background: var(--s2); padding: 1px 5px; border-radius: 5px; font-size: .88em; }
.msg .body pre { background: var(--s1); padding: 10px 12px; border-radius: 12px; overflow-x: auto; font-size: 13px; line-height: 1.4; white-space: pre; margin: 6px 0; }
.msg .body pre code { background: none; padding: 0; }
.msg .body a { color: var(--accent); text-underline-offset: 3px; }
.msg time { display: block; font-size: 11px; color: var(--faint); margin-top: 3px; }
.msg.user time { text-align: right; }
.report { align-self: stretch; max-width: none; background: var(--s1); border-radius: 16px; padding: 12px 14px; }
.report .rt { font-weight: 620; margin-bottom: 4px; display: flex; gap: 8px; align-items: baseline; }
.report .rt span { font-size: 12px; color: var(--muted); font-weight: 500; }

.atts { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.file { display: flex; align-items: center; gap: 12px; background: var(--s2); border-radius: 14px; padding: 10px 12px; text-decoration: none; color: inherit; min-width: 0; }
.msg.user .file { background: var(--s2); }
.file:active { background: var(--s3); }
.file svg { flex: none; color: var(--muted); }
.file .fn { font-size: 14.5px; font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .fs { font-size: 12px; color: var(--muted); }
.file .grow { min-width: 0; flex: 1; }
.file .get { color: var(--accent); font-size: 13px; font-weight: 600; }
.thumb { display: block; border-radius: 14px; max-width: min(260px, 100%); max-height: 300px; object-fit: cover; background: var(--s2); }

.approval { align-self: stretch; max-width: none; background: var(--s2); border-radius: 16px; padding: 14px; }
.approval .at { font-weight: 640; }
.approval .ad { color: var(--muted); font-size: 14px; margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.approval .row { display: flex; gap: 8px; margin-top: 12px; }
.approval .done { margin-top: 10px; font-size: 13px; color: var(--muted); }

.typing { padding: 4px 18px 10px; display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; }
.typing span { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: pulse 1.2s ease-in-out infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
.typing em { font-style: normal; margin-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.notify-bar { margin: 10px 16px 0; background: var(--s2); border-radius: 14px; padding: 10px 12px; display: flex; gap: 12px; align-items: center; font-size: 13.5px; color: var(--muted); }
.notify-bar span { flex: 1; }

/* buttons */
.btn { border: 0; background: var(--s3); color: var(--text); padding: 12px 16px; border-radius: 13px; font-weight: 600; font-size: 15px; }
.btn:active { filter: brightness(1.2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: color-mix(in srgb, var(--danger) 18%, var(--s2)); color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .5; }
.approval .btn { flex: 1; }

/* composer */
.composer { flex: none; padding: 8px 12px calc(var(--bot) + 10px); background: var(--bg); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; background: var(--s1); border-radius: 24px; padding: 4px 4px 4px 2px; }
#input { flex: 1; background: none; border: 0; color: var(--text); font: inherit; font-size: 16px; resize: none; padding: 9px 4px; max-height: 140px; outline: none; line-height: 1.35; }
#input::placeholder { color: var(--faint); }
.send { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; margin-bottom: 1px; transition: opacity .2s, transform .2s var(--ease); }
.send[disabled] { opacity: .25; transform: scale(.9); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 4px; }
.chips:not(:empty) { padding-bottom: 8px; }
.chip { background: var(--s2); border-radius: 10px; padding: 5px 6px 5px 10px; font-size: 13px; display: flex; gap: 6px; align-items: center; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.chip button { background: none; border: 0; color: var(--muted); padding: 0 4px; font-size: 16px; line-height: 1; }
.chip.up { color: var(--muted); }

/* tasks */
.task-list { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
.task { background: var(--s1); border: 0; text-align: left; width: 100%; border-radius: 16px; padding: 13px 14px; display: flex; gap: 12px; align-items: center; }
.task:active { background: var(--s2); }
.task .t-main { flex: 1; min-width: 0; }
.task .t-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task .t-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 12px; font-weight: 640; padding: 3px 9px; border-radius: 999px; background: var(--s3); color: var(--muted); flex: none; }
.pill.running { background: color-mix(in srgb, var(--accent) 18%, var(--s2)); color: var(--accent); }
.pill.done { color: var(--text); }
.pill.failed { background: color-mix(in srgb, var(--danger) 16%, var(--s2)); color: var(--danger); }
.empty { color: var(--muted); text-align: center; padding: 48px 24px; font-size: 14.5px; }

.detail { position: absolute; inset: 0; background: var(--bg); z-index: 5; }
.detail-head { display: flex; align-items: center; gap: 8px; padding: calc(var(--top) + 8px) 12px 8px; }
.detail-title { flex: 1; min-width: 0; font-weight: 620; }
.detail-title > div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary { margin: 0 16px 8px; background: var(--s1); border-radius: 14px; padding: 12px 14px; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.events { flex: 1; overflow-y: auto; padding: 8px 16px calc(var(--bot) + 16px); font-size: 12.5px; line-height: 1.5; display: flex; flex-direction: column; gap: 6px; }
.ev { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
.ev.assistant { color: var(--text); }
.ev.tool { color: var(--faint); }
.ev.result { color: var(--accent); }
.ev.error { color: var(--danger); }
.ev time { color: var(--faint); margin-right: 8px; }

/* pairing + sheet */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; }
.pair-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.pair-card h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.pair-card p { margin: 0; color: var(--muted); font-size: 14.5px; }
.pair-card code { background: var(--s2); padding: 1px 6px; border-radius: 6px; color: var(--text); }
.pair-card input { background: var(--s1); border: 0; color: var(--text); font: 600 24px ui-monospace, Menlo, Consolas, monospace; letter-spacing: .18em; text-align: center; padding: 16px; border-radius: 14px; text-transform: uppercase; outline: none; }
.pair-card input:focus { box-shadow: 0 0 0 2px var(--accent); }
.err { color: var(--danger) !important; min-height: 1.4em; }
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; display: flex; align-items: flex-end; }
.sheet-body { width: 100%; background: var(--s1); border-radius: 22px 22px 0 0; padding: 20px 16px calc(var(--bot) + 16px); display: flex; flex-direction: column; gap: 10px; animation: arrive .4s var(--ease); box-shadow: 0 -12px 40px rgba(0,0,0,.45); }
.sheet-body h2 { margin: 0 0 2px; font-size: 18px; }
.sheet-info { color: var(--muted); font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; }

* { scrollbar-width: thin; scrollbar-color: var(--s3) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; } ::-webkit-scrollbar-thumb { background: var(--s3); border-radius: 3px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (min-width: 700px) { #app { max-width: 560px; margin: 0 auto; } }
