:root {
  --bg: #f6f4f1; --card: #fff; --fg: #1d1b19; --muted: #6b645d; --line: #e4dfd8;
  --red: #c62828; --red-soft: #fdecea; --amber: #b26a00; --amber-soft: #fff4e0;
  --green: #2e7d32; --green-soft: #e8f5e9; --blue: #1565c0;
  --r: 14px; --tabs: 64px;
  font-size: 17px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #121110; --card: #1e1c1a; --fg: #f1ede8; --muted: #a8a097; --line: #34302c;
    --red: #ef5350; --red-soft: #3a1c1b; --amber: #ffb74d; --amber-soft: #3a2c16;
    --green: #66bb6a; --green-soft: #1b2e1c; --blue: #64b5f6;
  }
}
:root[data-theme=dark] {
  --bg: #121110; --card: #1e1c1a; --fg: #f1ede8; --muted: #a8a097; --line: #34302c;
  --red: #ef5350; --red-soft: #3a1c1b; --amber: #ffb74d; --amber-soft: #3a2c16;
  --green: #66bb6a; --green-soft: #1b2e1c; --blue: #64b5f6;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45; -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--tabs) + env(safe-area-inset-bottom));
}
a { color: var(--blue); }
h1 { font-size: 1.45rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .5rem; }
h3 { font-size: 1.02rem; margin: 1rem 0 .3rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); font-size: .9rem; }

/* Thanh trên */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .6rem;
  padding: calc(.5rem + env(safe-area-inset-top)) 1rem .5rem; background: var(--red); color: #fff;
}
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-size: 1.1rem; flex: 1; }
.brand img { background: #fff; border-radius: 8px; }
.net { font-size: .75rem; padding: .15rem .5rem; border-radius: 99px; background: rgba(255,255,255,.2); white-space: nowrap; }
.menu { text-decoration: none; font-size: 1.3rem; }

main { max-width: 760px; margin: 0 auto; padding: 1rem; outline: none; }

/* Thanh tab dưới */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: var(--tabs); text-decoration: none; color: var(--muted); font-size: .72rem; gap: 2px;
}
.tabs a i { font-style: normal; font-size: 1.35rem; line-height: 1; }
.tabs a.on { color: var(--red); font-weight: 600; }

/* Khối chung */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: .9rem 1rem; margin: .7rem 0; }
.btn, button {
  font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .5rem 1rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); text-decoration: none; cursor: pointer; margin: .2rem .2rem .2rem 0;
}
.btn.primary, button.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn.big, button.big { width: 100%; min-height: 56px; font-size: 1.1rem; }
button:disabled { opacity: .5; }
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: .5rem .6rem; min-height: 44px; width: 100%;
}
label.f { display: block; margin: .5rem 0; font-size: .9rem; color: var(--muted); }
label.f input, label.f select, label.f textarea { margin-top: .2rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* Số khẩn cấp */
.sos-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-bottom: .6rem; }
.sos-bar a {
  display: flex; flex-direction: column; align-items: center; padding: .55rem .2rem; border-radius: 12px;
  background: var(--red-soft); color: var(--red); text-decoration: none; border: 1px solid transparent;
}
.sos-bar a b { font-size: 1.45rem; line-height: 1.1; }
.sos-bar a span { font-size: .7rem; text-align: center; }

