/* Upkeep — calm, high-contrast, low-clutter.
   Design rules in force:
   - Overdue is clay/amber, never alarm red. A screen of red is a shutdown trigger.
   - Every date is paired with plain-language relative time (time blindness).
   - One primary action per card. Choice paralysis is the enemy.

   Theming: an inline script in <head> resolves system/light/dark and stamps
   data-theme on <html> before first paint, so each palette is defined exactly
   once here and there's no flash of the wrong theme. */

:root {
  --bg:        #faf9f7;
  --surface:   #ffffff;
  --surface-2: #f3f1ee;
  --line:      #e2ded8;
  --ink:       #1e2024;
  --ink-2:     #5c6068;
  --ink-3:     #8a8f98;

  --accent:    #0d7a70;
  --accent-in: #ffffff;
  --accent-bg: #e6f2f0;

  --overdue:   #a8590f;
  --overdue-bg:#fbf0e4;
  --due:       #0d7a70;
  --due-bg:    #e6f2f0;
  --soon:      #3b6ea5;
  --soon-bg:   #e9f0f8;
  --later:     #7b7f88;
  --later-bg:  #f0efec;

  --scrim:     rgba(20,22,26,.34);

  --radius: 12px;
  --shadow: 0 1px 2px rgba(20,22,26,.05), 0 4px 14px rgba(20,22,26,.05);
  --shadow-pop: 0 6px 28px rgba(20,22,26,.16), 0 1px 3px rgba(20,22,26,.1);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* Safe areas, so the sticky header clears the iPhone status bar/clock and
     bottom UI clears the home indicator. */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

:root[data-theme="dark"] {
  --bg:        #131519;
  --surface:   #1b1e23;
  --surface-2: #23272d;
  --line:      #2f343b;
  --ink:       #e8e9ec;
  --ink-2:     #a3a8b2;
  --ink-3:     #767c87;

  --accent:    #4bbfae;
  --accent-in: #10231f;
  --accent-bg: #17322e;

  --overdue:   #e0a463;
  --overdue-bg:#33261a;
  --due:       #4bbfae;
  --due-bg:    #17322e;
  --soon:      #7fadde;
  --soon-bg:   #1c2836;
  --later:     #8b919b;
  --later-bg:  #23272d;

  --scrim:     rgba(6,8,11,.6);

  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  --shadow-pop: 0 8px 34px rgba(0,0,0,.55), 0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

/* Anything carrying the hidden attribute must actually hide. Several components
   here set display, which would otherwise win over the UA's [hidden] rule --
   that bug is what left a permanent empty toast pill on screen. */
[hidden] { display: none !important; }

h2 { font-size: 1.25rem; letter-spacing: -.01em; margin: 0; }
h3 { font-size: 1.05rem; margin: 0 0 .25rem; }

/* ─────────────────────────────────────────────────────────────── topbar ── */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-t);
}
.topbar-in {
  max-width: 860px; margin: 0 auto;
  padding: .6rem calc(1rem + var(--safe-r)) .55rem calc(1rem + var(--safe-l));
  display: flex; flex-direction: column; gap: .55rem;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.mark { font-size: 1.35rem; line-height: 1; }
/* Anchoring the current date in the chrome, always visible, is deliberate:
   "what day is it" should never require a lookup. */
.today { font-weight: 640; font-size: 1.02rem; letter-spacing: -.01em; white-space: nowrap; }
.today-sub { font-size: .8rem; color: var(--ink-3); }

.topbar-actions { display: flex; align-items: center; gap: .25rem; flex-shrink: 0; }

.tabs { display: flex; gap: .2rem; background: var(--surface-2); padding: .2rem; border-radius: 10px; }
.tab {
  flex: 1 1 auto;
  border: 0; background: none; font: inherit; font-size: .88rem; font-weight: 550;
  color: var(--ink-2); padding: .42rem .8rem; border-radius: 8px; cursor: pointer;
  white-space: nowrap;
}
.tab.is-on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.wrap {
  max-width: 860px; margin: 0 auto;
  padding: 1.1rem calc(1rem + var(--safe-r)) calc(5rem + var(--safe-b)) calc(1rem + var(--safe-l));
}

/* ────────────────────────────────────────────────────────────── filters ── */

.filters { display: flex; gap: 1.4rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.filter-group { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.filter-label { font-size: .8rem; color: var(--ink-3); font-weight: 550; }
.chips { display: flex; gap: .3rem; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: .82rem; font-weight: 550;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  padding: .3rem .7rem; border-radius: 999px; cursor: pointer;
}
.chip:hover { border-color: var(--ink-3); }
.chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-in); }

/* ───────────────────────────────────────────────────────────────── hero ── */

/* The single most important element. When executive function is the bottleneck,
   the answer to "what do I do" has to be one thing, pre-decided, with the first
   physical step spelled out. */
.hero {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.3rem; margin-bottom: 1.6rem;
  position: relative; overflow: hidden;
}
.hero::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent);
}
.hero.is-overdue::before { background: var(--overdue); }
.hero-eyebrow {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .09em;
  font-weight: 700; color: var(--ink-3); margin-bottom: .5rem;
}
.hero-title { font-size: 1.5rem; font-weight: 660; letter-spacing: -.02em; margin: 0 0 .1rem; }
.hero-meta { font-size: .87rem; color: var(--ink-2); margin-bottom: .9rem; }
.hero-step {
  background: var(--accent-bg); border-radius: 9px; padding: .7rem .85rem;
  font-size: .95rem; margin-bottom: 1rem;
}
.hero-step b { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-2); margin-bottom: .15rem; font-weight: 700; }
.hero-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.hero-empty { text-align: center; padding: 2rem 1rem; }
.hero-empty .big { font-size: 2rem; margin-bottom: .3rem; }

