:root {
  --accent: #3B82F6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --bg: #F2F2F7;
  --surface: #FFFFFF;
  --surface-2: #F7F7FA;
  --border: #E5E5EA;
  --text: #1C1C1E;
  --text-secondary: #6B6B70;
  --danger: #EF4444;
  --success: #22C55E;
  --overdue: #EF4444;
  --warn: #F97316;
  --shadow: 0 8px 24px rgba(0,0,0,0.12);
  --cat-blue: #3B82F6;
  --cat-purple: #8B5CF6;
  --cat-orange: #F97316;
  --cat-pink: #EC4899;
  --cat-teal: #14B8A6;
  --cat-indigo: #6366F1;
  --cat-green: #22C55E;
  --cat-brown: #A16207;
  --cat-gray: #8E8E93;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1C1C1E;
    --surface-2: #2C2C2E;
    --border: #38383A;
    --text: #F2F2F7;
    --text-secondary: #9A9AA0;
    --accent-soft: rgba(59, 130, 246, 0.22);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app {
  max-width: 900px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 {
  flex: 1;
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  text-align: center;
}
.topbar-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  background: none;
  border: none;
  padding: 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }

.text-btn {
  background: none;
  border: none;
  font-size: 14px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text);
}
.text-btn.primary { color: var(--accent); font-weight: 600; }

/* Tabs */
.tabbar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 48px;
  z-index: 19;
}
.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tab-btn svg { width: 16px; height: 16px; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.body-shell { flex: 1; display: flex; position: relative; min-height: 0; }

/* Drawer */
.drawer-scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 29;
}
.drawer-scrim.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: 280px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(-100%);
  transition: transform .25s ease;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.drawer.open { transform: translateX(0); }
.drawer-head { font-size: 18px; font-weight: 700; padding: 20px 20px 12px; border-bottom: 1px solid var(--border); }
.drawer-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.drawer-add {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: var(--accent);
  font-size: 14px; font-weight: 500; padding: 12px 20px; cursor: pointer;
}
.drawer-add svg { width: 16px; height: 16px; }

.drawer-row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px 9px 20px;
  cursor: pointer;
  border-radius: 8px;
  margin: 0 6px;
}
.drawer-row:hover { background: var(--surface-2); }
.drawer-row.selected { background: var(--accent-soft); }
.drawer-row.drop-target { background: var(--accent-soft); outline: 2px dashed var(--accent); }
.drawer-row .chevron { width: 14px; height: 14px; flex-shrink: 0; color: var(--text-secondary); cursor: pointer; }
.drawer-row .chevron.empty { visibility: hidden; }
.drawer-row .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.drawer-row .name { flex: 1; font-size: 15px; }
.drawer-row.selected .name { font-weight: 600; }
.drawer-row .count { font-size: 13px; color: var(--text-secondary); }
.drawer-row .add-child {
  background: none; border: none; color: var(--text-secondary);
  width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.drawer-row .add-child svg { width: 11px; height: 11px; }

@media (min-width: 760px) {
  .drawer-scrim { display: none; }
  .drawer {
    position: sticky;
    transform: none;
    top: 96px;
    height: calc(100vh - 96px);
    box-shadow: none;
    border-right: 1px solid var(--border);
  }
}

/* Main content */
.content { flex: 1; min-width: 0; padding-bottom: 110px; }

.active-filter-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 6px;
  font-size: 13px; font-weight: 500;
}

.empty-state {
  text-align: center; color: var(--text-secondary); padding: 60px 24px; font-size: 14px;
}
.empty-state .pill-btn { margin-top: 12px; }

/* List view */
.group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 16px 16px 6px;
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
}
.group-header .dot { width: 8px; height: 8px; border-radius: 50%; }
.group-body { background: var(--surface); }

.todo-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.todo-row:last-child { border-bottom: none; }
.check-btn {
  background: none; border: none; padding: 0; margin-top: 1px; cursor: pointer;
  color: var(--text-secondary); flex-shrink: 0;
}
.check-btn.done { color: var(--success); }
.check-btn svg { width: 22px; height: 22px; }
.todo-main { flex: 1; min-width: 0; cursor: pointer; }
.todo-title { font-size: 15px; word-break: break-word; }
.todo-title.done { color: var(--text-secondary); text-decoration: line-through; }
.todo-notes { font-size: 12px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.todo-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.meta-chip { display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--text-secondary); }
.meta-chip svg { width: 12px; height: 12px; }
.meta-chip.overdue { color: var(--overdue); }
.meta-chip.reminder { color: var(--warn); }
.meta-cat { font-size: 10px; font-weight: 500; color: var(--text-secondary); background: var(--surface-2); padding: 2px 6px; border-radius: 8px; }
.swipe-delete { background: none; border: none; color: var(--danger); padding: 4px; cursor: pointer; flex-shrink: 0; }
.swipe-delete svg { width: 18px; height: 18px; }

