/* TBL Board - phase 1. Hand-rolled CSS, no framework, no build step. */

:root {
  color-scheme: light dark;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dfe4ec;
  --border-strong: #c6cede;
  --text: #16202e;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --accent: #2563eb;
  --accent-soft: #e0eaff;
  --danger: #c92a2a;
  --danger-soft: #ffe3e3;
  --ok: #2b8a3e;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.18);
  --radius: 10px;
  --radius-sm: 6px;
  --column-w: 292px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --surface: #171e2c;
    --surface-2: #1c2534;
    --border: #2a3548;
    --border-strong: #3a4860;
    --text: #e6ebf4;
    --text-muted: #9dabc2;
    --text-faint: #6f7f99;
    --accent: #6ea8fe;
    --accent-soft: #1e2f4d;
    --danger: #ff8787;
    --danger-soft: #3b1f22;
    --ok: #69db7c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

h1, h2, h3, p { margin: 0; }

/* ------------------------------------------------------------- primitives --- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, transform 60ms ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible,
.card:focus-visible, .column:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-icon {
  width: 26px; height: 26px; padding: 0; justify-content: center;
  border-radius: var(--radius-sm); font-size: 13px; line-height: 1;
}
.btn-sm { padding: 4px 8px; font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > label { font-size: 12px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.02em; }
.field input, .field select, .field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
}
.field textarea { resize: vertical; min-height: 84px; }
.field .hint { font-size: 11px; color: var(--text-faint); }
.field-error { font-size: 12px; color: var(--danger); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}

.avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  flex: none;
}

/* ------------------------------------------------------------------ login --- */

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px;
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.login-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.login-note {
  margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--border);
  font-size: 12px; color: var(--text-faint);
}

.logo {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 16px; font-weight: 700;
}

/* ---------------------------------------------------------------- topbar --- */

.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: 4px; }
.brand h1 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.phase {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--border);
}
.spacer { flex: 1 1 auto; }
.search {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 5px 9px; background: var(--surface-2); min-width: 200px;
}
.search input { border: 0; background: transparent; outline: none; width: 100%; font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.identity { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-muted); }

/* ----------------------------------------------------------------- board --- */

