:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --text: #141821;
  --muted: #667085;
  --border: #dde1e8;
  --accent: #5b5bd6;
  --accent-strong: #4848bf;
  --accent-soft: #e8e8fb;
  --danger: #3f6ea8;
  --danger-soft: #eef5fc;
  --open: #667085;
  --progress: #b54708;
  --done: #157347;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 8px 24px rgb(16 24 40 / 5%);
  --shadow-sheet: 0 -12px 48px rgb(16 24 40 / 20%);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b23;
    --surface-2: #232733;
    --text: #e9ecf3;
    --muted: #98a0b3;
    --border: #2c3140;
    --accent: #7c7cf0;
    --accent-strong: #9494f4;
    --accent-soft: #24243f;
    --danger: #8ab6e8;
    --danger-soft: #172538;
    --open: #98a0b3;
    --progress: #f5b34a;
    --done: #57c98b;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
    --shadow-sheet: 0 -12px 48px rgb(0 0 0 / 55%);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

/* Author display rules (for example .login-view { display: grid }) otherwise
   override the browser's [hidden] rule, leaving the login screen visible after
   sign-in. Keep [hidden] authoritative. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  /* Keep double taps from zooming the page. Pinch-to-zoom still works. */
  touch-action: manipulation;
  /* Never allow the page itself to scroll sideways; `clip` keeps the sticky
     header working because it does not create a scroll container. */
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

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

/* Login --------------------------------------------------------------- */

