*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Light mode (default) ───────────────────────────────────── */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #f3f4f6;
  --border: #d1d5db;
  --text: #111827;
  --text-dim: #4b5563;
  --text-head: #1f2937;
  --accent: #2563eb;
  --green-bg: #dcfce7;
  --green-text: #166534;
  --blue-bg: #dbeafe;
  --blue-text: #1e40af;
  --amber-bg: #fef9c3;
  --amber-text: #854d0e;
  --red-bg: #fee2e2;
  --red-text: #991b1b;
  --purple-bg: #ede9fe;
  --purple-text: #5b21b6;
  --radius: 6px;
}

/* ── Dark mode ──────────────────────────────────────────────── */
html.dark {
  --bg: #0f1117;
  --surface: #181b24;
  --surface2: #1f2330;
  --border: #2a2d3a;
  --text: #d1d5db;
  --text-dim: #6b7280;
  --text-head: #9ca3af;
  --accent: #3b82f6;
  --green-bg: #0d2e1a;
  --green-text: #4ade80;
  --blue-bg: #0f2340;
  --blue-text: #60a5fa;
  --amber-bg: #2d1f05;
  --amber-text: #fbbf24;
  --red-bg: #2d0f0f;
  --red-text: #f87171;
  --purple-bg: #1e1040;
  --purple-text: #a78bfa;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace; font-size: 13px; }

/* ── Header ─────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: .5px; }
header .subtitle { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ── Buttons ─────────────────────────────────────────────────── */
button { cursor: pointer; border: none; border-radius: var(--radius); font-family: inherit; font-size: 12px; transition: opacity .15s, background .15s; }
button:hover { opacity: .85; }
button:active { opacity: .7; }
.btn-primary { background: var(--accent); color: #fff; padding: 6px 14px; font-weight: 500; }
.btn-ghost { background: var(--surface2); color: var(--text); padding: 6px 12px; border: 1px solid var(--border); }
.btn-danger { background: var(--red-bg); color: var(--red-text); padding: 4px 10px; border: 1px solid #4b1c1c; }
.btn-small { padding: 3px 8px; font-size: 11px; }
.btn-icon { background: transparent; color: var(--text-dim); padding: 2px 6px; font-size: 14px; line-height: 1; border-radius: 4px; }
.btn-icon:hover { background: var(--surface2); color: var(--text); }

/* ── Main layout ─────────────────────────────────────────────── */
main { padding: 20px 24px 60px; }

/* ── Cluster block ───────────────────────────────────────────── */
.cluster {
  margin-bottom: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.cluster-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.cluster-header .drag-handle { color: var(--text-dim); cursor: grab; user-select: none; font-size: 16px; }
.cluster-header .drag-handle:active { cursor: grabbing; }
.cluster-name-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 2px 6px;
  width: 160px;
}
.cluster-name-input:hover { border-color: var(--border); }
.cluster-name-input:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.cluster-meta { color: var(--text-dim); font-size: 11px; margin-left: 4px; }
.hdr-badge { display: inline-block; padding: 3px 10px; border-radius: 4px; font-size: 12px; font-weight: 600; margin-left: 8px; border: 1px solid; }
.hdr-badge-blue  { background: var(--blue-bg);  color: var(--blue-text);  border-color: var(--blue-text); }
.hdr-badge-green { background: var(--green-bg); color: var(--green-text); border-color: var(--green-text); }

/* ── Theme toggle ────────────────────────────────────────────── */
.btn-theme { background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; font-size: 16px; line-height: 1; border-radius: var(--radius); cursor: pointer; transition: background .15s; }
.btn-theme:hover { background: var(--border); }
.cluster-actions { margin-left: auto; display: flex; gap: 6px; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 7px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-head);
  letter-spacing: .8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
thead th:first-child { width: 36px; }
thead th:nth-child(2) { min-width: 130px; }
thead th.col-stuck { min-width: 200px; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody tr.drag-over { background: rgba(59,130,246,.12); outline: 2px dashed var(--accent); outline-offset: -2px; }
tbody tr.dragging { opacity: .4; }

td {
  padding: 5px 8px;
  vertical-align: middle;
  white-space: nowrap;
}
td.col-drag { color: var(--text-dim); cursor: grab; font-size: 14px; text-align: center; width: 28px; }
td.col-drag:active { cursor: grabbing; }
td.col-name { font-weight: 600; color: var(--text); }
td.col-abbr { color: var(--text-dim); font-size: 11px; }
td.col-stuck { white-space: normal; max-width: 280px; }

/* ── Status chip ─────────────────────────────────────────────── */
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  min-width: 36px;
  text-align: center;
  transition: filter .15s;
  border: 1px solid transparent;
}
.chip:hover { filter: brightness(1.25); }
.chip-empty { background: var(--bg);       color: var(--text-dim);   border-color: var(--border); }
.chip-yes  { background: var(--green-bg);  color: var(--green-text); border-color: var(--green-text); }
.chip-date { background: var(--blue-bg);   color: var(--blue-text);  border-color: var(--blue-text); }
.chip-done { background: var(--green-bg);  color: var(--green-text); border-color: var(--green-text); }
.chip-amber{ background: var(--amber-bg);  color: var(--amber-text); border-color: var(--amber-text); }
.chip-red  { background: var(--red-bg);    color: var(--red-text);   border-color: var(--red-text); }

.stuck-text {
  color: var(--amber-text);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.stuck-text:hover { background: var(--amber-bg); }
.stuck-empty { color: var(--text-dim); font-size: 11px; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.stuck-empty:hover { background: var(--surface2); }
.notes-text { color: var(--purple-text); font-size: 11px; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.notes-text:hover { background: var(--purple-bg); }

/* ── Inline edit input ───────────────────────────────────────── */
.cell-input {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  padding: 2px 6px;
  width: 100%;
  min-width: 60px;
  outline: none;
}
.cell-input-wide { min-width: 200px; }

/* ── Add row button ──────────────────────────────────────────── */
.add-row td {
  padding: 6px 10px;
  border-top: 1px dashed var(--border);
}
.add-row button { width: 100%; background: transparent; color: var(--text-dim); font-size: 11px; padding: 4px; border: 1px dashed var(--border); border-radius: 4px; }
.add-row button:hover { color: var(--text); border-color: var(--accent); background: rgba(59,130,246,.06); }

/* ── Progress summary bar ────────────────────────────────────── */
.summary { display: flex; gap: 18px; flex-wrap: wrap; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); font-size: 12px; }
.summary-item { display: flex; align-items: center; gap: 6px; }
.summary-dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-done { background: var(--green-text); }
.dot-partial { background: var(--amber-text); }
.dot-pending { background: var(--border); }

/* ── Toast ───────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 16px;
  font-size: 12px; color: var(--text);
  opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none; z-index: 999;
}
#toast.show { opacity: 1; transform: none; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 200;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 24px; width: 380px; max-width: 95vw;
}
.modal h2 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
.modal label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; margin-top: 12px; }
.modal input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); font-family: inherit;
  font-size: 13px; padding: 7px 10px; outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Cluster drag (outer) ────────────────────────────────────── */
.cluster.drag-over-cluster { outline: 2px dashed var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 3px; opacity: .5; }
