/* ==========================================================================
   TodoList — Design System
   ========================================================================== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-hover: #f0f1f4;
  --surface-raised: #ffffff;
  --border: #e4e6ea;
  --text: #14161a;
  --text-muted: #6b7078;
  --text-faint: #9a9ea6;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: #eaf1ff;
  --danger: #ef4444;
  --danger-soft: #fdecec;
  --warning: #f97316;
  --warning-soft: #fff1e6;
  --success: #22c55e;
  --success-soft: #eafbf0;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(20, 22, 26, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 22, 26, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 22, 26, 0.14);

  --transition: 180ms ease;
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --bottomnav-h: 64px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d12;
    --surface: #14161c;
    --surface-hover: #1c1f27;
    --surface-raised: #191c23;
    --border: #262a33;
    --text: #e9eaed;
    --text-muted: #9a9ea6;
    --text-faint: #676c76;
    --primary: #5b9bff;
    --primary-hover: #7bacff;
    --primary-soft: #16233d;
    --danger: #f87171;
    --danger-soft: #33191b;
    --warning: #fb923c;
    --warning-soft: #35230f;
    --success: #4ade80;
    --success-soft: #12301e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0d12;
  --surface: #14161c;
  --surface-hover: #1c1f27;
  --surface-raised: #191c23;
  --border: #262a33;
  --text: #e9eaed;
  --text-muted: #9a9ea6;
  --text-faint: #676c76;
  --primary: #5b9bff;
  --primary-hover: #7bacff;
  --primary-soft: #16233d;
  --danger: #f87171;
  --danger-soft: #33191b;
  --warning: #fb923c;
  --warning-soft: #35230f;
  --success: #4ade80;
  --success-soft: #12301e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { cursor: pointer; background: none; border: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
img, svg { display: block; }

/* ---------- Auth pages ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.auth-logo {
  width: 52px; height: 52px; margin: 0 auto 16px;
  background: var(--primary); color: #fff;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-subtitle { color: var(--text-muted); margin: 0 0 20px; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.auth-form label { font-size: 13px; color: var(--text-muted); margin-top: 10px; }
.auth-form input[type="text"], .auth-form input[type="password"] {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; color: var(--text); min-height: 44px;
}
.auth-form input:focus { border-color: var(--primary); }
.auth-checkbox { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 14px; color: var(--text-muted); }
.auth-checkbox input { width: 18px; height: 18px; }
.btn-primary {
  background: var(--primary); color: #fff; border-radius: var(--radius-sm);
  padding: 13px; font-weight: 600; min-height: 46px; transition: background var(--transition);
}
.btn-primary:hover { background: var(--primary-hover); }
.auth-form .btn-primary { margin-top: 20px; }
.auth-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 12px; }
.auth-success { background: var(--success-soft); color: var(--success); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 12px; }

/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "topbar topbar" "sidebar main";
  height: 100vh;
  height: 100dvh;
}

.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.topbar-logo { width: 30px; height: 30px; background: var(--primary); color: #fff; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.topbar-search { flex: 1; max-width: 420px; }
.topbar-search input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 9px 16px; color: var(--text);
}
.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; position: relative; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.avatar-btn {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.dropdown {
  position: absolute; top: 46px; right: 0; background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); min-width: 200px; padding: 6px; z-index: 40;
}
.dropdown-item { display: block; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; }
.dropdown-item:hover { background: var(--surface-hover); }
.dropdown-item-danger { color: var(--danger); }

.sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-list-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 14px; font-weight: 500; transition: background var(--transition), color var(--transition);
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto; background: var(--surface-hover); color: var(--text-muted); font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: var(--radius-pill); min-width: 18px; text-align: center;
}
.nav-badge:empty { display: none; }
.nav-badge-danger { background: var(--danger-soft); color: var(--danger); }
.nav-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); font-weight: 700; padding: 18px 12px 6px; }
.nav-category-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.main-content {
  grid-area: main;
  overflow-y: auto;
  padding: 28px 32px 100px;
}
.main-content:focus { outline: none; }

/* ---------- View header / sections ---------- */
.view-header { margin-bottom: 22px; }
.view-greeting { font-size: 24px; font-weight: 700; margin: 0 0 2px; }
.view-date { color: var(--text-muted); font-size: 14px; margin: 0; }
.view-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.view-subtitle { color: var(--text-muted); font-size: 14px; margin: 0; }

