:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1f22;
  --muted: #62666d;
  --line: #dedbd4;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --soft: #eef3f7;
  --ok: #2e7d4f;
  --warn: #9a5b00;
  --danger: #a33a32;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --panel: #1d2024;
    --ink: #e8e6e1;
    --muted: #a0a4aa;
    --line: #33373d;
    --accent: #6aa9d6;
    --accent-ink: #0d1a24;
    --soft: #1f2a33;
    --ok: #6cc08e;
    --warn: #e0a450;
    --danger: #e98a82;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 650; color: var(--ink); text-decoration: none; }
#topnav { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
#topnav a, #topnav button { font-size: .9rem; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.narrow { max-width: 420px; margin: 40px auto; }

label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit; cursor: pointer; border-radius: 6px; padding: 7px 14px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
}
button.secondary { background: transparent; color: var(--accent); }
button.link { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 200px; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.error { color: var(--danger); margin-top: 8px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 8px 0 16px; overflow-x: auto; }
.tabs a {
  padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.project-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.project-list a.card { display: block; text-decoration: none; color: inherit; }
.badge {
  display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 999px;
  background: var(--soft); color: var(--accent); border: 1px solid var(--line); white-space: nowrap;
}
.badge.milestone { color: var(--ok); }
.badge.risk { color: var(--danger); }
.badge.decision { color: var(--warn); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* Messages */
.chat { display: grid; grid-template-columns: 220px 1fr; gap: 16px; min-height: 60vh; }
.chat-side { border-right: 1px solid var(--line); padding-right: 12px; }
.chat-side h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-top: 14px; }
.chat-side a { display: block; padding: 4px 8px; border-radius: 6px; text-decoration: none; color: var(--ink); }
.chat-side a.active { background: var(--soft); color: var(--accent); font-weight: 600; }
.chat-side a .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: 6px; }
.chat-main { display: flex; flex-direction: column; min-width: 0; }
.msgs { flex: 1; overflow-y: auto; max-height: 62vh; padding-right: 4px; }
.msg { padding: 8px 0; border-bottom: 1px solid var(--line); }
.msg-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.msg-head strong { font-size: .92rem; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.msg-tools { margin-left: auto; display: flex; gap: 10px; font-size: .8rem; }
.composer { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.composer textarea { min-height: 44px; }

/* Tasks */
.task { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.task input[type=checkbox] { width: auto; margin-top: 4px; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-main { flex: 1; min-width: 0; }
.task-meta { font-size: .82rem; color: var(--muted); }
.task select, .task input[type=date] { width: auto; padding: 3px 6px; font-size: .85rem; }

.update { padding: 12px 0; border-bottom: 1px solid var(--line); }
.update-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 6px; }

.invite-link { font-family: ui-monospace, monospace; font-size: .85rem; word-break: break-all; background: var(--soft); padding: 8px; border-radius: 6px; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 6px; max-width: calc(100% - 32px);
}

@media (max-width: 720px) {
  .chat { grid-template-columns: 1fr; }
  .chat-side { border-right: none; border-bottom: 1px solid var(--line); padding: 0 0 8px; }
  .msgs { max-height: 55vh; }
}
