/* ============================================
   Delports Carton Counter v2.0 — App Styles
   Dark theme, warehouse-optimized, mobile-first
   Brand: Delports Fumigation Est. 1974
   ============================================ */

:root {
  --bg-primary: #0D0833;
  --bg-secondary: #1A0E65;
  --bg-surface: #261775;
  --accent: #CCFF00;
  --accent-hover: #b8e600;
  --accent-glow: rgba(204, 255, 0, 0.25);
  --accent-text: #0D0833;
  --step-active: #CCFF00;
  --text-primary: #F5F5F5;
  --text-secondary: #c0c0d4;
  --text-muted: #9898b2;
  --success: #4caf50;
  --warning: #ff9800;
  --error: #f44336;
  --border: #3a2d8a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-elevated: 0 8px 32px rgba(0, 0, 0, 0.45);
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --screen-gap: 20px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Global heading scale */
h2 {
  font-size: clamp(1.3rem, 4vw, 1.75rem);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

h3 {
  font-size: clamp(1rem, 3vw, 1.2rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- Skip Link (Accessibility) --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 9999;
  text-decoration: none;
}
.skip-link:focus {
  top: 8px;
}

/* --- Header --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header h1 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--text-primary);
  text-transform: uppercase;
}

.header-logo {
  height: 32px;
  width: auto;
  vertical-align: middle;
}

.btn-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.4rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

.btn-icon:hover {
  color: var(--accent);
  background: rgba(204, 255, 0, 0.08);
}

.btn-icon:focus-visible {
  color: var(--accent);
  background: rgba(204, 255, 0, 0.08);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Progress Bar --- */
.progress-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  background: var(--bg-secondary);
  gap: 4px;
  flex-wrap: nowrap;
}

.progress-bar .step {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--border);
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: background var(--transition-normal), color var(--transition-normal), box-shadow var(--transition-normal);
}

.progress-bar .step.active {
  background: var(--step-active);
  color: var(--accent-text);
  box-shadow: 0 0 12px var(--accent-glow);
}

.progress-bar .step.done {
  background: var(--success);
  color: var(--text-primary);
}

.progress-bar .step-line {
  width: 16px;
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  flex-shrink: 0;
  transition: background var(--transition-normal);
}

.progress-bar .step-line.done {
  background: var(--success);
}

.progress-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px 16px 6px;
  background: var(--bg-secondary);
}

