:root {
  --bg: #121315;
  --surface: #181a1f;
  --surface-2: #21242b;
  --surface-3: #292d36;
  --text: #f4f6fb;
  --muted: #a5adbf;
  --border: rgba(244, 246, 251, 0.1);
  --primary: #6fa89d;
  --primary-strong: #4d8d81;
  --danger: #d97568;
  --warning: #d5a14b;
  --success: #67a96c;
  --radius-sm: 0.8rem;
  --radius-md: 1rem;
  --radius-lg: 1.4rem;
  --shadow-sm: 0 8px 20px rgba(0, 0, 0, 0.18);
  --shadow-md: 0 16px 36px rgba(0, 0, 0, 0.28);
  --content: 90rem;
}

html[data-theme="light"] {
  --bg: #f3efe8;
  --surface: #fbf8f3;
  --surface-2: #f1ebe3;
  --surface-3: #e6ddd1;
  --text: #191612;
  --muted: #655f56;
  --border: rgba(25, 22, 18, 0.12);
  --primary: #0f766e;
  --primary-strong: #0c5e58;
  --danger: #b4463d;
  --warning: #b8791b;
  --success: #3c7a42;
  --shadow-sm: 0 8px 20px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 16px 36px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
input, textarea, select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 0.85rem 0.95rem;
}
textarea { resize: vertical; }
.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  background: var(--text);
  color: var(--bg);
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  z-index: 100;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.5rem;
  padding: 0 1.25rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.header-left,
.header-center,
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.brand {
  font-family: "Caveat", cursive;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0;
}
.view-button,
.sidebar-item,
.sidebar-manage,
.icon-button,
.button {
  border: 1px solid transparent;
  transition: 0.2s ease;
}
.view-button,
.sidebar-item,
.sidebar-manage,
.icon-button {
  background: transparent;
  color: var(--muted);
}
.view-button {
  min-height: 2.6rem;
  padding: 0.65rem 1rem;
  border-radius: 999px;
}
.view-button.is-active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.icon-button {
  min-width: 2.6rem;
  min-height: 2.6rem;
  border-radius: 0.85rem;
  background: var(--surface-2);
}
.icon-button.danger { color: var(--danger); }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.8rem;
  padding: 0.75rem 1rem;
  border-radius: 999px;
}
.button-primary {
  background: var(--primary);
  color: white;
}
.button-primary:hover { background: var(--primary-strong); }
.button-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.app-body {
  width: min(100%, var(--content));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  gap: 1.25rem;
  padding: 1.25rem;
}
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  height: fit-content;
}
.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.sidebar-label {
  margin: 0 0 0.35rem;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.sidebar-item,
.sidebar-manage {
  min-height: 2.8rem;
  padding: 0.7rem 0.8rem;
  border-radius: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-item.is-active,
.sidebar-item:hover,
.sidebar-manage:hover {
  background: var(--surface-2);
  color: var(--text);
}
.main-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.notification-banner,
.stat-card,
.task-card,
.group-card,
.timeline-card,
.list-card,
.modal,
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.notification-banner {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  align-items: center;
}
.notification-banner p { margin: 0.25rem 0 0; color: var(--muted); }
.stats-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.stat-card {
  padding: 1rem 1.1rem;
}
.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stat-card strong {
  display: block;
  margin-top: 0.45rem;
  font-size: 2rem;
}
.stat-card.danger strong { color: var(--danger); }
.stat-card.success strong { color: var(--success); }
.toolbar {
  padding: 1rem;
}
.content-view { display: none; }
.content-view.is-active { display: block; }
.search-field input { min-height: 3rem; }
.task-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.task-card,
.group-card,
.timeline-card {
  padding: 1.15rem;
}
.task-card { position: relative; overflow: hidden; }
.task-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--cat-color, var(--primary));
}
.task-card.done { opacity: 0.7; }
.task-card[draggable="true"] { cursor: grab; }
.task-card[draggable="true"]:active { cursor: grabbing; }
.task-card.dragging { opacity: 0.35; outline: 2px dashed var(--primary); outline-offset: 2px; }
.sidebar-item.drag-over {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: scale(1.02);
  transition: background 0.1s, transform 0.1s;
}
.task-top,
.task-actions,
.task-meta,
.group-head,
.timeline-head,
.timeline-row,
.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.task-top { align-items: flex-start; }
.task-card h2,
.group-card h2,
.modal-head h2 {
  margin: 0.85rem 0 0.45rem;
  font-size: 1.05rem;
}
.task-card p,
.timeline-head,
.timeline-row strong,
.group-head span,
.list-card,
label span,
.modal-body p {
  color: var(--muted);
}
.pill,
.priority {
  display: inline-flex;
  align-items: center;
  min-height: 1.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}