/* ──────────────────────────────────────────────────────────────── lists ── */

.group { margin-bottom: 1.7rem; }
.group-head {
  display: flex; align-items: baseline; gap: .55rem;
  margin-bottom: .6rem; padding-bottom: .35rem; border-bottom: 1px solid var(--line);
}
.group-head h2 { font-size: .95rem; font-weight: 660; letter-spacing: -.005em; }
.group-count { font-size: .8rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.group-note { font-size: .78rem; color: var(--ink-3); margin-left: auto; }

.card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .3rem .8rem;
  align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .75rem .85rem; margin-bottom: .45rem;
  position: relative; overflow: hidden;
}
.card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--later); }
.card[data-status="overdue"]::before { background: var(--overdue); }
.card[data-status="due"]::before     { background: var(--due); }
.card[data-status="soon"]::before    { background: var(--soon); }
.card[data-status="snoozed"]::before,
.card[data-status="unscheduled"]::before { background: var(--line); }

.card-main { min-width: 0; padding-left: .35rem; }
.card-title { font-weight: 570; font-size: .98rem; letter-spacing: -.005em; }
.card-sub {
  font-size: .8rem; color: var(--ink-2); margin-top: .1rem;
  display: flex; gap: .45rem; flex-wrap: wrap; align-items: center;
}
.card-sub .card-meta { min-width: 0; }
.card-step { font-size: .8rem; color: var(--ink-3); margin-top: .2rem; font-style: italic; }

.card-actions { display: flex; gap: .3rem; align-items: center; }

/* Elapsed-cycle bar. A proportion is legible at a glance in a way that
   "-393" never was. */
.bar {
  grid-column: 1 / -1; height: 3px; border-radius: 2px;
  background: var(--surface-2); overflow: hidden; margin-top: .15rem;
}
.bar > i { display: block; height: 100%; background: var(--later); border-radius: 2px; }
.card[data-status="overdue"] .bar > i { background: var(--overdue); }
.card[data-status="due"] .bar > i     { background: var(--due); }
.card[data-status="soon"] .bar > i    { background: var(--soon); }

.pill {
  font-size: .72rem; font-weight: 640; padding: .1rem .45rem; border-radius: 999px;
  white-space: nowrap;
}
.pill-overdue { background: var(--overdue-bg); color: var(--overdue); }
.pill-due     { background: var(--due-bg);     color: var(--due); }
.pill-soon    { background: var(--soon-bg);    color: var(--soon); }
.pill-later   { background: var(--later-bg);   color: var(--later); }
.pill-deadline{ background: var(--later-bg);   color: var(--ink-3); }

/* ────────────────────────────────────────────────────────────── buttons ── */