.board {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 16px 18px 28px;
  overflow-x: auto;
  min-height: calc(100vh - 128px);
}
.column {
  flex: 0 0 var(--column-w);
  width: var(--column-w);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 64px);
  /* whole column is a drag target (controls and cards excepted) */
  cursor: grab;
}
.column.dragging { opacity: 0.45; }
.column.drop-source { border-style: dashed; }
.column-accent { height: 3px; border-radius: var(--radius) var(--radius) 0 0; background: var(--col-accent, var(--accent)); }
.column-head {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px 8px;
  border-bottom: 1px solid var(--border);
  user-select: none; /* cursor: grab inherited from .column */
}
.handle {
  cursor: grab; color: var(--text-faint); font-size: 14px; padding: 0 2px;
  user-select: none; touch-action: none;
}
.handle:active { cursor: grabbing; }
.col-name {
  font-size: 13px; font-weight: 700; letter-spacing: 0.01em;
  padding: 3px 6px; border-radius: var(--radius-sm); cursor: text;
  border: 1px solid transparent; flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.col-name:hover { border-color: var(--border-strong); background: var(--surface-2); }
.col-name-input {
  font-size: 13px; font-weight: 700; padding: 3px 6px; flex: 1 1 auto; min-width: 0;
  border: 1px solid var(--accent); border-radius: var(--radius-sm); background: var(--surface);
}
.col-count {
  font-size: 11px; color: var(--text-muted); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; flex: none;
}
.col-tools { display: flex; align-items: center; gap: 2px; flex: none; }
.column-body {
  padding: 10px; display: flex; flex-direction: column; gap: 9px;
  overflow-y: auto; min-height: 64px; flex: 1 1 auto;
}
.column-body.drop-active { background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.empty-col {
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  color: var(--text-faint); font-size: 12px; text-align: center; padding: 16px 8px;
}
.column-foot { padding: 8px 10px; border-top: 1px solid var(--border); }

.drop-indicator {
  height: 2px; background: var(--accent); border-radius: 2px;
  position: relative; flex: none; margin: -3px 0;
}
.drop-indicator::after {
  content: ''; position: absolute; left: -4px; top: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.column-drop-marker {
  flex: 0 0 6px; width: 4px; background: var(--accent); border-radius: 3px;
  align-self: stretch; margin: 0 -3px;
}

/* ------------------------------------------------------------------ card --- */

.card {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: 9px 10px; cursor: grab;
  box-shadow: var(--shadow);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.card:hover { border-color: var(--col-accent, var(--accent)); }
.card.dragging { opacity: 0.4; }
.card-top { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
.proj {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px;
  background: var(--col-accent-soft, var(--accent-soft));
  color: var(--col-accent-text, var(--accent));
  border: 1px solid var(--border);
}
.card-title { font-size: 13.5px; font-weight: 600; line-height: 1.35; margin-bottom: 7px; word-break: break-word; }
.lead { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.lead .blank { color: var(--text-faint); font-style: italic; }
.card-foot { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--border); padding-top: 7px; }
.card-meta {
  display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-faint);
  margin-left: auto; cursor: pointer; background: none; border: 0; padding: 2px 4px; border-radius: 4px;
}
.card-meta:hover { color: var(--accent); background: var(--accent-soft); }
.card-move {
  font-size: 11px; padding: 2px 4px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  flex: 1 1 auto; min-width: 0; max-width: 170px;
}

/* ----------------------------------------------------------------- modal --- */

.overlay {
  position: fixed; inset: 0; background: rgba(8, 12, 20, 0.55);
  display: grid; place-items: center; padding: 20px; z-index: 50;
  backdrop-filter: blur(2px);
}
.modal {
  width: min(760px, 100%); max-height: 90vh; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.modal-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 10px;
}
.modal-head h2 { font-size: 16px; line-height: 1.3; margin-top: 2px; }
.modal-head .sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; background: var(--surface-2);
}
.modal-close { margin-left: auto; }

/* Help modal: static quick-start guide (mirrors docs/USER_GUIDE.md). */
.help-body { font-size: 13.5px; line-height: 1.55; }
.help-body p { margin: 0 0 10px; }
.help-body h3 { font-size: 13px; margin: 16px 0 8px; }
.help-body h3:first-of-type { margin-top: 4px; }
.help-body ol, .help-body ul { margin: 0; padding-left: 22px; display: grid; gap: 7px; }
.help-body li::marker { color: var(--text-muted); }

.kv { display: grid; grid-template-columns: 88px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-muted); font-size: 12px; }
.kv dd { margin: 0; }
.badge-col {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2);
}

/* composer */
.composer { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 10px; background: var(--surface-2); }
.composer textarea {
  width: 100%; border: 0; background: transparent; outline: none; resize: vertical;
  min-height: 62px; font-size: 13px;
}
.composer-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.composer-foot .author-input {
  flex: 1 1 auto; min-width: 0; max-width: 240px;
  padding: 6px 9px; font-size: 12.5px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface);
}
.composer-foot .btn { flex: none; }

/* feed */
.feed { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.feed-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.feed-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; background: var(--surface); }
.feed-item.comment { border-left: 3px solid var(--accent); }
.feed-item.event {
  border-left: 3px solid var(--border-strong); background: var(--surface-2);
  border-style: dashed; padding: 7px 11px;
}
.feed-meta { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-muted); margin-bottom: 4px; }
.feed-item.event .feed-meta { margin-bottom: 2px; }
.feed-author { font-weight: 700; color: var(--text); }
.feed-time { font-variant-numeric: tabular-nums; }
.feed-body { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.feed-item.event .feed-body { color: var(--text-muted); font-size: 12.5px; }
.ev-icon { width: 16px; text-align: center; flex: none; }
.feed-del { margin-left: auto; opacity: 0; }
.feed-item:hover .feed-del { opacity: 1; }
.feed-empty { color: var(--text-faint); font-size: 12px; text-align: center; padding: 12px; }

/* drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); z-index: 60; display: flex; flex-direction: column;
  animation: slide-in 140ms ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0.6; } to { transform: none; } }
.drawer-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.drawer-body { padding: 14px 16px; overflow-y: auto; }

/* toast */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 999px;
  font-size: 13px; box-shadow: var(--shadow-lg); max-width: 90vw;
}
.toast.error { background: var(--danger); color: #fff; }

.hint-bar { padding: 8px 18px; font-size: 12px; color: var(--text-faint); border-top: 1px solid var(--border); background: var(--surface); }
.skeleton { color: var(--text-faint); padding: 40px; text-align: center; }

@media (max-width: 720px) {
  .board { padding: 12px; gap: 12px; }
  :root { --column-w: 84vw; }
  .topbar { padding: 10px 12px; }
  .search { min-width: 140px; }
}
