/* CT Repair Logger — Shared Styles
   Dark bench-friendly theme with CT amber accent
   Designed for mobile-first use at the repair shop */

:root {
  --bg: #0F1117;
  --bg-card: #1A1D27;
  --bg-input: #12151F;
  --bg-section: #161922;
  --amber: #F59E0B;
  --amber-dim: #92400E;
  --amber-glow: rgba(245, 158, 11, 0.12);
  --green: #10B981;
  --red: #EF4444;
  --blue: #3B82F6;
  --orange: #F97316;
  --text: #E5E7EB;
  --text-dim: #6B7280;
  --text-muted: #374151;
  --border: #1F2937;
  --border-active: #374151;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
  --font-body: 'Inter', system-ui, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── TYPOGRAPHY ─────────────────────────────────────────── */

.section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--amber);
  display: block;
  margin-bottom: 12px;
}

h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ── LAYOUT ─────────────────────────────────────────────── */

.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;         /* allow logo + nav to stack on narrow viewports */
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Fix 1 (L1-B F1): nav buttons allowed to wrap on narrow viewports.
   Avoids body scrollWidth expansion that caused fixed button to
   resolve 100% against scrollWidth on iOS Safari.
   Targets .app-header-right directly — L1-B.1 added .header-overflow-wrap
   as the new last child, so div:last-child no longer points here. */
.app-header-right {
  flex-wrap: wrap;
}

/* ── HEADER — mobile-only elements (hidden by default on desktop) ─ */

/* Back link: rendered in DOM always; visible only on mobile */
.app-header-back { display: none; }

/* Inline sync icon: icon-only indicator next to title; visible only on mobile */
.header-sync-icon {
  display: none;
  font-size: 12px;
  color: var(--text-dim);    /* muted when synced */
  margin-left: 4px;
  line-height: 1;
}
.header-sync-icon.header-sync-unsynced { color: var(--amber); } /* amber = unsynced */

/* Overflow button + menu: hidden by default; shown on mobile */
.header-overflow-wrap {
  display: none;
  position: relative;
}

.header-overflow-btn {
  min-width: 44px;
  min-height: 44px;
  font-size: 18px;
  padding: 0;
  letter-spacing: 0.05em;
}

/* Overflow dropdown menu */
.header-overflow-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  min-width: 140px;
  z-index: 200;
}

.header-overflow-menu.open { display: block; }

.header-overflow-menu a {
  display: block;
  padding: 10px 12px;
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font-mono);
  text-decoration: none;
  border-radius: var(--radius);
  white-space: nowrap;
}

.header-overflow-menu a:hover { color: var(--text); }

.app-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-logo-mark {
  width: 32px;
  height: 32px;
  background: var(--amber);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: #000;
}

.app-title {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 16px;
}

.page-content {
  padding: 20px 16px 100px;
  max-width: 600px;
  margin: 0 auto;
}

/* ── STATS BAR ──────────────────────────────────────────── */

.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.stat-item {
  background: var(--bg-card);
  padding: 14px 12px;
  text-align: center;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--amber);
  display: block;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── BUTTONS ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  text-decoration: none;
  font-family: var(--font-body);
  white-space: nowrap;
}

.btn-primary {
  background: var(--amber);
  color: #000;
}
.btn-primary:hover { background: #FBBF24; }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border-active);
}
.btn-secondary:hover { border-color: var(--amber); color: var(--amber); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  padding: 8px 12px;
}
.btn-ghost:hover { color: var(--amber); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  padding: 8px 14px;
  font-size: 13px;
}

.btn-full { width: 100%; }

.btn-lg {
  padding: 16px 24px;
  font-size: 16px;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12px;
}

/* Fix 2 (L1-B F1): use left/right anchoring instead of calc(100% - 32px).
   Percentage on position:fixed resolves against scrollWidth on iOS Safari
   when the page has horizontal overflow; explicit left+right anchors don't. */
.new-repair-btn {
  position: fixed;
  bottom: 24px;
  left: 16px;
  right: 16px;
  width: auto;
  max-width: 400px;
  padding: 16px;
  font-size: 16px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(245, 158, 11, 0.3);
  z-index: 90;
}

/* ── SEARCH ─────────────────────────────────────────────── */

.search-bar {
  position: relative;
  margin-bottom: 16px;
}

.search-bar input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 16px 11px 40px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-body);
}

.search-bar input:focus {
  outline: none;
  border-color: var(--amber);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 16px;
}