.pill { background: var(--surface-2); }
.priority.low { background: rgba(103, 169, 108, 0.15); color: var(--success); }
.priority.medium { background: rgba(213, 161, 75, 0.16); color: var(--warning); }
.priority.high { background: rgba(217, 117, 104, 0.16); color: var(--danger); }
.countdown { color: var(--text); font-size: 0.84rem; }
.countdown.overdue { color: var(--danger); }
.countdown.done-text { color: var(--success); }
.stack-group {
  display: grid;
  gap: 1rem;
}
.group-head {
  margin-bottom: 0.8rem;
}
.list-card {
  padding: 0.9rem 1rem;
  border-radius: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.timeline-head,
.timeline-row {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 1rem;
}
.timeline-head {
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.8rem;
  text-transform: uppercase;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
}
.timeline-row {
  align-items: center;
  padding: 0.7rem 0;
}
.timeline-bar {
  min-height: 2rem;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  padding: 0 0.85rem;
  white-space: nowrap;
}
.timeline-bar.overdue { background: var(--danger); }
.timeline-bar.alt { background: color-mix(in srgb, var(--primary) 70%, #7f67c9); }

/* ── Visual timeline ruler ─────────────────────────────────────────────── */
.tl-ruler-row {
  margin-bottom: 0.5rem;
}
.tl-label-cell {
  font-size: 0.84rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tl-ruler {
  position: relative;
  height: 2.75rem;
  border-bottom: 2px solid var(--border);
}
.tl-tick {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 0.2rem;
}
.tl-tick::before {
  content: '';
  display: block;
  width: 1px;
  height: 6px;
  background: var(--border);
}
.tl-tick span {
  font-size: 0.65rem;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1;
}
.tl-now-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--primary);
  transform: translateX(-50%);
  z-index: 1;
}
.tl-now-mark::after {
  content: 'Now';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  line-height: 1;
}
.tl-task-row {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.tl-task-row:last-child { border-bottom: none; }
.tl-track {
  position: relative;
  height: 2rem;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: visible;
}
.tl-now-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--primary);
  transform: translateX(-50%);
  border-radius: 1px;
  z-index: 1;
}
.tl-chip {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
  z-index: 2;
}
.sort-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.1rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.sort-bar > span {
  margin-right: 0.15rem;
}
.sort-btn {
  padding: 0.35rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sort-btn.is-active {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
  color: #fff;
}
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.56);
}
.modal {
  width: min(100%, 40rem);
  padding: 1rem;
}
.small-modal { width: min(100%, 28rem); }
.modal-head {
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.modal-body {
  display: grid;
  gap: 1rem;
  padding-top: 1rem;
}
.settings-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.gcal-section {
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}
.gcal-status-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.4rem;
}
.gcal-status-text {
  font-size: 0.84rem;
  color: var(--muted);
  flex: 1;
}
.gcal-hint {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
label {
  display: grid;
  gap: 0.45rem;
}

/* ── Subtasks ─────────────────────────────────────────── */
.subtasks-block {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.45rem;
}
.subtasks-progress-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.subtasks-bar-track {
  flex: 1;
  height: 4px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.subtasks-bar-fill {
  height: 100%;
  background: var(--cat-color, var(--primary));
  border-radius: 999px;
  transition: width 0.3s ease;
}
.subtasks-count {
  font-size: 0.73rem;
  color: var(--muted);
  white-space: nowrap;
}
.subtask-items {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.25rem;
}
.subtask-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.84rem;
}
.subtask-item input[type="checkbox"] {
  width: auto;
  min-width: unset;
  padding: 0;
  border: none;
  background: none;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.subtask-item.done span {
  text-decoration: line-through;
  color: var(--muted);
}
.subtask-section-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin: 0;
}
.modal-subtask-list {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
  display: grid;
  gap: 0.35rem;
}
.modal-subtask-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  background: var(--surface-2);
  border-radius: 0.75rem;
  border: 1px solid var(--border);
}
.modal-subtask-item input[type="checkbox"] {
  width: auto;
  min-width: unset;
  padding: 0;
  border: none;
  background: none;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.modal-subtask-item span {
  flex: 1;
  font-size: 0.87rem;
  color: var(--text);
}
.modal-subtask-item.done span {
  text-decoration: line-through;
  color: var(--muted);
}
.modal-subtask-item .icon-button {
  min-width: 1.75rem;
  min-height: 1.75rem;
  font-size: 0.72rem;
  flex-shrink: 0;
}
.subtask-date-input {
  width: auto;
  min-width: unset;
  padding: 0.2rem 0.4rem;
  font-size: 0.73rem;
  border-radius: 0.4rem;
  color: var(--muted);
  flex-shrink: 0;
  cursor: pointer;
}
.subtask-due {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}
.subtask-due.overdue { color: var(--danger); }

/* ── Task link ────────────────────────────────────────── */
.task-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--primary);
  text-decoration: none;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--primary);
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s;
}
.task-link:hover { background: var(--surface-2); }

