/* PersonalLab design system.
   Clean, high-contrast finance-app feel: true black / pure white surfaces,
   large type, one accent (green), red reserved for overdue / negative.
   All colors are tokens so themes stay consistent. */

:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --radius: 16px;
  --radius-sm: 10px;
  --gap: 16px;
  --nav-h: 64px;
  --side-w: 232px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}
:root[data-theme="dark"] {
  --bg: #000;
  --surface: #0f1012;
  --surface-2: #17191c;
  --line: #24272b;
  --text: #f5f6f7;
  --muted: #8d939b;
  --accent: #22d36b;
  --accent-ink: #001b0a;
  --accent-soft: rgba(34, 211, 107, .14);
  --danger: #ff5a4f;
  --danger-soft: rgba(255, 90, 79, .14);
  --warn: #f5b942;
  --shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
:root[data-theme="light"] {
  --bg: #fff;
  --surface: #fff;
  --surface-2: #f4f5f6;
  --line: #e6e8eb;
  --text: #0b0c0e;
  --muted: #6b7178;
  --accent: #0aa84f;
  --accent-ink: #fff;
  --accent-soft: rgba(10, 168, 79, .1);
  --danger: #e5372b;
  --danger-soft: rgba(229, 55, 43, .09);
  --warn: #b7791f;
  --shadow: 0 10px 30px rgba(0, 0, 0, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { min-height: 100dvh; }
.main { max-width: 760px; margin: 0 auto; padding: 0 18px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); }
.nav {
  position: fixed; inset: auto 0 0 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; justify-content: space-around; align-items: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); z-index: 20;
}
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 6px 10px; border-radius: 12px; }
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--text); }
.nav a.active svg { color: var(--accent); }
.nav .brand, .nav .nav-extra { display: none; }

@media (min-width: 900px) {
  .nav {
    inset: 0 auto 0 0; width: var(--side-w); height: auto; flex-direction: column; justify-content: flex-start;
    align-items: stretch; gap: 4px; padding: 24px 14px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 22px; color: var(--text); }
  .nav .brand img { width: 28px; height: 28px; }
  .nav a { flex-direction: row; gap: 12px; font-size: 15px; padding: 10px 12px; }
  .nav a.active { background: var(--surface-2); }
  .nav .nav-extra { display: flex; }
  .nav .spacer { flex: 1; }
  .main { margin-left: calc(var(--side-w) + max(0px, (100vw - var(--side-w) - 760px) / 2)); padding-bottom: 48px; padding-top: 36px; }
  .main { padding-top: 36px; }
}

/* ---------- type ---------- */
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
h1 { font-size: 34px; line-height: 1.1; letter-spacing: -.02em; margin: 4px 0 18px; font-weight: 700; }
h2 { font-size: 20px; margin: 28px 0 10px; font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
h2 .count { color: var(--muted); font-weight: 600; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- stats row ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 6px; }
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 14px; }
.stat .n { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat.danger .n { color: var(--danger); }
.stat.accent .n { color: var(--accent); }

/* ---------- capture bar ---------- */
.capture { position: relative; margin: 6px 0 4px; }
.capture textarea {
  width: 100%; resize: none; min-height: 54px; max-height: 180px; padding: 15px 56px 15px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface-2); outline: none; transition: border-color .15s;
}
.capture textarea:focus { border-color: var(--accent); }
.capture .send { position: absolute; right: 8px; bottom: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 2px 0; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 999px; padding: 11px 18px; font-weight: 650; cursor: pointer; background: var(--surface-2);
  color: var(--text); transition: transform .1s var(--ease), opacity .15s; display: inline-flex; align-items: center; gap: 8px;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.sm { padding: 7px 13px; font-size: 14px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; background: var(--accent); color: var(--accent-ink); }
.icon-btn svg { width: 20px; height: 20px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.item {
  display: flex; gap: 12px; align-items: flex-start; padding: 13px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow-wrap: anywhere; }
.item .meta { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.item .meta .overdue { color: var(--danger); font-weight: 600; }
.item .meta .soon { color: var(--warn); font-weight: 600; }
.item.done .t { color: var(--muted); text-decoration: line-through; }
.item .time { min-width: 64px; font-variant-numeric: tabular-nums; font-weight: 650; color: var(--text); font-size: 15px; padding-top: 1px; }
.check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--muted); flex: none; cursor: pointer; background: none;
  display: grid; place-items: center; margin-top: 1px; padding: 0;
}
.check:hover { border-color: var(--accent); }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check svg { width: 14px; height: 14px; }
.tag { background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 1px 8px; font-size: 12px; }
.pill { border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 600; }
.pill.p1 { background: var(--accent-soft); color: var(--accent); }
.pill.p2, .pill.p3 { background: var(--danger-soft); color: var(--danger); }
.kind-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--muted); }
.kind-dot.event { background: var(--accent); }
.kind-dot.todo { background: var(--warn); }
.kind-dot.note { background: #7c8cff; }
.empty { color: var(--muted); padding: 18px 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 12px 0; }
.segmented { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 999px; gap: 2px; flex-wrap: wrap; }
.segmented button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; }
.segmented button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-grid .dow { color: var(--muted); font-size: 12px; font-weight: 600; padding: 4px 0; }
.cal-day { aspect-ratio: 1; border-radius: 12px; border: 0; background: none; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-variant-numeric: tabular-nums; }
.cal-day.other { color: var(--muted); opacity: .5; }
.cal-day.today { color: var(--accent); font-weight: 700; }
.cal-day.sel { background: var(--text); color: var(--bg); }
.cal-day .dots { display: flex; gap: 2px; height: 5px; }
.cal-day .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-day .dots i.todo { background: var(--warn); }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.bubble { max-width: 85%; padding: 11px 15px; border-radius: 20px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.bubble.assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 6px; }
.bubble.pending { opacity: .6; }

