:root {
  --bg: #0a0a0b;
  --surface: #131316;
  --surface-2: #1c1c21;
  --border: #26262d;
  --text: #f4f4f5;
  --muted: #8a8a93;
  --accent: #a78bfa;
  --accent-soft: rgba(167, 139, 250, 0.12);
  --done: #4ade80;
  --danger: #f87171;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior: none;
}

button { font-family: inherit; }
input, button { font: inherit; color: inherit; }
.hidden { display: none !important; }

.screen { min-height: 100vh; }

/* ======= LOGIN ======= */
.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}
.logo {
  font-size: 36px;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
}
.login-card h1 {
  margin: 0 0 16px 0;
  text-align: center;
  font-weight: 600;
  letter-spacing: -0.5px;
}
.login-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.15s;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  background: var(--accent);
  color: #0a0a0b;
  border: 0;
  border-radius: 12px;
  padding: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.login-card button:hover { opacity: 0.9; }
.error { color: var(--danger); font-size: 14px; min-height: 18px; text-align: center; }

/* ======= APP LAYOUT ======= */
#app { max-width: 640px; margin: 0 auto; padding: 0 16px 100px; padding-top: env(safe-area-inset-top); }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 0 12px;
  position: sticky;
  top: 0;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
  z-index: 10;
}
.date-pill-wrap {
  flex: 1;
  position: relative;
}
.date-pill {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s;
}
.date-pill:hover { background: var(--surface-2); }
.date-picker-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
  font-size: 16px;
  background: transparent;
  color: transparent;
}
.date-picker-input::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 42px;
  height: 42px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.icon-btn.ghost:hover { background: var(--surface); color: var(--text); }

/* ======= PROGRESS ======= */
.progress-wrap {
  padding: 0 4px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.progress-wrap.hidden { display: none !important; }
.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--done));
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease-out;
}
.progress-text {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.progress-fill.full { background: var(--done); }

/* ======= TASK CARDS ======= */
.task-section { display: flex; flex-direction: column; gap: 6px; }

.task-group {
  margin-top: 18px;
}
.task-group:first-child { margin-top: 0; }
.task-group-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 4px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.task-group-title .group-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.swipe-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
}
.swipe-actions {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  pointer-events: none;
}
.swipe-action {
  flex: 1;
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  color: #0a0a0b;
  padding: 0 22px;
}
.swipe-action.complete {
  background: var(--done);
  justify-content: flex-start;
}
.swipe-action.delete {
  background: var(--danger);
  justify-content: flex-end;
}

.task {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  user-select: none;
  touch-action: pan-y;
}
.task:hover { background: var(--surface-2); }
.task:active { transform: scale(0.99); }
.task.dragging { transition: none; }

.cat-stripe {
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 2px;
}

.checkbox {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s;
}
.task.done .checkbox {
  background: var(--done);
  border-color: var(--done);
}
.task.done .checkbox::after {
  content: '✓';
  color: #0a0a0b;
  font-size: 13px;
  font-weight: 800;
}

.task-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.task-title {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
}
.task.done .task-title {
  text-decoration: line-through;
  color: var(--muted);
}
.task-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.time-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12px;
}
.cat-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.cat-badge .cat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}
.recur-badge {
  font-size: 11px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.task-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.task:hover .task-actions { opacity: 1; }
@media (hover: none) { .task-actions { opacity: 1; } }
.mini-btn {
  background: transparent;
  border: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mini-btn:hover { background: var(--bg); color: var(--text); }

.completed-toggle {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px 4px 8px;
  font-weight: 600;
}
.completed-toggle:hover { color: var(--text); }
.chevron { transition: transform 0.2s; display: inline-block; }
.completed-toggle.open .chevron { transform: rotate(180deg); }

.empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 48px; opacity: 0.3; margin-bottom: 12px; }

/* ======= FAB ======= */
.fab {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: #0a0a0b;
  border: 0;
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(167, 139, 250, 0.35);
  transition: transform 0.15s;
  z-index: 50;
}
.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(0.95); }

/* ======= MODAL ======= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 0.22s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@media (min-width: 600px) {
  .modal { align-items: center; padding: 24px; }
  .modal-card { border-radius: 20px; border-bottom: 1px solid var(--border); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field > span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.field em {
  font-style: normal;
  opacity: 0.7;
  font-size: 12px;
}
.field input, .field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  font-family: inherit;
  resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.segmented button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}
.segmented button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.segmented button:hover:not(.active) { background: var(--surface-2); color: var(--text); }

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.weekdays button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 4px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  transition: all 0.15s;
}
.weekdays button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}
.spacer { flex: 1; }
.btn-primary {
  background: var(--accent);
  color: #0a0a0b;
  border: 0;
  border-radius: 12px;
  padding: 12px 22px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 500;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-ghost.danger:hover { color: var(--danger); }

/* ======= SUBTASKS ======= */
.subtasks-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.subtask-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px 6px 12px;
}
.subtask-check {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.subtask-check.done {
  background: var(--done);
  border-color: var(--done);
}
.subtask-check.done::after {
  content: '✓';
  color: #0a0a0b;
  font-size: 11px;
  font-weight: 800;
}
.subtask-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  padding: 6px 0;
  font-size: 14px;
  color: var(--text);
}
.subtask-input.done { text-decoration: line-through; color: var(--muted); }
.subtask-remove {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 16px;
}
.subtask-remove:hover { background: var(--surface-2); color: var(--danger); }
.add-subtask-btn {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.add-subtask-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.subtask-progress {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.notes-badge {
  font-size: 11px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.inline-subtasks {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 16px 12px 52px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  margin-top: -14px;
  position: relative;
  z-index: 0;
}
.inline-subtask {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  transition: background 0.12s;
}
.inline-subtask:hover { background: var(--surface-2); }
.inline-subtask-check {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.inline-subtask-check.done {
  background: var(--done);
  border-color: var(--done);
}
.inline-subtask-check.done::after {
  content: '✓';
  color: #0a0a0b;
  font-size: 10px;
  font-weight: 800;
}
.inline-subtask-text {
  font-size: 14px;
  color: var(--text);
  word-break: break-word;
  line-height: 1.3;
}
.inline-subtask.done .inline-subtask-text {
  text-decoration: line-through;
  color: var(--muted);
}

/* ======= SEARCH ======= */
.search-card {
  padding: 16px;
  gap: 12px;
}
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 8px 4px 14px;
}
.search-bar input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  padding: 12px 0;
  font-size: 16px;
}
.search-icon { color: var(--muted); font-size: 18px; }
.search-results {
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.search-result:hover { background: var(--surface-2); }
.search-result.done .search-result-title { text-decoration: line-through; color: var(--muted); }
.search-result-title { flex: 1; font-size: 15px; min-width: 0; word-break: break-word; }
.search-result-date {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.search-empty { text-align: center; padding: 24px; color: var(--muted); font-size: 14px; }

/* ======= MENU ======= */
.menu-card {
  padding: 12px;
  gap: 4px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: transparent;
  border: 0;
  padding: 14px 12px;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--text);
  transition: background 0.15s;
}
.menu-item:hover { background: var(--bg); }
.menu-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--accent);
  flex-shrink: 0;
}
.menu-title { font-size: 15px; font-weight: 500; }
.menu-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ======= TOAST ======= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: toastIn 0.2s ease-out;
  max-width: calc(100% - 32px);
  text-align: center;
}
@keyframes toastIn {
  from { transform: translate(-50%, 16px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