/* ── Archive ──────────────────────────────────────────── */
.archive-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.archive-card-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.archive-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  align-items: flex-start;
}
.archive-card-actions .button {
  padding: 0.3rem 0.8rem;
  min-height: unset;
  font-size: 0.8rem;
  width: auto;
}
.subtask-add-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.subtask-add-row input {
  flex: 1;
}
.subtask-add-row .button {
  min-height: 2.8rem;
  white-space: nowrap;
  flex-shrink: 0;
  width: auto;
}

.mobile-only { display: none; }
[hidden] { display: none !important; }

@media (max-width: 1100px) {
  .task-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Sidebar backdrop — hidden on desktop */
.sidebar-backdrop {
  display: none;
}

@media (max-width: 860px) {
  /* Header: stack view tabs as a scrollable strip below the main row */
  .app-header {
    flex-wrap: wrap;
    row-gap: 0;
    min-height: unset;
    padding: 0.6rem 1rem 0;
  }

  .header-left  { flex: 1; }
  .header-actions { justify-content: flex-end; }

  .header-center {
    display: flex;
    width: 100%;
    overflow-x: auto;
    padding: 0.5rem 0 0.65rem;
    gap: 0.4rem;
    scrollbar-width: none;
  }
  .header-center::-webkit-scrollbar { display: none; }

  .app-body {
    grid-template-columns: 1fr;
  }

  /* Slide-in drawer from right */
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(22rem, 85vw);
    max-height: 100dvh;
    overflow-y: auto;
    padding-top: 5.5rem;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    z-index: 40;
    transform: translateX(110%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-md);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  /* Backdrop */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 39;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .sidebar-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-only {
    display: inline-flex;
  }
}

/* ── Sidebar Agenda ───────────────────────────────────── */
.agenda-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: transparent;
  border: none;
  padding: 0.4rem 0.5rem;
  border-radius: 0.75rem;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}
.agenda-toggle:hover { background: var(--surface-2); }
.agenda-toggle[aria-expanded="true"] .agenda-chevron { transform: rotate(90deg); }
.agenda-toggle-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.agenda-chevron {
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 1rem;
  line-height: 1;
}
.agenda-drawer {
  margin-top: 0.5rem;
  display: grid;
  gap: 0.35rem;
}
.agenda-quick-form {
  display: flex;
  gap: 0.4rem;
}
.agenda-quick-form input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.7rem;
  font-size: 0.82rem;
  border-radius: 0.75rem;
}
.agenda-add-btn {
  min-height: unset;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
  width: auto;
}
.agenda-sidebar-list {
  display: grid;
  gap: 0.25rem;
}
.agenda-sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.5rem;
  border-radius: 0.75rem;
  transition: background 0.12s;
}
.agenda-sidebar-item:hover { background: var(--surface-2); }
.agenda-sidebar-item input[type="checkbox"] {
  width: auto;
  min-width: unset;
  padding: 0;
  border: none;
  background: none;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.agenda-sidebar-title {
  flex: 1;
  font-size: 0.84rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agenda-sidebar-item.done .agenda-sidebar-title {
  text-decoration: line-through;
  color: var(--muted);
}
.agenda-sidebar-del {
  min-width: 1.6rem;
  min-height: 1.6rem;
  font-size: 0.65rem;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s;
}
.agenda-sidebar-item:hover .agenda-sidebar-del { opacity: 1; }
.agenda-empty {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
  padding: 0.25rem 0.5rem;
}

@media (max-width: 640px) {
  .app-header {
    padding: 0.6rem 0.85rem 0;
    gap: 0.5rem;
  }

  .header-actions {
    gap: 0.4rem;
  }

  .app-body {
    padding: 0.85rem;
    gap: 0.85rem;
  }

  /* Stats: keep 2×2, not single column */
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .task-grid,
  .form-grid,
  .timeline-head,
  .timeline-row {
    grid-template-columns: 1fr;
  }

  /* Only full-width in modal footer and banners — not task card buttons */
  .modal-actions .button,
  .notification-banner .button {
    width: 100%;
  }

  .notification-banner {
    flex-direction: column;
    align-items: flex-start;
  }

  .task-meta {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  /* Modal: scrollable when content is taller than viewport */
  .modal {
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
  }

  /* Archive cards: stack info above actions */
  .archive-card {
    flex-direction: column;
  }
  .archive-card-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  .archive-card-actions .button {
    flex: 1;
    min-width: 5rem;
  }
}