/* ---------------------------------------------------------------- tokens */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --border: #e3e6eb;
  --border-strong: #cdd3db;
  --text: #16191f;
  --text-muted: #656e7d;
  --text-faint: #8b94a3;

  --accent: #2f6df6;
  --accent-text: #ffffff;
  --accent-soft: #e8effe;

  --overdue: #d5372f;
  --overdue-soft: #fdeceb;
  --soon: #b26a00;
  --soon-soft: #fdf3e2;
  --ok: #1c8555;
  --ok-soft: #e6f5ee;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);

  --cat-slate: #64748b;
  --cat-rose: #e11d63;
  --cat-orange: #ea6a0b;
  --cat-amber: #c98a04;
  --cat-green: #16a34a;
  --cat-teal: #0d9488;
  --cat-blue: #2563eb;
  --cat-violet: #7c3aed;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #1e232c;
    --border: #272d37;
    --border-strong: #39414e;
    --text: #e8eaee;
    --text-muted: #9aa3b2;
    --text-faint: #6d7686;

    --accent: #5b8dff;
    --accent-text: #0e1116;
    --accent-soft: #1b2740;

    --overdue: #ff7b72;
    --overdue-soft: #2e1a1a;
    --soon: #e3a008;
    --soon-soft: #2c2415;
    --ok: #46c48a;
    --ok-soft: #14261f;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);

    --cat-slate: #94a3b8;
    --cat-rose: #f472a6;
    --cat-orange: #fb923c;
    --cat-amber: #fbbf24;
    --cat-green: #4ade80;
    --cat-teal: #2dd4bf;
    --cat-blue: #60a5fa;
    --cat-violet: #a78bfa;
  }
}

/* ------------------------------------------------------------------ base */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.011em;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }

p { margin: 0; }

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

button {
  font: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.app-loading::after {
  content: "";
  display: block;
  margin: 30vh auto;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --------------------------------------------------------------- layout */

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.0625rem;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 1.25rem; }

.nav {
  display: flex;
  gap: 2px;
  margin-right: auto;
}

.nav a {
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 550;
  font-size: 0.9375rem;
}
.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.nav a.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.main {
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.page-head .subtitle {
  color: var(--text-muted);
  font-size: 0.9375rem;
  margin-top: 3px;
}

.section {
  margin-bottom: 32px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2 { font-size: 1rem; }

.section-head .hint {
  font-size: 0.8125rem;
  color: var(--text-faint);
}

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 88%, black);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-danger {
  border-color: transparent;
  background: transparent;
  color: var(--overdue);
}
.btn-danger:hover:not(:disabled) { background: var(--overdue-soft); }

.btn-sm { padding: 5px 10px; font-size: 0.875rem; }
.btn-block { width: 100%; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad { padding: 18px; }

/* ------------------------------------------------------------ stat chips */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  margin-bottom: 28px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: var(--shadow);
  text-align: left;
  display: block;
  width: 100%;
  transition: border-color 0.12s, transform 0.08s;
}
button.stat:hover { border-color: var(--border-strong); }
button.stat:active { transform: translateY(1px); }
.stat.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.stat-value {
  font-size: 1.75rem;
  font-weight: 680;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.stat.overdue .stat-value { color: var(--overdue); }
.stat.due_soon .stat-value { color: var(--soon); }
.stat.ok .stat-value { color: var(--ok); }

/* ----------------------------------------------------------- task rows */

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

.task {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--cat, var(--border-strong));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.task:hover { box-shadow: var(--shadow-lg); }

.task-check {
  flex: none;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.task-body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  font: inherit;
  color: inherit;
}

.task-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.task-name {
  font-weight: 600;
  letter-spacing: -0.008em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 3px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.task-meta .sep { color: var(--text-faint); }

.task-actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.task.is-archived { opacity: 0.6; }

/* progress bar */

.progress {
  margin-top: 8px;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--ok);
  transition: width 0.3s ease;
}
.progress-fill.due_soon { background: var(--soon); }
.progress-fill.overdue { background: var(--overdue); }

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.overdue { background: var(--overdue-soft); color: var(--overdue); }
.badge.due_soon { background: var(--soon-soft); color: var(--soon); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.neutral { background: var(--surface-2); color: var(--text-muted); }

.cat-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8125rem;
  color: var(--cat, var(--text-muted));
  font-weight: 550;
}
.cat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cat, var(--text-faint));
  flex: none;
}

/* ------------------------------------------------------ suggestion cards */

.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(258px, 1fr));
  gap: 12px;
}

