:root {
  --bg: #0b0d12;
  --bg2: #12151d;
  --card: #171b25;
  --card2: #1d222e;
  --line: #262c3a;
  --txt: #e7ebf3;
  --muted: #8a93a6;
  --accent: #7c6cff;
  --accent2: #9a8dff;
  --plan: #4aa3ff;
  --default: #36c98d;
  --accept: #f0b429;
  --bypass: #ff5d5d;
  --write: #f0b429;
  --exec: #ff7849;
  --network: #4aa3ff;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--txt);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}
.mono { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.grow { flex: 1; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
.center { align-items: center; justify-content: center; gap: 18px; padding: 24px; }

/* login */
.brand { text-align: center; }
.logo {
  width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center; font-weight: 800; font-size: 26px; color: #fff;
  box-shadow: 0 8px 30px rgba(124,108,255,.4);
}
.brand h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -.5px; }

/* banner */
.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  padding: calc(6px + var(--safe-t)) 10px 6px; text-align: center; font-size: 13px;
  background: #3a2330; color: #ffb4b4;
}

/* header */
#hdr { background: var(--bg2); border-bottom: 1px solid var(--line); padding-top: var(--safe-t); }
.hdr-top { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.hdr-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hdr-title #hdr-ws { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  background: var(--card); border: 1px solid var(--line); color: var(--txt);
  width: 38px; height: 38px; border-radius: 10px; font-size: 16px; flex: none;
}
.chip {
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--card2); border: 1px solid var(--line);
}
.chip.thinking, .chip.starting { color: var(--accent2); }
.chip.streaming { color: var(--default); }
.chip.awaiting-approval { color: var(--exec); background: #2a1d18; }
.chip.idle { color: var(--muted); }
.chip.error { color: var(--bypass); }

/* mode bar */
.modebar { display: flex; gap: 6px; padding: 0 12px 10px; }
.modebar button {
  flex: 1; padding: 7px 4px; border-radius: 9px; font-size: 12px; font-weight: 600;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
}
.modebar button.on[data-mode=plan]   { color: #fff; background: var(--plan); border-color: var(--plan); }
.modebar button.on[data-mode=default]{ color: #04241a; background: var(--default); border-color: var(--default); }
.modebar button.on[data-mode=acceptEdits]{ color: #2a1f00; background: var(--accept); border-color: var(--accept); }
.modebar button.on[data-mode=auto]{ color: #04241a; background: #2bd4a8; border-color: #2bd4a8; }
.modebar button.on[data-mode=bypassPermissions]{ color: #fff; background: var(--bypass); border-color: var(--bypass); }

/* transcript */
.transcript { flex: 1; overflow-y: auto; padding: 14px 12px 20px; -webkit-overflow-scrolling: touch; }
.msg { margin-bottom: 12px; }
.bubble {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 13px; white-space: pre-wrap; word-break: break-word;
}
.bubble.assistant { border-top-left-radius: 4px; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble.usermsg {
  background: var(--accent); color: #fff; border: none;
  border-top-right-radius: 4px; max-width: 85%; white-space: pre-wrap; word-break: break-word;
}
.tool {
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 8px; overflow: hidden;
}
.tool-head { display: flex; align-items: center; gap: 9px; padding: 9px 11px; cursor: pointer; }
.tlabel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.tlverb { color: var(--muted); }
.tltarget { font-family: ui-monospace, monospace; font-size: 12.5px; }
.tlcmd { font-family: ui-monospace, monospace; font-size: 12px; color: var(--txt); background: var(--bg); padding: 2px 7px; border-radius: 6px; }
.tstatus { font-size: 11px; flex: none; }
.tstatus.run { color: var(--accent2); }
.tstatus.ok { color: var(--default); }
.tstatus.err { color: var(--bypass); }
.tlfile { color: var(--accent2); text-decoration: none; border-bottom: 1px dotted var(--accent2); cursor: pointer; }
.chev { color: var(--muted); font-size: 13px; transition: transform .15s; flex: none; }
.tool:not(.collapsed) .chev { transform: rotate(90deg); }
.tool.collapsed .tool-body { display: none; }
.tool-body { padding: 2px 11px 11px; }
.tool-body pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, monospace; font-size: 12px; max-height: 300px; overflow: auto; }
.tool-body .tin { margin-top: 6px; }
.cmdpre { color: var(--accent2); }
.tout { color: var(--muted); }
.diff { font-family: ui-monospace, monospace; font-size: 12px; max-height: 320px; overflow: auto; }
.dl { white-space: pre-wrap; word-break: break-word; padding: 0 4px; border-radius: 3px; }
.dl.add { color: #8fe6bd; background: rgba(54,201,141,.10); }
.dl.del { color: #f2a6a6; background: rgba(255,93,93,.10); }

/* markdown-rendered assistant text */
.bubble.rich { white-space: normal; }
.bubble.rich p { margin: 0 0 .55em; }
.bubble.rich p:last-child { margin-bottom: 0; }
.bubble.rich h1, .bubble.rich h2, .bubble.rich h3 { margin: .5em 0 .3em; font-size: 1.05em; }
.bubble.rich ul { margin: .2em 0 .6em; padding-left: 1.2em; }
.bubble.rich li { margin: .15em 0; }
.bubble.rich code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-family: ui-monospace, monospace; font-size: .92em; }
.bubble.rich pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow: auto; margin: .4em 0; }
.bubble.rich pre code { background: none; padding: 0; }
.bubble.rich a { color: var(--accent2); }
.bubble.rich strong { font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.run { background: var(--accent2); animation: pulse 1s infinite; }
.dot.ok { background: var(--default); }
.dot.err { background: var(--bypass); }
@keyframes pulse { 50% { opacity: .3; } }
.result { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0; }

.jump {
  position: fixed; bottom: 78px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; border: none; border-radius: 999px;
  padding: 7px 14px; font-size: 13px; z-index: 20; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

/* composer */
#composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px;
  padding-bottom: calc(8px + var(--safe-b));
  background: var(--bg2); border-top: 1px solid var(--line);
}
#prompt {
  flex: 1; resize: none; max-height: 180px; background: var(--card); color: var(--txt);
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; font: inherit; line-height: 1.45;
}
.send { background: var(--accent); color: #fff; border: none; width: 42px; height: 42px; border-radius: 12px; font-size: 17px; flex: none; }
.send:disabled { opacity: .4; }

/* approval sheet */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; }
.sheet-card {
  width: 100%; background: var(--card); border-top-left-radius: 20px; border-top-right-radius: 20px;
  border-top: 1px solid var(--line); padding: 16px 14px calc(16px + var(--safe-b));
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(40px); opacity: .6; } }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.badge { padding: 3px 9px; border-radius: 7px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.badge.exec { background: #3a241a; color: var(--exec); }
.badge.write { background: #3a2f12; color: var(--write); }
.badge.network { background: #16293d; color: var(--network); }
.badge.other { background: var(--card2); color: var(--muted); }
#ap-input, #ap-reason {
  width: 100%; background: var(--bg); color: var(--txt); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; font: inherit;
}
#ap-reason { margin-top: 8px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 12px; }
.sheet-actions button { flex: 1; padding: 13px; border-radius: 12px; font-weight: 700; font-size: 15px; border: none; }
.btn-allow { background: var(--default); color: #04241a; }
.btn-deny { background: var(--card2); color: var(--bypass); border: 1px solid var(--bypass) !important; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; }
.overlay-head { display: flex; align-items: center; gap: 12px; padding: calc(12px + var(--safe-t)) 12px 12px; border-bottom: 1px solid var(--line); }
.overlay-head h2 { margin: 0; font-size: 17px; }
.overlay-body { flex: 1; overflow-y: auto; padding: 12px; }

.ws-row, .file-row {
  display: flex; align-items: center; gap: 10px; padding: 12px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.ws-row .grow { min-width: 0; }
.ws-row .name { font-weight: 600; }
.ws-row.tappable { cursor: pointer; }
.ws-row.tappable:active { background: var(--card2); }
.grow.tappable { cursor: pointer; border-radius: 8px; margin: -6px; padding: 6px; }
.grow.tappable:active { background: var(--card2); }
.rowhint { font-size: 13px; color: var(--accent2); flex: none; }
.rowhint.muted { color: var(--muted); }
.row-actions { display: flex; gap: 6px; }
.mini { background: var(--card2); border: 1px solid var(--line); color: var(--txt); padding: 6px 10px; border-radius: 8px; font-size: 12px; }
.mini.danger { color: var(--bypass); border-color: var(--bypass); }

.newform { margin-top: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.newform summary { font-weight: 600; cursor: pointer; }
.newform input { display: block; width: 100%; margin: 8px 0; background: var(--bg); color: var(--txt); border: 1px solid var(--line); border-radius: 9px; padding: 9px; font: inherit; }
.clonelog { background: #000; padding: 8px; border-radius: 8px; max-height: 160px; overflow: auto; font-size: 11px; }

.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 10px; word-break: break-all; }
.crumbs a { color: var(--accent2); text-decoration: none; }
.file-row .ext { font-size: 11px; color: var(--muted); }
.fv-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#fv-edit { width: 100%; background: var(--bg); color: var(--txt); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.md { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.md h1,.md h2,.md h3 { margin: .6em 0 .3em; }
.md code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-family: ui-monospace, monospace; }
.md pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow: auto; }
.md a { color: var(--accent2); }

.env-section { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.env-section h3 { margin: 0 0 8px; font-size: 14px; }
.kv { display: flex; gap: 8px; margin: 6px 0; }
.kv input { flex: 1; background: var(--bg); color: var(--txt); border: 1px solid var(--line); border-radius: 8px; padding: 7px; font: inherit; }
.tier { font-size: 10px; padding: 2px 6px; border-radius: 5px; background: var(--card2); color: var(--muted); }
.ok-badge { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: #12331f; color: #4ade80; font-weight: 700; }
#account-body textarea { width: 100%; box-sizing: border-box; background: var(--bg); color: var(--txt); border: 1px solid var(--line); border-radius: 8px; padding: 7px; font: 12px/1.5 var(--mono, monospace); }
.gh-repos { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; }
#artifacts-list .file-row { text-decoration: none; color: inherit; }

#gbtn { min-height: 44px; }

#model-select {
  flex: none; background: var(--card); color: var(--txt); border: 1px solid var(--line);
  border-radius: 9px; padding: 6px 8px; font-size: 12px; font-weight: 600; max-width: 92px;
}

/* ---------------- lyncean (delivery board) ---------------- */
.lyn-project { background: var(--card2, #1e2330); color: var(--txt); border: 1px solid var(--line); border-radius: 8px; font-size: 12px; padding: 5px 6px; max-width: 130px; }
.lyn-unavail { color: var(--exec); background: #2a1d18; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 10px; }
.lyn-summary { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 4px 0 12px; }
.lyn-stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 10px; text-align: center; }
.lyn-big { font-size: 26px; font-weight: 700; line-height: 1.1; color: var(--txt); }
.lyn-bad { color: var(--bypass); }
.pbar { height: 8px; background: var(--line); border-radius: 6px; overflow: hidden; }
.pfill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--default)); border-radius: 6px; transition: width .3s; }
.lyn-split { height: 10px; border-radius: 6px; overflow: hidden; background: var(--default); margin-top: 4px; }
.lyn-split-agent { height: 100%; background: var(--accent); }
.lyn-legend { display: flex; gap: 16px; font-size: 11px; color: var(--muted); margin: 6px 0 4px; }
.lyn-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot-agent { background: var(--accent); }
.dot-human { background: var(--default); }
.lyn-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.lyn-spark { display: flex; align-items: flex-end; gap: 4px; height: 72px; padding: 4px 0; }
.spark-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.spark-bar { width: 100%; max-width: 22px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.spark-lbl { font-size: 9px; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.lyn-obj { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 12px; }
.lyn-obj-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
.lyn-obj-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lyn-obj-doc { margin-top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* responsive grid: ~3 columns on desktop, single column on a phone */
.lyn-objs { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.lyn-obj.stale { opacity: 0.55; }
.lyn-obj.stale .lyn-obj-title { text-decoration: line-through; }
.lyn-obj-foot { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.lyn-obj-foot .lyn-obj-doc { flex: 1; min-width: 0; }
.lyn-obj-actions { display: flex; gap: 2px; flex-shrink: 0; }
.lyn-ico { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 2px 6px; font-size: 12px; cursor: pointer; line-height: 1.4; }
.lyn-ico:active { background: var(--card2, #1e2330); color: var(--txt); }
.lyn-comments { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.lyn-cmt { font-size: 12px; margin-bottom: 6px; color: var(--txt); }
.lyn-cmt b { color: var(--accent); font-weight: 600; margin-right: 4px; }
.lyn-cmt-add { display: flex; gap: 6px; margin-top: 6px; }
.lyn-cmt-input { flex: 1; min-width: 0; background: var(--card2, #1e2330); border: 1px solid var(--line); color: var(--txt); border-radius: 8px; padding: 6px 8px; font-size: 12px; }

/* ---------------- issues ---------------- */
#iss-report-form { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
#iss-report-form input, #iss-report-form textarea { background: var(--card2, #1e2330); border: 1px solid var(--line); color: var(--txt); border-radius: 8px; padding: 8px; font-size: 13px; }
.iss-batchbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--accent); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 8px; position: sticky; top: 0; z-index: 2; }
.iss-row { display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.iss-chk { margin-top: 3px; }
.iss-main { min-width: 0; cursor: pointer; }
.iss-title { font-size: 13px; font-weight: 600; }
.iss-meta { display: flex; align-items: center; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.iss-acts { display: flex; gap: 2px; flex-shrink: 0; }
.iss-detail { grid-column: 1 / -1; margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.iss-fulltext { font-size: 12px; color: var(--txt); white-space: pre-wrap; margin-bottom: 8px; }
.iss-triage { font-size: 12px; color: var(--txt); background: var(--card2, #1e2330); border-radius: 8px; padding: 8px; margin-bottom: 8px; }
.iss-triage b { color: var(--accent); }
.iss-sev { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 5px; font-weight: 700; }
.iss-sev-critical { background: #3a1113; color: #ff8a8a; }
.iss-sev-high { background: #3a2410; color: #ffb070; }
.iss-sev-medium { background: #1e2330; color: var(--muted); }
.iss-sev-low { background: #16281c; color: #7fd6a3; }
.iss-status { font-size: 10px; padding: 1px 6px; border-radius: 5px; background: #1e2330; color: var(--muted); }
.iss-st-in_progress { color: var(--plan); }
.iss-st-resolved, .iss-st-closed { color: var(--default); }
.iss-st-reported { color: var(--exec); }
.tri-q { margin: 8px 0; }
.tri-q .tri-a { width: 100%; margin-top: 4px; }
.iss-triage .tri-u { width: 100%; margin: 8px 0; }
.iss-triage b { display: block; margin-bottom: 6px; color: var(--accent); }
