/* Usage — clean, compact UI following the family_net design language. */

:root {
  --bg: #f6f5f0;
  --card: #ffffff;
  --text: #26221c;
  --muted: #6f695e;
  --line: #e4e0d5;
  --accent: #2f6f4f;
  --accent-soft: #e3efe8;
  --danger: #b23a3a;
  --danger-soft: #f7e4e4;
  --ok: #2f6f4f;
  --radius-s: 10px;
  --radius-m: 16px;
  --shadow: 0 1px 3px rgba(38, 34, 28, 0.08), 0 6px 20px rgba(38, 34, 28, 0.06);
}

:root {
  /* Validated categorical series colors (dataviz reference palette). */
  --viz-1: #2a78d6;
  --viz-2: #eb6834;
  --viz-3: #1baf7a;
  --viz-grid: #e4e0d5;
}

:root[data-theme="dark"] {
  --viz-1: #3987e5;
  --viz-2: #d95926;
  --viz-3: #199e70;
  --viz-grid: #38342c;
}

:root[data-theme="dark"] {
  --bg: #191713;
  --card: #221f1a;
  --text: #ece8df;
  --muted: #a49c8d;
  --line: #38342c;
  --accent: #6fbf95;
  --accent-soft: #24352c;
  --danger: #e08a8a;
  --danger-soft: #3a2626;
  --ok: #6fbf95;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

/* The hidden attribute must beat any display rule (e.g. .public-page's flex). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 1rem; }
.wrap.narrow { max-width: 460px; }

.brand { display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 700; font-size: 1.15rem; }
.brand-logo { width: 26px; height: 26px; flex: none; }
.version { color: var(--muted); font-size: 0.75rem; font-weight: 400; margin-left: 0.35rem; }

.public-page { min-height: 100vh; display: flex; align-items: flex-start; }
.public-header { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0 1.5rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

label { display: block; margin: 0.75rem 0; font-size: 0.9rem; color: var(--muted); }
input, select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-s);
  border: 1px solid transparent;
  padding: 0.5rem 0.9rem;
}
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--accent-soft); }
button.ghost.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
button.compact { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
button.danger { background: var(--danger-soft); color: var(--danger); }

.actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }

button.busy { opacity: 0.75; pointer-events: none; }
button.busy::after {
  content: "";
  display: inline-block;
  vertical-align: -2px;
  width: 12px;
  height: 12px;
  margin-left: 0.45rem;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-right-color: currentColor;
  border-radius: 50%;
  animation: busy-spin 0.7s linear infinite;
}

@keyframes busy-spin {
  to { transform: rotate(360deg); }
}

.meta { color: var(--muted); font-size: 0.9rem; }
.notice { color: var(--ok); background: var(--accent-soft); padding: 0.6rem 0.8rem; border-radius: var(--radius-s); word-break: break-all; }
.error { color: var(--danger); background: var(--danger-soft); padding: 0.6rem 0.8rem; border-radius: var(--radius-s); }

.msym { width: 18px; height: 18px; flex: none; }
button.icon-button { display: inline-flex; align-items: center; justify-content: center; padding: 0.45rem; }

/* The theme button shows the mode it switches TO. */
.icon-light { display: none; }
:root[data-theme="dark"] .icon-light { display: inline; }
:root[data-theme="dark"] .icon-dark { display: none; }

/* One-line sticky top banner: brand, nav, account icons (our-stories layout).
   The header is a full-width child of the shell - no 100vw tricks, so
   position: sticky works everywhere and nothing overflows sideways. */
.app-header {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 56px;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.app-nav { display: flex; flex: 1; justify-content: center; gap: 0.3rem; }
.app-nav button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  white-space: nowrap;
}
.app-nav button.active { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.account-bar { display: flex; flex: none; gap: 0.3rem; }
.house-button { gap: 0.35rem; }
.house-name { max-width: 130px; overflow: hidden; font-size: 0.8rem; text-overflow: ellipsis; white-space: nowrap; }

.modal-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.45);
}
.modal {
  width: min(100%, 420px);
  max-height: calc(100vh - 2rem);
  padding: 1.25rem;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow);
}
.modal .actions { justify-content: flex-end; }
.modal .actions .push-left { margin-right: auto; }
td.cell-reading { cursor: pointer; }