.login-view {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.login-card {
  width: min(100%, 380px);
  padding: 26px 22px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 1.6rem;
}

.login-subtitle {
  margin: 6px 0 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-submit {
  width: 100%;
  margin-top: 2px;
}

/* Header -------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 14px 16px 12px;
}

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

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

h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.pill-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
}

.pill-button:active {
  background: var(--surface-2);
}

.pill-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.icon-button {
  justify-content: center;
  width: 40px;
  padding: 0;
}

.icon-button svg {
  display: block;
}

.count-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
}

.filters {
  display: flex;
  gap: 8px;
  margin: 14px -16px 0;
  padding: 0 16px 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
}

.chip.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.chip-count {
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

.list-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.list-filter select {
  flex: 1;
  min-height: 48px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  /* 16px minimum: iOS Safari zooms the page when a focused control is
     smaller, and does not zoom back out. */
  font-size: max(16px, 0.9rem);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

/* Content ------------------------------------------------------------- */

.content {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(104px + env(safe-area-inset-bottom));
}

.banner {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.875rem;
}

.banner.success {
  border-color: color-mix(in srgb, var(--done) 35%, var(--border));
  background: color-mix(in srgb, var(--done) 12%, var(--surface));
  color: var(--done);
}

.task-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.task-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 10px;
  padding: 7px 8px 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-toggle {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--open);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
}

.status-toggle:active {
  transform: scale(0.94);
}

.task-card[data-status="~"] .status-toggle {
  color: var(--progress);
  border-color: color-mix(in srgb, var(--progress) 40%, var(--border));
}

.task-card[data-status="+"] .status-toggle {
  color: var(--done);
  border-color: color-mix(in srgb, var(--done) 40%, var(--border));
  background: color-mix(in srgb, var(--done) 12%, var(--surface));
}

.task-body {
  min-width: 0;
  align-self: center;
  border-radius: 6px;
  cursor: pointer;
}

.task-description {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  line-height: 1.3;
}

.task-card[data-status="+"] .task-description {
  color: var(--muted);
  text-decoration: line-through;
}

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

.list-tag {
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  line-height: 1.55;
}

.task-id {
  white-space: nowrap;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

.task-date {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.task-actions {
  display: flex;
  align-self: center;
  gap: 0;
}

.action-button {
  min-width: 32px;
  min-height: 32px;
  padding: 0 5px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.action-button:active {
  background: var(--surface-2);
}

.action-button.danger {
  color: var(--danger);
}

.empty-state {
  margin: 48px auto;
  max-width: 280px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* Calendar ------------------------------------------------------------ */

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.week-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.week-nav {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
}

.week-nav:active {
  background: var(--surface-2);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.calendar-day {
  display: flex;
  flex-direction: column;
  min-height: 116px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.calendar-day.is-today {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}

.calendar-day.is-placeholder {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.calendar-day-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.calendar-day.is-today .calendar-day-label {
  color: var(--accent);
}

.calendar-tasks {
  display: grid;
  gap: 4px;
  align-content: start;
}

.calendar-task {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  width: 100%;
  padding: 4px 5px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.76rem;
  line-height: 1.25;
  text-align: left;
}

.calendar-task:active {
  border-color: var(--accent);
}

.calendar-task-status {
  flex: 0 0 auto;
  width: 12px;
  color: var(--open);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-weight: 700;
  text-align: center;
}

.calendar-task[data-status="~"] .calendar-task-status {
  color: var(--progress);
}

.calendar-task[data-status="+"] .calendar-task-status {
  color: var(--done);
}

.calendar-task-description {
  min-width: 0;
  overflow-wrap: anywhere;
}

.calendar-task[data-status="+"] .calendar-task-description {
  color: var(--muted);
  text-decoration: line-through;
}

/* Floating action button ---------------------------------------------- */

.fab {
  position: fixed;
  right: max(20px, calc((100% - 680px) / 2 + 20px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  font-size: 2rem;
  font-weight: 300;
  line-height: 1;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 45%, transparent);
}

.fab:active {
  background: var(--accent-strong);
  transform: scale(0.96);
}

.fab span {
  transform: translateY(-1px);
}

/* Bottom sheets ------------------------------------------------------- */

.sheet {
  width: min(100%, 520px);
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sheet);
}

.sheet[open] {
  animation: sheet-in 180ms ease-out;
}

.sheet::backdrop {
  background: rgb(8 12 24 / 52%);
  backdrop-filter: blur(2px);
}

@keyframes sheet-in {
  from {
    opacity: 0.4;
    transform: translateY(32px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sheet-form {
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: 0 auto 16px;
  border-radius: 999px;
  background: var(--border);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.field textarea,
.field input,
.field select,
.add-list-form input,
.list-row input {
  width: 100%;
  min-height: 44px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  /* 16px minimum: iOS Safari zooms the page when a focused control is
     smaller, and does not zoom back out. */
  font-size: max(16px, 0.95rem);
  font-weight: 400;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.date-field {
  display: flex;
  gap: 8px;
}

.date-field input {
  flex: 1;
  min-width: 0;
}

.date-clear {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.date-clear:disabled {
  cursor: default;
  opacity: 0.45;
}

.field textarea::placeholder,
.add-list-form input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.status-field {
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

.status-field legend {
  margin-bottom: 6px;
  padding: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: var(--surface-2);
}

.segmented label {
  position: relative;
  display: block;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented span {
  display: block;
  padding: 10px 6px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(16 24 40 / 14%);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-error {
  margin: 0 0 12px;
  color: var(--danger);
  font-size: 0.85rem;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.button {
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 0.92rem;
  font-weight: 600;
}

.button.primary {
  flex: 1;
  background: var(--accent);
  color: #fff;
}

.button.primary:active {
  background: var(--accent-strong);
}

.button.secondary {
  flex: 1;
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.button:disabled {
  cursor: progress;
  opacity: 0.6;
}

/* Lists sheet --------------------------------------------------------- */

.add-list-form {
  display: flex;
  gap: 8px;
}

.add-list-form input {
  flex: 1;
  min-width: 0;
}

.add-list-form .button {
  flex: 0 0 auto;
  padding: 0 16px;
}

.list-rows {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 54px;
  padding: 6px 8px 6px 12px;
  border-radius: 12px;
  background: var(--surface-2);
}

.list-row .list-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  font-weight: 600;
}

.list-row .list-count {
  flex: 0 0 auto;
  min-width: 24px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.list-row input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  background: var(--surface);
}

.list-row .row-action {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.list-row .row-action:active {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.list-row .row-action.danger {
  color: var(--danger);
}

/* Desktop ------------------------------------------------------------- */

@media (min-width: 640px) {
  .header-inner {
    padding: 18px 24px 14px;
  }

  .filters {
    margin: 16px 0 0;
    padding: 0;
  }

  .content {
    padding: 20px 24px 112px;
  }

  .calendar-day {
    min-height: 148px;
  }

  .sheet {
    margin: auto;
    border-radius: 20px;
  }

  @keyframes sheet-in {
    from {
      opacity: 0;
      transform: translateY(16px) scale(0.98);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }
}

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