/* Dig or Not? — mobile-first Progressive Web App
   Base styles target phones; enhance at larger breakpoints. */

:root,
[data-theme="dark"] {
  --bg: #0f1419;
  --bg-elevated: #1a222c;
  --bg-card: #1e2833;
  --border: #2d3a47;
  --text: #e8eef4;
  --text-muted: #8b9aab;
  --accent: #d4a017;
  --accent-hover: #e8b82a;
  --accent-dim: rgba(212, 160, 23, 0.15);
  --dig: #2ecc71;
  --dig-bg: rgba(46, 204, 113, 0.12);
  --maybe: #f39c12;
  --maybe-bg: rgba(243, 156, 18, 0.12);
  --skip: #e74c3c;
  --skip-bg: rgba(231, 76, 60, 0.12);
  --danger: #e74c3c;
  --input-bg: #121820;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 12px;
  --touch: 48px; /* min touch target */
  --nav-h: 60px;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --page-pad: 14px;
  /* Space so last content clears fixed bottom nav (safe area + extra gap) */
  --scroll-pad-bottom: calc(var(--nav-h) + var(--safe-bottom) + 48px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto,
    "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f4f6f8;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #d8e0e8;
  --text: #1a222c;
  --text-muted: #5a6a7a;
  --accent: #b8860b;
  --accent-hover: #9a7209;
  --accent-dim: rgba(184, 134, 11, 0.12);
  --input-bg: #eef2f6;
  --shadow: 0 8px 28px rgba(15, 20, 25, 0.08);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  width: 100%;
  max-width: 100%;
  /* height: auto — do NOT lock html to 100% or long pages cannot scroll */
  height: auto;
  min-height: 100%;
  font-size: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Keep focused inputs / anchors above bottom nav */
  scroll-padding-bottom: var(--scroll-pad-bottom);
  /* Pan only — avoid browser treating the page as a zoomed canvas */
  touch-action: manipulation;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 1rem; /* ~16px; rem follows html */
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  overflow-x: hidden;
  overflow-y: visible; /* body grows; document scrolls */
  overscroll-behavior-y: auto;
  -webkit-tap-highlight-color: transparent;
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
  padding-top: 0;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  /* Clear fixed bottom nav so Profile / Admin / Links bottoms are visible */
  padding-bottom: calc(var(--scroll-pad-bottom) + var(--kb-inset, 0px));
}

/* Auth screen must always fill the phone width (no shrink-to-fit) */
body.auth-only,
body.auth-only main,
body.auth-only #view-auth,
body.auth-only .auth-wrap,
body.auth-only .card {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

#view-auth.active {
  width: 100%;
  max-width: 100%;
}

/* Installed app (Android/iOS home screen) — fill the screen, readable type */
html.pwa-standalone {
  /* Slightly larger base type on installed apps (often feels “too small” vs browser chrome) */
  font-size: 17px;
}

html.pwa-standalone body {
  min-height: 100%;
  min-height: 100dvh;
  padding-top: 0;
  /* Extra room under tall bottom nav on installed apps */
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 56px + var(--kb-inset, 0px));
}

html.pwa-standalone .app-header {
  padding-top: calc(10px + var(--safe-top));
}

html.pwa-standalone main {
  /* Use full phone width in standalone — no narrow “card column” feel */
  width: 100%;
  max-width: 100%;
  padding-left: max(var(--page-pad), var(--safe-left));
  padding-right: max(var(--page-pad), var(--safe-right));
}

html.pwa-standalone .bottom-nav {
  padding-bottom: max(var(--safe-bottom), 8px);
}

html.pwa-standalone .card {
  /* a bit more air on phone screens */
  padding: 18px 16px;
}

html.pwa-standalone .btn {
  min-height: 52px;
  font-size: 1.05rem;
}

html.pwa-standalone .bottom-nav button {
  font-size: 0.72rem;
}

html.pwa-standalone .bottom-nav button .nav-icon {
  font-size: 1.45rem;
}

@media all and (display-mode: standalone) {
  html {
    font-size: 17px;
  }
  main {
    max-width: 100%;
  }
  .app-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }
}

/* ---------- iPhone / iOS (Safari + Add to Home Screen) ---------- */
html.ios-device {
  /* iOS text size adjust can shrink UI; keep at 100% */
  -webkit-text-size-adjust: 100%;
}

