/* ─── Variables & Reset ──────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --indigo: #6366f1;
  --indigo-dark: #4f46e5;
  --indigo-light: #e0e7ff;
  --green: #22c55e;
  --green-light: #dcfce7;
  --orange: #f97316;
  --orange-light: #ffedd5;
  --red: #ef4444;
  --red-light: #fee2e2;
  --gray: #6b7280;
  --gray-light: #f3f4f6;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --transition: 0.2s ease;

  --nav-h: 68px;
  --fab-size: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --border: #334155;
    --text: #f1f5f9;
    --text-2: #94a3b8;
    --text-3: #475569;
    --gray-light: #1e293b;
    --shadow: 0 2px 12px rgba(0,0,0,.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
    --indigo-light: #312e81;
    --green-light: #14532d;
    --orange-light: #431407;
    --red-light: #450a0a;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px 12px;
  backdrop-filter: blur(12px);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.header-subtitle {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 2px;
}

.header-badge {
  background: var(--indigo);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}

main {
  padding: 16px 16px calc(var(--nav-h) + 24px);
}

/* ─── Empty State ─────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-3);
}

.empty-state svg { opacity: .4; margin-bottom: 16px; }
.empty-state h3 { font-size: 17px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.empty-state p { font-size: 14px; }

/* ─── Task Card ──────────────────────────────────────────────────────────── */

.task-list { display: flex; flex-direction: column; gap: 10px; }

.task-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  touch-action: pan-y;
  user-select: none;
}

.task-card:active { transform: scale(0.99); }
.task-card.done-card { opacity: .65; }
.task-card.done-card .task-title { text-decoration: line-through; color: var(--text-3); }

/* priority stripe */
.task-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: 4px 0 0 4px;
}
.task-card.priority-low::before { background: var(--gray); }
.task-card.priority-medium::before { background: var(--orange); }
.task-card.priority-high::before { background: var(--red); }

/* swipe delete overlay */
.task-card .swipe-delete {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 80px;
  background: var(--red);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 22px;
  transform: translateX(100%);
  transition: transform var(--transition);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.task-checkbox {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  margin: -10px -6px -10px -10px;
}
.task-checkbox::after {
  content: '';
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.task-checkbox.checked::after {
  background: var(--green);
  border-color: var(--green);
}
.task-checkbox svg { display: none; position: absolute; pointer-events: none; }
.task-checkbox.checked svg { display: block; position: absolute; }

.task-body { flex: 1; min-width: 0; }

.task-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.badge-low    { background: var(--gray-light); color: var(--gray); }
.badge-medium { background: var(--orange-light); color: var(--orange); }
.badge-high   { background: var(--red-light); color: var(--red); }
.badge-todo        { background: var(--gray-light); color: var(--gray); }
.badge-in_progress { background: var(--indigo-light); color: var(--indigo); }
.badge-done        { background: var(--green-light); color: var(--green); }

.meta-date {
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 3px;
}
.meta-date.overdue { color: var(--red); }

.meta-reminder {
  font-size: 12px;
  color: var(--indigo);
  display: flex;
  align-items: center;
  gap: 3px;
}

/* Progress bar */
.progress-wrap {
  margin-top: 10px;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 4px;
}
.progress-bar {
  height: 5px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* ─── Bottom Nav ─────────────────────────────────────────────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
  box-shadow: 0 -4px 20px rgba(0,0,0,.06);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: color var(--transition);
  padding: 8px 0;
  position: relative;
}

.nav-btn.active { color: var(--indigo); }
.nav-btn.active svg { stroke: var(--indigo); }

.nav-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.nav-count {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ─── FAB ────────────────────────────────────────────────────────────────── */

.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  right: max(16px, calc(50vw - 224px));
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: var(--indigo);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(99,102,241,.5);
  font-size: 28px;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
  z-index: 25;
}
.fab:active { transform: scale(0.9); }
.fab:hover { background: var(--indigo-dark); }
.fab svg { width: 26px; height: 26px; stroke: #fff; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* ─── Modal / Bottom Sheet ───────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal-sheet {
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 0 0 32px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(.32,.72,0,1);
}

.modal-overlay.open .modal-sheet {
  transform: translateY(0);
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  margin-right: 8px;
  overflow: hidden;
}

.inline-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-close {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--border); }

.modal-body { padding: 20px; }

/* ─── Form ───────────────────────────────────────────────────────────────── */

.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

input[type="text"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition);
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

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

/* Radio-style priority selector */
.priority-group {
  display: flex;
  gap: 8px;
}

.priority-btn {
  flex: 1;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
  color: var(--text-2);
}

.priority-btn.active-low    { border-color: var(--gray); background: var(--gray-light); color: var(--gray); }
.priority-btn.active-medium { border-color: var(--orange); background: var(--orange-light); color: var(--orange); }
.priority-btn.active-high   { border-color: var(--red); background: var(--red-light); color: var(--red); }

/* ─── Submit Btn ─────────────────────────────────────────────────────────── */

.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--indigo);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  margin-top: 8px;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:hover { background: var(--indigo-dark); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-danger {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--red);
  background: transparent;
  color: var(--red);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 8px;
}
.btn-danger:hover { background: var(--red-light); }