.btn {
  font: inherit; font-size: .85rem; font-weight: 570;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: .42rem .75rem; border-radius: 8px; cursor: pointer; white-space: nowrap;
  min-height: 34px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-in); }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-lg { font-size: .98rem; padding: .6rem 1.15rem; border-radius: 10px; min-height: 44px; }
.btn-quiet { border-color: transparent; background: none; color: var(--ink-2); }
.btn-quiet:hover { background: var(--surface-2); }
.btn-icon { padding: .3rem .55rem; font-size: 1rem; line-height: 1; min-width: 38px; }
.btn-danger-quiet { border-color: transparent; background: none; color: var(--overdue); }
.btn-danger-quiet:hover { background: var(--overdue-bg); }

.btn-bell { filter: grayscale(1); opacity: .65; }
.btn-bell:hover { opacity: 1; }
.btn-bell.is-muted { filter: none; opacity: 1; }

/* ──────────────────────────────────────────────── menus / bottom sheets ── */

/* Menus live at the end of <body> and are position: fixed, so they can never be
   clipped by a card's overflow or pushed off-screen by a right-aligned parent —
   the two bugs this replaced. On phones they become a bottom sheet with large
   targets instead of a cramped popover. */

.sheet-scrim {
  position: fixed; inset: 0; z-index: 60;
  background: var(--scrim);
  animation: fade-in .12s ease-out;
}

.menu {
  position: fixed; z-index: 61;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-pop); padding: .3rem; min-width: 210px; max-width: min(92vw, 320px);
  max-height: 70vh; overflow-y: auto;
  animation: pop-in .12s ease-out;
}
.menu button {
  display: block; width: 100%; text-align: left; font: inherit; font-size: .88rem;
  border: 0; background: none; color: var(--ink); padding: .5rem .6rem;
  border-radius: 8px; cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }
.menu button em,
.menu button .when { display: block; font-size: .76rem; color: var(--ink-3); font-style: normal;
  margin-top: .1rem; line-height: 1.3; }
.menu button.is-danger { color: var(--overdue); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: .3rem .2rem; }
.menu-title {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
  color: var(--ink-3); padding: .45rem .6rem .3rem;
}

/* Bottom-sheet variant (phones) */
.menu.is-sheet {
  left: 0; right: 0; bottom: 0; top: auto;
  max-width: none; width: 100%;
  border-radius: 16px 16px 0 0; border-bottom: 0;
  padding: .5rem .5rem calc(.5rem + var(--safe-b));
  max-height: 82vh;
  animation: slide-up .18s cubic-bezier(.2,.8,.2,1);
}
/* Entry animations deliberately start close to their final state. An animation
   that begins at translateY(100%) or opacity:0 can leave the menu invisible if
   the animation clock ever stalls (throttled/background tab) — cosmetic polish
   must never be able to hide the UI. */
.menu.is-sheet button { padding: .8rem .8rem; font-size: 1rem; border-radius: 10px; }
.menu.is-sheet button em,
.menu.is-sheet button .when { font-size: .84rem; }
.menu.is-sheet .menu-title { padding: .5rem .8rem .4rem; font-size: .76rem; }
.menu.is-sheet::before {
  content: ""; display: block; width: 36px; height: 4px; border-radius: 2px;
  background: var(--line); margin: .25rem auto .5rem;
}

@keyframes fade-in  { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop-in   { from { opacity: .35; transform: translateY(-4px) } to { opacity: 1; transform: none } }
@keyframes slide-up { from { transform: translateY(10px) } to { transform: none } }

@media (prefers-reduced-motion: reduce) {
  .sheet-scrim, .menu { animation: none; }
}

/* ─────────────────────────────────────────────────────────── all / more ── */

.section-head { display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; margin-bottom: 1rem; }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .6rem; margin-bottom: 1.6rem;
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem;
}
.stat-n { font-size: 1.7rem; font-weight: 680; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat-l { font-size: .78rem; color: var(--ink-2); }

.log { list-style: none; padding: 0; margin: 0; }
.log li {
  display: flex; gap: .6rem; align-items: baseline; padding: .4rem 0;
  border-bottom: 1px solid var(--line); font-size: .87rem;
}
.log .when { color: var(--ink-3); font-size: .8rem; min-width: 6.5rem; font-variant-numeric: tabular-nums; }

/* Category rows in More */
.cat-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem 0; border-bottom: 1px solid var(--line);
}
.cat-row:last-child { border-bottom: 0; }
.cat-name { font-weight: 570; font-size: .92rem; }
.cat-count { font-size: .78rem; color: var(--ink-3); margin-right: auto; }
.cat-row input {
  font: inherit; font-size: .9rem; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: .35rem .5rem; flex: 1; min-width: 0;
}