html.ios-device body {
  /* Classic iOS Safari 100vh bug: use fill-available as fallback */
  min-height: -webkit-fill-available;
}

/* Home-screen web app on iPhone (navigator.standalone) */
html.ios-standalone,
html.ios-device.pwa-standalone {
  font-size: 17px;
}

html.ios-standalone body,
html.ios-device.pwa-standalone body {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  /* Allow normal document scroll (none blocked bottoms of long pages) */
  overscroll-behavior-y: auto;
  position: relative;
  overflow-y: visible;
}

html.ios-standalone .app-header,
html.ios-device.pwa-standalone .app-header {
  /* Notch / Dynamic Island */
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
}

html.ios-standalone main,
html.ios-device.pwa-standalone main {
  width: 100%;
  max-width: 100%;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

html.ios-standalone .bottom-nav,
html.ios-device.pwa-standalone .bottom-nav {
  /* Home indicator bar */
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 10px);
  min-height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  /* Solid bar so content never shows through oddly on iOS */
  background: var(--bg-elevated);
}

html.ios-standalone body,
html.ios-device.pwa-standalone body {
  /* Home indicator + nav bar + breathing room so Save / last cards clear the dock */
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 64px + var(--kb-inset, 0px));
}

html.ios-standalone .btn,
html.ios-device.pwa-standalone .btn {
  min-height: 52px;
  font-size: 1.06rem;
  /* iOS removes 300ms delay with touch-action; keep 44pt+ targets */
  -webkit-appearance: none;
}

html.ios-standalone .bottom-nav button .nav-icon,
html.ios-device.pwa-standalone .bottom-nav button .nav-icon {
  font-size: 1.5rem;
}

html.ios-standalone .card h1,
html.ios-device.pwa-standalone .card h1,
html.ios-standalone .page-title,
html.ios-device.pwa-standalone .page-title {
  font-size: 1.45rem;
}

/* iOS input zoom prevention — keep controls at least 16px */
html.ios-device input,
html.ios-device select,
html.ios-device textarea {
  font-size: 16px !important;
}

@supports (-webkit-touch-callout: none) {
  /* Any WebKit iOS browser */
  body {
    min-height: -webkit-fill-available;
  }
}

body.auth-only {
  padding-bottom: calc(24px + var(--safe-bottom) + var(--kb-inset, 0px));
}

body.keyboard-open .bottom-nav {
  /* hide nav while typing so fields stay visible */
  transform: translateY(110%);
  pointer-events: none;
}

body.keyboard-open {
  padding-bottom: calc(16px + var(--safe-bottom) + var(--kb-inset, 0px));
}

a {
  color: var(--accent);
  text-decoration: none;
  touch-action: manipulation;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button,
input,
select,
textarea {
  font: inherit;
  font-size: 16px; /* critical: iOS zooms if < 16px */
  color: inherit;
  touch-action: manipulation;
}

button {
  -webkit-appearance: none;
  appearance: none;
}

/* ---------- Header (phone-first sticky) ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--header-h);
  padding: 8px var(--page-pad);
  padding-top: calc(8px + var(--safe-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  color: var(--text);
  min-width: 0;
}

.brand span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-mark {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--accent), #8b6914);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  box-shadow: 0 2px 8px rgba(212, 160, 23, 0.35);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: var(--touch);
  height: var(--touch);
  min-width: var(--touch);
  min-height: var(--touch);
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 1.15rem;
}

.icon-btn:active {
  background: var(--border);
  color: var(--text);
}

/* ---------- Main content ---------- */
main {
  width: 100%;
  /* Phone: always full width. Cap only on larger screens (see media queries). */
  max-width: 100%;
  margin: 0 auto;
  padding: var(--page-pad);
  /* Extra bottom space inside main so last button/card is never under the nav */
  padding-bottom: calc(var(--page-pad) + 24px);
  overflow: visible;
}

.view {
  display: none;
  animation: fadeIn 0.18s ease;
  overflow: visible;
}

.view.active {
  display: block;
  /* Long forms (profile, admin) must extend document height so the page scrolls */
  min-height: 0;
  padding-bottom: 8px;
  overflow: visible;
}

/* Explicit scroll room on longer screens */
#view-profile.active,
#view-admin.active,
#view-links.active,
#view-history.active,
#view-detail.active,
#view-home.active,
#view-dig.active,
#view-result.active {
  padding-bottom: 32px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.card h1,
.page-title {
  margin: 0 0 8px;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 700;
}

.lead {
  color: var(--text-muted);
  margin: 0 0 16px;
  font-size: 0.95rem;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---------- Profile sections (hunting area / detector profile) ---------- */
.profile-section {
  margin: 8px 0 20px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--input-bg);
}

.profile-section-title {
  margin: 0 0 10px !important;
  font-size: 1.05rem !important;
  font-weight: 700 !important;
  letter-spacing: -0.01em;
}

.profile-section.detector-profile {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  background: color-mix(in srgb, var(--accent-dim) 45%, var(--input-bg));
}

.profile-section .field:last-child {
  margin-bottom: 0;
}

/* ---------- Forms (thumb-friendly) ---------- */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 650;
  margin-bottom: 8px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.field .hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.35;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
select,
textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--input-bg);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  /* iOS form polish */
  -webkit-appearance: none;
  appearance: none;
}

