:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --grouped: #FFFFFF;
  --label: #000000;
  --secondary: rgba(60, 60, 67, 0.6);
  --tertiary: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.29);
  --sep-light: rgba(60, 60, 67, 0.12);
  --accent: #007AFF;
  --accent-press: #0063D1;
  --green: #34C759;
  --red: #FF3B30;
  --orange: #FF9500;
  --yellow: #FFCC00;
  --navy: #0B1C2D;
  --gold: #D4B06A;
  --gold-deep: #A07830;
  --cream: #F7F4EE;
  --fill: rgba(120, 120, 128, 0.16);
  --fill-input: rgba(118, 118, 128, 0.12);
  --input-bg: #FFFFFF;
  --tab-bg: rgba(249, 249, 249, 0.92);
  --nav-bg: rgba(249, 249, 249, 0.86);
  --hairline: 0.5px;
  --nav-h: 44px;
  --tab-h: 49px;
  --radius: 10px;
  --radius-lg: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  --shadow-sheet: 0 -8px 30px rgba(0, 0, 0, 0.18);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1C1C1E;
    --grouped: #1C1C1E;
    --label: #FFFFFF;
    --secondary: rgba(235, 235, 245, 0.6);
    --tertiary: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.65);
    --sep-light: rgba(84, 84, 88, 0.4);
    --fill: rgba(120, 120, 128, 0.32);
    --fill-input: rgba(118, 118, 128, 0.24);
    --input-bg: #1C1C1E;
    --tab-bg: rgba(22, 22, 22, 0.92);
    --nav-bg: rgba(22, 22, 22, 0.86);
    --accent: #0A84FF;
    --accent-press: #409CFF;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
html { background: var(--navy); }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--label);
  font-size: 17px;
  line-height: 1.25;
  overscroll-behavior: none;
  min-height: 100%;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; display: block; }
input, textarea, select { appearance: none; -webkit-appearance: none; border: 0; background: transparent; }
input:focus, textarea:focus, select:focus { outline: none; }
::placeholder { color: var(--tertiary); }

#app { min-height: 100%; min-height: 100dvh; }

/* ===== Splash ===== */
.splash {
  position: fixed; inset: 0; z-index: 100;
  background: var(--navy);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--cream);
  animation: splashFade 0.35s ease both;
}
.splash.leaving { animation: splashOut 0.45s ease forwards; }
.splash-icon {
  width: 180px; height: 180px; border-radius: 40px; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0,0,0,0.35);
}
.splash-icon img { width: 100%; height: 100%; object-fit: cover; }
.splash-title {
  margin: 28px 0 0;
  font-size: 34px; font-weight: 700; letter-spacing: -0.6px;
}
.splash-sub {
  margin-top: 6px; font-size: 13px; letter-spacing: 0.22em;
  color: var(--gold); font-weight: 600; text-transform: uppercase;
}
@keyframes splashFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes splashOut { to { opacity: 0; transform: scale(1.04); } }

