:root {
  --bg: #0b0c0f;
  --surface: #15171c;
  --surface-2: #1d2027;
  --border: #2a2e37;
  --text: #ececf1;
  --muted: #8b919e;
  --accent: #4f8cff;
  --accent-soft: #15284d;
  --ok: #34d399;
  --ok-soft: #0f2e24;
  --warn: #fbbf24;
  --warn-soft: #3a2a08;
  --bad: #f87171;
  --bad-soft: #3b1515;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.35);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 650; }
.topbar .sub { color: var(--muted); font-size: 13px; }

.container { max-width: 1400px; margin: 0 auto; padding: 20px; }
.narrow { max-width: 620px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 500;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.12); }
.btn.active { outline: 2px solid var(--accent); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }

label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
label.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
input[type=text], input[type=email], input[type=url], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: #5f6675; }
textarea { min-height: 80px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .row { grid-template-columns: 1fr; } }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.hidden { display: none !important; }

/* ---- kanban ---- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col.drag-over { outline: 2px dashed var(--accent); }
.col h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); display: flex; justify-content: space-between; }
.col h3 .count { background: var(--surface); border-radius: 999px; padding: 0 7px; font-size: 11px; }

.kcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3); cursor: pointer; position: relative;
}
.kcard:hover { border-color: #3a404c; }
.kcard[draggable=true] { cursor: grab; }
.kcard.dragging { opacity: 0.5; }
.kcard.dim { opacity: 0.55; }
.kcard .name { font-weight: 600; margin-bottom: 2px; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.kcard .role { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kcard .meta { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 12px; color: var(--text); }
.kcard .meta b { color: var(--muted); font-weight: 500; }
.kcard .links { margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; }

/* ---- side drawer ---- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--surface);
  border-left: 1px solid var(--border); z-index: 21; overflow-y: auto; padding: 20px; box-shadow: -8px 0 30px rgba(0,0,0,0.08);
}
.drawer h2 { margin: 0 0 4px; font-size: 18px; }
.drawer .section { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.drawer .section h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.drawer .close { position: absolute; top: 12px; right: 12px; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

.linkbox { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.linkbox input { flex: 1; min-width: 160px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 12px; display: flex; gap: 8px; }
.timeline li time { color: var(--muted); white-space: nowrap; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #0b0c0f;
  padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 50; opacity: 0; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* ---- thread ---- */
.thread { display: flex; flex-direction: column; gap: 8px; max-height: 360px; overflow-y: auto; padding-right: 4px; }
.msg { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; max-width: 92%; align-self: flex-start; }
.msg.mine { background: var(--accent-soft); align-self: flex-end; }
.msg.sys { background: transparent; border: 1px dashed var(--border); align-self: stretch; max-width: none; }
.msg.sys.small { border: 0; padding: 2px 4px; }
.msg-head { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 2px; display: flex; gap: 8px; }
.msg-head time { font-weight: 400; }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.composer { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.composer textarea { min-height: 42px; }

.decisions { display: flex; gap: 8px; flex-wrap: wrap; }
.decisions .btn.active { outline: 2px solid var(--accent); }

.dot {
  position: absolute; top: -5px; right: -5px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--bad); border: 2px solid var(--surface);
}
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; }

.client-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.client-tile { cursor: pointer; }
.client-tile:hover { border-color: var(--accent); }
.client-tile h3 { margin: 0 0 2px; font-size: 15px; }
.client-tile .stats { display: flex; gap: 12px; margin-top: 10px; color: var(--muted); font-size: 12px; }