/* Hide progress bar on camera, preview, settings, and history screens */
body:has(#screen-camera.active) .progress-bar,
body:has(#screen-camera.active) .progress-label,
body:has(#screen-preview.active) .progress-bar,
body:has(#screen-preview.active) .progress-label,
body:has(#screen-settings.active) .progress-bar,
body:has(#screen-settings.active) .progress-label,
body:has(#screen-history.active) .progress-bar,
body:has(#screen-history.active) .progress-label {
  display: none;
}

/* --- Screen Container --- */
.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  animation: screen-enter 250ms ease both;
}

@keyframes screen-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Camera and preview skip the entry animation */
.camera-screen.active,
.preview-screen.active {
  animation: none;
}

/* --- Screen 1: Start New Count --- */
.start-screen {
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 24px 16px;
}

.logo-area { text-align: center; }
.logo-area h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }
.logo-area p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
  max-width: 28ch;
  margin: 0 auto;
}

.app-logo {
  max-width: 220px;
  height: auto;
  margin-bottom: 12px;
}

.form-group {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

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

.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-muted);
}

/* Validation error styles */
@keyframes shake-field {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

.field-error {
  animation: shake-field 350ms ease;
  border-color: var(--error) !important;
}

.field-error-msg {
  font-size: 0.8rem;
  color: var(--error);
  margin-top: 4px;
  font-weight: 600;
}

/* --- Buttons --- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 24px;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 56px;
  width: 100%;
  max-width: 400px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:focus-visible {
  box-shadow: 0 4px 20px var(--accent-glow);
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.btn-primary:active { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--text-muted); cursor: not-allowed; box-shadow: none; color: var(--bg-primary); }

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 2px solid var(--border);
}

.btn-secondary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-secondary:active { background: var(--border); }

.btn-small {
  padding: 10px 16px;
  font-size: 0.9rem;
  min-height: 44px;
}

/* Accent outline button (used for Duplicate Stack) */
.btn-accent-outline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 24px;
  font-size: 1.1rem;
  font-weight: 700;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 56px;
  width: 100%;
  max-width: 400px;
  background: transparent;
  color: var(--accent);
  transition: transform var(--transition-fast), background var(--transition-fast), color var(--transition-fast);
}

.btn-accent-outline:hover,
.btn-accent-outline:focus-visible {
  background: rgba(204, 255, 0, 0.1);
}

.btn-accent-outline:active {
  transform: scale(0.97);
  background: var(--accent);
  color: var(--accent-text);
}

/* Duplicate badge */
.duplicate-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 8px;
  vertical-align: middle;
}

/* --- Camera Screen --- */
.camera-screen {
  padding: 0;
  position: relative;
  background: #000;
}

.camera-back-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 15;
  background: rgba(13, 8, 51, 0.85);
  border: none;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px 20px;
  min-height: 48px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.camera-back-btn:hover {
  background: rgba(26, 14, 101, 0.95);
}

.camera-back-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.camera-overlay-label {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 60px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
  z-index: 10;
  text-align: center;
}

.camera-overlay-label h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}

.camera-overlay-label p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.camera-instructions {
  position: absolute;
  top: 60px;
  left: 12px;
  right: 12px;
  background: rgba(13, 8, 51, 0.92);
  border-radius: var(--radius-sm);
  padding: 10px;
  z-index: 10;
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.camera-instructions.collapsed { display: none; }

.camera-instructions-toggle {
  position: absolute;
  top: 60px;
  right: 12px;
  z-index: 11;
  background: rgba(13, 8, 51, 0.8);
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 700;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-instructions-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Landscape hint (non-blocking banner) */
.landscape-hint {
  position: absolute;
  bottom: 100px;
  left: 12px;
  right: 12px;
  background: rgba(255, 152, 0, 0.9);
  color: #000;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.landscape-hint.hidden { display: none; }

.landscape-hint button {
  background: none;
  border: none;
  color: #000;
  font-size: 1.1rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewfinder {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* Vignette overlay */
.viewfinder::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
  z-index: 1;
}

.viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.viewfinder canvas { display: none; }

.camera-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  z-index: 10;
}

.btn-capture {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: var(--accent);
  cursor: pointer;
  position: relative;
  transition: transform var(--transition-fast);
  animation: pulse-ring 2s infinite;
  will-change: transform, box-shadow;
}

.btn-capture:active { transform: scale(0.92); }

.btn-capture:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}

.btn-capture::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(204, 255, 0, 0.5); }
  70% { box-shadow: 0 0 0 12px rgba(204, 255, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(204, 255, 0, 0); }
}

/* Fallback camera (native file-input mode) */
.fallback-camera {
  position: absolute;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px;
  text-align: center;
  z-index: 5;
}

.fallback-camera p {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.fallback-capture-btn {
  max-width: 280px;
  font-size: 1.2rem;
  min-height: 64px;
}

/* Camera error */
.camera-error {
  position: absolute;
  inset: 0;
  background: rgba(13, 8, 51, 0.97);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  text-align: center;
  z-index: 25;
}

.camera-error h3 {
  font-size: 1.2rem;
  color: var(--error);
}

.camera-error p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.camera-error-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

/* --- Preview Screen --- */
.preview-screen {
  padding: 0;
  position: relative;
  background: #000;
}

.preview-image-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.preview-image-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.preview-controls {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: var(--bg-secondary);
}

.preview-controls .btn {
  flex: 1;
  max-width: 200px;
}

/* --- Review Screen --- */
.review-screen {
  gap: var(--screen-gap);
  padding: 16px;
}

.review-photos {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.review-photo-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--border);
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition-fast);
}

.review-photo-card:hover {
  border-color: var(--accent);
}

.review-photo-card .photo-label {
  padding: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
  text-transform: uppercase;
}

.review-photo-card .photo-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
}

.review-photo-card .btn-retake {
  margin: 0 6px 6px;
  padding: 10px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  min-height: 44px;
  transition: background var(--transition-fast);
}

.review-photo-card .btn-retake:hover {
  background: var(--border);
}

.review-photo-card .btn-retake:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Count Screen --- */
.count-screen {
  gap: var(--screen-gap);
  padding: 16px;
  align-items: stretch;
}

