/* Bacon Care Log */
:root {
  --bg: #f6f1ea;
  --card: #fffdf9;
  --ink: #2a241d;
  --muted: #7a6f63;
  --line: #e7ddd0;
  --soft: #f1e9de;
  --accent: #c2603d;
  --accent-ink: #fff;
  --accent-soft: #f7e3d9;
  --good: #3f8a5a;
  --good-soft: #e1f0e5;
  --warn: #b7791f;
  --warn-soft: #fbefd5;
  --bad: #b83a3a;
  --bad-soft: #f8dfdf;
  --blue: #3c6e9f;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --card: #211d18;
    --ink: #efe7dc;
    --muted: #a3978a;
    --line: #362f27;
    --soft: #2a251f;
    --accent: #e08462;
    --accent-ink: #1b120d;
    --accent-soft: #3a261d;
    --good: #6cc08a;
    --good-soft: #1f3326;
    --warn: #e0b057;
    --warn-soft: #3a2f19;
    --bad: #ef7d7d;
    --bad-soft: #3d2020;
    --blue: #86b3df;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small, small { font-size: .82rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .25rem 0 .75rem; }
.wrap { max-width: 980px; margin: 0 auto; padding: 12px 16px 24px; }

/* top + tab bars */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); font-size: 1.1rem; }
.topnav { display: none; gap: 4px; flex: 1; }
.topnav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; }
.topnav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.who { margin-left: auto; color: var(--muted); font-size: .85rem; }
.reload {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 1.25rem; line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.reload.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* pull-to-refresh indicator */
.ptr {
  position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 50%; z-index: 40;
  width: 40px; height: 40px; margin-left: -20px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 1.3rem; color: var(--accent);
  transform: translateY(-70px); opacity: 0; pointer-events: none;
}
.ptr.ready { color: var(--accent-ink); background: var(--accent); }
.ptr.spin { transform: translateY(40px); opacity: 1; animation: spin .8s linear infinite; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; padding: 4px 0;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a:last-child svg { fill: currentColor; stroke: none; }
.tabbar a.on { color: var(--accent); font-weight: 600; }
@media (min-width: 820px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  body { padding-bottom: 24px; }
}

/* cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 14px 0; box-shadow: var(--shadow);
}
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.flash { background: var(--good-soft); color: var(--good); padding: 10px 14px; border-radius: 12px; margin: 10px 0; font-weight: 500; }
.flash.err { background: var(--bad-soft); color: var(--bad); }

/* forms */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
label { display: block; font-size: .85rem; color: var(--muted); }
label > input, label > select, label > textarea, label > .row { margin-top: 4px; color: var(--ink); }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.row.end { justify-content: flex-end; flex-wrap: wrap; }
.row.end .muted { margin-right: auto; }
.w-s { max-width: 90px; }
.center { text-align: center; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-bottom: 12px; }
.fgrid .full { grid-column: 1 / -1; }
@media (min-width: 640px) { .fgrid { grid-template-columns: repeat(3, 1fr); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); background: transparent; }
.btn:disabled { opacity: .55; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; font-size: .9rem; text-decoration: none; }

/* segmented + chips */
.seg { display: inline-flex; flex-wrap: wrap; background: var(--soft); border-radius: 12px; padding: 3px; gap: 2px; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 12px; border-radius: 9px; color: var(--muted); cursor: pointer; font-size: .88rem; }
.seg input:checked + span { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg.small span { padding: 5px 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { margin: 0; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; color: var(--ink); cursor: pointer; }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); }
.chipbtn { padding: 10px 16px; min-width: 52px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); cursor: pointer; font-weight: 600; }
.chipbtn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chips.big { gap: 8px; }

/* day header + stats */
.dayhead { display: flex; align-items: center; gap: 10px; margin: 6px 0 10px; }
.daytitle { flex: 1; text-align: center; }
.navbtn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: 1.5rem;
}
.navbtn.ghost { visibility: hidden; }
.datepick { position: relative; display: inline-block; color: var(--muted); font-size: .9rem; cursor: pointer; }
.datepick input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat .k { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: .8rem; font-weight: 500; color: var(--muted); margin-left: 2px; }
.stat .s { font-size: .78rem; color: var(--muted); }