/* ── REPAIR CARDS ───────────────────────────────────────── */

.repairs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.repair-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-decoration: none;
  display: block;
  transition: border-color 0.15s;
  cursor: pointer;
}

.repair-card:hover { border-color: var(--border-active); }

.repair-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}


.repair-device {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repair-customer {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 700;
  flex-shrink: 0;
}

/* Legacy statuses (pre-L1-A1) */
.status-received    { background: rgba(156, 163, 175, 0.15); color: #9CA3AF; }
.status-in_progress { background: rgba(245, 158, 11,  0.15); color: var(--amber); }
.status-completed   { background: rgba(16,  185, 129, 0.15); color: var(--green); }
.status-returned    { background: rgba(239, 68,  68,  0.15); color: var(--red); }
.status-referred    { background: rgba(59,  130, 246, 0.15); color: var(--blue); }

/* L1 statuses (13-status enum, L1-A1+) */
.status-in_repair         { background: rgba(245, 158, 11,  0.15); color: var(--amber); }
.status-repair_blocked    { background: rgba(239, 68,  68,  0.15); color: var(--red); }
.status-diagnosis_pending { background: rgba(245, 158, 11,  0.15); color: var(--amber); }
.status-go                { background: rgba(16,  185, 129, 0.15); color: var(--green); }
.status-under_observation { background: rgba(59,  130, 246, 0.15); color: var(--blue); }
.status-ready_for_pickup  { background: rgba(16,  185, 129, 0.15); color: var(--green); }
.status-quick_check       { background: rgba(59,  130, 246, 0.15); color: var(--blue); }
.status-intake_done       { background: rgba(156, 163, 175, 0.15); color: #9CA3AF; }
.status-walk_in_active    { background: rgba(245, 158, 11,  0.15); color: var(--amber); }
.status-closed            { background: rgba(16,  185, 129, 0.15); color: var(--green); }
.status-no_go             { background: rgba(239, 68,  68,  0.15); color: var(--red); }
.status-abandoned         { background: rgba(156, 163, 175, 0.15); color: #6B7280; }
.status-referred_out      { background: rgba(59,  130, 246, 0.15); color: var(--blue); }

.repair-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.fault-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg);
  padding: 3px 8px;
  border-radius: 4px;
}

.repair-date {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── FORM SECTIONS ──────────────────────────────────────── */

.form-section {
  background: var(--bg-section);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 12px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input[type="text"],
input[type="email"],
input[type="number"],
textarea,
select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-body);
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--amber);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

select option { background: var(--bg-input); }

/* ── QUICK SELECT BUTTONS ───────────────────────────────── */

.quick-select {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.quick-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all 0.15s;
}

.quick-btn:hover { border-color: var(--amber); color: var(--amber); }
.quick-btn.active { background: var(--amber-glow); border-color: var(--amber); color: var(--amber); }

/* ── CATEGORY TOGGLE ────────────────────────────────────── */

.category-toggle {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.category-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  transition: all 0.15s;
}

.category-btn.active.hardware { border-color: var(--amber); color: var(--amber); background: var(--amber-glow); }
.category-btn.active.software { border-color: var(--blue); color: var(--blue); background: rgba(59,130,246,0.1); }
.category-btn.active.mechanical { border-color: var(--green); color: var(--green); background: rgba(16,185,129,0.1); }

/* ── MEASUREMENT ROWS ───────────────────────────────────── */

.measurement-row {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  position: relative;
}

.measurement-row.anomalous {
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.05);
}

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

.measurement-row .row-number {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  position: absolute;
  top: 8px;
  right: 10px;
}

.anomaly-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  cursor: pointer;
}

.anomaly-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--red);
}

.anomaly-toggle span {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.remove-row-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  float: right;
}

.remove-row-btn:hover { color: var(--red); }

.add-row-btn {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border-active);
  border-radius: var(--radius);
  padding: 10px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all 0.15s;
  margin-top: 4px;
}

.add-row-btn:hover { border-color: var(--amber); color: var(--amber); }

/* ── PROFILE SELECTOR ───────────────────────────────────── */

.profile-selector {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.profile-btn:hover { border-color: var(--border-active); }
.profile-btn.active { border-color: var(--amber); background: var(--amber-glow); }
.profile-btn.active.danger { border-color: var(--red); background: rgba(239,68,68,0.1); }

.profile-number {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--amber);
  width: 28px;
  flex-shrink: 0;
}

