:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e4ea;
  --primary: #4f6df5;
  --primary-dark: #3d56cc;
  --danger: #e5484d;
  --shadow: 0 1px 3px rgba(20, 24, 40, .08), 0 4px 14px rgba(20, 24, 40, .06);
  --radius: 10px;
  --col-1: #28a745;
  --col-2: #e5484d;
  --col-3: #8b5cf6;
  --col-4: #f59e0b;
  --col-5: #06b6d4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
  color: var(--text);
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

.sync-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #c3c7d1;
  display: inline-block;
}
.sync-dot.ok { background: #28a745; }
.sync-dot.err { background: var(--danger); }
.sync-dot.busy { background: #f59e0b; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f1f5; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fdf0f0; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #eef0f4; }
.btn-small { padding: 4px 10px; font-size: 13px; }

/* ---------- views ---------- */
.view { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }

/* ---------- setup ---------- */
.setup-card {
  max-width: 760px;
  margin: 20px auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 36px;
}
.setup-card h1 { margin-top: 0; }
.steps { padding-left: 22px; display: flex; flex-direction: column; gap: 18px; }
.steps li { line-height: 1.6; }

.code-box {
  position: relative;
  margin-top: 8px;
}
.code-box pre {
  background: #14161f;
  color: #d6deeb;
  border-radius: 8px;
  padding: 14px;
  max-height: 240px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
}
.code-box .btn { position: absolute; top: 8px; right: 8px; background: #2a2e3d; color: #fff; border-color: #3a3f52; }
.code-box .btn:hover { background: #3a3f52; }

.callout {
  background: #fff8e6;
  border: 1px solid #f3e2af;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.55;
  margin-top: 10px;
}

.connect-row { display: flex; gap: 8px; margin-top: 8px; }
.connect-row input {
  flex: 1;
  font: inherit;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.connect-status { margin-top: 8px; font-size: 14px; min-height: 20px; }
.connect-status.ok { color: #1d8f3c; }
.connect-status.err { color: var(--danger); }

/* ---------- dashboard ---------- */
.dash-head { display: flex; align-items: center; justify-content: space-between; }
.dash-actions { display: flex; align-items: center; gap: 8px; }
.board-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.board-tile {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color .15s, transform .1s;
  position: relative;
}
.board-tile:hover { border-color: var(--primary); transform: translateY(-2px); }
.board-tile h3 { margin: 0 0 6px; font-size: 16px; }
.board-tile .meta { font-size: 13px; color: var(--muted); }
.board-tile .tile-delete {
  position: absolute; top: 10px; right: 10px;
  opacity: 0;
  border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: 14px;
}
.board-tile:hover .tile-delete { opacity: 1; }
.board-tile .tile-delete:hover { color: var(--danger); }

/* ---------- board ---------- */
.board-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
#board-title {
  margin: 0;
  font-size: 24px;
  padding: 2px 8px;
  border-radius: 6px;
  outline: none;
}
#board-title:hover, #board-title:focus { background: #ecedf2; }
.board-tools { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.sort-toggle { font-size: 14px; color: var(--muted); user-select: none; cursor: pointer; }

.timer { display: flex; align-items: center; gap: 6px; }
.timer-display {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 16px;
  min-width: 56px;
  text-align: center;
}
.timer-display.done { color: var(--danger); animation: pulse 0.8s infinite; }
#timer-min { width: 52px; font: inherit; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; }

.columns {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 1fr);
  gap: 16px;
  margin-top: 20px;
  align-items: start;
  overflow-x: auto;
  padding-bottom: 20px;
}

.column {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
}
.column.drag-over { outline: 2px dashed var(--primary); outline-offset: -2px; }

.column-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  padding: 2px 4px;
}
.column-head .dot { width: 10px; height: 10px; border-radius: 50%; }
.column-head .count { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 13px; }

.add-card-form textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  resize: none;
  min-height: 38px;
}
.add-card-form textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }

.card {
  background: #fbfbfd;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent, var(--primary));
  border-radius: 8px;
  padding: 10px 12px;
  cursor: grab;
}
.card.dragging { opacity: .5; }
.card .card-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.45; }
.card .card-text[contenteditable="true"]:focus { outline: 2px solid var(--primary); border-radius: 4px; }
.card-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}
.card-foot .author { margin-right: auto; font-size: 12px; }
.vote-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 2px 10px;
  cursor: pointer;
  font-size: 13px;
}
.vote-btn:hover { border-color: var(--primary); }
.vote-btn.voted { background: var(--primary); border-color: var(--primary); color: #fff; }
.icon-btn { border: none; background: none; cursor: pointer; color: var(--muted); padding: 2px 4px; }
.icon-btn:hover { color: var(--danger); }

/* ---------- modals ---------- */
dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 28px;
  width: min(440px, 92vw);
}
dialog::backdrop { background: rgba(20, 24, 40, .45); }
dialog h2 { margin-top: 0; }
dialog form { display: flex; flex-direction: column; gap: 14px; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
dialog input, dialog select {
  font: inherit;
  font-weight: 400;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---------- skeleton loading ---------- */
.skeleton {
  background: linear-gradient(90deg, #e9eaef 25%, #f3f4f7 50%, #e9eaef 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.board-tile.sk { cursor: default; pointer-events: none; }
.column .skeleton + .skeleton { margin-top: 10px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2430;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 100;
}