.count-screen h2 { margin-bottom: 4px; }

.dimension-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.dimension-row label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex: 1;
}

/* Stepper */
.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}

.stepper-btn {
  width: 48px;
  height: 48px;
  background: var(--bg-surface);
  border: none;
  color: var(--text-primary);
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.stepper-btn:active {
  background: var(--accent);
  color: var(--accent-text);
  transform: scale(0.92);
}

.stepper-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.stepper input {
  width: 56px;
  height: 48px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  background: var(--bg-primary);
  border: none;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text-primary);
  -moz-appearance: textfield;
  outline: none;
}

.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Stepper value flash animation */
@keyframes value-flash {
  0%   { background: var(--accent); color: var(--accent-text); }
  100% { background: var(--bg-primary); color: var(--text-primary); }
}

.stepper input.flash {
  animation: value-flash 200ms ease;
}

/* Toggle group */
.toggle-group {
  display: flex;
  gap: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}

.toggle-btn {
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 700;
  background: var(--bg-surface);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.toggle-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

.toggle-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.toggle-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* Exceptions help text */
.exceptions-help {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.4;
}

/* --- Row Detail Cards (detailed mode) --- */
.row-card {
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition-fast);
}

.row-card.modified {
  border-color: var(--warning);
}

.row-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-card-label {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--accent);
  min-width: 30px;
}

.row-card-inputs {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.dimension-mini {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mini-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 700;
  min-width: 12px;
}

.row-card-subtotal {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
  margin-left: auto;
}

/* Mini stepper */
.stepper-mini {
  border-width: 1px;
}

.stepper-mini .stepper-btn {
  width: 44px;
  height: 44px;
  font-size: 1rem;
}

.stepper-mini input {
  width: 44px;
  height: 44px;
  font-size: 1rem;
}

/* Column adjustments area within a row card */
.row-exceptions-area {
  margin-top: 6px;
}

/* "+ Adjust columns" button */
.btn-adjust-cols {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  margin-top: 4px;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-adjust-cols:active {
  background: var(--accent);
  color: var(--accent-text);
}

.col-exception-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  margin-bottom: 4px;
}

.col-exc-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
}

.col-exc-col,
.col-exc-height {
  width: 48px;
  height: 36px;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  -moz-appearance: textfield;
  outline: none;
  transition: border-color var(--transition-fast);
}

.col-exc-col:focus,
.col-exc-height:focus {
  border-color: var(--accent);
}

.col-exc-col::-webkit-inner-spin-button,
.col-exc-col::-webkit-outer-spin-button,
.col-exc-height::-webkit-inner-spin-button,
.col-exc-height::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.col-exception-remove {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--error);
  border: none;
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  transition: opacity var(--transition-fast);
}

.col-exception-remove:active {
  opacity: 0.8;
}

.col-exception-remove:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Live calculation display */
.calc-display {
  background: var(--bg-secondary);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: 0 0 24px var(--accent-glow);
}