/* select arrow */
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.4;
  padding-top: 12px;
}

/* stack fields on phones — single column default */
.row-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--touch);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 650;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-hover), var(--accent));
  color: #1a1408;
}

.btn-google {
  background: #ffffff;
  color: #1f1f1f;
  border: 1px solid #dadce0;
  font-weight: 600;
  margin-bottom: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.btn-google .google-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-google:active:not(:disabled) {
  background: #f7f8f8;
}

[data-theme="dark"] .btn-google {
  background: #ffffff;
  color: #1f1f1f;
}

.google-divider {
  margin-top: 18px;
}

.btn-secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
}

.btn-danger {
  background: var(--skip-bg);
  color: var(--skip);
  border: 1px solid color-mix(in srgb, var(--skip) 40%, transparent);
}

/* still tappable — never smaller than ~40px */
.btn-sm {
  width: auto;
  min-height: 44px;
  padding: 10px 16px;
  font-size: 0.95rem;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

/* Dig wizard sticky action bar (above bottom nav) */
.dig-actions {
  position: sticky;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
  margin-bottom: 16px;
  padding: 12px 0 8px;
  background: linear-gradient(180deg, transparent, var(--bg) 28%);
}

body.keyboard-open .dig-actions {
  bottom: calc(8px + var(--safe-bottom));
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 16px 0;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.95rem;
  line-height: 1.4;
}

.alert-error {
  background: var(--skip-bg);
  border: 1px solid color-mix(in srgb, var(--skip) 35%, transparent);
  color: var(--skip);
}

.alert-ok {
  background: var(--dig-bg);
  border: 1px solid color-mix(in srgb, var(--dig) 35%, transparent);
  color: var(--dig);
}

.alert-info {
  background: var(--accent-dim);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent);
}

/* ---------- Bottom nav (thumb zone) ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  min-height: calc(var(--nav-h) + var(--safe-bottom));
  padding: 4px 2px;
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  background: color-mix(in srgb, var(--bg-elevated) 96%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  transition: transform 0.2s ease;
}

.bottom-nav button {
  flex: 1;
  min-width: 0;
  min-height: var(--nav-h);
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  padding: 6px 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 10px;
}

.bottom-nav button:active {
  background: var(--accent-dim);
}

.bottom-nav button .nav-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.bottom-nav button.active {
  color: var(--accent);
}

/* When admin is visible, slightly tighter nav labels */
.bottom-nav:has(#nav-admin:not(.hidden)) button {
  font-size: 0.58rem;
  padding: 6px 1px;
}

/* ---------- Site links (tomashworth.com apps) ---------- */
.site-links-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.site-link-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 72px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
}

.site-link-card:active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--bg-card) 80%, var(--accent-dim));
}

.site-link-card.is-current {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent-dim) 50%, var(--bg-card));
}

.site-link-icon {
  font-size: 1.6rem;
  line-height: 1;
  width: 2rem;
  text-align: center;
}

.site-link-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.site-link-title {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.25;
}

.site-link-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.site-link-chevron {
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 700;
}

.site-link-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 750;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  vertical-align: middle;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ---------- Dig wizard ---------- */
.dig-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.dig-head h1 {
  margin: 0;
  font-size: 1.25rem;
}

.wizard-progress {
  display: flex;
  gap: 5px;
  margin-bottom: 16px;
}