.stat-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.stat-pill {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 8px 14px; font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px;
}
.stat-pill strong { color: var(--text); font-weight: 700; }

.section { margin-bottom: 28px; }
.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-faint); margin: 0 0 10px; padding: 0 4px; display: flex; align-items: center; gap: 8px;
}
.section-title.section-title-danger { color: var(--danger); }
.section-count { font-weight: 500; color: var(--text-faint); }

.task-list { display: flex; flex-direction: column; gap: 8px; border-radius: var(--radius-md); }
.task-list.drag-over { background: var(--primary-soft); outline: 2px dashed var(--primary); outline-offset: 4px; }

/* ---------- Task item ---------- */
.task-item {
  display: flex; align-items: flex-start; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 13px 14px; position: relative; transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
  touch-action: pan-y;
}
.task-item:hover { box-shadow: var(--shadow-sm); }
.task-item.dragging { opacity: 0.5; }
.task-item.completed .task-title { text-decoration: line-through; color: var(--text-faint); }
.task-item.completed { opacity: 0.65; }
.task-item.overdue .task-when { color: var(--danger); font-weight: 600; }

.task-checkbox {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0; margin-top: 1px;
  display: flex; align-items: center; justify-content: center; color: #fff; transition: all 150ms ease;
}
.task-checkbox svg { opacity: 0; transform: scale(0.5); transition: all 150ms ease; }
.task-item.completed .task-checkbox { background: var(--success); border-color: var(--success); }
.task-item.completed .task-checkbox svg { opacity: 1; transform: scale(1); }
.task-checkbox:active { transform: scale(0.9); }

.task-body { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-size: 14.5px; font-weight: 500; word-break: break-word; }
.task-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.task-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--surface-hover); font-weight: 600; }
.task-when { color: var(--text-faint); }
.task-priority-bar { width: 4px; align-self: stretch; border-radius: 3px; flex-shrink: 0; }

.priority-low .task-priority-bar { background: transparent; }
.priority-normal .task-priority-bar { background: var(--primary); opacity: 0.4; }
.priority-high .task-priority-bar { background: var(--warning); }
.priority-urgent .task-priority-bar { background: var(--danger); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text); margin: 0 0 4px; }
.empty-state-text { font-size: 14px; margin: 0 0 18px; }
.btn-outline {
  border: 1px solid var(--border); background: var(--surface); padding: 10px 18px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; transition: background var(--transition);
}
.btn-outline:hover { background: var(--surface-hover); }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 28px; bottom: 28px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; box-shadow: var(--shadow-lg); display: flex; align-items: center; justify-content: center;
  z-index: 30; transition: transform 150ms ease, background var(--transition);
}
.fab:hover { background: var(--primary-hover); transform: scale(1.05); }
.fab:active { transform: scale(0.95); }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav { display: none; }