/* ===== Nav / page chrome ===== */
.page {
  min-height: 100dvh;
  padding-top: calc(var(--nav-h) + env(safe-area-inset-top));
  padding-bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom));
}
.page.no-tab { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.page.no-nav { padding-top: env(safe-area-inset-top); }

.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 8px; padding-right: 12px;
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: var(--hairline) solid var(--sep-light);
}
.nav-title {
  position: absolute; left: 80px; right: 80px;
  text-align: center; font-weight: 600; font-size: 17px;
  pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-btn {
  color: var(--accent); font-size: 17px; font-weight: 400;
  padding: 8px 8px; min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; gap: 2px;
}
.nav-btn.strong { font-weight: 600; }
.nav-btn:active { opacity: 0.5; }
.chev { font-weight: 500; font-size: 28px; line-height: 1; margin-top: -2px; }

.large-title {
  font-size: 34px; font-weight: 700; letter-spacing: -0.6px;
  margin: 6px 16px 12px; line-height: 1.1;
}

/* ===== Tab bar ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: space-around; align-items: stretch;
  background: var(--tab-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: var(--hairline) solid var(--sep-light);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--secondary); font-size: 10px; font-weight: 500; min-width: 0;
}
.tab svg { width: 26px; height: 26px; }
.tab.active { color: var(--accent); }

/* ===== Grouped lists ===== */
.section-label {
  margin: 18px 32px 6px;
  font-size: 13px; font-weight: 400; color: var(--secondary);
  text-transform: uppercase; letter-spacing: 0.02em;
}
.section-foot {
  margin: 6px 32px 4px;
  font-size: 13px; color: var(--secondary); line-height: 1.35;
}
.group {
  margin: 0 16px 12px;
  background: var(--grouped);
  border-radius: var(--radius);
  overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 8px 16px;
  position: relative; background: var(--grouped);
  width: 100%; text-align: left; color: inherit;
}
.row + .row::before,
.row-sep::before {
  content: ""; position: absolute; left: 16px; right: 0; top: 0;
  height: var(--hairline); background: var(--sep);
}
.row.has-icon + .row.has-icon::before { left: 60px; }
.row:active, .row.pressable:active { background: var(--fill); }
.row-icon {
  width: 30px; height: 30px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex: 0 0 auto; font-size: 15px;
}
.row-icon svg { width: 18px; height: 18px; }
.row-body { flex: 1; min-width: 0; }
.row-title { font-size: 17px; font-weight: 400; }
.row-sub { font-size: 13px; color: var(--secondary); margin-top: 1px; }
.row-value { color: var(--secondary); font-variant-numeric: tabular-nums; }
.row-chev { color: var(--tertiary); font-size: 20px; font-weight: 500; }
.badge {
  background: var(--fill); color: var(--label);
  border-radius: 10px; padding: 1px 7px; font-size: 13px; font-weight: 600;
}

/* Inputs inside rows */
.row input[type="text"],
.row input[type="number"],
.row input[type="tel"],
.row input[type="date"],
.row input[type="time"],
.row input[type="search"],
.row textarea,
.row select {
  flex: 1; text-align: right; min-width: 0;
  font-variant-numeric: tabular-nums;
}
.row.stack { flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 16px; }
.row.stack input, .row.stack textarea, .row.stack select { text-align: left; }
.row label.grow { flex: 1; color: var(--label); }
textarea { width: 100%; resize: vertical; min-height: 72px; line-height: 1.35; }

.result {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.3px;
}
.result.lg { font-size: 28px; letter-spacing: -0.5px; }
.unit { font-weight: 400; font-size: 13px; color: var(--secondary); margin-left: 4px; }

/* Cards / dashboard */
.hero-card {
  margin: 0 16px 14px;
  background: linear-gradient(160deg, #16324A 0%, #0B1C2D 100%);
  color: var(--cream);
  border-radius: 16px;
  padding: 18px 18px 16px;
  position: relative; overflow: hidden;
}
.hero-card h2 { margin: 0 0 2px; font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.hero-card .meta { color: rgba(247,244,238,0.7); font-size: 13px; }
.hero-stats { display: flex; gap: 16px; margin-top: 14px; }
.hero-stat .k { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.hero-stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 16px 14px; }
.mini-card {
  background: var(--card); border-radius: 14px; padding: 14px;
  min-height: 110px;
}
.mini-card .k { font-size: 13px; color: var(--secondary); font-weight: 500; }
.mini-card .v { font-size: 22px; font-weight: 700; margin-top: 6px; letter-spacing: -0.4px; font-variant-numeric: tabular-nums; }

/* OWR ring */
.owr-wrap { display: flex; align-items: center; gap: 14px; }
.owr-ring { width: 86px; height: 86px; flex: 0 0 auto; }
.owr-label { font-size: 18px; font-weight: 700; letter-spacing: -0.4px; }
.owr-sub { font-size: 12px; color: var(--secondary); }

/* Buttons */
.btn-row { display: flex; gap: 10px; margin: 16px; }
.btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 50px; border-radius: 12px; padding: 0 16px;
  font-weight: 600; font-size: 17px; width: 100%;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.secondary { background: var(--fill); color: var(--accent); }
.btn.danger { background: rgba(255,59,48,0.12); color: var(--red); }
.btn:active { opacity: 0.85; }

/* Segmented */
.segmented {
  display: flex; margin: 0 16px 14px; padding: 2px;
  background: var(--fill); border-radius: 9px;
}
.segmented button {
  flex: 1; text-align: center; padding: 6px 8px;
  font-size: 13px; font-weight: 600; border-radius: 7px; color: var(--label);
}
.segmented button.on { background: var(--card); box-shadow: 0 1px 4px rgba(0,0,0,0.12); }

/* Forms / calc blocks */
.calc-block { margin: 0 16px 16px; }
.hint { font-size: 13px; color: var(--secondary); margin: 0 16px 12px; line-height: 1.4; }

/* Charts */
.chart { width: 100%; height: 120px; display: block; }
.chart-legend { display: flex; gap: 12px; font-size: 12px; color: var(--secondary); margin-top: 6px; }

/* Empty state */
.empty {
  text-align: center; padding: 36px 28px; color: var(--secondary);
}
.empty h3 { color: var(--label); margin: 0 0 6px; font-size: 20px; }
.empty p { margin: 0; font-size: 15px; line-height: 1.4; }

/* Checklist */
.check {
  width: 22px; height: 22px; border-radius: 11px; flex: 0 0 auto;
  border: 1.5px solid var(--sep);
  display: flex; align-items: center; justify-content: center;
}
.check.on { background: var(--green); border-color: var(--green); color: #fff; }
.streak {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,149,0,0.15); color: var(--orange);
  border-radius: 20px; padding: 4px 10px; font-weight: 700; font-size: 13px;
}

/* Progress bar */
.bar { height: 6px; background: var(--fill); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--green); border-radius: 3px; }

/* Well picker */
.well-card {
  margin: 0 16px 10px;
  background: var(--card);
  border-radius: 14px;
  padding: 16px 16px 14px;
  display: flex; align-items: center; gap: 12px;
  width: auto; text-align: left; color: inherit;
}
.well-card:active { opacity: 0.7; }
.well-avatar {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--navy); overflow: hidden; flex: 0 0 auto;
}
.well-avatar img { width: 100%; height: 100%; object-fit: cover; }
.fab {
  position: fixed; right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 28px;
  background: var(--accent); color: #fff;
  font-size: 32px; font-weight: 400; line-height: 1;
  box-shadow: 0 8px 20px rgba(0,122,255,0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
}
.page.has-tab .fab { bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); }
.fab:active { transform: scale(0.94); }

/* Treatment product table */
.prod-count {
  width: 72px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600;
}
.prod-unit { width: 72px; text-align: right; color: var(--secondary); font-size: 15px; }

/* Notes / procedure steps */
.steps { margin: 0 16px 16px; counter-reset: step; }
.step {
  background: var(--card); border-radius: 12px; padding: 12px 14px 12px 44px;
  margin-bottom: 8px; position: relative;
}
.step::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 12px; top: 12px;
  width: 22px; height: 22px; border-radius: 11px;
  background: var(--navy); color: var(--gold);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.step h4 { margin: 0 0 4px; font-size: 15px; }
.step p { margin: 0; font-size: 14px; color: var(--secondary); }

/* Sheet modal */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  width: 100%; max-width: 560px;
  padding: 8px 0 calc(16px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-sheet);
  animation: sheetUp 0.32s cubic-bezier(.2,.8,.2,1);
}
.sheet-grab { width: 36px; height: 5px; border-radius: 3px; background: var(--fill); margin: 6px auto 8px; }
@keyframes sheetUp { from { transform: translateY(24px); opacity: 0.5; } to { transform: none; opacity: 1; } }

