:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --surface-raised: #ffffff;
  --surface-muted: #ececf0;
  --text: #17181b;
  --text-secondary: #6c6f78;
  --line: rgba(23, 24, 27, 0.1);
  --accent: #1d1d1f;
  --accent-contrast: #ffffff;
  --danger: #c9362b;
  --danger-soft: #fff0ee;
  --success: #287a4c;
  --success-soft: #edf8f1;
  --favorite: #b06b00;
  --focus: #0a84ff;
  --shadow: 0 12px 36px rgba(20, 21, 24, 0.08);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 10% -10%, rgba(255, 255, 255, 0.9), transparent 34rem),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

button,
summary,
input,
textarea {
  touch-action: manipulation;
}

button:focus-visible,
summary:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 60%, transparent);
  outline-offset: 2px;
}

.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;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: calc(var(--safe-top) + 8px);
  left: 12px;
  transform: translateY(-160%);
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--accent-contrast);
  background: var(--accent);
}

.skip-link:focus {
  transform: none;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 20px) 18px calc(var(--safe-bottom) + 96px);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-transform: capitalize;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.72rem, 6.4vw, 2.2rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.icon-button {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  font-size: 2rem;
  line-height: 1;
}

.primary-action {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 8px 24px rgba(23, 24, 27, 0.18);
}

.primary-action:active {
  transform: scale(0.96);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-bottom: 18px;
}

.metric {
  min-width: 0;
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
}

.metric strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1.42rem;
  line-height: 1;
  letter-spacing: -0.03em;
}

.metric span {
  display: block;
  color: var(--text-secondary);
  font-size: 0.72rem;
  line-height: 1.2;
}

.metric.danger strong {
  color: var(--danger);
}

.metric.success strong {
  color: var(--success);
}

.controls {
  margin-bottom: 24px;
}

.search-field {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-solid);
  box-shadow: 0 3px 14px rgba(20, 21, 24, 0.025);
}

.search-field:focus-within {
  border-color: color-mix(in srgb, var(--focus) 65%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 15%, transparent);
}

.search-icon {
  color: var(--text-secondary);
  font-size: 1.35rem;
  transform: rotate(-18deg);
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 1rem;
}

.search-field input::placeholder {
  color: var(--text-secondary);
}

.filter-row {
  display: flex;
  gap: 8px;
  margin: 12px -18px 0;
  padding: 0 18px 3px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.filter-row::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  min-height: 38px;
  flex: 0 0 auto;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-solid);
  font-size: 0.86rem;
  font-weight: 650;
  scroll-snap-align: start;
}

.filter-chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 10px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 1.04rem;
  letter-spacing: -0.015em;
}

.section-heading span {
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.task-group + .task-group {
  margin-top: 25px;
}

.task-group-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 2px 9px;
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.task-group-heading.danger-label {
  color: var(--danger);
}

.task-group-count {
  min-width: 21px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-size: 0.7rem;
  text-align: center;
}

.task-group-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  box-shadow: 0 8px 26px rgba(20, 21, 24, 0.035);
}

.task-card {
  min-height: 70px;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: stretch;
  position: relative;
}

.task-card + .task-card::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 54px;
  height: 1px;
  background: var(--line);
}

.complete-button,
.task-open-button {
  border: 0;
  background: transparent;
}

.complete-button {
  min-width: 54px;
  min-height: 54px;
  display: grid;
  place-items: center;
  align-self: stretch;
  padding: 0;
}

