:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --border: #e2dfd6;
  --text: #1d1c19;
  --muted: #6b6860;
  --faint: #9a968c;
  --accent: #1f6f5c;
  --accent-soft: #e2f0eb;
  --on-accent: #ffffff;
  --ok: #2f7d4f;    --ok-soft: #e3f2e8;
  --warn: #a8630a;  --warn-soft: #fbefd9;
  --bad: #b5372b;   --bad-soft: #fbe4e1;
  --claude: #9a4f2c; --claude-soft: #f8e9e1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(30, 25, 15, .05), 0 2px 8px rgba(30, 25, 15, .04);
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513; --surface: #1d1d1a; --surface-2: #262622; --border: #34332e;
    --text: #ecebe6; --muted: #a3a097; --faint: #77746b;
    --accent: #5cc0a3; --accent-soft: #1d342d; --on-accent: #0d211b;
    --ok: #6ccf93; --ok-soft: #1c3226; --warn: #e8a94a; --warn-soft: #3a2c15;
    --bad: #f07a6d; --bad-soft: #3d1f1b; --claude: #e59a72; --claude-soft: #3a261c;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 'IBM Plex Sans', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--border); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 0 8px 18px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: var(--on-accent); font-size: 15px; }
.nav a { white-space: nowrap; display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--border); }
.nav .badge { font-size: 11.5px; font-family: var(--mono); background: var(--bad-soft); color: var(--bad); border-radius: 99px; padding: 0 7px; }
.side-foot { margin-top: auto; padding: 8px; font-size: 13px; color: var(--muted); }
.side-foot button { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; }
main { padding: 28px 36px 80px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- primitives ---------- */
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
label.field { display: grid; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.empty { color: var(--faint); font-size: 14px; padding: 6px 0; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.h-on-track { color: var(--ok); background: var(--ok-soft); }
.h-at-risk { color: var(--warn); background: var(--warn-soft); }
.h-blocked { color: var(--bad); background: var(--bad-soft); }
.s-on-hold, .s-done { color: var(--muted); background: var(--surface-2); }
.tag { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--muted); }
.tag.k-blocker { background: var(--bad-soft); color: var(--bad); }
.tag.k-decision { background: var(--accent-soft); color: var(--accent); }
.tag.k-client { background: var(--warn-soft); color: var(--warn); }
.by-claude { color: var(--claude); background: var(--claude-soft); }
.due-over { color: var(--bad); font-weight: 600; }
.due-today { color: var(--warn); font-weight: 600; }

/* ---------- today ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
.stat { padding: 14px 16px; }
.stat b { display: block; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.alert b { color: var(--bad); }
.stat.warn b { color: var(--warn); }
.today-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.today-grid > .card { padding: 16px 18px; }
.today-grid h2 { margin-bottom: 10px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 0; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-start; }
.list li:first-child { border-top: 0; padding-top: 2px; }
.list .what { flex: 1; min-width: 0; }
.list .what a { font-weight: 600; text-decoration: none; }
.list .what a:hover { text-decoration: underline; }
.list .sub { font-size: 13.5px; color: var(--muted); overflow-wrap: anywhere; }
.list .acts { display: flex; gap: 4px; flex-shrink: 0; }

/* ---------- projects ---------- */
.tabs { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.proj { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; text-decoration: none; transition: border-color .15s; }
.proj:hover { border-color: var(--faint); }
.proj .top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.proj h3 { font-size: 16px; }
.proj .client { font-size: 13px; color: var(--muted); }
.proj .next { font-size: 14px; }
.proj .next b { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-right: 4px; }
.proj .last { font-size: 13.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.proj .meta { display: flex; gap: 14px; font-size: 12.5px; color: var(--faint); margin-top: auto; flex-wrap: wrap; }

/* ---------- project detail ---------- */
.crumb { font-size: 13px; color: var(--muted); text-decoration: none; }
.crumb:hover { color: var(--text); }
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.detail-main, .detail-side { display: grid; gap: 16px; }
.status-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.editable { cursor: text; border-radius: 6px; padding: 2px 4px; margin: -2px -4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.editable:hover { background: var(--surface-2); }
.editable.placeholder { color: var(--faint); }
.box-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.composer textarea { min-height: 84px; }
.composer .opts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 8px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 12px 0; border-top: 1px solid var(--border); }
.timeline li:first-child { border-top: 0; }
.timeline .who { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.timeline .who strong { color: var(--text); font-weight: 600; }
.timeline .body { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline .body .sys { color: var(--muted); font-size: 13.5px; }
.timeline .del { margin-left: auto; opacity: 0; }
.timeline li:hover .del { opacity: 1; }
.task { display: flex; gap: 9px; align-items: flex-start; padding: 7px 0; border-top: 1px solid var(--border); }
.task:first-child { border-top: 0; }
.task input[type=checkbox] { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.task .t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.task .t small { display: block; color: var(--muted); font-size: 12.5px; }
.task.done .t { color: var(--faint); text-decoration: line-through; }
.task .x { opacity: 0; }
.task:hover .x { opacity: 1; }
.add-task { display: grid; grid-template-columns: 1fr 130px; gap: 6px; margin-top: 10px; }
.add-task input:first-child { grid-column: 1 / -1; }
.kv { display: grid; gap: 10px; font-size: 14px; }
.kv > div > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- activity ---------- */
.feed-day { margin: 22px 0 8px; }
.feed-day:first-child { margin-top: 0; }
.feed .proj-link { font-weight: 600; text-decoration: none; }
.feed .proj-link:hover { text-decoration: underline; }

/* ---------- dialog / login / toast ---------- */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(20, 18, 14, .4); }
dialog form { display: grid; gap: 12px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; display: grid; gap: 14px; }
.err { color: var(--bad); font-size: 14px; min-height: 1em; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 9px; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; z-index: 10; }
#toast.show { opacity: 1; transform: translateX(-50%); }
pre.code { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; margin: 8px 0; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .detail { grid-template-columns: 1fr; }
  .today-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; background: var(--bg); border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .brand span { display: none; }
  .nav { display: flex; gap: 2px; }
  .side-foot { display: none; }
  main { padding: 18px 16px 60px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .status-strip, .composer .opts { grid-template-columns: 1fr; }
  .proj-grid { grid-template-columns: 1fr; }
  .timeline .del, .task .x { opacity: 1; }
}

/* ---------- view-only accounts ---------- */
body.viewer .edit-only { display: none !important; }
.readonly { white-space: pre-wrap; overflow-wrap: anywhere; }