/* Hộ gia đình */
.steppers { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .8rem; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: .3rem; }
.stepper span { font-size: .92rem; }
.stepper .ctl { display: flex; align-items: center; gap: .2rem; }
.stepper button { min-width: 40px; min-height: 40px; padding: 0; margin: 0; border-radius: 50%; font-size: 1.2rem; }
.stepper output { min-width: 1.6rem; text-align: center; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.chip {
  min-height: 38px; padding: .3rem .75rem; border-radius: 99px; border: 1px solid var(--line);
  background: var(--bg); font-size: .88rem; margin: 0;
}
.chip.on { background: var(--red); border-color: var(--red); color: #fff; }

/* Tiến độ */
.progress { height: 12px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width .3s; }
.stat { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .35rem; }
.stat b { font-size: 1.4rem; }

/* Danh sách đồ */
details.cat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin: .6rem 0; }
details.cat > summary {
  list-style: none; cursor: pointer; padding: .8rem 1rem; display: flex; align-items: center; gap: .6rem; font-weight: 600;
}
details.cat > summary::-webkit-details-marker { display: none; }
details.cat > summary .n { margin-left: auto; font-weight: 400; color: var(--muted); font-size: .85rem; }
.item { display: flex; gap: .7rem; padding: .65rem 1rem; border-top: 1px solid var(--line); }
.item input[type=checkbox] { width: 26px; height: 26px; min-height: 0; flex: none; margin-top: .1rem; accent-color: var(--green); }
.item .t { flex: 1; min-width: 0; }
.item .q { color: var(--red); font-weight: 600; font-size: .92rem; }
.item.done .name { text-decoration: line-through; color: var(--muted); }
.item .note { font-size: .85rem; color: var(--muted); }
.tag { display: inline-block; font-size: .68rem; padding: 0 .4rem; border-radius: 6px; margin-left: .25rem; vertical-align: 2px; }
.tag.bag { background: var(--amber-soft); color: var(--amber); }
.tag.must { background: var(--red-soft); color: var(--red); }
.exp { display: flex; align-items: center; gap: .4rem; margin-top: .3rem; font-size: .82rem; color: var(--muted); }
.exp input { width: auto; min-height: 34px; padding: .2rem .4rem; font-size: .85rem; }
.exp.late { color: var(--red); font-weight: 600; }
.exp.soon { color: var(--amber); font-weight: 600; }

.alert { border-radius: var(--r); padding: .7rem 1rem; margin: .6rem 0; }
.alert.warn { background: var(--amber-soft); color: var(--fg); border-left: 5px solid var(--amber); }
.alert.ok { background: var(--green-soft); border-left: 5px solid var(--green); }
.alert.red { background: var(--red-soft); border-left: 5px solid var(--red); }

/* Kế hoạch 72 giờ */
.clock { text-align: center; padding: 1rem; }
.clock .h { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.phase { border-left: 5px solid var(--line); }
.phase.now { border-left-color: var(--red); box-shadow: 0 0 0 2px var(--red-soft); }
.phase.past { opacity: .7; }
.phase h3 { margin-top: 0; }
.step { display: flex; gap: .6rem; padding: .35rem 0; align-items: flex-start; }
.step input { width: 24px; height: 24px; min-height: 0; flex: none; margin-top: .15rem; accent-color: var(--green); }
.step.done span { color: var(--muted); text-decoration: line-through; }

/* Cẩm nang */
.list a.g {
  display: flex; align-items: center; gap: .7rem; padding: .8rem 1rem; text-decoration: none; color: var(--fg);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin: .45rem 0;
}
.list a.g i { font-style: normal; font-size: 1.4rem; }
.list a.g.urgent { border-color: var(--red); }
.list a.g .chev { margin-left: auto; color: var(--muted); }
.guide { font-size: 1.05rem; }
.guide ol.big li { margin: .45rem 0; }
.guide li { margin: .25rem 0; }
.guide .warn { background: var(--red-soft); border-radius: 10px; padding: .6rem .8rem; }
.back { display: inline-block; margin-bottom: .4rem; text-decoration: none; }

/* Công cụ */
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.tools a {
  display: flex; flex-direction: column; gap: .2rem; padding: 1rem; border-radius: var(--r); text-decoration: none;
  color: var(--fg); background: var(--card); border: 1px solid var(--line); min-height: 110px;
}
.tools a i { font-style: normal; font-size: 2rem; }
.tools a span { font-size: .8rem; color: var(--muted); }
.coords { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; word-break: break-all; }
.compass { width: 240px; height: 240px; margin: 1rem auto; position: relative; border-radius: 50%; border: 3px solid var(--fg); }
.compass .dial { position: absolute; inset: 0; transition: transform .15s linear; }
.compass .dial b { position: absolute; left: 50%; transform: translateX(-50%); font-size: 1.3rem; }
.compass .dial b.n { top: 6px; color: var(--red); } .compass .dial b.s { bottom: 6px; }
.compass .dial b.e, .compass .dial b.w { top: 50%; transform: translateY(-50%); left: auto; }
.compass .dial b.e { right: 10px; } .compass .dial b.w { left: 10px; }
.compass .needle { position: absolute; left: 50%; top: 18px; width: 4px; height: 102px; margin-left: -2px; background: var(--red); border-radius: 4px; }
.big-num { font-size: 4rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.beat { width: 160px; height: 160px; border-radius: 50%; background: var(--red); margin: 1rem auto; transition: transform .08s; }
.beat.on { transform: scale(.85); }

/* Gia đình */
.member { border-top: 1px solid var(--line); padding-top: .6rem; margin-top: .6rem; }
.member:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; }

/* Lớp phủ đèn, SOS */
#overlay {
  position: fixed; inset: 0; z-index: 100; background: #fff; display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: calc(2rem + env(safe-area-inset-bottom));
}
#overlay[hidden] { display: none; }
#overlay.dark { background: #000; }
#overlay button { background: rgba(0,0,0,.6); color: #fff; border: 0; min-width: 200px; }

.print-only { display: none; }
@media print {
  .top, .tabs, .no-print, .sos-bar, button, .btn { display: none !important; }
  body { padding: 0; background: #fff; color: #000; }
  main { max-width: none; padding: 0; }
  .print-only { display: block; }
  details.cat { break-inside: avoid; border: 1px solid #999; }
  .card { border: 1px solid #999; break-inside: avoid; }
  .item input { display: none; }
  .item::before { content: "☐"; font-size: 1.2rem; }
  .item.done::before { content: "☑"; }
  .exp input { border: 0; }
}

/* Gói làm sẵn */
.shop-cta { display: flex; gap: .7rem; align-items: center; text-decoration: none; color: var(--fg); border-color: var(--red); }
.shop-cta > span:first-child { font-size: 1.8rem; }
.pack { position: relative; }
.pack.best { border: 2px solid var(--red); }
.pack .ribbon { position: absolute; top: -.7rem; right: .8rem; background: var(--red); color: #fff; font-size: .75rem; padding: .15rem .6rem; border-radius: 99px; }
.pack-h { display: flex; gap: .6rem; align-items: center; }
.pack-h .pi { font-size: 2rem; }
.pack p { margin: .5rem 0; }
.pack .price { font-size: 1.05rem; margin: .3rem 0; }
.pack .price b { color: var(--red); }
.pack .price s { color: var(--muted); font-size: .9rem; }
.pack details summary { cursor: pointer; color: var(--blue); margin: .3rem 0; }
ul.pk { margin: .3rem 0; padding-left: 1.2rem; font-size: .92rem; }
ul.pk li.got { color: var(--muted); }
.qty output { min-width: 2rem; text-align: center; font-weight: 600; }
ul.rec { list-style: none; padding: 0; margin: .4rem 0; }
ul.rec li { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
