* { box-sizing: border-box; }
:root {
  color-scheme: dark;

  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #20242c;
  --border: rgba(255, 255, 255, .07);
  --border-strong: rgba(255, 255, 255, .12);
  --text: #e8e9ec;
  --text-muted: #8b8f99;
  --text-faint: #666a75;
  --accent-default: #5b8def;
  --accent-default-hover: #4877d6;
  --danger: #e0605a;
  --danger-hover: #c94e49;
  --neutral: #2a2e37;
  --neutral-hover: #343945;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .45);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--neutral); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--neutral-hover); }
* { scrollbar-color: var(--neutral) transparent; scrollbar-width: thin; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title { display: flex; align-items: baseline; gap: 10px; }
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.rate-badge { font-size: 12px; color: var(--text-faint); }
.usd-equiv { font-size: 12px; font-weight: 400; color: var(--text-faint); }
.section-budget .usd-equiv { margin-top: 2px; }
.topbar button {
  margin-left: 8px;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: var(--accent-default);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}
.topbar button:hover { background: var(--accent-default-hover); }
#logout-btn { background: var(--neutral); color: var(--text); }
#logout-btn:hover { background: var(--neutral-hover); }

#board {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.board-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.section-heading {
  margin: 0;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.section-budget { padding: 4px 16px 0; max-width: 280px; }
.section-budget .progress { margin-bottom: 4px; }
.section-budget .numbers { display: flex; align-items: center; gap: 6px; }
.section-budget-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
}
.section-budget-edit-btn:hover { color: var(--text); }
.board {
  display: flex;
  gap: 14px;
  padding: 16px;
  overflow-x: auto;
  align-items: flex-start;
}
.column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 260px;
  max-width: 280px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--accent, #999);
}
.column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px 4px;
}
.column-header h2 { font-size: 15px; margin: 0; font-weight: 600; }
.edit-btn { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--text-muted); }
.edit-btn:hover { color: var(--text); }
.column-summary { padding: 0 14px 10px; }
.progress { background: var(--neutral); border-radius: 4px; height: 8px; overflow: hidden; margin-bottom: 6px; }
.progress-fill { height: 100%; background: var(--accent-default); transition: width .3s; }
.progress-fill.over { background: var(--danger); }
.numbers { font-size: 13px; font-weight: 600; }
.numbers.over { color: var(--danger); }
.period-label { font-size: 11px; color: var(--text-faint); }
.card-list { min-height: 60px; padding: 6px 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: grab;
  font-size: 13px;
}
.card:active { cursor: grabbing; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-amount { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.manual-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--neutral);
  color: var(--text-muted);
  white-space: nowrap;
}
.card-desc { color: var(--text-muted); margin-top: 2px; }
.card-date { color: var(--text-faint); font-size: 11px; margin-top: 4px; }
.archive-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-faint);
  padding: 0;
}
.archive-btn svg { width: 15px; height: 15px; }
.archive-btn:hover { color: var(--text); background: var(--neutral); }
.move-select { display: none; }
.row-dots { display: none; }

.sortable-ghost { opacity: .4; }

.login-page { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--bg); }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 32px;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { font-size: 18px; margin: 0 0 8px; text-align: center; }
.login-card input { padding: 10px; border: 1px solid var(--border-strong); border-radius: 6px; font-size: 14px; background: var(--surface-2); color: var(--text); }
.login-card button { padding: 10px; border: none; border-radius: 6px; background: var(--accent-default); color: #fff; font-weight: 600; cursor: pointer; }
.login-card button:hover { background: var(--accent-default-hover); }
.error { color: var(--danger); font-size: 13px; text-align: center; }
.hidden { display: none; }

dialog { border: none; border-radius: 14px; padding: 0; width: 320px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
#category-form, #period-budget-form, #transaction-form { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
#category-form h2, #period-budget-form h2, #transaction-form h2 { margin: 0; font-size: 16px; }
#category-form label, #period-budget-form label, #transaction-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
#category-form input, #category-form select, #period-budget-form input, #transaction-form input, #transaction-form select { padding: 8px; border: 1px solid var(--border-strong); border-radius: 6px; font-size: 14px; background: var(--surface-2); color: var(--text); }
.color-swatches { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 2px; }
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.dialog-actions button { padding: 8px 14px; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; }
#category-save-btn, #period-budget-save-btn, #transaction-save-btn { background: var(--accent-default); color: #fff; }
#category-save-btn:hover, #period-budget-save-btn:hover, #transaction-save-btn:hover { background: var(--accent-default-hover); }
#category-cancel-btn, #period-budget-cancel-btn, #transaction-cancel-btn { background: var(--neutral); color: var(--text); }
#category-cancel-btn:hover, #period-budget-cancel-btn:hover, #transaction-cancel-btn:hover { background: var(--neutral-hover); }
.danger { background: var(--danger); color: #fff; margin-right: auto; }
.danger:hover { background: var(--danger-hover); }

#archive-dialog { width: 380px; max-height: 80vh; }
.archive-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.archive-header h2 { font-size: 16px; margin: 0; }
#archive-close-btn { padding: 6px 12px; border: none; border-radius: 6px; background: var(--neutral); color: var(--text); cursor: pointer; font-size: 13px; }
#archive-close-btn:hover { background: var(--neutral-hover); }
.archive-list { max-height: 60vh; overflow-y: auto; padding: 12px 20px 20px; display: flex; flex-direction: column; gap: 8px; }
.archive-empty { color: var(--text-muted); font-size: 13px; padding: 12px 0; }
.restore-btn { padding: 3px 8px; border: none; border-radius: 5px; background: var(--accent-default); color: #fff; cursor: pointer; font-size: 12px; }
.restore-btn:hover { background: var(--accent-default-hover); }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topbar-title { width: 100%; }
  .topbar > div { display: flex; gap: 8px; width: 100%; }
  .topbar button { margin-left: 0; }

  .board { scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
  .column { min-width: 100%; max-width: 100%; scroll-snap-align: start; }

  .row-dots { display: flex; justify-content: center; gap: 6px; padding: 6px 0; }
  .row-dot { width: 8px; height: 8px; border-radius: 50%; border: none; background: var(--neutral); padding: 0; }
  .row-dot.active { background: var(--accent-default); }

  .move-select { display: block; width: 100%; margin-top: 6px; padding: 8px; border: 1px solid var(--border-strong); border-radius: 6px; font-size: 13px; background: var(--surface-2); color: var(--text); }

  .edit-btn { font-size: 20px; padding: 6px; }
  .archive-btn { width: 32px; height: 32px; }
  .archive-btn svg { width: 18px; height: 18px; }
  .restore-btn { padding: 8px 14px; font-size: 14px; }
  #archive-close-btn { padding: 10px 16px; font-size: 14px; }

  dialog { width: calc(100vw - 32px); }
  #archive-dialog { width: calc(100vw - 32px); }
}