.suggestion {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--cat, var(--border-strong));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.suggestion-name {
  font-weight: 620;
  letter-spacing: -0.01em;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  font-size: 1rem;
  color: inherit;
}
.suggestion-name:hover { color: var(--accent); }
.suggestion-why {
  font-size: 0.8125rem;
  color: var(--text-muted);
  flex: 1;
}
.suggestion-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* -------------------------------------------------------------- timeline */

.timeline {
  position: relative;
  padding-left: 22px;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border);
}

.timeline-day + .timeline-day { margin-top: 18px; }

.timeline-date {
  font-size: 0.8125rem;
  font-weight: 620;
  color: var(--text-muted);
  margin-bottom: 6px;
  position: relative;
}
.timeline-date::before {
  content: "";
  position: absolute;
  left: -21px;
  top: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
  border: 2px solid var(--bg);
}

.timeline-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.timeline-entry + .timeline-entry { margin-top: 6px; }
.timeline-entry .entry-name {
  font-weight: 550;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 550;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.timeline-entry .entry-name:hover { color: var(--accent); }
.timeline-entry .entry-notes {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-left: auto;
  text-align: right;
  max-width: 45%;
}

/* ----------------------------------------------------------------- forms */

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.field .help {
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 8px 11px;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
textarea { resize: vertical; min-height: 66px; }

.field-row {
  display: flex;
  gap: 10px;
}
.field-row > * { flex: 1; }

.form-error {
  padding: 9px 12px;
  margin-bottom: 14px;
  background: var(--overdue-soft);
  color: var(--overdue);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}
.form-actions .spacer { margin-right: auto; }

/* preset interval chips */

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.preset {
  padding: 4px 10px;
  font-size: 0.8125rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
}
.preset:hover { background: var(--surface-2); color: var(--text); }
.preset.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px 16px;
  overflow-y: auto;
  animation: fade 0.14s ease;
}

@keyframes fade { from { opacity: 0; } }

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.16s ease;
}
.modal.modal-wide { max-width: 640px; }

@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 0;
}
.modal-head .modal-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 3px;
}
.modal-body { padding: 16px 20px 20px; }
.modal-close {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 1.25rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

/* ---------------------------------------------------------------- toast */

#toast-root {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 550;
  pointer-events: auto;
  animation: rise 0.16s ease;
}
.toast button {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  padding: 0;
  opacity: 0.85;
}
.toast.error { background: var(--overdue); color: #fff; }

/* -------------------------------------------------------------- filters */

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.toolbar .search { flex: 1; min-width: 190px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  padding: 5px 11px;
  font-size: 0.875rem;
  font-weight: 550;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
}
.chip:hover { background: var(--surface-2); }
.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.bulk-bar {
  position: sticky;
  bottom: 16px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.bulk-bar .count { font-weight: 600; margin-right: auto; }
.bulk-bar input[type="date"] { width: auto; }

/* --------------------------------------------------------- empty states */

.empty {
  padding: 44px 24px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
}
.empty h3 { margin-bottom: 6px; color: var(--text); }
.empty p { font-size: 0.9375rem; margin-bottom: 16px; }
.empty-icon { font-size: 2rem; display: block; margin-bottom: 10px; }

/* ------------------------------------------------------------ task page */

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 20px;
  align-items: start;
}

.stat-rows { display: flex; flex-direction: column; gap: 2px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: 0; }
.stat-row dt { color: var(--text-muted); }
.stat-row dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.history-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9375rem;
}
.history-entry:last-child { border-bottom: 0; }
.history-entry .when { font-weight: 600; min-width: 108px; }
.history-entry .ago { color: var(--text-muted); font-size: 0.8125rem; }
.history-entry .gap {
  margin-left: auto;
  font-size: 0.8125rem;
  color: var(--text-faint);
  white-space: nowrap;
}
.history-entry .note {
  font-size: 0.8125rem;
  color: var(--text-muted);
  flex: 1;
}

/* --------------------------------------------------------- auth screen */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 396px; }
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head .mark { font-size: 2.25rem; display: block; margin-bottom: 8px; }
.auth-head p { color: var(--text-muted); margin-top: 6px; font-size: 0.9375rem; }
.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 760px) {
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .main { padding: 20px 14px 72px; }
  .topbar-inner { padding: 0 14px; gap: 10px; }
  .brand span:not(.brand-mark) { display: none; }
  .nav a { padding: 6px 9px; font-size: 0.875rem; }
  .task { flex-wrap: wrap; gap: 10px; }
  .task-actions { width: 100%; justify-content: flex-end; }
  .suggestions { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .history-entry { flex-wrap: wrap; }
  /* The explanatory hint crowds the heading at this width; stack it instead. */
  .section-head { flex-direction: column; align-items: flex-start; gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