.checkmark {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  border: 2px solid #bbbcc2;
  border-radius: 50%;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.complete-button:active .checkmark {
  transform: scale(0.86);
}

.task-card.completed .checkmark {
  border-color: var(--success);
  background: var(--success);
}

.task-card.completed .checkmark::after {
  content: "✓";
  color: #fff;
  font-size: 0.77rem;
  font-weight: 850;
}

.task-open-button {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px 13px 0;
  text-align: left;
}

.task-copy {
  min-width: 0;
  display: block;
}

.task-title-line {
  display: flex;
  align-items: center;
  gap: 7px;
}

.task-title {
  overflow: hidden;
  color: var(--text);
  font-size: 0.96rem;
  line-height: 1.28;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-card.completed .task-title {
  color: var(--text-secondary);
  text-decoration: line-through;
}

.favorite-star {
  flex: 0 0 auto;
  color: var(--favorite);
  font-size: 0.8rem;
}

.task-meta {
  display: block;
  overflow: hidden;
  margin-top: 5px;
  color: var(--text-secondary);
  font-size: 0.79rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overdue-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--danger);
}

.empty-state {
  padding: 54px 24px 45px;
  text-align: center;
}

.empty-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  border-radius: 17px;
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-size: 1.6rem;
}

.empty-state h3 {
  margin-bottom: 6px;
  font-size: 1.05rem;
}

.empty-state p {
  margin-bottom: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.bottom-actions {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  width: min(100%, 760px);
  display: flex;
  gap: 9px;
  margin: 0 auto;
  padding: 12px 18px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  backdrop-filter: blur(24px) saturate(160%);
}

.review-button {
  min-height: 48px;
  flex: 1 1 auto;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 750;
}

.review-button span {
  margin-right: 5px;
  font-size: 1.12rem;
}

.more-menu {
  position: relative;
}

.more-menu summary {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-solid);
  cursor: pointer;
  font-weight: 850;
  list-style: none;
}

.more-menu summary::-webkit-details-marker {
  display: none;
}

.menu-panel {
  width: min(280px, calc(100vw - 36px));
  overflow: hidden;
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}

.menu-panel button {
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  text-align: left;
}

.menu-panel button + button {
  border-top: 1px solid var(--line);
}

.danger-text {
  color: var(--danger);
}

dialog {
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.sheet-dialog {
  width: min(100%, 760px);
  max-width: none;
  height: min(92dvh, 850px);
  max-height: none;
  margin: auto auto 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--bg);
  box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.15);
}

.sheet-dialog[open] {
  animation: sheet-in 220ms cubic-bezier(0.22, 0.85, 0.35, 1);
}

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

.sheet-dialog > form,
.sheet-dialog > div {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.dialog-header {
  min-height: 62px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1rem;
  text-align: center;
}

.text-button {
  min-height: 44px;
  justify-self: start;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
}

.text-button.strong {
  justify-self: end;
  color: var(--focus);
  font-weight: 750;
}

.header-spacer {
  width: 52px;
}

.form-content,
.review-content {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 18px calc(28px + var(--safe-bottom));
}

.field + .field,
.form-grid + .field,
.field + .form-grid {
  margin-top: 17px;
}

.field label,
.confirm-dialog label {
  display: flex;
  justify-content: space-between;
  margin: 0 2px 7px;
  font-size: 0.82rem;
  font-weight: 700;
}

.optional {
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
}

.field input,
.field textarea,
.confirm-dialog input {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: 0;
  color: var(--text);
  background: var(--surface-solid);
}

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

.field input:focus,
.field textarea:focus,
.confirm-dialog input:focus {
  border-color: color-mix(in srgb, var(--focus) 70%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 14%, transparent);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-error {
  min-height: 17px;
  margin: 5px 2px -11px;
  color: var(--danger);
  font-size: 0.76rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 11px;
}

.switch-row {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  position: relative;
  margin-top: 20px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-solid);
}

.switch-row strong,
.switch-row small {
  display: block;
}

.switch-row strong {
  font-size: 0.9rem;
}

.switch-row small {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  width: 50px;
  height: 30px;
  flex: 0 0 auto;
  position: relative;
  border-radius: 999px;
  background: #c8c9ce;
  transition: background 160ms ease;
}

.switch::after {
  content: "";
  width: 26px;
  height: 26px;
  position: absolute;
  top: 2px;
  left: 2px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: transform 160ms ease;
}

.switch-row input:checked + .switch {
  background: var(--success);
}

.switch-row input:checked + .switch::after {
  transform: translateX(20px);
}

.switch-row:has(input:focus-visible) {
  outline: 3px solid color-mix(in srgb, var(--focus) 60%, transparent);
  outline-offset: 2px;
}

.task-tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 20px;
}