/* ---------- forms ---------- */
label.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 14px; color: var(--muted); font-weight: 600; }
.field input, .field textarea, .field select {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; outline: none; color: var(--text); font-weight: 400; font-size: 16px; width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { min-height: 96px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.switch:last-child { border-bottom: 0; }
.switch input[type="checkbox"] { width: 46px; height: 28px; appearance: none; background: var(--line); border-radius: 999px; position: relative; cursor: pointer; transition: background .2s; flex: none; }
.switch input[type="checkbox"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); }
.switch input[type="checkbox"]:checked { background: var(--accent); }
.switch input[type="checkbox"]:checked::after { transform: translateX(18px); }
.switch input[type="time"], .switch input[type="number"], .switch select { width: auto; border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 6px 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.code-box { font-family: ui-monospace, Menlo, monospace; font-size: 28px; letter-spacing: .15em; font-weight: 700; padding: 10px 0; }
table.usage { width: 100%; border-collapse: collapse; font-size: 14px; }
table.usage td, table.usage th { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
table.usage td.num, table.usage th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- modal / sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); animation: up .22s var(--ease);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 22px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth .box { width: 100%; max-width: 380px; }
.auth .logo { width: 56px; height: 56px; margin-bottom: 18px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(92vw, 520px); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-size: 15px; box-shadow: var(--shadow); animation: up .2s var(--ease); white-space: pre-wrap; pointer-events: auto; }
.toast.error { background: var(--danger); color: #fff; }
@media (min-width: 900px) { #toasts { bottom: 28px; left: calc(50% + var(--side-w) / 2); } }

.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.m0 { margin: 0 !important; }
.mobile-top { max-width: 760px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 6px) 8px 0; gap: 2px; }
.mobile-top svg { width: 20px; height: 20px; }
@media (min-width: 900px) { .mobile-top { display: none; } }
.switch .row input:not([type="checkbox"]) { max-width: 220px; }

/* Inputs outside .field (settings rows) get the same look. */
.card input:not([type="checkbox"]), .card select {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-sm); padding: 9px 11px;
  color: var(--text); outline: none; font-size: 16px; min-width: 0;
}
.card input:focus, .card select:focus { border-color: var(--accent); }
.switch { flex-wrap: wrap; }
.switch > div:first-child { flex: 1 1 180px; }
.switch .row { flex-wrap: wrap; justify-content: flex-end; }
.card > .row > input { flex: 1 1 200px; }
.switch input[type="number"] { width: 84px; }

/* ---------- collapsible panels ---------- */
details.panel > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; user-select: none; -webkit-tap-highlight-color: transparent; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary .panel-title { font-weight: 700; letter-spacing: -.01em; }
details.panel > summary .panel-meta { color: var(--muted); font-size: 14px; font-weight: 600; margin-left: auto; text-align: right; }
details.panel > summary .chev { display: grid; place-items: center; color: var(--muted); transition: transform .2s var(--ease); flex: none; }
details.panel > summary .panel-meta + .chev { margin-left: 0; }
details.panel > summary .panel-title + .chev { margin-left: auto; }
details.panel > summary .chev svg { width: 18px; height: 18px; }
details.panel[open] > summary .chev { transform: rotate(90deg); }
details.panel.card > summary .panel-title { font-size: 20px; }
details.panel.card[open] > summary { margin-bottom: 6px; }
details.panel.section { margin-top: 22px; }
details.panel.section > summary { padding: 6px 0; }
details.panel.section > summary .panel-title { font-size: 20px; }
details.panel.section > summary .panel-meta { margin-left: 0; }
details.panel.section > summary .panel-meta + .chev { margin-left: auto; }
.model-row { display: flex; gap: 8px; align-items: center; }
.model-row select { flex: 1; min-width: 0; }
.model-note { font-size: 12px; color: var(--muted); font-weight: 400; }
details.panel > summary .panel-title { white-space: nowrap; }
details.panel > summary .panel-meta { font-size: 13px; }

/* ---------- agents & visualizer ---------- */
.avatar { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; flex: none;
  background: color-mix(in srgb, var(--agent, var(--accent)) 18%, transparent); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--agent, var(--accent)) 55%, transparent); }