.profile-btn.danger .profile-number { color: var(--red); }

.profile-info { flex: 1; }
.profile-range {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}
.profile-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-top: 1px;
}

/* ── PHOTO UPLOAD ───────────────────────────────────────── */

.photo-upload-zone {
  border: 2px dashed var(--border-active);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}

.photo-upload-zone:hover { border-color: var(--amber); }

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

.photo-thumb {
  aspect-ratio: 1;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
}

/* ── GSM POINTS PREVIEW ─────────────────────────────────── */

.gsm-preview {
  background: var(--amber-glow);
  border: 1px solid var(--amber-dim);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.gsm-preview-label {
  font-size: 12px;
  color: var(--amber);
  font-family: var(--font-mono);
}

.gsm-preview-points {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--amber);
}

/* ── SYNC STATUS ────────────────────────────────────────── */

.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.sync-dot.pending { background: var(--amber); animation: pulse 1.5s infinite; }
.sync-dot.offline { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── DETAIL SECTIONS ────────────────────────────────────── */

.detail-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 10px;
}

.detail-row {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.detail-row:last-child { border-bottom: none; }

.detail-key {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  width: 100px;
  flex-shrink: 0;
  padding-top: 1px;
}

.detail-value { color: var(--text); flex: 1; }

.measurement-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.measurement-chip.anomalous {
  border-color: var(--red);
  background: rgba(239,68,68,0.05);
}

/* ── REPORT STYLES ──────────────────────────────────────── */

.report-page {
  background: #fff;
  color: #111;
  padding: 32px;
  max-width: 680px;
  margin: 0 auto;
  font-family: 'Inter', system-ui, sans-serif;
}

.report-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #F59E0B;
  padding-bottom: 16px;
  margin-bottom: 24px;
}

.report-shop-name {
  font-size: 18px;
  font-weight: 700;
  color: #111;
}

.report-ct-tag {
  font-size: 11px;
  color: #6B7280;
  font-family: 'IBM Plex Mono', monospace;
}

.report-section {
  margin-bottom: 20px;
}

.report-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #F59E0B;
  font-family: 'IBM Plex Mono', monospace;
  margin-bottom: 8px;
}

.report-content {
  font-size: 14px;
  line-height: 1.7;
  color: #374151;
}

.report-evidence-item {
  display: flex;
  gap: 8px;
  font-size: 13px;
  font-family: 'IBM Plex Mono', monospace;
  color: #374151;
  margin-bottom: 4px;
}

.report-outcome-box {
  background: #F9FAFB;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  padding: 16px;
  margin-top: 8px;
}