.task-tools button,
.delete-button {
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-solid);
  font-size: 0.8rem;
  font-weight: 650;
}

.delete-button {
  width: 100%;
  margin-top: 26px;
  border-color: color-mix(in srgb, var(--danger) 24%, transparent);
  color: var(--danger);
  background: var(--danger-soft);
}

.review-content {
  padding-top: 15px;
}

.review-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
  margin-bottom: 25px;
}

.review-summary div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-solid);
}

.review-summary strong,
.review-summary span {
  display: block;
}

.review-summary strong {
  margin-bottom: 4px;
  font-size: 1.35rem;
}

.review-summary span {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.review-section + .review-section {
  margin-top: 24px;
}

.review-section h3 {
  margin: 0 2px 9px;
  font-size: 0.92rem;
}

.review-empty {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 13px;
  color: var(--text-secondary);
  font-size: 0.83rem;
}

.review-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-solid);
}

.review-item {
  padding: 13px;
}

.review-item + .review-item {
  border-top: 1px solid var(--line);
}

.review-item-title {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.review-item-meta {
  color: var(--text-secondary);
  font-size: 0.76rem;
}

.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 11px;
}

.review-actions button {
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-muted);
  font-size: 0.75rem;
  font-weight: 650;
}

.review-actions .complete-review-button {
  color: var(--success);
}

.confirm-dialog {
  width: min(calc(100% - 36px), 370px);
  padding: 21px;
  border: 0;
  border-radius: 20px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}

.confirm-dialog h2 {
  margin-bottom: 10px;
  font-size: 1.08rem;
}

.confirm-dialog p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.45;
}

.confirm-dialog input {
  margin-bottom: 18px;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.confirm-actions button,
.stacked-actions button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
  font-weight: 700;
}

.primary-button {
  border-color: var(--accent) !important;
  background: var(--accent) !important;
  color: var(--accent-contrast);
}

.stacked-actions {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.toast {
  max-width: min(calc(100% - 36px), 420px);
  position: fixed;
  z-index: 1000;
  right: 18px;
  bottom: calc(82px + var(--safe-bottom));
  left: 18px;
  margin: auto;
  padding: 12px 16px;
  border-radius: 13px;
  background: #26272b;
  color: white;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  font-size: 0.86rem;
  font-weight: 650;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 600px) {
  .app-shell {
    padding-right: 28px;
    padding-left: 28px;
  }

  .filter-row {
    margin-right: -28px;
    margin-left: -28px;
    padding-right: 28px;
    padding-left: 28px;
  }

  .bottom-actions {
    padding-right: 28px;
    padding-left: 28px;
  }

  .sheet-dialog {
    height: min(86dvh, 820px);
    margin-bottom: 4vh;
    border-radius: 24px;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-right: 14px;
    padding-left: 14px;
  }

  .metrics {
    gap: 6px;
  }

  .metric {
    padding: 12px 9px;
  }

  .metric span {
    font-size: 0.67rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .task-tools {
    grid-template-columns: 1fr;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101114;
    --surface: rgba(29, 30, 34, 0.9);
    --surface-solid: #1c1d21;
    --surface-raised: #232429;
    --surface-muted: #292b30;
    --text: #f4f4f6;
    --text-secondary: #a7a9b1;
    --line: rgba(255, 255, 255, 0.1);
    --accent: #f2f2f4;
    --accent-contrast: #17181b;
    --danger: #ff746c;
    --danger-soft: rgba(255, 116, 108, 0.11);
    --success: #56c785;
    --success-soft: rgba(86, 199, 133, 0.1);
    --favorite: #ffbd54;
    --shadow: 0 16px 42px rgba(0, 0, 0, 0.36);
  }

  body {
    background:
      radial-gradient(circle at 10% -10%, rgba(55, 57, 64, 0.3), transparent 32rem),
      var(--bg);
  }

  .checkmark {
    border-color: #656870;
  }
}

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