.view-heading { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem; }
.view-heading h2 { margin: 0; }
.modal-backdrop.top-layer { z-index: 60; }
.icon-actions { display: inline-flex; gap: 0.3rem; }
button.icon-only { display: inline-flex; align-items: center; justify-content: center; padding: 0.3rem 0.45rem; }
button.icon-only .msym { width: 16px; height: 16px; }
.modal-heading {
  margin: 1rem 0 0.35rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.modal button.option { display: flex; width: 100%; margin: 0.35rem 0; justify-content: flex-start; }
.modal button.option.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.app-main { padding-top: 1rem; }

.tabs { display: flex; gap: 0.3rem; flex-wrap: nowrap; margin-bottom: 1rem; }
.tabs button { display: inline-flex; flex: none; align-items: center; gap: 0.4rem; white-space: nowrap; }
.tabs button { color: var(--muted); }
.tabs button.active { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

.version-tag {
  position: relative;
  display: inline-flex;
  flex: 0 1 auto;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.66rem;
  white-space: nowrap;
  cursor: default;
}
.version-tag > .msym { display: none; width: 16px; height: 16px; }
.version-tag .version-text { overflow: hidden; text-overflow: ellipsis; }

.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}
.mini-row:last-child { border-bottom: none; }
.mini-row.wrap-row { flex-wrap: wrap; }
.mini-row.inactive { opacity: 0.55; }

.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 140px; margin-top: 0; }
.stack-form { margin-top: 0.75rem; }
label.check { display: flex; align-items: center; gap: 0.35rem; margin: 0.5rem 0; color: var(--text); }
label.check input { width: auto; margin: 0; }
label.check.compact { display: inline-flex; margin: 0 0.4rem 0 0; font-size: 0.85rem; }
.house-checks { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.badge {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
}

.table-wrap { overflow-x: auto; }

/* The entries page never scrolls as a whole - only the table body does,
   under a sticky header row. A flex chain from the shell down hands the
   table exactly the height left over on any screen. */
body.view-fixed #app { display: flex; flex-direction: column; height: 100dvh; }
body.view-fixed .app-main { display: flex; flex: 1; flex-direction: column; min-height: 0; padding-bottom: 0; }
body.view-fixed #view-entries { display: flex; flex: 1; flex-direction: column; min-height: 0; }
body.view-fixed #view-entries .card {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0.4rem;
}
body.view-fixed #reading-list { display: flex; flex: 1; flex-direction: column; min-height: 0; }
body.view-fixed #app-error { width: 100%; }
#reading-list .table-wrap {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
}
#reading-list thead th {
  position: sticky;
  z-index: 1;
  top: 0;
  background: var(--card);
}

#reading-list td:first-child { white-space: nowrap; }
/* The first row of each year stands out slightly. */
#reading-list tr.year-row td {
  border-top: 2px solid var(--accent);
  background: color-mix(in srgb, var(--card) 94%, var(--accent) 6%);
}

#reading-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: nowrap;
  margin-top: 0.5rem;
  white-space: nowrap;
}
#reading-pager button[disabled] { opacity: 0.35; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.table-wrap th, .table-wrap td { padding: 0.3rem 0.45rem; text-align: right; border-bottom: 1px solid var(--line); }
.table-wrap th:first-child, .table-wrap td:first-child { text-align: left; }
.table-wrap thead th { color: var(--muted); font-weight: 600; }
.table-wrap td.total { font-weight: 700; }
.table-wrap th.hl-col, .table-wrap td.hl-col { background: var(--accent-soft); }
.table-wrap tr.hl-row th, .table-wrap tr.hl-row td { background: var(--accent-soft); }
.table-wrap tr.hl-row td.hl-col, .table-wrap tr.hl-row th.hl-col {
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--accent) 30%);
}