.calc-total, .calc-weight {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.calc-total { border-bottom: 1px solid var(--border); }

.calc-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.calc-value {
  font-size: clamp(2rem, 6vw, 2.4rem);
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.calc-breakdown {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.count-actions {
  display: flex;
  gap: 12px;
  padding-top: 8px;
}

.count-actions .btn { flex: 1; }

/* --- Report Screen --- */
.report-screen {
  gap: var(--screen-gap);
  padding: 16px;
  align-items: center;
}

.report-summary {
  width: 100%;
  max-width: 400px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 0.85rem;
  line-height: 1.6;
  box-shadow: var(--shadow-card);
}

.report-summary .report-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

.report-summary .report-row .label {
  color: var(--text-secondary);
}

.report-summary .report-row .value {
  font-weight: 700;
}

.report-summary .report-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.report-summary .report-big {
  text-align: center;
  padding: 12px 0;
}

.report-summary .report-big .value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  display: block;
}

.report-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

/* --- Stack Name Screen --- */
.stack-name-screen {
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 24px 16px;
}

/* --- Stack Complete Screen --- */
.stack-complete-screen {
  gap: var(--screen-gap);
  padding: 16px;
  align-items: center;
}

.stack-complete-screen h2 {
  margin-bottom: 4px;
  animation: saved-pop 400ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes saved-pop {
  0%   { transform: scale(0.85); opacity: 0; }
  60%  { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}

.completed-stack-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-card);
}

.stack-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.stack-card-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stack-card-stats {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stack-card-stats span {
  font-weight: 600;
}

.running-total {
  width: 100%;
  max-width: 400px;
  background: var(--bg-secondary);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
  box-shadow: 0 0 20px var(--accent-glow);
}

.running-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}

.running-total-row + .running-total-row {
  border-top: 1px solid var(--border);
}

.running-total-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.running-total-value {
  font-size: clamp(1.6rem, 5vw, 2rem);
  font-weight: 800;
  color: var(--accent);
}

.stack-complete-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  margin-top: 8px;
}

/* --- Settings Screen --- */
.settings-screen {
  gap: var(--screen-gap);
  padding: 16px;
  align-items: center;
}

.settings-form {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.settings-version {
  margin-top: 16px;
  text-align: center;
}

.settings-version p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* --- Job History Screen --- */
.history-screen {
  gap: 16px;
  padding: 16px;
  align-items: center;
}

.history-search {
  width: 100%;
  max-width: 500px;
}

.history-search input {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.history-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.history-search input::placeholder {
  color: var(--text-muted);
}

.history-list {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.history-date-group {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-top: 4px;
}

.history-card {
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition-fast);
}

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

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

.history-card-id {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  font-family: monospace;
}

.history-card-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.history-card-details {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.history-card-details span {
  white-space: nowrap;
}

.history-card-details strong {
  color: var(--text-primary);
  font-weight: 700;
}

.history-card-totals {
  display: flex;
  gap: 16px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.history-card-totals .total-item {
  display: flex;
  flex-direction: column;
}

.history-card-totals .total-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.history-card-totals .total-value {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-primary);
}

.history-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.history-btn {
  flex: 1;
  padding: 10px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  text-align: center;
  min-height: 44px;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.history-btn:active {
  transform: scale(0.96);
}

.history-btn-pdf {
  background: var(--accent);
  color: var(--accent-text);
}

.history-btn-pdf:hover {
  background: var(--accent-hover);
}

.history-btn-pdf.generating {
  opacity: 0.6;
  cursor: wait;
}

.history-btn-delete {
  background: var(--bg-surface);
  color: var(--error);
  border: 1px solid var(--error);
}

.history-btn-delete:hover {
  background: var(--error);
  color: #fff;
}

.history-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.history-actions {
  width: 100%;
  max-width: 500px;
  margin-top: 8px;
}

/* --- Resume Overlay --- */
.resume-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 8, 51, 0.92);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.resume-card {
  background: var(--bg-secondary);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-elevated);
}

.resume-card h3 {
  color: var(--accent);
  margin-bottom: 4px;
}

.resume-card > p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.resume-details {
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 20px;
  font-size: 0.85rem;
}

.resume-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}

.resume-row .label {
  color: var(--text-secondary);
}

.resume-row .value {
  font-weight: 700;
  color: var(--text-primary);
}

.resume-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

.resume-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* --- Autosave Indicator --- */
.autosave-indicator {
  position: fixed;
  top: 8px;
  right: 8px;
  background: rgba(76, 175, 80, 0.9);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  z-index: 9998;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
}

.autosave-indicator.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Modal Overlay (custom confirm/alert) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 8, 51, 0.85);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-box {
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-elevated);
}

.modal-box p {
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.5;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.modal-actions .btn {
  flex: 1;
}

/* --- Loading Spinner --- */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 24px auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Toast Notifications --- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-elevated);
  z-index: 9999;
  opacity: 0;
  transition: transform 300ms ease, opacity 300ms ease;
  pointer-events: none;
  max-width: min(90vw, 400px);
  text-align: center;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--error); }

/* --- Utility --- */
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.w-full { width: 100%; max-width: 400px; }
.hidden { display: none !important; }

/* --- Safe areas (notch phones) --- */
@supports (padding: env(safe-area-inset-top)) {
  .app-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .camera-controls {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .screen {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .preview-controls {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* --- Responsive: Small Screens --- */
@media (max-width: 360px) {
  .review-photos {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .row-card-inputs {
    gap: 6px;
  }

  .row-card-subtotal {
    width: 100%;
    text-align: right;
    margin-left: 0;
  }
}