/* Board view */
.board-layout { padding: 16px; overflow-x: auto; }
.board-columns { display: flex; gap: 12px; align-items: flex-start; }
.board-column {
  width: 220px; flex-shrink: 0;
  background: var(--surface-2);
  border-radius: 16px;
  padding: 12px;
}
.board-column-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.board-column-head .dot { width: 8px; height: 8px; border-radius: 50%; }
.board-column-head .title { flex: 1; font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-column-head .count { font-size: 12px; color: var(--text-secondary); }
.board-cards { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.board-card {
  background: var(--surface); border-radius: 10px; padding: 10px;
  display: flex; gap: 8px; align-items: flex-start; cursor: pointer;
}
.board-card .check-btn svg { width: 18px; height: 18px; }
.board-card-title { font-size: 13px; }
.board-card-title.done { color: var(--text-secondary); text-decoration: line-through; }
.board-card-notes { font-size: 10px; color: var(--text-secondary); margin-top: 4px; }
.board-add-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; margin-top: 8px; padding: 8px; border-radius: 10px;
  background: var(--surface); border: none; color: var(--text-secondary);
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.board-add-btn svg { width: 14px; height: 14px; }
.board-add-section {
  width: 120px; height: 120px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: none; border: 1px dashed var(--border); border-radius: 16px;
  color: var(--text-secondary); font-size: 13px; font-weight: 500; cursor: pointer; margin-top: 4px;
}

/* Calendar */
.cal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px 8px; }
.cal-header span { font-size: 17px; font-weight: 700; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); padding: 0 16px; }
.cal-weekdays span { text-align: center; font-size: 12px; font-weight: 500; color: var(--text-secondary); padding: 4px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; padding: 4px 16px 8px; }
.cal-cell { height: 44px; }
.cal-day-btn {
  width: 100%; height: 100%; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--text);
}
.cal-day-num {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.cal-day-btn.today .cal-day-num { color: var(--accent); font-weight: 700; }
.cal-day-btn.selected .cal-day-num { background: var(--accent); color: white; }
.cal-day-dot { width: 5px; height: 5px; border-radius: 50%; background: transparent; }
.cal-day-dot.has-items { background: var(--warn); }

.agenda-list { background: var(--surface); margin-top: 8px; }
.agenda-header { padding: 14px 16px 6px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.agenda-header.overdue { color: var(--overdue); }
.agenda-row { display: flex; align-items: flex-start; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.agenda-main { flex: 1; min-width: 0; }
.agenda-cat { font-size: 11px; color: var(--text-secondary); text-align: right; flex-shrink: 0; }
.agenda-empty { padding: 12px 16px 18px; font-size: 13px; color: var(--text-secondary); }

/* FAB / status bar */
.fab {
  position: fixed; right: 20px; bottom: 76px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: white; border: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25); cursor: pointer; z-index: 15;
}
.fab svg { width: 24px; height: 24px; stroke-width: 2.4; }

.statusbar {
  position: sticky; bottom: 0;
  text-align: center; font-size: 13px; color: var(--text-secondary);
  padding: 10px; background: var(--surface); border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

/* Sheets (modals) */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 39;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 900px; margin: 0 auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform .25s ease;
  z-index: 40;
  max-height: 88vh;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.open { transform: translateY(0); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-size: 15px; font-weight: 600;
}
.sheet-body { padding: 16px; overflow-y: auto; }

.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin: 16px 0 6px; text-transform: uppercase; letter-spacing: 0.3px; }
.field-label.small { text-transform: none; margin-top: 12px; }
.field-label:first-child { margin-top: 0; }
.field-row { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 0; }
.field-row .field-label { margin: 0; }

.text-input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 15px;
}
.text-input.small { width: auto; }
textarea.text-input { resize: vertical; }
.indented-fields { padding-left: 4px; margin-top: 8px; display: flex; flex-direction: column; gap: 10px; }
.custom-reminder-row { display: flex; gap: 8px; }
.custom-reminder-row input { width: 80px; }
.custom-reminder-row select { flex: 1; }
.hint { font-size: 11px; color: var(--text-secondary); margin: 2px 0 0; }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--border); border-radius: 26px; transition: .2s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; background: white; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.danger-btn {
  width: 100%; margin-top: 24px; padding: 12px; border-radius: 12px;
  background: none; border: 1px solid var(--danger); color: var(--danger);
  font-size: 14px; font-weight: 600; cursor: pointer;
}

.pill-btn {
  padding: 8px 16px; border-radius: 20px; border: 1px solid var(--accent);
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer;
}

.layout-options { display: flex; gap: 12px; }
.layout-option {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary); cursor: pointer; font-size: 13px; font-weight: 500;
}
.layout-option svg { width: 26px; height: 26px; }
.layout-option.active { border-color: var(--accent); border-width: 2px; color: var(--accent); }
.layout-option.active .layout-label { color: var(--text); }

.sheet.small { max-height: 60vh; }

/* Prompt dialog */
.prompt-dialog {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.9);
  width: min(320px, 88vw);
  background: var(--surface); border-radius: 16px; padding: 20px;
  opacity: 0; pointer-events: none; transition: all .15s ease; z-index: 50;
}
.prompt-dialog.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.prompt-dialog h3 { margin: 0 0 12px; font-size: 16px; }
.prompt-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Utility: category color dots inherit via inline style */