.stats-toggles {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

label.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}
label.switch input { position: absolute; width: 0; height: 0; opacity: 0; }
/* Long switch labels (e.g. the reminder opt-in) wrap inside cards. */
.card label.switch { margin: 0.75rem 0 0; white-space: normal; }
label.switch .slider {
  position: relative;
  flex: none;
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.15s;
}
label.switch .slider::after {
  content: "";
  position: absolute;
  top: 2.5px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
label.switch input:checked + .slider { background: var(--accent); }
label.switch input:checked + .slider::after { transform: translateX(14px); }
label.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

.viz-chart { width: 100%; height: auto; display: block; margin-top: 0.5rem; }
.viz-chart .grid line { stroke: var(--viz-grid); stroke-width: 1; }
.viz-chart .axis text { fill: var(--muted); font-size: 11px; }
.viz-chart .series path { fill: none; stroke-width: 2; }
.viz-chart .series circle.dot { stroke: var(--card); stroke-width: 2; }

.year-range { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.year-range .meta { flex: none; min-width: 84px; text-align: right; }
.year-slider {
  position: relative;
  flex: 1;
  height: 24px;
  cursor: pointer;
  touch-action: none;
}
.year-track {
  position: absolute;
  top: 10px;
  right: 0;
  left: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}
.year-fill { position: absolute; top: 0; height: 4px; border-radius: 2px; background: var(--accent); }
.year-thumb {
  position: absolute;
  top: 4px;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 2px solid var(--card);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: var(--shadow);
  cursor: grab;
}
.year-thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#year-reset { flex: none; }
#year-reset:disabled { opacity: 0.35; cursor: default; }

.viz-holder { position: relative; }
.viz-hover line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.viz-hover line.hov-main { stroke: var(--accent); stroke-dasharray: none; }
.viz-tip {
  position: absolute;
  z-index: 5;
  padding: 0.35rem 0.55rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
  line-height: 1.5;
  pointer-events: none;
  white-space: nowrap;
}
.viz-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.25rem; }
.viz-legend span, .viz-legend .legend-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text);
}
.viz-legend .legend-toggle { padding: 0.15rem 0.35rem; border: none; background: none; cursor: pointer; }
.viz-legend .legend-toggle:hover { background: var(--accent-soft); border-radius: var(--radius-s); }
.viz-legend .legend-toggle.off { opacity: 0.45; text-decoration: line-through; }
.viz-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }

@media (max-width: 760px) {
  /* The nav becomes a fixed bottom bar (our-stories pattern); the top banner
     keeps the brand and account icons on one line. */
  /* Reserve exactly the bottom bar's height (buttons + its paddings). */
  .app-shell { padding-bottom: calc(3.7rem + env(safe-area-inset-bottom, 0px)); }
  .account-bar { margin-left: auto; }
  .app-nav {
    position: fixed;
    z-index: 35;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0;
    padding: 0.3rem 0.3rem max(0.3rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--card);
    box-shadow: var(--shadow);
  }
  .app-nav button {
    flex-direction: column;
    gap: 0.15rem;
    min-height: 48px;
    padding: 0.3rem 0.1rem;
    border-color: transparent;
    font-size: 0.62rem;
  }
  .app-nav button .msym { width: 20px; height: 20px; }
  .house-name { display: none; }
  /* The build stamp shrinks to an info icon; a tap reveals it in a bubble. */
  .version-tag { cursor: pointer; }
  .version-tag > .msym { display: block; }
  .version-tag .version-text { display: none; }
  .version-tag.open .version-text {
    display: block;
    position: absolute;
    z-index: 40;
    top: calc(100% + 0.6rem);
    left: 0;
    overflow: visible;
    padding: 0.4rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    background: var(--card);
    box-shadow: var(--shadow);
  }
  /* The tab strip shares the width instead of scrolling: icon-only tabs
     (the title attribute keeps the name available). */
  .tabs { gap: 0.25rem; }
  .tabs button {
    flex: 1 1 0;
    justify-content: center;
    min-width: 0;
    min-height: 40px;
    padding: 0.4rem 0.2rem;
  }
  .tabs button span { display: none; }
  .tabs button .msym { width: 20px; height: 20px; }
  .inline-form input, .inline-form select { flex-basis: 100%; }
  .mini-row.wrap-row { flex-direction: column; align-items: stretch; }
  /* Compact spacing: slimmer paddings, margins and titles. */
  .wrap { padding: 0.4rem 0.6rem; }
  .app-main { padding-top: 0.4rem; }
  .app-header { min-height: 48px; padding: 0.35rem 0.6rem; }
  h2 { font-size: 1.05rem; margin-bottom: 0.35rem; }
  .card { padding: 0.7rem 0.75rem; margin-bottom: 0.55rem; }
  .card h3 { font-size: 0.9rem; margin-bottom: 0.3rem; }
  .stats-toggles { margin-bottom: 0.55rem; }
  .year-range { margin-bottom: 0.55rem; }
  /* The three switches stay on one row. */
  .stats-toggles { gap: 0.6rem; flex-wrap: nowrap; }
  label.switch { gap: 0.3rem; font-size: 0.78rem; }
  label.switch .slider { width: 30px; height: 17px; }
  label.switch .slider::after { top: 2.5px; width: 12px; height: 12px; }
  label.switch input:checked + .slider::after { transform: translateX(12px); }
}