/* Utility */
.muted { color: var(--secondary); }
.danger-text { color: var(--red); }
.ok-text { color: var(--green); }
.warn-text { color: var(--orange); }
.tabular { font-variant-numeric: tabular-nums; }
.pad { padding: 0 16px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.mono { font-variant-numeric: tabular-nums; }
.gain { color: var(--green); }
.loss { color: var(--red); }
.center { text-align: center; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }

.install-banner {
  margin: 0 16px 14px;
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 14px;
  color: var(--secondary);
  line-height: 1.4;
}
.install-banner strong { color: var(--label); font-weight: 600; }

/* Number keypad-friendly inputs */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Log table-ish list */
.gl-row .row-title { font-weight: 600; }
.pill {
  font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 8px;
  background: var(--fill);
}
.pill.gain { background: rgba(52,199,89,0.18); color: var(--green); }
.pill.loss { background: rgba(255,59,48,0.18); color: var(--red); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(30,30,30,0.92); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  z-index: 80; animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

@media (min-width: 700px) {
  .page { max-width: 430px; margin: 0 auto; background: var(--bg); box-shadow: 0 0 0 1px var(--sep-light); }
  .nav, .tabbar { max-width: 430px; left: 50%; transform: translateX(-50%); }
  .fab { right: calc(50% - 215px + 16px); }
  .overlay { justify-content: center; }
}