.report-outcome-box.returned { background: #FEF2F2; border-color: #FECACA; }
.report-outcome-box.solved { background: #ECFDF5; border-color: #A7F3D0; }

.report-footer {
  border-top: 1px solid #E5E7EB;
  padding-top: 16px;
  margin-top: 24px;
  font-size: 11px;
  color: #9CA3AF;
  font-family: 'IBM Plex Mono', monospace;
  display: flex;
  justify-content: space-between;
}

/* ── EMPTY STATE ────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state h3 {
  color: var(--text-dim);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 280px;
  margin: 0 auto;
}

/* ── UTILITIES ──────────────────────────────────────────── */

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

.text-amber { color: var(--amber); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-dim { color: var(--text-dim); }
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }

.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

.hidden { display: none !important; }

/* ── PRINT STYLES ───────────────────────────────────────── */

@media print {
  body { background: #fff; color: #111; }
  .no-print { display: none !important; }
  .report-page { padding: 0; }
}

/* ── RESPONSIVE ─────────────────────────────────────────── */

@media (min-width: 480px) {
  .stats-bar { grid-template-columns: repeat(3, 1fr); }
}

/* CT Repair Diary — canonical mobile breakpoint. Covers 360px–640px
   (Android mid-range through wider phones). Established in L1-B.1. */
@media (max-width: 640px) {

  /* ── Header mobile layout ───────────────────────────────── */

  /* Back button: leftmost, 44px tap target */
  .app-header-back {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
  }

  /* Logo: grows to fill center space, centered */
  .app-logo {
    flex: 1;
    justify-content: center;
  }

  /* Inline sync icon: visible on mobile */
  .header-sync-icon { display: inline; }

  /* Desktop right nav: hidden on mobile */
  .app-header-right { display: none !important; }

  /* Overflow wrapper: visible on mobile */
  .header-overflow-wrap { display: block; }

  /* ── Stats bar mobile layout ────────────────────────────── */

  /* Active: full-width row 1, primary visual weight */
  .stat-item-active {
    grid-column: 1 / -1;
    order: -1;
    padding: 16px;
  }

  .stat-item-active .stat-value {
    font-size: 1.75rem;
  }

  .stat-item-active .stat-label {
    letter-spacing: 0.08em;
  }

  /* Secondary stats (Total, Streak, CT Tokens): row 2, smaller numbers */
  .stat-item:not(.stat-item-active) .stat-value {
    font-size: 1rem;
  }

  /* Remove CT Tokens inline border-left on mobile (not needed in 3-col row 2) */
  .stat-item-tokens {
    border-left: none !important;
    padding-left: 12px !important;
  }

  /* ── Bug 3 (L1-B.2): Stage 2 / work.html header — two-row mobile layout ── */

  /* Back button: ensure 44px tap target (inline style sets padding:8px which under-shoots) */
  .repair-header-back { min-height: 44px; }

  /* Identity row (device name + job ref/date): wraps to row 2.
     Depends on flex-wrap:wrap in .app-header base rule — do not change to nowrap. */
  .repair-header-mid {
    order: 2;
    flex: 1 1 100% !important; /* override inline flex:1 — forces wrap to new row */
    padding: 4px 0 !important; /* override inline padding: 0 8px */
  }

  /* Actions row (autosave + CT Tokens + status badge):
     On mobile, hide autosave dot and CT Tokens — only the status badge stays visible.
     CT Tokens is already visible in the dashboard stats bar. */
  .repair-header-end > *:not(.status-badge) { display: none; }
}

/* ── TAB BAR (dashboard Active / Completed tabs) ───────── */

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab-btn {
  padding: 8px 16px;
  min-height: 44px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn.active {
  color: var(--amber);
  border-bottom-color: var(--amber);
}
.tab-btn:hover:not(.active) { color: var(--text); }

/* ── SECTION CARDS (work.html expandable diagnostic cards) ── */

.section-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  overflow: hidden;
  background: var(--surface);
}
.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}
.card-header:hover { background: rgba(255,255,255,0.03); }
.card-status {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.card-status.done    { background: var(--green); }
.card-status.started { background: var(--amber); }
.card-status.empty   { background: var(--border); }
.card-title {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}
.card-saved {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.card-chevron {
  font-size: 10px;
  color: var(--text-dim);
  transition: transform 0.2s;
}
.card-chevron.open { transform: rotate(180deg); }
.card-body {
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}
.card-close {
  margin-top: 12px;
  text-align: right;
}

/* ── INTAKE SUMMARY (work.html top-of-page snapshot) ────── */

.intake-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
}
.intake-summary-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.intake-key {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.intake-val {
  font-size: 13px;
  color: var(--text);
}

/* ── HYPOTHESIS LOG ─────────────────────────────────────── */

.hypothesis-entry {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.hypothesis-entry:last-child { border-bottom: none; }
.hypothesis-time {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 3px;
}
.hypothesis-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

/* ── AUTOSAVE INDICATOR ─────────────────────────────────── */

.autosave-dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}
.autosave-dot::before {
  content: '';
  display: block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s;
}
.autosave-dot.saving::before { background: var(--amber); }
.autosave-dot.saved::before  { background: var(--green); }

/* ── FAULT GRID (shared — used in stage1 and ctx sheets) ── */

.fault-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.fault-grid-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 12px;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  transition: all 0.15s;
}
.fault-grid-btn:hover { border-color: var(--amber); color: var(--amber); }
.fault-grid-btn.active { background: var(--amber-glow); border-color: var(--amber); color: var(--amber); }

/* ── REPAIR CONTEXT BAR ─────────────────────────────────── */

/* Sticky chrome wrapper — collapses header + nav + context bar into one sticky unit */
.repair-top-chrome {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
}
/* When app-header is inside the wrapper it doesn't need its own sticky */
.repair-top-chrome .app-header {
  position: relative;
  top: auto;
  z-index: auto;
}

.repair-ctx-bar {
  background: #111420;
  border-bottom: 1px solid var(--border);
  padding: 4px 10px;
  display: flex;
  gap: 5px;
  overflow-x: auto;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.repair-ctx-bar::-webkit-scrollbar { display: none; }

.repair-ctx-chip {
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  min-height: 44px;
  cursor: pointer;
  flex-shrink: 0;
  max-width: 160px;
  min-width: 80px; /* L1-B.2: bumped from 52px — ensures chip labels are readable at narrow widths */
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.repair-ctx-chip:hover,
.repair-ctx-chip:active { border-color: var(--amber); }
.repair-ctx-chip:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.repair-ctx-chip-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6B7280;
  white-space: nowrap;
}
.repair-ctx-chip-value {
  font-size: 12px;
  font-weight: 500;
  color: #D1D5DB;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
  margin-top: 2px;
}
.repair-ctx-chip-value.empty {
  color: #6B7280;
  font-style: italic;
}
.repair-ctx-sep {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
  align-self: stretch;
  margin: 4px 0;
}

/* F1 (ctx-bar): 2×2 grid on mobile — all four chips always visible */
@media (max-width: 640px) {
  .repair-ctx-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    overflow-x: visible;
  }
  .repair-ctx-sep { display: none; }
  .repair-ctx-chip {
    max-width: none;
    min-width: 0;
    width: 100%;
  }
}

/* Quick-edit bottom sheet */
@keyframes ctx-overlay-in {
  from { background: rgba(0,0,0,0); }
  to   { background: rgba(0,0,0,0.65); }
}
@keyframes ctx-sheet-in {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ctx-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: ctx-overlay-in 0.18s ease-out both;
}
.ctx-sheet {
  background: var(--bg-card);
  border-top: 2px solid var(--amber);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 600px;
  padding: 20px 20px calc(32px + env(safe-area-inset-bottom, 0px));
  animation: ctx-sheet-in 0.22s ease-out both;
  z-index: 1; /* L1-B.2: defensive — ensures sheet participates in overlay stacking during transform animation */
  position: relative; /* needed for z-index to take effect */
  max-height: 80vh; /* L1-B.4: prevent sheet from overflowing screen height on mobile */
  display: flex; /* L1-B.5: flex column so list can grow and buttons stay pinned */
  flex-direction: column;
}
.ctx-sheet-title {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--amber);
  margin-bottom: 14px;
}
.ctx-sheet-input-label {
  font-size: 11px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 5px;
  margin-top: 12px;
  display: block;
}
.ctx-sheet-input-label:first-of-type { margin-top: 0; }
.ctx-sheet-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 16px;
  color: var(--text);
  box-sizing: border-box;
}
.ctx-sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-shrink: 0; /* L1-B.5: prevent buttons from being squeezed off screen when list grows */
}
.ctx-sheet-actions .ctx-btn-cancel {
  flex: 1;
  padding: 13px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.ctx-sheet-actions .ctx-btn-save {
  flex: 1;
  padding: 13px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--amber);
  color: #000;
  border: none;
}