.wizard-progress span {
  flex: 1;
  height: 5px;
  border-radius: 5px;
  background: var(--border);
}

.wizard-progress span.done {
  background: var(--accent);
}

.wizard-progress span.current {
  background: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.step {
  display: none;
}

.step.active {
  display: block;
}

.step-title {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0 0 12px;
}

/* ---------- Decision result ---------- */
.decision-hero {
  text-align: center;
  padding: 28px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.decision-hero.dig {
  background: var(--dig-bg);
  border-color: color-mix(in srgb, var(--dig) 40%, var(--border));
}

.decision-hero.maybe {
  background: var(--maybe-bg);
  border-color: color-mix(in srgb, var(--maybe) 40%, var(--border));
}

.decision-hero.skip {
  background: var(--skip-bg);
  border-color: color-mix(in srgb, var(--skip) 40%, var(--border));
}

.decision-label {
  font-size: clamp(2rem, 10vw, 2.6rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0 0 8px;
  line-height: 1.05;
}

.decision-hero.dig .decision-label {
  color: var(--dig);
}

.decision-hero.maybe .decision-label {
  color: var(--maybe);
}

.decision-hero.skip .decision-label {
  color: var(--skip);
}

.confidence {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.reasons {
  list-style: none;
  padding: 0;
  margin: 0;
}

.reasons li {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  font-size: 0.95rem;
  line-height: 1.4;
}

/* ---------- History export + list ---------- */
.export-bar {
  margin-bottom: 14px;
}

.export-bar-title {
  margin: 0 0 4px;
  font-weight: 700;
  font-size: 1rem;
}

.export-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.export-btns .btn {
  width: auto;
  min-width: 88px;
  flex: 1 1 auto;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 72px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: inherit;
  -webkit-user-select: none;
  user-select: none;
}

.history-item:active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--bg-card) 80%, var(--accent-dim));
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 36px;
  text-align: center;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-dig {
  background: var(--dig-bg);
  color: var(--dig);
}

.badge-maybe {
  background: var(--maybe-bg);
  color: var(--maybe);
}

.badge-skip {
  background: var(--skip-bg);
  color: var(--skip);
}

.history-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.3;
}

.history-title {
  font-weight: 650;
  font-size: 0.95rem;
  line-height: 1.3;
}

.thumb,
.thumb-empty {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  flex-shrink: 0;
}

.thumb {
  object-fit: cover;
  background: var(--input-bg);
  border: 1px solid var(--border);
}

.thumb-empty {
  background: var(--input-bg);
  border: 1px dashed var(--border);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* Solid / broken signal picker */
.choice-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}

.choice-card {
  display: block;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.choice-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-card-body {
  display: block;
  min-height: var(--touch);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--input-bg);
  transition: border-color 0.15s, background 0.15s;
}

.choice-card-title {
  display: block;
  font-weight: 750;
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.choice-card-desc {
  display: block;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.choice-card input:checked + .choice-card-body {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.choice-card input:focus-visible + .choice-card-body {
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.choice-card:active .choice-card-body {
  transform: scale(0.99);
}

.followup-card h2 {
  margin-top: 0;
}

.field-label-inline {
  display: block;
  font-size: 0.8rem;
  font-weight: 650;
  margin-bottom: 8px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.photo-gallery {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.photo-gallery .gallery-img {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  margin: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.photo-gallery .gallery-img:only-child {
  grid-column: 1 / -1;
  max-height: min(50vh, 320px);
}

.edit-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.edit-photo-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--input-bg);
}

.edit-photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.edit-photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.edit-photo-kb {
  position: absolute;
  left: 4px;
  bottom: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 2px 6px;
  border-radius: 6px;
}

.disabled-upload {
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- Photo capture (post-dig only) ---------- */
.photo-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  background: var(--input-bg);
}

.photo-box img {
  max-height: 220px;
  width: 100%;
  object-fit: contain;
  border-radius: 10px;
  margin: 0 auto 10px;
}

.photo-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.photo-actions .btn,
.photo-actions label.btn {
  flex: 1 1 140px;
  max-width: 100%;
}

/* ---------- Home ---------- */
.hero-home {
  text-align: center;
  padding: 4px 0;
}

.hero-home .shovel {
  font-size: 2.4rem;
  margin-bottom: 8px;
  line-height: 1;
}

.stat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 14px 0 16px;
}

.pill {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Admin ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  min-height: 72px;
}

.stat-card .num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}

.stat-card .lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

table.simple {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 0.8rem;
}

table.simple th,
table.simple td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.simple th {
  color: var(--text-muted);
  font-weight: 600;
}

/* ---------- Auth (full-screen mobile) ---------- */
.auth-wrap {
  min-height: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 12px 0 48px;
  max-width: 100%;
  margin: 0 auto;
}

@media (min-height: 640px) {
  .auth-wrap {
    min-height: calc(100dvh - var(--header-h) - var(--safe-top) - 48px);
    justify-content: center;
  }
}

.logo-lg {
  text-align: center;
  margin-bottom: 20px;
}

.logo-lg .brand-mark {
  width: 68px;
  height: 68px;
  font-size: 1.9rem;
  margin: 0 auto 12px;
  border-radius: 18px;
}

.logo-lg h1 {
  margin: 0;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}

.logo-lg p {
  margin: 8px 12px 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--input-bg);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  min-height: 44px;
  padding: 10px 8px;
  border-radius: 10px;
  color: var(--text-muted);
  font-weight: 650;
  font-size: 0.95rem;
  cursor: pointer;
}

.tabs button.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.hidden {
  display: none !important;
}

.offline-banner {
  position: sticky;
  top: 0;
  z-index: 45;
  background: var(--maybe-bg);
  color: var(--maybe);
  text-align: center;
  padding: 10px 12px;
  padding-top: calc(10px + var(--safe-top));
  font-size: 0.85rem;
  font-weight: 600;
  border-bottom: 1px solid color-mix(in srgb, var(--maybe) 30%, transparent);
}

/* when offline banner shows, header doesn't need double safe-top */
body:has(.offline-banner:not(.hidden)) .app-header {
  padding-top: 8px;
}

.detail-photo {
  width: 100%;
  max-height: min(50vh, 320px);
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.kv {
  display: grid;
  grid-template-columns: minmax(96px, 34%) 1fr;
  gap: 8px 10px;
  font-size: 0.92rem;
  margin-bottom: 14px;
}

.kv dt {
  color: var(--text-muted);
  margin: 0;
}

.kv dd {
  margin: 0;
  font-weight: 550;
  word-break: break-word;
}

.footer-note {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 18px;
  line-height: 1.45;
  padding: 0 4px;
}

.how-list {
  margin: 0;
  padding-left: 1.25rem;
}

.how-list li {
  margin-bottom: 10px;
  padding-left: 4px;
  line-height: 1.4;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  html {
    scroll-behavior: auto;
  }
}

/* Landscape phones: tighter vertical chrome */
@media (max-height: 480px) and (orientation: landscape) {
  .logo-lg {
    margin-bottom: 10px;
  }
  .logo-lg .brand-mark {
    width: 48px;
    height: 48px;
    font-size: 1.3rem;
  }
  .auth-wrap {
    justify-content: flex-start;
    min-height: auto;
  }
  .decision-hero {
    padding: 16px;
  }
  .decision-label {
    font-size: 1.8rem;
  }
}

/* ---------- Tablet+ enhancements (still mobile-first base) ---------- */
@media (min-width: 480px) {
  :root {
    --page-pad: 18px;
  }

  .row-2 {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .card {
    padding: 20px;
  }
}

/* Only constrain width when the screen is clearly larger than a phone */
@media (min-width: 600px) {
  main {
    max-width: 520px;
  }

  /* Don't constrain installed PWA on wide foldables unless very wide */
  html.pwa-standalone main {
    max-width: min(100%, 560px);
  }
}

@media (min-width: 768px) {
  main {
    max-width: 560px;
    padding: 24px 20px;
  }

  .bottom-nav button {
    font-size: 0.72rem;
  }

  .bottom-nav button:hover {
    color: var(--text);
  }

  .history-item:hover {
    border-color: var(--accent);
  }

  .icon-btn:hover {
    color: var(--text);
    border-color: var(--accent);
  }

  .btn-primary:hover:not(:disabled) {
    filter: brightness(1.05);
  }
}

/* Very small phones */
@media (max-width: 340px) {
  .brand span {
    font-size: 0.9rem;
  }
  .bottom-nav button {
    font-size: 0.58rem;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
