/* Storm Vault: mobile-first, usable at 375 px, light and dark. No inline styles (the CSP blocks them).
   Low-power mode sets data-theme="dark" and data-low="1" on <html>: dark colors, no animations or transitions. */
:root {
  --accent: #173a5e; --accent-ink: #ffffff; --accent-soft: #e4ecf5; --link: #1d5c9a;
  --alert: #b4410f; --alert-bg: #fdeee4; --ok: #1d6b45;
  --bg: #f3f5f8; --card: #ffffff; --text: #18202a; --muted: #5a6573; --line: #dde3ea;
  --danger: #b3261e; --tag: #fff1c2; --tag-ink: #6b4b00;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #8fc1f0; --accent-ink: #0b1622; --accent-soft: #1a2a3b; --link: #9ccaff;
    --alert: #ffb68a; --alert-bg: #3a2216; --ok: #8fd8b0;
    --bg: #0f1720; --card: #17212c; --text: #e9eef3; --muted: #a3afbc; --line: #2a3644;
    --danger: #ffb4ab; --tag: #4a3b10; --tag-ink: #ffe08a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #8fc1f0; --accent-ink: #0b1622; --accent-soft: #1a2a3b; --link: #9ccaff;
  --alert: #ffb68a; --alert-bg: #3a2216; --ok: #8fd8b0;
  --bg: #0f1720; --card: #17212c; --text: #e9eef3; --muted: #a3afbc; --line: #2a3644;
  --danger: #ffb4ab; --tag: #4a3b10; --tag-ink: #ffe08a;
  color-scheme: dark;
}
:root[data-low="1"] *, :root[data-low="1"] *::before, :root[data-low="1"] *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.45 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); }
h1 { font-size: 1.5rem; line-height: 1.2; margin: 8px 0 10px; }
h2 { font-size: 1rem; margin: 0 0 8px; color: var(--accent); }
h2.sec { margin: 18px 2px 8px; text-transform: uppercase; letter-spacing: .04em; font-size: .85rem; }
p { margin: 6px 0; }
ul { margin: 6px 0; padding-left: 20px; } li { margin: 4px 0; }
.muted { color: var(--muted); } .small { font-size: .86rem; } .center { text-align: center; } .pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.big { font-size: 1.25rem; font-weight: 700; }
.warn { color: var(--alert); font-weight: 600; }
.danger { color: var(--danger) !important; }

