:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --line: #d4d4d0;
  --line-strong: #1f1f1f;
  --text: #1f1f1f;
  --muted: #6b6b66;
  --link: #0b57d0;
  --accent: #0b57d0;
  --danger: #b3261e;
  --excluded: #9a9a94;
  --radius: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
a:hover { text-decoration-thickness: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
  position: sticky;
  top: 0;
  z-index: 5;
}

.board-title {
  font-size: 20px;
  font-weight: 650;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 4px 6px;
  background: transparent;
  min-width: 0;
  flex: 1 1 200px;
}
.board-title:hover, .board-title:focus { border-color: var(--line); outline: none; }

.topbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

.total strong { font-size: 18px; font-variant-numeric: tabular-nums; }

.currency { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.currency input { width: 4.5em; padding: 4px 6px; border: 1px solid var(--line); border-radius: var(--radius); text-transform: uppercase; }

.toggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.toggle button { border: 0; background: var(--surface); padding: 5px 12px; cursor: pointer; }
.toggle button + button { border-left: 1px solid var(--line-strong); }
.toggle button.active { background: var(--line-strong); color: #fff; }

.save-status { color: var(--muted); font-size: 13px; min-width: 4.5em; }
.save-status.error { color: var(--danger); }
.viewers { color: #1e7d32; font-size: 13px; white-space: nowrap; }

.hidden-note { color: var(--muted); font-size: 12px; padding: 0 10px 6px; }

.hint { margin: 10px 16px 0; color: var(--muted); font-size: 13px; }

.btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 5px 12px;
  cursor: pointer;
}
.btn:hover { background: #ececea; }
.btn.primary { background: var(--line-strong); color: #fff; }
.btn.primary:hover { background: #3a3a3a; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 2px 6px; }
.btn.ghost:hover { color: var(--text); background: #ececea; }

/* ---------- board ---------- */
.board { padding: 16px; display: flex; gap: 16px; align-items: flex-start; }
.board.columns { flex-direction: row; overflow-x: auto; min-height: calc(100vh - 110px); }
.board.rows { flex-direction: column; align-items: stretch; }

.section {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
}
/* A section is as wide as its lanes of cards. */
.board.columns .section { flex: 0 0 auto; min-width: 298px; }

/* Drag a card's right edge to resize its lane; double-click resets. */
.resizer {
  position: absolute;
  top: 0;
  right: -6px;
  width: 11px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
  touch-action: none;
}
.resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 5px;
  width: 1px;
}
.resizer:hover::after, .resizer.active::after { background: var(--accent); width: 3px; left: 4px; }
body.resizing { cursor: col-resize; user-select: none; }
.section.dragging { opacity: 0.4; }

.section-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 4px;
  border-bottom: 1px solid var(--line);
}

.handle {
  cursor: grab;
  color: var(--muted);
  padding: 2px 4px;
  user-select: none;
  line-height: 1;
  font-size: 16px;
}
.handle:active { cursor: grabbing; }

.section-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 3px 5px;
  background: transparent;
}
.section-title:hover, .section-title:focus { border-color: var(--line); outline: none; }

.section-sum { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.cards {
  padding: 8px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 56px;
  overflow-x: auto;
}

/* A lane is one vertical stack of cards inside a section. */
.lane { display: flex; flex-direction: column; gap: 8px; flex: 0 0 auto; max-width: 100%; min-height: 40px; }

/* Only shown while dragging a card: drop here to start a new lane. */
.lane-new { display: none; }
body.dragging-card .lane-new {
  display: flex;
  width: auto !important;
  min-width: 48px;
  align-self: stretch;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
}

.add-card { margin: 0 8px 8px; align-self: flex-start; }

/* ---------- cards ---------- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  cursor: grab;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card:hover { border-color: #a9a9a4; border-left-color: var(--line-strong); }
.card.dragging { opacity: 0.4; }
.card.excluded { border-left-color: var(--excluded); }
.card.excluded .card-price { color: var(--excluded); text-decoration: line-through; }

.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-title { font-weight: 600; overflow-wrap: anywhere; }
.card-price { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card-link { font-size: 13px; }
.card-desc { font-size: 13px; color: #3d3d3a; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-actions { display: flex; justify-content: flex-end; gap: 4px; margin-top: 2px; }
.card-actions input { margin: 0; }
.card-actions label { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin-right: auto; cursor: pointer; }

.placeholder {
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  min-height: 48px;
  background: #eef3fd;
}
.board.columns .section-placeholder { align-self: stretch; }
.board.rows .section-placeholder { min-height: 80px; }

.empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0;
  width: min(480px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
dialog input[type="text"], dialog input[type="number"], dialog textarea, dialog select {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 9px;
  background: var(--surface);
  font-size: 15px;
  color: var(--text);
}
dialog input:focus, dialog textarea:focus, dialog select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
dialog textarea { resize: vertical; }
.dialog-actions { display: flex; gap: 8px; }
.spacer { flex: 1; }

@media (max-width: 600px) {
  .board.columns { flex-direction: column; align-items: stretch; }
  .board.columns .section { min-width: 0; flex: none; }
  .cards { flex-wrap: wrap; }
  .lane { width: 100% !important; }
  .resizer { display: none; }
}
