:root {
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --bg-sheet: #ffffff;
  --text: #16181d;
  --text-2: #5d6370;
  --text-3: #9aa0ab;
  --line: #e7e8ec;
  --line-strong: #cfd2d8;
  --brand: #1E40AF;
  --brand-soft: #e8edfb;
  --on-brand: #ffffff;
  --flag: #d9480f;
  --flag-soft: #fff1e8;
  --danger: #c92a2a;
  --scrim: rgba(15, 18, 25, 0.35);
  --radius: 12px;
  --addbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --bg-soft: #1c1e22;
    --bg-sheet: #18191c;
    --text: #eceef2;
    --text-2: #a4a9b4;
    --text-3: #6b717c;
    --line: #2a2d33;
    --line-strong: #3a3e46;
    --brand: #6d8ef0;
    --brand-soft: #1d2640;
    --on-brand: #0d1220;
    --flag: #ff8a4c;
    --flag-soft: #3a2116;
    --danger: #ff6b6b;
    --scrim: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
h1 { font-size: 24px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--text-2); margin: 6px 0 0; }

/* ---------- Lock screen ---------- */
.screen.center {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-t)) 24px calc(24px + var(--safe-b));
  text-align: center;
}
.brand { margin-bottom: 28px; }
/* The navy mark. On a dark screen it sits on a white tile so it keeps its contrast. */
.brand-logo { display: block; width: 180px; height: auto; margin: 0 auto 10px; box-sizing: content-box; }
@media (prefers-color-scheme: dark) {
  .brand-logo { background: #fff; padding: 14px; border-radius: 18px; }
}
.dots { display: flex; gap: 18px; margin-bottom: 10px; }
.dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); transition: all .12s; }
.dots span.on { background: var(--brand); border-color: var(--brand); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.error { color: var(--danger); min-height: 22px; margin: 4px 0 14px; font-size: 15px; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%;
  background: var(--bg-soft); font-size: 28px; font-weight: 400;
  transition: background .1s, transform .1s;
}
.keypad button:active { background: var(--line-strong); transform: scale(0.96); }
.keypad .key-ghost { background: none; font-size: 24px; color: var(--text-2); }

input[type=text], textarea, .field-select {
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg);
  padding: 11px 13px; font-size: 16px; outline: none; min-width: 0;
}
input[type=text]:focus, textarea:focus { border-color: var(--brand); }
.btn {
  border-radius: 10px; padding: 11px 16px; font-weight: 600;
  background: var(--brand); color: var(--on-brand);
}
.btn-quiet { background: var(--bg-soft); color: var(--text); font-weight: 500; }
.btn-danger { background: none; color: var(--danger); font-weight: 500; }

.initial {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: var(--brand-soft); color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 650; font-size: 14px;
}

/* ---------- Main list ---------- */
#main { min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  padding: calc(10px + var(--safe-t)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.topbar-row, .progress-row { max-width: 760px; margin: 0 auto; }
.topbar-row { display: flex; align-items: center; gap: 4px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-2); }
.icon-btn:active { background: var(--bg-soft); }
/* A quiet wordmark beside the day title where there's room; phones keep the row for the title. */
.topbar-logo { display: none; height: 22px; width: auto; opacity: .8; margin: 0 8px 0 4px; }
@media (min-width: 600px) { .topbar-logo { display: block; } }
@media (prefers-color-scheme: dark) { .topbar-logo { filter: brightness(0) invert(1); opacity: .7; } }
.day-title { flex: 1; text-align: left; padding: 2px 6px; min-width: 0; }
#day-name { display: block; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.day-sub { display: block; font-size: 13px; color: var(--text-2); }
.avatar { margin-left: 6px; }
.avatar .initial { width: 36px; height: 36px; }
.progress-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.progress { flex: 1; height: 5px; border-radius: 3px; background: var(--bg-soft); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--brand); border-radius: 3px; transition: width .3s; }
.progress-label { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }

/* ---------- Section tabs ---------- */
.tabs {
  max-width: 760px; margin: 10px auto 0;
  display: flex; gap: 2px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  margin-bottom: -10px; /* sit on the top bar's bottom border */
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 12px 11px; font-size: 15px; font-weight: 550; color: var(--text-2);
  border-bottom: 2.5px solid transparent; margin-bottom: -1px;
  white-space: nowrap; transition: color .12s, border-color .12s;
}
.tab:active { background: var(--bg-soft); border-radius: 8px 8px 0 0; }
.tab.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 650; }
.tab-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--bg-soft); color: var(--text-2);
  font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; justify-content: center;
}
.tab.on .tab-badge { background: var(--brand); color: var(--on-brand); }
.tab.attention .tab-badge { background: var(--flag-soft); color: var(--flag); }
.tab.attention.on .tab-badge { background: var(--flag); color: #fff; }
.tab-done { color: var(--brand); opacity: .7; display: inline-flex; }
.tab-short { display: none; }
/* Phones: five tabs share the width evenly, name above the count. */
@media (max-width: 520px) {
  .tabs { gap: 0; }
  .tab { flex: 1 1 0; flex-direction: column; gap: 1px; padding: 6px 2px 8px; font-size: 13px; min-width: 0; }
  .tab-label { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tab-long { display: none; }
  .tab-short { display: inline; }
  .tab-badge { min-width: 18px; height: 18px; font-size: 11px; padding: 0 5px; }
  .tab-done { height: 18px; align-items: center; }
  /* A tab with nothing to count still reserves the count's row under its name, so every name sits at the same height. */
  .tab:not(.complete):not(:has(.tab-badge))::after { content: ""; height: 18px; }
}

.list {
  max-width: 760px; margin: 0 auto;
  padding: 6px 16px calc(var(--addbar-h) + 140px + var(--safe-b));
}
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 13px; font-weight: 650; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 20px 2px 6px;
}
.section-head .count { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--text-3); }
.item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.item:active { background: var(--bg-soft); }
.item.selected { background: var(--brand-soft); border-radius: 8px; }
.check {
  flex: none; width: 26px; height: 26px; margin-top: -1px;
  border-radius: 50%; border: 2px solid var(--line-strong);
  display: flex; align-items: center; justify-content: center;
  color: transparent; transition: all .15s;
  position: relative;
}
.check::after { content: ""; position: absolute; inset: -10px; } /* bigger tap target */
.item.flagged .check { border-color: var(--flag); }
.check.done { background: var(--brand); border-color: var(--brand) !important; color: var(--on-brand); }
.check.pop { animation: pop .25s; }
@keyframes pop { 50% { transform: scale(1.18); } }
.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.item.done .item-title { color: var(--text-3); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; font-size: 13px; color: var(--text-2); }
.item-meta span { display: inline-flex; align-items: center; gap: 4px; }
.item-meta .flag { color: var(--flag); font-weight: 600; }
.item-meta .done-by { color: var(--brand); font-weight: 500; }
.item-meta .carried { color: var(--flag); }
.item-meta .photo { color: var(--brand); font-weight: 500; }
.item-meta .photo-missing { color: var(--flag); font-weight: 600; }
/* Tomorrow's repeating to-dos, shown before midnight adds them: look planned, not live. */
.item.preview { cursor: default; }
.item.preview .item-title { color: var(--text-2); }
.item.preview .check { border-style: dashed; color: transparent; }
.item-meta .preview-note { color: var(--text-3); }

/* Notes for the managers: everyone adds, only admins check off and clear. */
.section-head .clear-btn { font-size: 13px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--brand); padding: 2px 4px; }
.mnote { cursor: default; }
.mnote:active { background: none; }
.mnote .item-title { white-space: pre-wrap; }
.check.static { cursor: default; }
.mnotes-empty { font-size: 14px; color: var(--text-3); padding: 8px 2px 12px; margin: 0; }

.empty { text-align: center; color: var(--text-2); padding: 60px 20px; }
.empty-mark { width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* ---------- Add bar ---------- */
.addbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
}
.add-row, .add-options { max-width: 760px; margin: 0 auto; }
.add-row { display: flex; gap: 8px; align-items: center; }
.add-row input { flex: 1; border-radius: 22px; padding: 11px 16px; background: var(--bg-soft); border-color: transparent; }
.add-row input:focus { background: var(--bg); border-color: var(--brand); }
.add-send {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--brand); color: var(--on-brand);
  display: flex; align-items: center; justify-content: center;
}
.add-options { display: none; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.addbar.open .add-options { display: flex; }
.add-toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.version { text-align: center; font-size: 10px; color: var(--text-3); margin: 6px 0 -4px; letter-spacing: .02em; user-select: none; }
.add-where { font-size: 13px; font-weight: 600; color: var(--brand); letter-spacing: .01em; padding: 4px 2px; margin-right: auto; }

/* Five sections don't fit one row on a phone; the last wraps rather than hides. */
.seg { display: inline-flex; flex-wrap: wrap; background: var(--bg-soft); border-radius: 10px; padding: 3px; max-width: 100%; }
.seg button { white-space: nowrap; }
.seg button { padding: 6px 11px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--text-2); }
.seg button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
@media (prefers-color-scheme: dark) { .seg button.on { background: var(--line-strong); } }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 10px; font-size: 14px; font-weight: 500;
  background: var(--bg-soft); color: var(--text-2); position: relative;
}
.chip[aria-pressed=true] { background: var(--brand-soft); color: var(--brand); }
.chip.flag-chip[aria-pressed=true] { background: var(--flag-soft); color: var(--flag); }
#add-for-label { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip-select select { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; font-size: 16px; }