/* top bar and tabs */
.top { position: sticky; top: 0; z-index: 5; padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--card); border-bottom: 1px solid var(--line); }
.top .bar { display: flex; align-items: center; gap: 8px; max-width: 680px; margin: 0 auto; }
.top .status { display: flex; flex-wrap: wrap; gap: 6px; max-width: 680px; margin: 6px auto 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text); text-decoration: none; min-width: 0; }
.brand img { border-radius: 7px; flex: 0 0 auto; }
.brand span { white-space: nowrap; }
.sp { flex: 1 1 auto; }
.chip { font-size: .72rem; padding: 3px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.chip.off { background: var(--alert-bg); color: var(--alert); font-weight: 700; }
.chip.warn { background: var(--tag); color: var(--tag-ink); }
.hb { flex: 0 0 auto; background: transparent; color: var(--accent); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-weight: 600; min-height: 36px; font-size: .9rem; }
main { padding: 12px 16px calc(92px + env(safe-area-inset-bottom)); max-width: 680px; margin: 0 auto; }
main.center { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: .74rem; color: var(--muted); text-decoration: none; }
.tabs a span { font-size: 1.3rem; line-height: 1; }
.tabs a.on { color: var(--accent); font-weight: 700; }

/* blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 0 0 12px; }
.card.vault { border-color: var(--accent); }
.card.tip { background: var(--accent-soft); border-color: transparent; }
.card.safety { border-left: 5px solid var(--alert); }
.card.follow { border-left: 5px solid var(--accent); }
.card.done { border-left: 5px solid var(--ok); }
.hero { background: linear-gradient(135deg, #173a5e, #285f93); color: #fff; border-radius: 16px; padding: 16px; margin-bottom: 12px; }
.hero.after { background: linear-gradient(135deg, #7a2e0e, #b4410f); }
.hero h1 { margin-top: 0; color: #fff; }
.hero a { color: #fff; }
.hero .tag.verify { color: var(--tag-ink); }
.flash { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 8px 12px; }
.lowbar { background: var(--alert-bg); color: var(--alert); border-radius: 10px; padding: 8px 12px; font-size: .86rem; font-weight: 600; }
.note { background: var(--alert-bg); border-radius: 10px; padding: 8px 12px; }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.tag.verify { background: var(--tag); color: var(--tag-ink); }
.tag.warn { background: var(--alert-bg); color: var(--alert); }
.src { color: var(--muted); overflow-wrap: anywhere; }
.back { margin: 0 0 4px; } .back a { text-decoration: none; font-weight: 600; }
.cta { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 10px; }

/* buttons */
.btn, button.btn, a.btn { display: inline-block; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 700; text-decoration: none; text-align: center; cursor: pointer; min-height: 44px; }
.btn.big { display: block; width: 100%; padding: 15px; font-size: 1.08rem; margin: 6px 0 14px; }
.btn:disabled, button:disabled { opacity: .5; cursor: default; }
button.ghost, .btn.ghost, .btnlike { display: inline-block; background: transparent; color: var(--accent); border: 1px solid var(--line); border-radius: 12px; padding: 9px 13px; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 44px; }
.btn.small, .ghost.small, .btnlike.small { padding: 6px 10px; font-size: .85rem; min-height: 36px; }
button.link { background: none; border: 0; color: var(--link); text-decoration: underline; padding: 0; cursor: pointer; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.row > input { flex: 1 1 160px; min-width: 0; }
.picks label.btn { cursor: pointer; }

/* forms */
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); min-height: 44px; }
textarea { min-height: 84px; resize: vertical; }
.form label { display: block; margin-bottom: 12px; font-size: .86rem; color: var(--muted); font-weight: 600; }
.form label > .small { display: block; font-weight: 400; }
.form label input, .form label select, .form label textarea { margin-top: 4px; color: var(--text); font-size: 1rem; font-weight: 400; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-size: .95rem; color: var(--text); font-weight: 400; cursor: pointer; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--accent); }
.setting { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.setting .row { margin-top: 0; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-top: 8px; }

/* lists */
.tile { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 0 0 10px; color: var(--text); text-decoration: none; }
.tile .ti { font-size: 1.6rem; width: 36px; text-align: center; flex: 0 0 auto; }
.tile .tt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.tile .tt b { overflow-wrap: anywhere; }
.go { color: var(--muted); font-size: 1.4rem; flex: 0 0 auto; }
.step { padding: 10px 0; border-top: 1px solid var(--line); }
.step:first-of-type { border-top: 0; padding-top: 0; }
.step.done b { text-decoration: line-through; color: var(--muted); }
.step p.small { margin-left: 32px; }
.step .src { margin-left: 32px; }
.progress { font-weight: 700; color: var(--accent); }
.links { padding-left: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.chipbtn { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--accent); border-radius: 999px; padding: 6px 12px; font-size: .86rem; text-decoration: none; cursor: pointer; }
.docrow { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 0; color: var(--text); cursor: pointer; }
.docrow img, .docic { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex: 0 0 auto; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 700; color: var(--accent); }
.doctx { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.itemrow { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.itemrow > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.amt { white-space: nowrap; font-variant-numeric: tabular-nums; }
.contact { padding: 10px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.contact .row { margin-top: 6px; }
.kv { display: grid; grid-template-columns: minmax(0, 40%) minmax(0, 60%); gap: 4px 10px; margin: 0 0 6px; }
.kv dt { color: var(--muted); font-size: .86rem; } .kv dd { margin: 0; overflow-wrap: anywhere; }
.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.totals div { display: flex; flex-direction: column; min-width: 0; }
.totals b { font-size: 1.15rem; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.card.sum { background: var(--accent-soft); border-color: transparent; }

/* photos */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 8px 0; }
.ph { position: relative; padding: 0; border: 0; background: var(--accent-soft); border-radius: 8px; overflow: hidden; aspect-ratio: 1; cursor: pointer; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .noimg { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 1.6rem; }
.ph .cap { position: absolute; left: 0; right: 0; bottom: 0; font-size: .62rem; line-height: 1.2; color: #fff; background: rgba(0, 0, 0, .55); padding: 3px 4px; text-align: left; }
.thumbs figure { margin: 8px 0; }
.thumbs img, .thumbs .pdf { max-width: 160px; max-height: 160px; border-radius: 8px; display: block; }
.thumbs .pdf { width: 100px; height: 100px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--accent); }
.thumbs figcaption { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }

/* viewer: an in-page layer, never the browser's full screen */
.overlay { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; }
.dv-bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line); background: var(--card); }
.dv-bar > div { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.dv-x { background: none; border: 1px solid var(--line); border-radius: 999px; width: 40px; height: 40px; flex: 0 0 auto; cursor: pointer; color: var(--text); }
.dv-stage { flex: 1 1 auto; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #000; }
.dv-stage.zoom { touch-action: none; }
.dv-stage img { max-width: 100%; max-height: 100%; transform-origin: center; user-select: none; }
.dv-stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.dv-file { color: #fff; text-align: center; padding: 20px; }
.dv-tools { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.dv-hint { text-align: center; margin: 0; padding: 0 0 6px; background: var(--card); }

@media (min-width: 700px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media print { .top, .tabs { display: none; } main { padding: 0; } }