.avatar.sm { width: 30px; height: 30px; border-radius: 10px; font-size: 15px; }
.avatar.lg { width: 56px; height: 56px; border-radius: 18px; font-size: 28px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; color: var(--muted); }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.status.idle i { background: var(--accent); }
.status.busy { color: var(--warn); }
.status.busy i { background: var(--warn); animation: pulse 1.1s ease-in-out infinite; }
.status.err { color: var(--danger); }
.status.err i { background: var(--danger); }
.status.off { opacity: .7; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.6); opacity: .45; } }
.agent-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 14px 0; }
@media (min-width: 640px) { .agent-grid { grid-template-columns: 1fr 1fr; } }
.agent-card { display: flex; flex-direction: column; gap: 8px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--text); transition: transform .12s var(--ease), border-color .15s; }
.agent-card:hover { border-color: var(--muted); }
.agent-card:active { transform: scale(.99); }
.agent-card.disabled { opacity: .6; }
.agent-name { font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.agent-desc { min-height: 2.6em; }
.agent-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--surface-2); border-radius: 12px; padding: 10px; }
.agent-stats div { display: flex; flex-direction: column; min-width: 0; }
.agent-stats b { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-stats span { font-size: 12px; color: var(--muted); }
.agent-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.agent-foot span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-warn, .hint.warn { font-size: 13px; color: var(--warn); }
.agent-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.agent-head .back { padding: 6px; }
.agent-head h1 { font-size: 28px; }
.run-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.run-row:last-child { border-bottom: 0; }
.run-row .grow { flex: 1; min-width: 0; }
.run-row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-row .meta { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.run-row .meta .overdue { color: var(--danger); font-weight: 600; }
.run-row .meta .soon { color: var(--warn); font-weight: 600; }
.run-channel { width: 30px; text-align: center; font-size: 16px; }
.trace-link { display: block; margin-top: 6px; border: 0; background: none; color: var(--muted); font-size: 12px; padding: 0; cursor: pointer; text-decoration: underline; }
.trace-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13px; margin: 8px 0 14px; }
.timeline { position: relative; }
.timeline::before { content: ""; position: absolute; left: 15px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.tl-node { position: relative; display: flex; gap: 12px; padding: 6px 0 10px; }
.tl-dot { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 15px; flex: none; z-index: 1; box-shadow: 0 0 0 4px var(--surface); }
.tl-body { flex: 1; min-width: 0; padding-top: 5px; }
.tl-title { font-weight: 650; overflow-wrap: anywhere; }
.tl-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tl-text { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: 15px; }
.tl-node.reply .tl-text { background: var(--accent-soft); }
.tl-node.error .tl-title, .tl-node.error .tl-text { color: var(--danger); }
.tl-details { margin-top: 6px; }
.tl-details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.tl-k { font-size: 12px; font-weight: 700; color: var(--muted); margin: 8px 0 4px; text-transform: uppercase; letter-spacing: .03em; }
.tl-details pre { margin: 0; background: var(--surface-2); border-radius: 10px; padding: 10px; font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow: auto; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 12px; }
.field input[type="color"] { height: 46px; padding: 4px; }
textarea.instructions { width: 100%; min-height: 260px; font-family: ui-monospace, Menlo, monospace; font-size: 13.5px; line-height: 1.5; border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; color: var(--text); resize: vertical; }
.tool-row { cursor: pointer; }
.sticky-save { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); padding: 8px 0; z-index: 5; }
@media (min-width: 900px) { .sticky-save { bottom: 12px; } }
.agent-head + .hint, .segmented + div { margin-top: 12px; }
details.panel.section > summary .panel-title { white-space: normal; }