/* ---------- Sheets (detail and settings) ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 10; }
.sheet {
  position: fixed; z-index: 11; background: var(--bg-sheet);
  left: 0; right: 0; bottom: 0; top: calc(var(--safe-t) + 36px);
  border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column;
  box-shadow: 0 -8px 30px rgba(0,0,0,.15);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes in { from { transform: translateX(40px); opacity: .4; } }
@media (min-width: 900px) {
  .sheet {
    left: auto; top: 0; width: 440px; border-radius: 0;
    border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(0,0,0,.08);
    animation: in .2s ease-out;
  }
}
/* Wide iPad / desktop: the list slides over and stays tappable beside the detail panel. */
@media (min-width: 1100px) {
  body.detail-open #main { padding-right: 440px; }
  body.detail-open .addbar { right: 440px; }
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 8px 16px;
}
.sheet-head h2 { font-size: 17px; margin: 0; font-weight: 650; }
.sheet-body { flex: 1; overflow-y: auto; padding: 4px 18px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.link-btn { color: var(--brand); font-weight: 600; padding: 8px 6px; }

.detail-title { display: flex; gap: 12px; align-items: flex-start; margin: 4px 0 18px; }
.detail-title .check { width: 30px; height: 30px; margin-top: 4px; }
.detail-title textarea {
  flex: 1; border: 0; padding: 4px 0; font-size: 21px; font-weight: 600; line-height: 1.3;
  resize: none; background: none; outline: none; overflow: hidden;
}
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); min-height: 52px; }
.field-label { color: var(--text-2); font-size: 15px; flex: none; }
.field-select { padding: 7px 10px; font-size: 16px; max-width: 60%; }
.weekdays { display: flex; gap: 5px; }
.weekdays button {
  width: 32px; height: 32px; border-radius: 50%; font-size: 13px; font-weight: 600;
  background: var(--bg-soft); color: var(--text-2);
}
.weekdays button.on { background: var(--brand); color: var(--on-brand); }
.repeat-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.repeat-hint { font-size: 12px; color: var(--text-3); }
.fine { font-size: 13px; color: var(--text-2); padding: 12px 0 0; line-height: 1.6; }

.notes-head { font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; margin: 26px 0 10px; }
.note { background: var(--bg-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.note-meta { font-size: 12px; color: var(--text-2); display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.note-meta button { color: var(--text-3); font-size: 12px; padding: 2px 4px; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.note-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 6px; }
.note-form textarea { flex: 1; resize: none; min-height: 46px; max-height: 160px; }
/* Photos on a to-do: square thumbnails plus an add tile; tap a thumbnail for the full picture. */
.photos { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-thumb, .photo-add { width: 72px; height: 72px; border-radius: 10px; overflow: hidden; background: var(--bg-soft); flex: none; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb.broken { opacity: .4; }
.photo-add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--brand); font-size: 12px; font-weight: 600; border: 1.5px dashed var(--line-strong); background: none; }
.viewer { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .93); display: flex; flex-direction: column; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: calc(var(--safe-t) + 10px) 10px 8px 16px; color: #fff; font-size: 14px; }
.viewer-bar button { color: #fff; font-weight: 600; padding: 8px 10px; }
.viewer-bar .viewer-delete { color: #ff8a4c; }
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; padding-bottom: var(--safe-b); box-sizing: border-box; }

/* The staging copy wears a tag at the top of every screen. */
body.staging::before {
  content: attr(data-env); position: fixed; top: var(--safe-t); left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--flag); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  padding: 2px 10px 3px; border-radius: 0 0 8px 8px; pointer-events: none;
}

.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 26px; }
.detail-actions .btn-quiet, .detail-actions .btn-danger { display: inline-flex; align-items: center; gap: 6px; padding: 10px 14px; border-radius: 10px; }

.settings-group { margin: 18px 0 6px; font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; }
.row-sub { font-size: 13px; color: var(--text-2); }
.row button.small { font-size: 14px; color: var(--danger); padding: 6px 4px; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1; }
.inline-form input.code-input { flex: none; width: 92px; font-variant-numeric: tabular-nums; }
.row button.code-btn { font-size: 14px; color: var(--brand); padding: 6px 4px; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--addbar-h) + 24px + var(--safe-b));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 15px; max-width: calc(100% - 32px); display: flex; gap: 14px; align-items: center;
}
.toast button { color: var(--brand-soft); font-weight: 650; }
@media (prefers-color-scheme: dark) { .toast button { color: var(--brand); } }
.offline { position: fixed; top: calc(var(--safe-t) + 4px); left: 50%; transform: translateX(-50%); z-index: 30; background: var(--flag); color: #fff; font-size: 13px; padding: 4px 12px; border-radius: 10px; }