.plans { background: var(--warn-soft); border-color: transparent; }

/* daily quote */
.quote {
  position: relative; margin: 14px 0; padding: 16px 18px 16px 52px;
  background: linear-gradient(135deg, var(--accent-soft), var(--card));
  border: 1px solid var(--line); border-radius: var(--radius);
}
.quote .q-mark {
  position: absolute; left: 14px; top: 2px; font-size: 3.4rem; line-height: 1;
  color: var(--accent); font-family: Georgia, "Times New Roman", serif; opacity: .7;
}
.quote blockquote { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.05rem; font-style: italic; line-height: 1.45; }
.plans ul { margin: 6px 0 0; padding-left: 20px; }

/* quick log */
.timechip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: .9rem; }
.timechip.set { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); font-weight: 600; }
.qgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .qgrid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 820px) { .qgrid { grid-template-columns: repeat(6, 1fr); } }
.qbtn {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 82px; padding: 10px 6px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; transition: transform .12s;
}
.qbtn:active, .qbtn.pop { transform: scale(.94); }
.qbtn .qi { font-size: 1.6rem; line-height: 1; }
.qbtn .ql { font-size: .82rem; font-weight: 600; text-align: center; }
.qbtn .qs { font-size: .72rem; color: var(--muted); }
.qbtn .qc {
  position: absolute; top: 6px; right: 6px; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .75rem; font-weight: 700;
  display: grid; place-items: center;
}
.qbtn .qc:empty { display: none; }
.qbtn.concern { border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.qbtn.special { background: var(--soft); }
.qbtn.asleep { background: var(--accent-soft); border-color: var(--accent); }

/* meds */
.medlist { list-style: none; margin: 0; padding: 0; }
.medlist li { padding: 10px 0; border-top: 1px solid var(--line); }
.medlist li:first-child { border-top: 0; padding-top: 0; }
.med-name { margin-bottom: 6px; }
.slots { display: flex; flex-wrap: wrap; gap: 6px; }
.slot {
  display: inline-flex; flex-direction: column; align-items: center; line-height: 1.1;
  min-height: 40px; min-width: 70px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer; font-size: .85rem; font-weight: 600;
}
.slot small { font-weight: 400; font-size: .7rem; opacity: .8; }
.slot.done { background: var(--good-soft); color: var(--good); border-color: transparent; }
.slot.due { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.slot.missed { border-color: var(--bad); color: var(--bad); }
.slot.later { color: var(--muted); }
.slot.add { border-style: dashed; color: var(--muted); font-weight: 500; }

/* symptom grid */
.gridwrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.grid { width: 100%; border-collapse: collapse; font-size: .85rem; min-width: 520px; }
.grid th, .grid td { border-bottom: 1px solid var(--line); padding: 6px 6px; text-align: left; vertical-align: top; }
.grid thead th { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.grid tbody th { white-space: nowrap; font-weight: 600; }
.grid .ic { display: inline-block; width: 1.4em; }
.grid tr.zero th { color: var(--muted); font-weight: 500; }
.grid .tally { font-weight: 700; letter-spacing: 2px; color: var(--accent); display: block; }
.grid td small { color: var(--muted); display: block; line-height: 1.25; }
.grid .tot { font-weight: 700; text-align: center; }
.grid tr.concern:not(.zero) th { color: var(--bad); }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 62px 26px 1fr auto; gap: 6px; align-items: start; padding: 9px 0; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.timeline time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; padding-top: 1px; }
.tl-ic { text-align: center; }
.tl-body { min-width: 0; overflow-wrap: anywhere; }
.tl-note { color: var(--muted); font-size: .88rem; margin-top: 2px; }
.by { display: inline-block; font-size: .72rem; color: var(--muted); background: var(--soft); border-radius: 6px; padding: 0 6px; margin-top: 3px; }
.timeline .x { border: 0; background: none; color: var(--muted); font-size: 1.3rem; width: 36px; height: 32px; cursor: pointer; border-radius: 8px; }
.timeline .x:hover { background: var(--bad-soft); color: var(--bad); }
.timeline li.note-concern .tl-text { color: var(--bad); font-weight: 600; }
.timeline li.note-plan .tl-text { color: var(--warn); font-weight: 600; }
.timeline li.visit { background: var(--accent-soft); border-radius: 10px; padding-left: 6px; padding-right: 6px; border-top-color: transparent; }
.timeline li.visit a { font-weight: 600; color: var(--ink); }
.empty { padding: 10px 0; }

.redflags summary { cursor: pointer; list-style: none; }
.redflags summary::-webkit-details-marker { display: none; }
.redflags summary h2 { display: inline; }
.redflags .prose { margin-top: 10px; }

/* dialogs */
dialog.sheet {
  border: 0; border-radius: 20px; padding: 20px; width: min(520px, calc(100vw - 24px));
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(20, 14, 8, .45); }
@media (max-width: 560px) {
  dialog.sheet { margin: auto auto 0; width: 100%; max-width: 100%; border-radius: 20px 20px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
.rr-tap {
  width: 100%; min-height: 160px; border-radius: 20px; border: 0; background: var(--accent); color: var(--accent-ink);
  font-size: 1.6rem; font-weight: 700; cursor: pointer; touch-action: manipulation; margin: 8px 0;
}
.rr-tap:active { transform: scale(.98); }
.rr-tap:disabled { background: var(--good); }
.rr-read { font-variant-numeric: tabular-nums; color: var(--muted); }
.rr-result { font-size: 1.4rem; margin: 8px 0; }
.rr-result b { font-size: 2.4rem; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 12px; display: flex; gap: 12px; align-items: center;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); font-size: .92rem;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.err { background: var(--bad); color: #fff; }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; padding: 4px; }
@media (prefers-color-scheme: dark) { .toast button { color: var(--accent-ink); filter: invert(1); } }

/* generic lists / tables */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); }
.badge.tap { background: var(--accent); color: var(--accent-ink); }
.badge.bill { background: var(--warn-soft); color: var(--warn); }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 4px; flex-wrap: wrap; }

/* visits */
.visit-card h3 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.fluids { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.fluid { background: var(--soft); border-radius: 10px; padding: 6px 10px; font-size: .85rem; }
.fluid b { font-size: 1.05rem; }
.prose { white-space: normal; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* files */
.fgallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.fitem { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; text-decoration: none; color: var(--ink); }
.fthumb { aspect-ratio: 4 / 3; background: var(--soft); display: grid; place-items: center; font-size: 2.2rem; overflow: hidden; }
.fthumb img { width: 100%; height: 100%; object-fit: cover; }
.fmeta { padding: 8px 10px; font-size: .82rem; }
.fmeta b { display: block; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* trends */
.chartbox { position: relative; height: 240px; }
.chartgrid { display: grid; gap: 14px; }
@media (min-width: 900px) { .chartgrid { grid-template-columns: 1fr 1fr; } }
.chartgrid .card { margin: 0; }

/* more page */
.menu { list-style: none; margin: 0; padding: 0; }
.menu a { display: flex; align-items: center; gap: 12px; padding: 14px 4px; border-top: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 500; }
.menu li:first-child a { border-top: 0; }
.menu .mi { font-size: 1.3rem; width: 30px; text-align: center; }
.menu small { display: block; color: var(--muted); font-weight: 400; }

/* login */
.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { text-align: center; margin-bottom: 14px; }

/* print / report */
.report h1 { font-size: 1.5rem; }
.report .day { break-inside: avoid; page-break-inside: avoid; }
.report .day h2 { border-bottom: 2px solid var(--ink); padding-bottom: 4px; margin: 18px 0 8px; }
.report .grid { min-width: 0; font-size: .78rem; }
.report .timeline li { padding: 4px 0; grid-template-columns: 62px 22px 1fr; }
@media print {
  :root { --bg: #fff; --card: #fff; --ink: #000; --muted: #555; --line: #ccc; --soft: #f3f3f3; --accent: #000; --accent-soft: #f3f3f3; }
  body { padding: 0; font-size: 11pt; }
  .no-print, .tabbar, .topbar, .toast { display: none !important; }
  .card { box-shadow: none; border: 0; padding: 0; margin: 10px 0; }
  .wrap { max-width: none; padding: 0; }
  a { color: inherit; text-decoration: none; }
  .gridwrap { overflow: visible; margin: 0; padding: 0; }
}
