/* ============================================================
   Ann Arbor Inspections — mobile-first design system
   ============================================================ */
:root {
  --c-primary: #0f4c75;
  --c-primary-deep: #093557;
  --c-accent: #3282b8;
  --c-bg: #f5f7fa;
  --c-card: #ffffff;
  --c-border: #e2e8f0;
  --c-text: #1a202c;
  --c-text-muted: #64748b;
  --c-success: #16a34a;
  --c-warn: #f59e0b;
  --c-danger: #dc2626;
  --c-held: #dc2626;
  --c-active: #16a34a;
  --c-passed: #16a34a;
  --c-scheduled: #2563eb;
  --c-upcoming: #94a3b8;

  --trade-BP: #475569;
  --trade-EP: #d97706;
  --trade-PP: #0891b2;
  --trade-MP: #059669;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

  --header-h: 60px;
  --maxw: 720px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  padding-top: var(--header-h);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--c-text-muted); font-size: 13px; }

/* ============================================================
   Header (sticky)
   ============================================================ */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--c-primary);
  color: white;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.15);
  padding-top: env(safe-area-inset-top);
}
.app-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  text-decoration: none;
  font-weight: 700;
}
.app-header__brand:hover { text-decoration: none; }
.app-header__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  font-size: 18px;
}
.app-header__title { font-size: 15px; letter-spacing: 0.01em; }

/* Language toggle */
.lang-toggle {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 3px;
  gap: 0;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.05em;
}
.lang-toggle__opt {
  padding: 6px 12px;
  border-radius: 999px;
  transition: background 0.18s ease, color 0.18s ease;
}
.lang-toggle__opt.active {
  background: white;
  color: var(--c-primary);
}

/* ============================================================
   View
   ============================================================ */
.view {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ============================================================
   Stage cards (main page)
   ============================================================ */
.intro {
  margin: 0 0 24px;
  padding: 18px 20px;
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-deep) 100%);
  color: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.intro__title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.intro__meta { margin: 6px 0 0; font-size: 13px; opacity: 0.85; }
.intro__sub { margin: 12px 0 0; font-size: 14px; opacity: 0.92; line-height: 1.55; }

.stage-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }

.stage-card {
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--c-border);
  text-decoration: none;
  color: var(--c-text);
  display: block;
  transition: transform 0.15s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  position: relative;
  overflow: hidden;
}
.stage-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }
.stage-card:active { transform: translateY(0); }

.stage-card__head { display: flex; align-items: center; gap: 14px; }
.stage-num {
  flex: none;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  color: white;
  background: var(--c-primary);
  border-radius: 12px;
  letter-spacing: -0.02em;
}
.stage-card[data-status="held"] .stage-num { background: var(--c-held); }
.stage-card[data-status="passed"] .stage-num { background: var(--c-passed); }
.stage-card[data-status="scheduled"] .stage-num { background: var(--c-scheduled); }
.stage-card[data-status="upcoming"] .stage-num { background: var(--c-upcoming); }

.stage-card__title { flex: 1; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.3; margin: 0; }
.stage-card__arrow { color: var(--c-text-muted); font-size: 22px; line-height: 1; }

.stage-card__codes { margin: 12px 0 0; display: flex; gap: 6px; flex-wrap: wrap; }
.code-pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--c-text);
  letter-spacing: 0.02em;
}
.code-pill[data-trade="BP"] { background: rgba(71, 85, 105, 0.12); color: var(--trade-BP); }
.code-pill[data-trade="EP"] { background: rgba(217, 119, 6, 0.14); color: var(--trade-EP); }
.code-pill[data-trade="PP"] { background: rgba(8, 145, 178, 0.14); color: var(--trade-PP); }
.code-pill[data-trade="MP"] { background: rgba(5, 150, 105, 0.14); color: var(--trade-MP); }

.stage-card__summary { margin: 10px 0 0; font-size: 14px; color: var(--c-text-muted); line-height: 1.5; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.status-pill::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.status-pill[data-status="held"] { background: rgba(220, 38, 38, 0.1); color: var(--c-held); }
.status-pill[data-status="active"] { background: rgba(22, 163, 74, 0.1); color: var(--c-active); }
.status-pill[data-status="passed"] { background: rgba(22, 163, 74, 0.12); color: var(--c-passed); }
.status-pill[data-status="scheduled"] { background: rgba(37, 99, 235, 0.12); color: var(--c-scheduled); }
.status-pill[data-status="upcoming"] { background: rgba(148, 163, 184, 0.15); color: var(--c-upcoming); }

.progress-row { display: flex; align-items: center; gap: 12px; margin: 14px 0 0; }
.progress-bar {
  flex: 1;
  height: 6px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-active), var(--c-accent));
  transition: width 0.4s ease;
}
.progress-text { font-size: 12px; font-weight: 600; color: var(--c-text-muted); flex: none; }

