/* Lodestar: mobile-first, works on a small phone in bright sunlight. */
:root {
  color-scheme: light dark;
  --navy: #0b1f3a;
  --gold: #f5b301;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #111827;
  --muted: #5b6474;
  --border: #d9dee8;
  --primary: #0b1f3a;
  --primary-text: #ffffff;
  --accent: #b77f00;
  --danger: #b42318;
  --ok: #067647;
  --radius: 14px;
  --tap: 48px; /* minimum touch target */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1426;
    --surface: #11213d;
    --text: #eef2f8;
    --muted: #a7b1c3;
    --border: #23365a;
    --primary: #f5b301;
    --primary-text: #0b1f3a;
    --accent: #f5b301;
    --danger: #ff8a7a;
    --ok: #5fd39a;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
body.has-tabbar { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0.5rem 0 0.75rem; }
h2 { font-size: 1.2rem; margin: 1.75rem 0 0.75rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.25rem; }
.lead { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; background: var(--surface); padding: 0.5rem 1rem; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 0.5rem;
  padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem;
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 0.5rem; color: #fff; text-decoration: none; font-weight: 700; margin-right: auto; min-height: var(--tap); }
.brand-product { color: var(--gold); font-weight: 600; }
.topbar-link {
  color: #fff; background: none; border: 0; font: inherit; cursor: pointer;
  min-height: var(--tap); padding: 0 0.5rem; display: inline-flex; align-items: center; text-decoration: none;
}
.topbar-link:hover { text-decoration: underline; }
.envbar { margin: 0; padding: 0.25rem 1rem; background: #fde68a; color: #422006; font-size: 0.85rem; text-transform: capitalize; }

main { width: 100%; max-width: 44rem; margin: 0 auto; padding: 1rem; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1rem; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; min-height: 64px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none; font-weight: 600;
}
.tabbar a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: var(--tap); padding: 0 1.25rem; border-radius: 999px;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.button.subtle { border-color: transparent; color: var(--muted); }
.button.block { width: 100%; }
.button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
form.inline { display: inline; margin: 0; }

.hero { padding: 1rem 0 0.5rem; }
.hero .button { margin: 0.25rem 0.5rem 0.25rem 0; }
.cards { display: grid; gap: 0.75rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
.plain { list-style: none; padding: 0; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.card.active { border-color: var(--accent); }
.card p { margin: 0.25rem 0; }
.card h2, .card h3 { margin-top: 0; }
.tagline { font-weight: 600; }
.actions { margin-top: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.badge { display: inline-block; font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--border); color: var(--text); vertical-align: middle; }
.badge.on { background: var(--ok); color: #fff; }
.note { background: var(--surface); border-left: 4px solid var(--gold); border-radius: var(--radius); padding: 0.75rem 1rem; margin: 1rem 0; }
.warning { background: #fff4e5; color: #5c3a00; border-radius: var(--radius); padding: 0.75rem 1rem; }

.form { display: grid; gap: 1rem; }
.field { display: grid; gap: 0.35rem; border: 0; padding: 0; margin: 0; }
label, legend { font-weight: 600; }
input, select {
  font: inherit; font-size: 1rem; /* 16px+ stops iOS zooming into fields */
  min-height: var(--tap); padding: 0 0.75rem; width: 100%;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.choice { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; min-height: var(--tap); }
.choice input { width: 1.4rem; min-height: 1.4rem; }
.invalid input, .invalid select { border-color: var(--danger); }
.error { color: var(--danger); margin: 0; font-weight: 600; }

.list { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: 0.75rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; display: grid; }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--surface); }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }

/* Very narrow phones: inside a product, the product name is enough. */
@media (max-width: 400px) {
  body:not(.site-www):not(.site-app) .brand-name { display: none; }
}

/* ---- shared bits used by product screens ---- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.prewrap { white-space: pre-wrap; }
textarea {
  font: inherit; font-size: 1rem; width: 100%; padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.invalid textarea { border-color: var(--danger); }
.button.small { min-height: 40px; padding: 0 0.9rem; font-size: 0.95rem; }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.row { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.empty { text-align: center; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 1.5rem 1rem; margin: 1rem 0; }
.empty h2 { margin-top: 0; }
.alert { background: var(--surface); border-left: 4px solid var(--danger); border-radius: var(--radius); padding: 0.25rem 1rem 0.75rem; margin-bottom: 1rem; }
.alert h2 { margin-top: 0.75rem; }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 0.5rem; }
.danger-zone { display: inline-block; }

/* sub-navigation inside a product */
.subnav { display: flex; gap: 0.25rem; align-items: center; margin: 0 0 1rem; border-bottom: 1px solid var(--border); }
.subnav a:not(.button) {
  min-height: var(--tap); display: inline-flex; align-items: center; padding: 0 0.75rem;
  color: var(--muted); text-decoration: none; font-weight: 600;
}
.subnav a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.subnav .button { margin-left: auto; }

/* search + simple link lists */
.search { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.search input { flex: 1; }
.list-links { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.list-links li + li { border-top: 1px solid var(--border); }
.list-links a { display: flex; flex-direction: column; padding: 0.75rem 1rem; min-height: var(--tap); text-decoration: none; color: var(--text); }
.list-links .muted { font-size: 0.9rem; }

/* schedule */
.weeknav { display: flex; gap: 0.5rem; justify-content: space-between; margin-bottom: 0.5rem; }
.day h2 { font-size: 1.05rem; margin: 1.25rem 0 0.5rem; }
.day.today h2 { color: var(--accent); }
.visits { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.visit { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; }
.visit.status-done { opacity: 0.75; }
.visit.status-cancelled { opacity: 0.55; }
.visit-main { display: grid; gap: 0.1rem; text-decoration: none; color: var(--text); }
.visit-time { font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.visit-title { font-weight: 700; font-size: 1.05rem; }
.visit-who { color: var(--muted); }
.visit-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.6rem; }
.move[open] { flex-basis: 100%; }
.move-form { display: grid; gap: 0.5rem; grid-template-columns: 1fr 1fr; align-items: end; margin-bottom: 0.5rem; }
.move-form label { font-size: 0.9rem; display: grid; gap: 0.25rem; }
.move-form button { grid-column: 1 / -1; }

/* ---- money, quotes and invoices ---- */
.split { display: flex; justify-content: space-between; gap: 1rem; }
.badge.late { background: var(--danger); color: #fff; }
.badge.seen { background: transparent; border: 1px solid var(--border); }
.stat.late .stat-value { color: var(--danger); }
.actions { margin: 0.75rem 0; }
.panel, .share { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.25rem 1rem 1rem; margin: 1rem 0; }
.panel h2, .share h2 { margin-top: 0.75rem; }
.panel .row label { display: grid; gap: 0.25rem; font-size: 0.9rem; }
.span2 { grid-column: 1 / -1; }
.copy { font-size: 0.9rem; }
.alert-text { color: var(--danger); font-weight: 600; }
.pre { white-space: pre-line; margin: 0.25rem 0; }

.line-rows { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.75rem; }
.line-row { display: grid; gap: 0.4rem; padding-bottom: 0.75rem; border-bottom: 1px dashed var(--border); }
.line-nums { display: grid; gap: 0.5rem; grid-template-columns: 1fr 1.4fr; }
.line-nums label { display: grid; gap: 0.2rem; font-size: 0.85rem; font-weight: 600; }
.line-nums label:nth-child(3) { grid-column: 1 / -1; }
@media (min-width: 640px) { .line-nums { grid-template-columns: 0.7fr 1fr 1.6fr; } .line-nums label:nth-child(3) { grid-column: auto; } }

/* The document itself: always light, like paper. */
.sheet {
  position: relative; background: #fff; color: #111827; border: 1px solid #d9dee8; border-radius: var(--radius);
  padding: 1.25rem; margin: 1rem 0; overflow: hidden; color-scheme: light;
}
.sheet a { color: #0b1f3a; }
.sheet .muted { color: #5b6474; }
.sheet-head { display: grid; gap: 1rem; grid-template-columns: 1fr; border-bottom: 2px solid #0b1f3a; padding-bottom: 0.75rem; }
@media (min-width: 560px) { .sheet-head { grid-template-columns: 1fr 1fr; } .sheet-from { text-align: right; } }
.sheet-kind { margin: 0; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8rem; color: #b77f00; font-weight: 700; }
.sheet-number { margin: 0.1rem 0; font-size: 1.4rem; }
.sheet-title { margin: 0; font-weight: 600; }
.sheet-from p { margin: 0.1rem 0; }
.sheet-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; padding: 0.75rem 0; }
.sheet-meta p { margin: 0.1rem 0; }
.sheet-meta dl { display: grid; grid-template-columns: max-content max-content; gap: 0.2rem 0.75rem; margin: 0; }
.sheet-meta dt { color: #5b6474; }
.sheet-meta dd { margin: 0; font-weight: 600; }
.sheet .lines { width: 100%; border-collapse: collapse; background: transparent; }
.sheet .lines th { font-size: 0.8rem; color: #5b6474; border-bottom: 1px solid #d9dee8; }
.sheet .lines td, .sheet .lines th { padding: 0.45rem 0.35rem; white-space: normal; border-bottom: 1px solid #eef0f4; vertical-align: top; }
.sheet .num { text-align: right; white-space: nowrap; }
.totals { display: grid; grid-template-columns: 1fr max-content; gap: 0.25rem 1rem; margin: 0.75rem 0 0 auto; max-width: 18rem; }
.totals dt { text-align: right; color: #5b6474; }
.totals dd { margin: 0; text-align: right; }
.totals .grand { font-weight: 800; font-size: 1.15rem; color: #111827; border-top: 2px solid #0b1f3a; padding-top: 0.25rem; }
.sheet-box { background: #f6f7fb; border-radius: 10px; padding: 0.5rem 0.9rem; margin-top: 1rem; }
.sheet-box h3 { font-size: 0.9rem; margin: 0.25rem 0; }
.sheet-foot { color: #5b6474; font-size: 0.9rem; text-align: center; margin-top: 1rem; }
.stamp {
  position: absolute; top: 1.2rem; right: -2.6rem; transform: rotate(35deg); padding: 0.2rem 3rem;
  font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; font-size: 0.8rem; color: #fff; margin: 0;
}
.stamp.paid { background: #067647; }
.stamp.void { background: #b42318; }
/* Narrow phones: stack each line as a small card. */
@media (max-width: 559px) {
  .sheet .lines thead { display: none; }
  .sheet .lines tr { display: grid; grid-template-columns: 1fr 1fr; padding: 0.4rem 0; border-bottom: 1px solid #eef0f4; }
  .sheet .lines td { border: 0; padding: 0.1rem 0.35rem; }
  .sheet .lines td.desc { grid-column: 1 / -1; font-weight: 600; }
  .sheet .lines td.num { text-align: left; }
  .sheet .lines td.num::before { content: attr(data-label) ": "; color: #5b6474; font-size: 0.85rem; }
}

@media print {
  .topbar, .tabbar, .envbar, .footer, .subnav, .no-print, .skip { display: none !important; }
  body { background: #fff; padding: 0 !important; }
  main { max-width: none; padding: 0; }
  .sheet { border: 0; margin: 0; padding: 0; }
}
.subnav a:not(.button) { padding: 0 0.6rem; }
.subnav .button { white-space: nowrap; flex-shrink: 0; }
.line-rows { padding-left: 0; }

/* Email and reminders on a document */
.email-box { margin-top: 0.75rem; }
.email-box form { margin-top: 0.5rem; }
.reminders { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: 0.25rem; }
.reminders h3 { font-size: 1rem; margin: 0.75rem 0 0.25rem; }
.history { margin: 1.5rem 0; }
.history li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.25rem 1rem; }
.history li > span:first-child { overflow-wrap: anywhere; }

/* Admin console */
table .num { text-align: right; white-space: nowrap; }
h2 .small { font-weight: 400; }
.site-admin .stats { margin-bottom: 0.75rem; }