/* ---------- Modal / Bottom sheet ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 12, 16, 0.5); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px; animation: fade-in 150ms ease;
}
.modal {
  background: var(--surface-raised); border-radius: var(--radius-lg); width: 100%; max-width: 480px;
  max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop-in 180ms ease;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 16px; margin: 0; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.modal-footer .btn-primary,
.modal-footer .btn-text { padding: 10px 16px; min-height: 40px; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.modal-close:hover { background: var(--surface-hover); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }
.form-control {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 13px; color: var(--text); min-height: 44px;
}
.form-control:focus { border-color: var(--primary); }
textarea.form-control { min-height: 80px; resize: vertical; }
.form-row { display: flex; gap: 10px; }
.form-row > * { flex: 1; }
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface);
  font-size: 13px; font-weight: 600; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; min-height: 38px;
}
.chip.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.chip.chip-danger.active { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.chip.has-value::after { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.qc-toggles { margin-bottom: 18px; }
.qc-section { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 4px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-text { color: var(--text-muted); padding: 10px 14px; border-radius: var(--radius-sm); font-weight: 600; }
.btn-text:hover { background: var(--surface-hover); color: var(--text); }

.task-detail-info { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.task-detail-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); border-bottom: 1px dashed var(--border); padding-bottom: 8px; }
.task-detail-row strong { color: var(--text); font-weight: 600; }
.task-actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- Toasts ---------- */
.toast-root { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #1c1e24; color: #fff; padding: 12px 18px; border-radius: var(--radius-pill); font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 12px; pointer-events: auto; animation: toast-in 200ms ease;
}
.toast-undo { color: #7bacff; font-weight: 700; }
.toast.toast-error { background: #3a1418; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; background: var(--warning); color: #1a1200; text-align: center;
  font-size: 13px; font-weight: 600; padding: 8px; z-index: 300;
}

/* ---------- Category color dot ---------- */
.color-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- Settings ---------- */
.settings-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px; margin-bottom: 18px; max-width: 640px; }
.settings-section h3 { margin: 0 0 14px; font-size: 15px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 12px; }
.settings-row:last-child { border-bottom: none; }
.settings-row-label { font-size: 14px; }
.settings-row-sub { font-size: 12px; color: var(--text-muted); }
.device-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); gap: 12px; }
.device-item:last-child { border-bottom: none; }
.device-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.device-current-badge { font-size: 10px; background: var(--success-soft); color: var(--success); padding: 2px 7px; border-radius: var(--radius-pill); font-weight: 700; }
.device-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.theme-options { display: flex; gap: 10px; }

/* ---------- Category list items (sidebar / management) ---------- */
.category-list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.category-list-item:last-child { border-bottom: none; }
.category-list-item-name { flex: 1; font-size: 14px; font-weight: 500; }

/* ---------- Agenda ---------- */
.agenda-day { margin-bottom: 22px; }
.agenda-day-title { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin: 0 0 10px; }

/* ---------- Loading ---------- */
.loading-spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-inline { display: flex; align-items: center; justify-content: center; padding: 40px; }

/* ---------- Swipe (mobile task actions) ---------- */
.task-item-wrap { position: relative; overflow: hidden; border-radius: var(--radius-md); }
.task-swipe-actions { position: absolute; inset: 0; display: flex; justify-content: flex-end; align-items: stretch; }
.task-swipe-btn { width: 76px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700; flex-direction: column; gap: 4px; }
.task-swipe-btn.complete { background: var(--success); }
.task-swipe-btn.delete { background: var(--danger); }

/* ==========================================================================
   Responsive: tablet & mobile
   ========================================================================== */
@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 84px 1fr; }
  .sidebar .nav-link span:not(.nav-icon):not(.nav-badge) { display: none; }
  .nav-section-title { display: none; }
  #sidebar-categories { display: none; }
  .topbar-search { max-width: 260px; }
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr var(--bottomnav-h);
    grid-template-areas: "topbar" "main" "bottomnav";
  }
  .sidebar { display: none; }
  .main-content { padding: 18px 16px calc(90px + env(safe-area-inset-bottom)); }
  .topbar-search { display: none; }
  .bottom-nav {
    grid-area: bottomnav;
    display: flex; justify-content: space-around; align-items: center;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom); z-index: 30;
  }
  .bottom-nav-item { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--text-faint); font-size: 10px; font-weight: 600; padding: 8px 10px; flex: 1; }
  .bottom-nav-item.active { color: var(--primary); }
  .bn-icon { font-size: 19px; }
  .fab { right: 18px; bottom: calc(var(--bottomnav-h) + 18px + env(safe-area-inset-bottom)); width: 58px; height: 58px; }

  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { max-width: 100%; border-radius: 20px 20px 0 0; max-height: 92vh; animation: sheet-in 220ms ease; }
  @keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }

  .view-greeting { font-size: 21px; }
  .stat-row { gap: 8px; }
  .stat-pill { font-size: 12px; padding: 7px 12px; }
}

@media (max-width: 420px) {
  .main-content { padding: 16px 12px 96px; }
  .task-item { padding: 12px; }
}
