:root {
  --bg: #f7f8fa; --card: #ffffff; --ink: #17181c; --muted: #6b7280;
  --line: #e6e8ec; --accent: #2f6df6; --accent-soft: #e8f0fe;
  --pill: #eef1f5; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e0f13; --card: #16181e; --ink: #e9eaee; --muted: #9aa1ad;
    --line: #262932; --accent: #6a9bff; --accent-soft: #17233f; --pill: #1e222b;
    --shadow: 0 1px 2px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-size: 13px; }

.topbar { display: flex; align-items: baseline; gap: 12px; padding: 14px 22px;
  border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; letter-spacing: .2px; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 26px 22px 60px; }
.foot { max-width: 1080px; margin: 0 auto; padding: 20px 22px 40px; }

.head h1 { margin: 6px 0 2px; font-size: 24px; letter-spacing: -.3px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.dash-list { list-style: none; margin: 0; padding: 0; }
.dash-list li { padding: 6px 0; }
.pill { display: inline-block; background: var(--pill); color: var(--muted); font-size: 11px;
  font-weight: 600; padding: 2px 7px; border-radius: 999px; vertical-align: middle; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 18px 0; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; box-shadow: var(--shadow); }
.kpi-v { font-size: 30px; font-weight: 700; letter-spacing: -.5px; }
.kpi-k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin-top: 4px; }
@media (max-width: 720px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
@media (max-width: 860px) { .two { grid-template-columns: 1fr; } }

.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.url { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tbody tr:hover { background: var(--accent-soft); }

.spark { width: 100%; height: 140px; display: block; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark-area { fill: var(--accent-soft); stroke: none; }
.spark-max { fill: var(--muted); font-size: 11px; }

/* ---- topbar spacer / mini links ---- */
.spacer { flex: 1; }
.mini { font-size: 12px; color: var(--muted); }

/* ---- OS home ---- */
.summary { display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px;
  box-shadow: var(--shadow); margin-bottom: 18px; flex-wrap: wrap; }
.summary .big { font-size: 26px; font-weight: 700; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--pill); color: var(--muted); font-size: 12px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }

h2.tier { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
  margin: 26px 0 10px; }
.cgroup { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.chead { font-weight: 700; padding: 11px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.prow { display: grid; grid-template-columns: 24px 1.4fr 130px 2fr 68px; gap: 12px; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.prow:last-child { border-bottom: 0; }
.prow:hover { background: var(--accent-soft); text-decoration: none; }
.pcat { text-align: center; font-size: 16px; }
.pname { font-weight: 600; }
.pnext { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pago { color: var(--muted); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 720px) {
  .prow { grid-template-columns: 22px 1fr auto; }
  .pnext, .pago { display: none; }
}

/* recently worked strip */
.rgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.rcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  box-shadow: var(--shadow); color: var(--ink); text-decoration: none; display: block; }
.rcard:hover { border-color: var(--accent); text-decoration: none; }
.rtop { font-size: 15px; }
.rmeta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.ago { color: var(--accent); font-weight: 600; }
.worklede { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; font-size: 14px; margin: 10px 0 4px; }
.obstacles { background: #fff4e5; color: #7a4b00; border: 1px solid #f5d9a8; border-radius: 10px;
  padding: 10px 14px; font-size: 14px; margin: 8px 0 4px; }
@media (prefers-color-scheme: dark) { .obstacles { background: #2e2205; color: #f0c674; border-color: #4a3a12; } }
.pstatus { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--pill); white-space: nowrap; text-align: center; }
.pstatus.big { font-size: 14px; padding: 6px 14px; }
.st-building { background: #fef0c7; color: #92600a; }
.st-live { background: #d5f5e3; color: #157347; }
.st-maintained { background: #e2e8f0; color: #475569; }
.st-parked { background: #ede9fe; color: #6d28d9; }
.st-dormant, .st-archived { background: var(--pill); color: var(--muted); }
.st-scaffold, .st-planned { background: #e0edff; color: #1d4ed8; }
@media (prefers-color-scheme: dark) {
  .st-building { background: #3a2f0c; color: #f2cd6b; }
  .st-live { background: #10331f; color: #6ee7a8; }
  .st-maintained { background: #24303f; color: #a9b6c6; }
  .st-parked { background: #241a45; color: #c4b5fd; }
  .st-scaffold, .st-planned { background: #12233f; color: #8fb6ff; }
}
.dcard { display: block; }
.dcard b { display: block; margin-top: 6px; }

/* ---- project detail ---- */
.crumb { margin: 0 0 12px; }
.actions { margin: 8px 0; }
.vsbtn { display: inline-block; background: var(--ink); color: var(--bg); font-weight: 600; font-size: 13px;
  padding: 7px 14px; border-radius: 8px; text-decoration: none; }
.vsbtn:hover { opacity: .88; text-decoration: none; }
.phead { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.phead h1 { margin: 4px 0 0; font-size: 24px; letter-spacing: -.3px; }
.editform { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-top: 12px; }
.editform label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.editform label.wide { grid-column: 1 / -1; }
.editform select, .editform textarea, .logincard input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); }
.editform button, .logincard button {
  grid-column: 1 / -1; justify-self: start; background: var(--accent); color: #fff; border: 0;
  padding: 9px 18px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.timeline li:last-child { border-bottom: 0; }
.tdate { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; margin-right: 8px; }
.decisions { white-space: pre-wrap; font-size: 13px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px; overflow-x: auto; }

/* progression timeline */
.timeline-card { margin-top: 14px; }
.progression { list-style: none; margin: 0; padding: 0; }
.progression li { display: grid; grid-template-columns: 96px 1fr; gap: 14px; padding: 11px 0;
  border-bottom: 1px solid var(--line); }
.progression li:last-child { border-bottom: 0; }
.progression .tdate { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; padding-top: 1px; }
.progression .tbody { font-size: 14px; }
.tk { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 2px 6px; border-radius: 4px; margin-right: 6px; vertical-align: middle; }
.tk-log { background: var(--accent-soft); color: var(--accent); }
.tk-sess { background: var(--pill); color: var(--muted); }

/* ---- login ---- */
.loginwrap { min-height: 80vh; display: grid; place-items: center; padding: 40px 20px; }
.logincard { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 30px; width: 320px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.logincard .brand.big { font-size: 22px; font-weight: 800; }
.logincard input { text-align: left; }
.logincard button { width: 100%; justify-self: stretch; }
.err { color: #dc2626; font-size: 13px; margin: 0; }

/* ===== per-project agent chat ===== */
.agent-card { margin: 18px 0; }
.agent-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.agent-head h3 { margin: 0; }
.agent-repo { margin-left: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.ag-repo-name { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); }
.ag-badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.ag-badge-push { background: #e6f4ea; color: #1a7f37; }
.ag-badge-ro { background: var(--pill); color: var(--muted); }
.ag-resetbtn { margin-left: 4px; border: 1px solid var(--line); background: var(--pill); border-radius: 8px;
  padding: 3px 9px; cursor: pointer; color: var(--muted); }
.ag-resetbtn:hover { color: var(--ink); }

.agent-log { border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  padding: 14px; min-height: 180px; max-height: 520px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.ag-empty { margin: auto; text-align: center; }

.ag-msg { display: flex; flex-direction: column; gap: 4px; max-width: 100%; }
.ag-who { font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; }
.ag-body { font-size: 14.5px; line-height: 1.6; word-wrap: break-word; overflow-wrap: anywhere; }

.ag-user { align-items: flex-end; }
.ag-user .ag-who { color: var(--accent); }
.ag-user .ag-body { background: var(--accent); color: #fff; padding: 9px 13px; border-radius: 13px 13px 4px 13px; max-width: 85%; }

.ag-agent .ag-who { color: var(--accent); }
.ag-agent .ag-body { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 4px 12px 12px 12px; }

.ag-error .ag-who { color: #b45309; }
.ag-error .ag-body { background: #fff4e5; color: #7a4b00; border: 1px solid #f5d9a8; padding: 9px 12px; border-radius: 10px; font-size: 13px; }

/* markdown inside an agent reply */
.ag-body > *:first-child { margin-top: 0; }
.ag-body > *:last-child { margin-bottom: 0; }
.ag-body p { margin: 8px 0; }
.ag-body .ag-h { margin: 12px 0 6px; line-height: 1.3; font-weight: 700; }
h1.ag-h { font-size: 18px; } h2.ag-h { font-size: 16px; } h3.ag-h { font-size: 14.5px; }
h4.ag-h, h5.ag-h, h6.ag-h { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.ag-body ul, .ag-body ol { margin: 8px 0; padding-left: 22px; }
.ag-body li { margin: 3px 0; }
.ag-body strong { font-weight: 700; }
.ag-body a { text-decoration: underline; }
.ag-body blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.ag-body hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.ag-body code { background: rgba(127,127,127,.16); padding: 1px 5px; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.ag-code { background: #0d1117; color: #e6edf3; padding: 11px 13px; border-radius: 9px; overflow-x: auto;
  margin: 9px 0; font-size: 12.5px; line-height: 1.5; }
.ag-code code { background: none; padding: 0; color: inherit; }

.ag-tool { align-self: flex-start; font-size: 12px; color: var(--muted); display: flex; align-items: baseline; gap: 6px;
  background: var(--pill); padding: 4px 10px; border-radius: 8px; max-width: 100%; }
.ag-tool-icon { opacity: .7; }
.ag-tool b { color: var(--ink); font-weight: 600; }
.ag-tool-detail { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; opacity: .85;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.agent-status { min-height: 18px; margin: 10px 2px 0; font-size: 12px; color: var(--muted); }
.ag-working::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%;
  background: var(--accent); animation: agpulse 1s ease-in-out infinite; vertical-align: middle; }
@keyframes agpulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }

.agent-form { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.agent-form textarea { flex: 1; resize: vertical; min-height: 46px; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 11px; background: var(--card); color: var(--ink); font: inherit; line-height: 1.45; }
.agent-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.agent-form button { padding: 11px 22px; border: none; border-radius: 11px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.agent-form button:hover { filter: brightness(1.05); }
.agent-form button:disabled { opacity: .5; cursor: not-allowed; }

@media (prefers-color-scheme: dark) {
  .ag-error .ag-body { background: #2a1e0a; color: #f0c98a; border-color: #4a380f; }
  .ag-badge-push { background: #123322; color: #4ade80; }
  .ag-code { background: #0b0e14; border: 1px solid var(--line); }
}
@media (max-width: 640px) {
  .ag-user .ag-body { max-width: 92%; }
  .agent-form button { padding: 11px 16px; }
  .agent-log { max-height: 60vh; }
}

/* ===== Ava nav + page ===== */
.ava-nav { font-weight: 600; color: var(--accent); padding: 4px 12px; border-radius: 999px; background: var(--accent-soft); }
.ava-nav:hover { text-decoration: none; filter: brightness(1.03); }
.ava-hero { display: flex; align-items: center; gap: 14px; margin: 8px 0 18px; }
.ava-avatar { width: 52px; height: 52px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff; font-weight: 800; font-size: 24px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ava-hero h1 { margin: 0 0 2px; font-size: 24px; }
.needs-card { margin-bottom: 18px; }
.needs-list { list-style: none; margin: 4px 0 0; padding: 0; }
.needs-list li { padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.needs-list li:first-child { border-top: none; }

/* ===== goals & milestones ===== */
.goals-card { margin: 18px 0; }
.goal-form textarea { width: 100%; resize: vertical; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--card); color: var(--ink); font: inherit; }
.goal-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.goal-row input[type=date] { padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--ink); font: inherit; }
.pm-btn { font-size: 12px; padding: 6px 13px; border: 1px solid var(--line); background: var(--pill); color: var(--ink);
  border-radius: 8px; cursor: pointer; font-weight: 600; }
.pm-btn:hover { border-color: var(--accent); }
.ms-list { list-style: none; margin: 14px 0 0; padding: 0; }
.ms-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.ms-row:first-child { border-top: none; }
.ms-check { width: 17px; height: 17px; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
.ms-title { flex: 1; }
.ms-is-done .ms-title { text-decoration: line-through; color: var(--muted); }
.ms-due { font-size: 12px; white-space: nowrap; }
.ms-del { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.ms-del:hover { color: #dc2626; background: rgba(220,38,38,.1); }
.ms-empty { padding: 8px 0; }
.ms-add { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.ms-add input[type=text] { flex: 1; min-width: 140px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); color: var(--ink); font: inherit; }
.ms-add input[type=date] { padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); color: var(--ink); font: inherit; }
.ms-badge { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.ms-soon { background: var(--accent-soft); color: var(--accent); }
.ms-overdue { background: #fde8e8; color: #c0271f; }
.ms-done { background: #e6f4ea; color: #1a7f37; }
@media (prefers-color-scheme: dark) {
  .ms-overdue { background: #351314; color: #f6a5a0; }
  .ms-done { background: #123322; color: #4ade80; }
}
@media (max-width: 640px) { .goal-row, .ms-add { gap: 8px; } }

/* ===== screenshot attach in chat ===== */
.agent-form .ag-attach { flex-shrink: 0; width: 46px; height: 46px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); border-radius: 11px; cursor: pointer; font-size: 18px; line-height: 1; font-weight: 400; padding: 0; }
.agent-form .ag-attach:hover { border-color: var(--accent); filter: none; }
.ag-preview { align-items: center; gap: 10px; margin: 10px 0 0; }
.ag-preview img { max-height: 92px; max-width: 150px; border-radius: 9px; border: 1px solid var(--line); object-fit: cover; }
.ag-preview-x { border: none; background: var(--pill); color: var(--muted); border-radius: 50%; width: 24px; height: 24px;
  cursor: pointer; font-size: 12px; line-height: 1; }
.ag-preview-x:hover { color: #dc2626; }
.ag-shot { display: block; max-width: 220px; max-height: 240px; margin-top: 6px; border-radius: 10px; border: 1px solid rgba(255,255,255,.35); }
.ag-shot-chip { display: inline-block; margin-top: 4px; font-size: 12px; opacity: .85; }

/* ===== voice mic ===== */
.agent-form .ag-mic { flex-shrink: 0; width: 46px; height: 46px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); border-radius: 11px; cursor: pointer; font-size: 18px; line-height: 1; padding: 0; font-weight: 400; }
.agent-form .ag-mic:hover { border-color: var(--accent); filter: none; }
.agent-form .ag-mic.rec { background: #dc2626; color: #fff; border-color: #dc2626; animation: agpulse 1s infinite; }

/* ===== cloud/desktop mode toggle ===== */
.mode-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; vertical-align: middle; }
.mode-opt { border: none; background: var(--card); color: var(--muted); font-size: 12px; padding: 4px 9px; cursor: pointer; font-weight: 600; }
.mode-opt + .mode-opt { border-left: 1px solid var(--line); }
.mode-opt.on { background: var(--accent); color: #fff; }
.mode-info { font-size: 12px; color: var(--muted); margin-left: 8px; display: inline-flex; align-items: center; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; }
.dot.on { background: #1a7f37; } .dot.off { background: #c0271f; }

/* ===== desktop worker control ===== */
.worker-card { margin: 0 0 18px; }
.worker-head { display: flex; align-items: center; gap: 10px; }
.worker-head h3 { margin: 0; }
.worker-status { margin-left: auto; font-size: 13px; font-weight: 600; }
.wk-live { color: #1a7f37; } .wk-pending { color: #b45309; } .wk-offline { color: var(--muted); }
.worker-btns { display: flex; gap: 8px; margin-top: 10px; }
.pm-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