/* ============================================================
   Stage detail view
   ============================================================ */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-primary);
  margin: 0 0 16px;
  background: none;
  border: 0;
  padding: 8px 0;
}
.back-link:hover { text-decoration: none; }
.back-link::before { content: "←"; font-size: 18px; }

.stage-hero {
  background: var(--c-card);
  border-radius: var(--radius);
  padding: 22px 20px 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--c-border);
  margin-bottom: 16px;
}
.stage-hero__num {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--c-text-muted);
  text-transform: uppercase;
}
.stage-hero__title { margin: 6px 0 12px; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.stage-hero__summary { margin: 0; color: var(--c-text-muted); font-size: 15px; line-height: 1.55; }

.alert {
  margin: 16px 0 0;
  padding: 12px 14px;
  background: rgba(220, 38, 38, 0.08);
  border-left: 3px solid var(--c-danger);
  border-radius: 6px;
  font-size: 14px;
  color: var(--c-text);
  line-height: 1.5;
}
.stage-hero[data-status="passed"] .alert {
  background: rgba(22, 163, 74, 0.09);
  border-left-color: var(--c-passed);
}
.stage-hero[data-status="scheduled"] .alert {
  background: rgba(37, 99, 235, 0.09);
  border-left-color: var(--c-scheduled);
}

.tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  padding: 10px 16px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--c-text);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tab.active {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}

.inspection {
  background: var(--c-card);
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 16px;
}
.inspection__head {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--c-border);
  background: #fafbfc;
}
.inspection__meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inspection__name { margin: 8px 0 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.inspection__pdf {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-accent);
}
.inspection__pdf::before { content: "📄"; }

.section { padding: 0 18px; }
.section + .section { border-top: 1px solid var(--c-border); }
.section__title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-text-muted);
  padding: 18px 0 10px;
  border-bottom: 1px solid var(--c-border);
  margin: 0;
}

.item-list { list-style: none; padding: 0; margin: 0; }
.item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--c-border);
  align-items: flex-start;
}
.item:last-child { border-bottom: 0; }
.item__check {
  flex: none;
  width: 24px;
  height: 24px;
  border: 2px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background: white;
  transition: background 0.15s, border-color 0.15s;
  margin-top: 2px;
  position: relative;
}
.item__check:checked {
  background: var(--c-active);
  border-color: var(--c-active);
}
.item__check:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid white;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
.item__body { flex: 1; font-size: 15px; line-height: 1.5; }
.item.is-checked .item__body { color: var(--c-text-muted); }
.item.is-checked .item__body .item__text { text-decoration: line-through; }
.item__text { display: block; }
.item__ref { display: block; font-size: 12px; color: var(--c-text-muted); margin-top: 4px; font-style: italic; }

.reset-row { text-align: center; margin: 20px 0; }
.reset-btn {
  background: white;
  border: 1px solid var(--c-border);
  color: var(--c-text-muted);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}
.reset-btn:hover { color: var(--c-danger); border-color: var(--c-danger); }

/* ============================================================
   Footer
   ============================================================ */
.app-footer {
  border-top: 1px solid var(--c-border);
  background: white;
  margin-top: 40px;
  padding: 18px 16px;
}
.app-footer__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  text-align: center;
  font-size: 13px;
  color: var(--c-text-muted);
}
.app-footer p { margin: 4px 0; }

/* ============================================================
   Lang visibility
   ============================================================ */
[data-lang-show] { display: none; }
body[data-lang="en"] [data-lang-show="en"] { display: block; }
body[data-lang="es"] [data-lang-show="es"] { display: block; }
body[data-lang="en"] [data-lang-show="en"].inline,
body[data-lang="es"] [data-lang-show="es"].inline { display: inline; }

/* ============================================================
   Responsive tweaks
   ============================================================ */
@media (min-width: 600px) {
  body { font-size: 16px; }
  .stage-hero__title { font-size: 28px; }
  .stage-card__head { gap: 18px; }
  .stage-num { width: 50px; height: 50px; font-size: 20px; }
  .stage-card__title { font-size: 17px; }
}

/* ============================================================
   Print
   ============================================================ */
@media print {
  body { background: white; padding-top: 0; }
  .app-header, .app-footer, .lang-toggle, .reset-row, .back-link, .tabs { display: none; }
  .stage-hero, .inspection, .stage-card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .item { break-inside: avoid; }
  .item__check { width: 16px; height: 16px; border: 1.5px solid #333; }
}
