:root {
  --brand: #1f3a5f;
  --brand-2: #2c5282;
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #5b6472;
  --line: #d9dde3;
  --error: #b3261e;
  --error-bg: #fdecea;
  --ok: #1e7a46;
  --ok-bg: #e7f5ec;
  --radius: 14px;
  --tap: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  /* Stop the browser's own pull-to-refresh / bounce so ours is the only one. */
  overscroll-behavior-y: contain;
}
body {
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: #fff;
  padding: calc(12px + var(--safe-top)) calc(16px + var(--safe-right)) 12px calc(16px + var(--safe-left));
  display: flex; align-items: center; gap: 12px;
}
.topbar img { width: 32px; height: 32px; border-radius: 8px; }
.topbar h1 { font-size: 1.1rem; margin: 0; font-weight: 650; flex: 1; }
.topbar .who { font-size: .8rem; opacity: .85; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main {
  max-width: 560px; margin: 0 auto;
  padding: 16px calc(16px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
main.wide { max-width: 900px; }
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.intro h2 { margin: 4px 0 6px; font-size: 1.45rem; }
.intro p { margin: 0 0 8px; color: var(--muted); }
.field { margin-top: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 360px) { .row { grid-template-columns: 1fr; } }
input, select, textarea {
  width: 100%; min-height: var(--tap);
  font: inherit; font-size: 17px; /* >=16px stops iOS zoom on focus */
  padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text);
  appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid #7aa7e0; outline-offset: 1px; border-color: var(--brand-2); }
.field.invalid input, .field.invalid select { border-color: var(--error); background: #fffafa; }
.field .msg { color: var(--error); font-size: .9rem; margin-top: 4px; min-height: 0; }
.consent { display: flex; gap: 12px; align-items: flex-start; margin-top: 20px; padding: 14px; border: 1.5px solid var(--line); border-radius: 10px; }
.consent input { width: 26px; height: 26px; min-height: 26px; flex: 0 0 26px; margin: 2px 0 0; appearance: auto; -webkit-appearance: checkbox; accent-color: var(--brand); }
.consent label { font-weight: 500; }
.consent.invalid { border-color: var(--error); }
.privacy { font-size: .9rem; color: var(--muted); margin: 8px 0 0; }
.ts { margin-top: 18px; min-height: 65px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px;
  font: inherit; font-weight: 650;
  border-radius: 12px; border: 0; cursor: pointer;
  background: var(--brand); color: #fff; text-decoration: none;
}
.btn.block { width: 100%; margin-top: 20px; font-size: 1.05rem; }
.btn.secondary { background: #e8edf4; color: var(--brand); }
.btn.danger { background: var(--error-bg); color: var(--error); }
.btn[disabled] { opacity: .6; cursor: progress; }
.alert { border-radius: 10px; padding: 12px 14px; margin-top: 16px; }
.alert.error { background: var(--error-bg); color: var(--error); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.success { text-align: center; padding: 32px 20px; }
.success .check { width: 72px; height: 72px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); display: grid; place-items: center; margin: 0 auto 12px; font-size: 40px; }
.success h2 { margin: 8px 0; }
.success p { color: var(--muted); }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.spin { width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Pull-to-refresh */
.ptr {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 8px); z-index: 20;
  width: 40px; height: 40px; margin-left: -20px; border-radius: 50%;
  background: #fff; color: var(--brand); box-shadow: 0 2px 8px rgba(0,0,0,.18);
  display: grid; place-items: center;
  transform: translateY(-70px); opacity: 0; pointer-events: none;
}
.ptr svg { width: 22px; height: 22px; }
.ptr.loading svg { animation: spin .8s linear infinite; }
.ptr.anim { transition: transform .25s ease, opacity .25s ease; }

/* Admin */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 220px; }
.count { color: var(--muted); font-size: .9rem; margin: 12px 2px 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { margin-top: 8px; }
.list button {
  width: 100%; text-align: left; font: inherit; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; min-height: 64px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
}
.list .name { font-weight: 650; }
.list .meta { color: var(--muted); font-size: .9rem; grid-column: 1 / -1; overflow-wrap: anywhere; }
.list .date { color: var(--muted); font-size: .85rem; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom)); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.sheet-head h2 { flex: 1; font-size: 1.1rem; margin: 0; }
.sheet-body { padding: 4px 16px 16px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.sheet-actions .btn { flex: 1 1 140px; }
.audit { color: var(--muted); font-size: .85rem; margin-top: 14px; }
.icon-btn { min-width: 44px; min-height: 44px; border: 0; background: transparent; font-size: 24px; cursor: pointer; border-radius: 10px; color: var(--muted); }
