/* Outreach: iOS-style look that works in light and dark mode. */
:root {
  --accent: #8d202a;
  --accent-soft: rgba(141, 32, 42, 0.12);
  --accent-fill: #8d202a;
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6c6c70;
  --faint: #aeaeb2;
  --separator: rgba(60, 60, 67, 0.18);
  --overdue: #d70015;
  --soon: #c93400;
  --ok: #248a3d;
  --blue: #0a7aff;
  --bar: rgba(249, 249, 249, 0.86);
  --radius: 12px;
  --tabbar-h: 56px;
  --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 {
    --accent: #ff6b73;
    --accent-soft: rgba(255, 107, 115, 0.16);
    --accent-fill: #b02a36;
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989f;
    --faint: #636366;
    --separator: rgba(84, 84, 88, 0.6);
    --overdue: #ff453a;
    --soon: #ff9f0a;
    --ok: #30d158;
    --blue: #0a84ff;
    --bar: rgba(22, 22, 24, 0.86);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
body.no-scroll { overflow: hidden; }

a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
p { margin: 0.4em 0; }

.icon { flex-shrink: 0; display: block; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.pad { padding: 24px 16px; }
.pad-x { padding: 4px 16px 0; }
.accent { color: var(--accent); }
.destructive { color: var(--overdue) !important; }
.prewrap { white-space: pre-wrap; }
.clamp-2, .clamp-3 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-2 { -webkit-line-clamp: 2; }
.clamp-3 { -webkit-line-clamp: 3; }
.status-overdue { color: var(--overdue); }
.status-soon { color: var(--soon); }
.status-ok { color: var(--ok); }
[hidden] { display: none !important; }

/* ---- Layout -------------------------------------------------------------- */

#app { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px); min-height: 100vh; }
.content { max-width: 720px; margin: 0 auto; padding: 0 16px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: var(--safe-t);
  background: var(--bg);
}
.scrolled .topbar { background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 0.5px solid var(--separator); }
.topbar-row {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: 44px; padding: 0 8px; max-width: 720px; margin: 0 auto;
}
.topbar-side { display: flex; gap: 4px; align-items: center; }
.topbar-side.right { justify-content: flex-end; }
.topbar-title { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.hidden-until-scroll { opacity: 0; transition: opacity 0.15s; }
.scrolled .hidden-until-scroll { opacity: 1; }
.large-title { font-size: 34px; font-weight: 700; letter-spacing: 0.01em; padding: 2px 16px 8px; max-width: 720px; margin: 0 auto; line-height: 1.15; }
.scrolled .large-title { visibility: hidden; }
.topbar.compact { background: var(--bar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-bottom: 0.5px solid var(--separator); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 0; background: none; color: var(--accent);
  border-radius: 20px; cursor: pointer;
}
.icon-btn.active { background: var(--accent-soft); }
.icon-btn.small { width: 30px; height: 30px; color: var(--faint); font-size: 14px; }
.link-btn { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 8px; cursor: pointer; }
.link-btn.strong { font-weight: 600; }
.link-btn.small { font-size: 13px; padding: 0; }
.link-btn:disabled { opacity: 0.4; }

/* ---- Tab bar ------------------------------------------------------------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  padding-bottom: var(--safe-b);
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  height: var(--tabbar-h); justify-content: center;
  color: var(--faint); font-size: 10px; font-weight: 500;
}
.tabbar a.active { color: var(--accent); }

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

.group-title {
  font-size: 13px; font-weight: 400; text-transform: uppercase; letter-spacing: 0.02em;
  color: var(--muted); padding: 22px 16px 7px;
}
.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--card); border-radius: var(--radius); overflow: hidden;
}
.list.inset { margin-bottom: 8px; }
.list > li + li { border-top: 0.5px solid var(--separator); margin-left: 16px; }
.list > li + li > .row, .list > li + li > .row-wrap > .row { margin-left: -16px; padding-left: 16px; }
.row-wrap { display: flex; align-items: stretch; }
.row-wrap > .row { flex: 1; min-width: 0; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 16px; min-height: 44px;
  background: none; border: 0; text-align: left; color: var(--text); cursor: pointer;
}
button.row:active, a.row:active, label.row:active { background: var(--separator); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-main strong { font-weight: 600; }
.row-sub { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.row-main > .row-sub { white-space: nowrap; }
.row-main > .row-sub.clamp-2, .row-main > .row-sub.clamp-3 { white-space: normal; }
.row-meta { font-size: 13px; color: var(--muted); }
.row-meta.status-ok { color: var(--muted); }
.row-action {
  border: 0; background: none; color: var(--ok); width: 52px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; border-left: 0.5px solid var(--separator);
}
.row-action:active { background: var(--separator); }
.chev { color: var(--faint); }
.emoji { width: 28px; text-align: center; font-size: 20px; flex-shrink: 0; }
.add-row strong { color: var(--accent); font-weight: 500; }
.note { font-size: 15px; margin-top: 4px; white-space: pre-wrap; }
.history { align-items: flex-start; }
.check-row input { width: 22px; height: 22px; accent-color: var(--accent); flex-shrink: 0; }

.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-overdue { background: var(--overdue); }
.dot-soon { background: var(--soon); }
.dot-ok { background: var(--ok); }

.pill { font-size: 13px; font-weight: 600; color: var(--muted); padding: 2px 10px; border-radius: 10px; background: var(--bg); white-space: nowrap; }
.pill-accent { background: var(--accent-fill); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); border: 0; }
.chip-x { cursor: pointer; }

/* ---- Cards & stats ------------------------------------------------------- */

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.status-card { margin-top: 8px; }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 22px; font-weight: 700; }
.snoozed { display: flex; align-items: center; gap: 6px; color: #5e5ce6; }
.date-line { color: var(--muted); font-size: 15px; margin: -4px 0 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.stat b { display: block; font-size: 28px; line-height: 1.1; color: var(--muted); }
.stat span { font-size: 13px; color: var(--muted); }
.small-stats { margin-top: 28px; }
.small-stats .stat b { font-size: 20px; color: var(--text); }
.all-clear { text-align: center; color: var(--ok); padding: 28px 0 8px; font-weight: 500; }
.install-card { margin-top: 8px; border: 1px solid var(--accent-soft); }

.empty { text-align: center; padding: 48px 24px; }
.empty-icon { font-size: 48px; margin-bottom: 8px; }
.empty h2 { font-size: 22px; margin-bottom: 6px; }
.empty p { color: var(--muted); margin-bottom: 18px; }

/* ---- Members ------------------------------------------------------------- */

.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px; text-transform: uppercase;
}
.member-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 0 16px 12px; }
.list > li + li.member .member-actions { margin-left: -16px; }
.member-actions button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 0; border-radius: 10px; padding: 8px 0 6px; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 500;
}
.member-actions button:disabled { opacity: 0.35; cursor: default; }
.member-actions button:not(:disabled):active { filter: brightness(0.9); }

/* ---- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 16px;
}
.btn-primary { background: var(--accent-fill); color: #fff; }
.btn-danger { background: rgba(215, 0, 21, 0.1); color: var(--overdue); }
.btn-block { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: 0.5; }
.btn:not(:disabled):active { filter: brightness(0.92); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.stack { display: grid; gap: 10px; margin-top: 16px; }
.file-btn { position: relative; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ---- Search -------------------------------------------------------------- */

.search { padding: 0 0 10px; }
.search input {
  width: 100%; height: 38px; border-radius: 10px; border: 0; padding: 0 12px 0 34px;
  font-size: 17px; color: var(--text);
  background: var(--separator) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238e8e93' stroke-width='2' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 11px center;
  -webkit-appearance: none; appearance: none;
}
.search input:focus { outline: 2px solid var(--accent-soft); }

/* ---- Forms --------------------------------------------------------------- */

.form { padding-bottom: 24px; }
.field-group { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.form .group-title { padding-top: 4px; }
.field { display: flex; flex-direction: column; gap: 2px; padding: 9px 16px; }
.field + .field { border-top: 0.5px solid var(--separator); }
.field > span:first-child { font-size: 13px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.field.inline > span:first-child { font-size: 17px; color: var(--text); }
.field input:not([type=checkbox]):not([type=radio]), .field textarea, .field select {
  border: 0; background: none; color: var(--text); font: inherit; font-size: 17px; padding: 4px 0; width: 100%;
  outline: none; -webkit-appearance: none; appearance: none; resize: vertical;
}
.field.inline input:not([type=checkbox]), .field.inline select { width: auto; text-align: right; color: var(--accent); max-width: 60%; }
.field select { cursor: pointer; }
.field.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.pair { display: flex; gap: 8px; }
.pair select { color: var(--accent) !important; }
.field ::placeholder { color: var(--faint); }

.kind-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 18px; }
.kind-option input { position: absolute; opacity: 0; pointer-events: none; }
.kind-option > span {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px;
  border-radius: 12px; background: var(--card); font-size: 13px; cursor: pointer; border: 1.5px solid transparent;
}
.kind-icon { font-size: 20px; }
.kind-option input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.kind-option input:focus-visible + span { outline: 2px solid var(--accent); }

.switch { position: relative; width: 51px; height: 31px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--separator); border-radius: 16px; transition: background 0.2s; cursor: pointer; }
.switch span::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transition: transform 0.2s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

.howto { padding-left: 20px; margin: 0 0 8px; line-height: 1.5; }
.howto li { margin-bottom: 6px; }

/* ---- Sheets -------------------------------------------------------------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, 0);
  display: flex; align-items: flex-end; justify-content: center; transition: background 0.25s;
}
.sheet-backdrop.open { background: rgba(0, 0, 0, 0.4); }
.sheet {
  width: 100%; max-width: 640px; max-height: calc(100vh - var(--safe-t) - 24px);
  background: var(--bg); border-radius: 14px 14px 0 0; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sheet-tall { height: calc(100vh - var(--safe-t) - 24px); }
.sheet-backdrop.open .sheet { transform: none; }
.sheet-header {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 6px 8px; border-bottom: 0.5px solid var(--separator);
}
.sheet-header h2 { font-size: 17px; font-weight: 600; text-align: center; }
.sheet-header .link-btn:last-child, .sheet-header .spacer { justify-self: end; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px calc(16px + var(--safe-b)); }

.action-sheet {
  width: 100%; max-width: 480px; padding: 8px 8px calc(8px + var(--safe-b));
  transform: translateY(100%); transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sheet-backdrop.open .action-sheet { transform: none; }
.action-group { background: var(--card); border-radius: 14px; overflow: hidden; margin-bottom: 8px; }
.action-title { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; text-align: center; font-size: 13px; color: var(--muted); border-bottom: 0.5px solid var(--separator); }
.action-title strong { font-size: 13px; font-weight: 600; }
.action-btn { display: block; width: 100%; padding: 16px; border: 0; background: none; color: var(--blue); font-size: 19px; cursor: pointer; }
.action-btn + .action-btn { border-top: 0.5px solid var(--separator); }
.action-btn.strong { font-weight: 600; }
.action-btn.destructive { color: var(--overdue); }
.action-btn:active { background: var(--separator); }

/* ---- Toast --------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 200;
  transform: translate(-50%, 20px); opacity: 0; transition: all 0.25s;
  background: rgba(30, 30, 32, 0.92); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 15px; max-width: calc(100vw - 32px); text-align: center; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--overdue); }

/* ---- Map ----------------------------------------------------------------- */

body[data-route="map"] #app { padding-bottom: 0; }
.map-wrap { position: fixed; top: calc(44px + var(--safe-t)); left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); }
#map { position: absolute; inset: 0; background: var(--bg); }
.map-panel {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 500;
  max-width: 520px; margin: 0 auto;
  background: var(--bar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 16px; padding: 12px 14px; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.map-panel .btn-row { margin-top: 10px; }
.map-locate {
  position: absolute; top: 12px; right: 12px; z-index: 500; width: 44px; height: 44px; border-radius: 12px;
  border: 0; background: var(--bar); color: var(--blue); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); cursor: pointer;
}
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 13px; justify-content: center; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { width: 9px; height: 9px; }
.pin-wrap { background: none; border: 0; }
.pin {
  position: relative; width: 30px; height: 30px; border-radius: 50%; margin: 2px;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 15px; font-weight: 700;
  border: 2.5px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); transition: transform 0.15s;
}
.pin::after {
  content: ''; position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top: 7px solid #fff;
}
.pin-overdue { background: var(--overdue); }
.pin-soon { background: var(--soon); }
.pin-ok { background: var(--ok); }
.pin-selected { transform: scale(1.25); }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10px; }

/* ---- Auth & loading ------------------------------------------------------ */

.auth { max-width: 360px; margin: 0 auto; padding: calc(64px + var(--safe-t)) 24px 24px; text-align: center; }
.auth-icon { border-radius: 20px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); margin-bottom: 16px; }
.auth h1 { font-size: 30px; margin-bottom: 4px; }
.auth-form { display: grid; gap: 10px; margin: 24px 0 12px; }
.auth-form input {
  height: 48px; border-radius: 12px; border: 0; background: var(--card); color: var(--text);
  padding: 0 16px; font-size: 17px; outline: none;
}
.auth-form input:focus { box-shadow: 0 0 0 2px var(--accent); }
.auth-error { color: var(--overdue); min-height: 1.2em; font-size: 15px; margin: 0; }

.loading { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--separator); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 760px) {
  .member-actions { max-width: 480px; }
}
