:root {
  --page: #f4f7f6;
  --surface: #ffffff;
  --primary: #145c5a;
  --primary-dark: #0d3f3d;
  --accent: #e2984b;
  --ink: #16241f;
  --muted: #5c6f69;
  --border: #d8e4e1;
  --danger: #b4483a;
  --success: #3f8f5f;
  --excellent: #7d5ba6;
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }

/* ---- shell ---------------------------------------------------------------- */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { font-weight: 800; font-size: 17px; }
.brand small { display: block; font-weight: 500; font-size: 12px; color: #cfe3e1; margin-top: 1px; }

.sync-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  white-space: nowrap;
  border: 0;
  font-family: inherit;
}
.sync-pill.warn { background: var(--accent); color: #2b1a05; }
.sync-pill.err { background: var(--danger); }
button.sync-pill { cursor: pointer; }

.nav {
  background: var(--primary-dark);
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 0 8px;
  padding-left: calc(8px + env(safe-area-inset-left, 0px));
  -webkit-overflow-scrolling: touch;
}
.nav a {
  color: #cfe3e1;
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
  padding: 12px 12px;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.nav a.active { color: #fff; border-bottom-color: var(--accent); }
.badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #2b1a05;
  font-size: 12px;
  text-align: center;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 14px calc(60px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
}
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row.top { align-items: flex-start; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.right { text-align: right; }
.title { font-size: 20px; font-weight: 800; }
.section-title { font-size: 15px; font-weight: 800; }

/* ---- buttons ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--primary); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--border); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13.5px; }
.btn.block { display: flex; width: 100%; }
.linkbtn {
  background: none; border: 0; padding: 6px 2px; font: inherit; font-weight: 700;
  color: var(--primary); cursor: pointer; text-decoration: none;
}
.linkbtn.danger { color: var(--danger); }
.linkbtn.muted { color: var(--muted); }
.btn:focus-visible, .linkbtn:focus-visible, a:focus-visible, .card.link:focus-visible {
  outline: 3px solid rgba(20, 92, 90, 0.4);
  outline-offset: 2px;
}

/* ---- cards ---------------------------------------------------------------------- */
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 13px 14px;
  color: inherit;
  text-decoration: none;
}
.card.plain { border-left-color: var(--border); }
.card.link { cursor: pointer; }
.card.link:active { background: #f1f6f5; }
.card .name { font-weight: 800; font-size: 15.5px; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; word-break: break-word; }
.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---- score ------------------------------------------------------------------------ */
.score-card { padding: 14px 16px; }
.score-label { font-size: 12px; font-weight: 800; color: var(--muted); }
.score-big { display: flex; align-items: baseline; gap: 6px; margin-top: 4px; }
.score-num { font-size: 34px; font-weight: 800; line-height: 1; }
.score-of { color: var(--muted); font-size: 15px; }
.score-mini { font-weight: 800; font-size: 15px; }
.excellent { color: var(--excellent); }
.good { color: var(--success); }
.fair { color: var(--accent); }
.low { color: var(--danger); }
.trend.up { color: var(--success); font-weight: 700; }
.trend.down { color: var(--danger); font-weight: 700; }
.trend.steady, .trend.unavailable { color: var(--muted); font-weight: 700; }

/* ---- status chips ---------------------------------------------------------------------- */
.chip {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e6efed;
  color: var(--muted);
  white-space: nowrap;
}
.chip.pending { background: #fbeedc; color: #8a5413; }
.chip.approved { background: #dcefe3; color: #25623e; }
.chip.local { background: #e8e0f2; color: #5a3f86; }

/* ---- forms ------------------------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label, .field > .label { font-size: 12.5px; font-weight: 800; color: var(--muted); }
input, select, textarea {
  font: inherit;
  font-size: 16px; /* 16px stops iOS Safari zooming the page when a field is tapped */
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 92, 90, 0.15);
}
input[type='checkbox'] { width: 22px; height: 22px; min-height: 0; padding: 0; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14.5px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.chem-row { display: grid; grid-template-columns: 1fr 76px 112px 40px; gap: 6px; align-items: center; margin-bottom: 6px; }
.chem-row .x { min-height: 40px; }
.price-row { display: grid; grid-template-columns: 1fr 120px; gap: 8px; align-items: center; margin-bottom: 8px; }
.chem-price-row { display: grid; grid-template-columns: 1fr 112px 96px 40px; gap: 6px; align-items: center; margin-bottom: 6px; }
@media (max-width: 480px) {
  .chem-row { grid-template-columns: 1fr 64px 96px 36px; }
  .chem-price-row { grid-template-columns: 1fr 92px 80px 36px; }
}

/* ---- banners + messages ------------------------------------------------------------------------ */
.banner { padding: 11px 13px; border-radius: var(--radius); font-size: 14px; border: 1px solid; }
.banner.info { background: #eaf3f2; border-color: #c6dcd9; color: #1c4b49; }
.banner.warn { background: #fdf3e3; border-color: #f0d6a8; color: #7a4a0a; }
.banner.error { background: #fbeceA; border-color: #efc4be; color: #7e2a20; }
.banner.ok { background: #e4f3ea; border-color: #bfdfcb; color: #1f5a37; }
.banner ul { margin: 6px 0 0; padding-left: 18px; }

/* ---- log text + charges -------------------------------------------------------------------------- */
.log-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px;
}
.lines { width: 100%; border-collapse: collapse; font-size: 14px; }
.lines td { padding: 6px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.lines td.amt { text-align: right; white-space: nowrap; padding-left: 12px; font-variant-numeric: tabular-nums; }
.lines tr.total td { border-bottom: 0; font-weight: 800; font-size: 16px; padding-top: 10px; }
.history-entry { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.history-head {
  width: 100%; text-align: left; background: none; border: 0; font: inherit; cursor: pointer;
  padding: 11px 13px; display: flex; justify-content: space-between; align-items: center; gap: 10px; color: inherit;
}
.history-head .d { font-weight: 800; }
.history-body { padding: 0 13px 13px; }
.history-body > * + * { margin-top: 10px; }

/* ---- toasts + login ------------------------------------------------------------------------------------ */
#toasts {
  position: fixed; left: 0; right: 0; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 50;
}
.toast {
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; max-width: 90vw; text-align: center;
}
.toast.err { background: var(--danger); }
.login-wrap { max-width: 400px; margin: 0 auto; padding: 56px 20px 40px; }
.login-logo { width: 72px; height: 72px; border-radius: 16px; display: block; margin: 0 auto 16px; }
.login-wrap h1 { text-align: center; font-size: 22px; margin-bottom: 4px; }
.login-wrap .lead { text-align: center; color: var(--muted); margin-bottom: 24px; }
.boot { padding: 60px 20px; text-align: center; color: var(--muted); }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
input[type='search'] { -webkit-appearance: none; appearance: none; }
.chip.err { background: #f6dad6; color: #7e2a20; }