/* ─── Detail Modal ───────────────────────────────────────────────────────── */

.detail-desc {
  font-size: 14px;
  color: var(--text-2);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.detail-meta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.subtask-section { margin-top: 8px; }

.subtask-section h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.subtask-list { display: flex; flex-direction: column; gap: 6px; }

.subtask-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.subtask-check {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  margin: -8px -4px -8px -8px;
  position: relative;
}
.subtask-check::after {
  content: '';
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: all var(--transition);
}
.subtask-check.checked::after { background: var(--green); border-color: var(--green); }
.subtask-check svg { display: none; width: 12px; height: 12px; stroke: #fff; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; position: absolute; }
.subtask-check.checked svg { display: block; }

.subtask-title {
  flex: 1;
  font-size: 14px;
  color: var(--text);
}
.subtask-title.done { text-decoration: line-through; color: var(--text-3); }

.subtask-del {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: all var(--transition);
  margin: -8px -8px -8px 0;
}
.subtask-del:hover { background: var(--red-light); color: var(--red); }

.add-subtask-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.add-subtask-row input { flex: 1; }
.add-subtask-btn {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--indigo);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.add-subtask-btn:hover { background: var(--indigo-dark); }

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.detail-actions .btn-primary { margin-top: 0; }
.detail-actions .btn-danger { margin-top: 0; }

/* ─── Notification Toast ─────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.3s ease;
  pointer-events: all;
}

.toast-success { border-left: 4px solid var(--green); }
.toast-error   { border-left: 4px solid var(--red); }
.toast-info    { border-left: 4px solid var(--indigo); }
.toast-undo    { border-left: 4px solid var(--orange); }

.toast-undo-btn {
  margin-left: auto;
  flex-shrink: 0;
  padding: 6px 14px;
  border: none;
  border-radius: 20px;
  background: var(--orange);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.toast-undo-btn:active { opacity: 0.8; }

.toast-progress {
  position: absolute;
  bottom: 0; left: 0;
  height: 3px;
  background: var(--orange);
  border-radius: 0 0 0 var(--radius-sm);
  animation: toastProgress 5s linear forwards;
}

@keyframes toastProgress {
  from { width: 100%; }
  to   { width: 0%; }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Loading Spinner ────────────────────────────────────────────────────── */

.spinner {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner::after {
  content: '';
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--indigo);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Quick Add Sheet ────────────────────────────────────────────────────── */

.quick-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 12px 16px 32px;
  padding-bottom: max(32px, env(safe-area-inset-bottom, 16px));
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), padding-bottom 0.1s ease;
  z-index: 200;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
}

.modal-overlay.open .quick-sheet {
  transform: translateY(0);
}

#quickForm {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

#qTitle {
  flex: 1;
  border: none;
  outline: none;
  font-size: 26px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-1);
  background: transparent;
  padding: 8px 12px;
  caret-color: var(--indigo);
}

#qTitle::placeholder { color: var(--text-3); }

.quick-save-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--indigo);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
}
.quick-save-btn:active { transform: scale(0.9); opacity: 0.8; }

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