/* Status option list inside sheet */
.ctx-status-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto; /* L1-B.4/L1-B.5: scroll status options when list exceeds sheet height */
  flex: 1 1 auto; /* L1-B.5: grow to fill available sheet height so overflow-y triggers */
}
.ctx-status-btn {
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
}
.ctx-status-btn.active {
  background: var(--amber-glow);
  border-color: var(--amber);
  color: var(--amber);
}

/* ── Zone A/B tab toggle (Stage 2) ──────────────────────────────────── */
.zone-tab-bar {
  display: flex;
  border-top: 1px solid #2A2A2A;
  background: #111318;
}
.zone-tab-btn {
  flex: 1;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: #9CA3AF; /* #6B7280 text-dim fails 4.5:1 at 13px — use lighter gray (7.3:1) */
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  min-height: 44px;
  letter-spacing: 0.02em;
}
.zone-tab-btn.active {
  color: var(--amber);
  border-bottom-color: var(--amber);
}
.zone-tab-btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: -2px;
}

/* Zone panels — mobile: only show active tab */
.zone-panel {
  display: none;
}
.zone-panel.tab-active {
  display: block;
}

/* Print: always show both zones (not tab-dependent) */
@media print {
  .zone-tab-bar { display: none !important; }
  .zone-panel { display: block !important; }
}

/* Desktop (768px+): side-by-side, hide tab bar */
@media (min-width: 768px) {
  .zone-tab-bar {
    display: none !important;
  }
  /* Widen stage2-content (only) to let both zones breathe side-by-side */
  .stage2-content {
    max-width: 900px;
  }
  .zone-panels-wrap {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
  }
  .zone-panel {
    display: block !important;
  }
}