/* ───────────────────────────────────────────────────────────── editor ──── */

dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--ink);
  max-width: 540px; width: calc(100% - 2rem); box-shadow: 0 20px 50px rgba(0,0,0,.25);
  max-height: 88vh;
}
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
.editor-form { padding: 1.2rem; display: flex; flex-direction: column; gap: .8rem; }

.fld { display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; color: var(--ink-2); }
.fld > span { font-weight: 570; }
.fld em { font-style: normal; color: var(--ink-3); font-weight: 400; }
.fld input, .fld select, .fld textarea {
  font: inherit; font-size: .95rem; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .55rem;
  width: 100%;
}
.fld input:focus, .fld select:focus, .fld textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.fld-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.inline { display: flex; gap: .4rem; }
.w-num { max-width: 5rem; }

.anchor-fld { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; margin: 0; }
.anchor-fld legend { font-size: .78rem; font-weight: 600; color: var(--ink-2); padding: 0 .3rem; }
.radio { display: flex; gap: .5rem; align-items: flex-start; padding: .3rem 0; cursor: pointer; }
.radio input { margin-top: .28rem; accent-color: var(--accent); }
.radio b { display: block; font-size: .88rem; color: var(--ink); font-weight: 570; }
.radio em { display: block; font-size: .77rem; color: var(--ink-3); font-style: normal; line-height: 1.35; }

.editor-actions { display: flex; gap: .5rem; align-items: center; margin-top: .3rem; }
.spacer { flex: 1; }

/* ────────────────────────────────────────────────────────────── toast ──── */

.toast {
  position: fixed; left: 50%; bottom: calc(1.4rem + var(--safe-b));
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 999px;
  font-size: .87rem; font-weight: 550; box-shadow: var(--shadow-pop); z-index: 100;
  display: flex; align-items: center; gap: .8rem;
  max-width: calc(100vw - 2rem);
}
.toast button {
  font: inherit; font-size: .82rem; font-weight: 640; border: 0; background: none;
  color: var(--bg); text-decoration: underline; cursor: pointer; padding: 0;
  opacity: .85; flex-shrink: 0;
}

/* Mute notice. A mute always announces itself and always shows its end time. */
.mute-banner {
  background: var(--overdue-bg); color: var(--overdue);
  border-top: 1px solid var(--line);
  font-size: .84rem; font-weight: 550;
  padding: .45rem 1rem; text-align: center;
}
.mute-banner button {
  font: inherit; font-weight: 700; border: 0; background: none; color: inherit;
  text-decoration: underline; cursor: pointer; margin-left: .5rem; padding: 0;
}

.empty { color: var(--ink-3); font-size: .88rem; padding: .6rem 0; }

/* ────────────────────────────────────────────────────────────── login ──── */

.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 2rem 1.6rem; text-align: center;
  display: flex; flex-direction: column; gap: .6rem;
}
.login-mark { font-size: 2.2rem; }
.login-card h1 { font-size: 1.5rem; letter-spacing: -.02em; margin: 0; }
.login-sub { color: var(--ink-2); font-size: .9rem; margin: 0 0 .5rem; }
.login-card input {
  font: inherit; font-size: 1rem; text-align: center;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 9px; padding: .6rem .7rem;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.login-err { color: var(--overdue); font-size: .85rem; font-weight: 550; margin: .1rem 0 0; }
.login-note { color: var(--ink-3); font-size: .78rem; margin: .4rem 0 0; }

/* ───────────────────────────────────────────────────────────── narrow ──── */

@media (max-width: 560px) {
  .today { font-size: .98rem; }
  .card { grid-template-columns: 1fr; }
  .card-actions { justify-content: flex-start; padding-left: .35rem; }
  .fld-row { grid-template-columns: 1fr; }
  .hero-title { font-size: 1.3rem; }
  .filters { gap: .7rem; flex-direction: column; align-items: flex-start; }
  .hero-actions .btn-lg { flex: 1 1 auto; }
}
