/* ═══════════════════════════════════════════════════
   Chemical Scanner — Standalone Frontend Styles
   ═══════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
  --primary: #1BAB5A;
  --primary-dark: #137A40;
  --primary-light: #22D46F;
  --accent: #E91E63;
  --success: #4CAF50;
  --danger: #F44336;
  --warning: #FF9800;
  --info: #009688;
  --bg-primary: #FFFFFF;
  --bg-secondary: #FAFAFA;
  --bg-tertiary: #F5F5F5;
  --bg-card: #FFFFFF;
  --text-primary: #212121;
  --text-inverse: #FFFFFF;
  --text-secondary: #424242;
  --border-color: #E0E0E0;
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --radius-md: 16px;
  --spacing-md: 16px;
  --header-height: 60px;
  --footer-height: 80px;
  --vh: 1vh;
  --dvh: 1dvh;
}

/* ── Reset ── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  overflow: hidden;
  height: 100vh;
}

#app {
  max-width: 500px;
  margin: 0 auto;
  height: 100%;
  background: var(--bg-secondary);
  box-shadow: var(--shadow-sm);
  position: relative;
}

/* ── Global Spinner ── */
#global-spinner {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
#global-spinner.hidden { display: none; }
#global-spinner .spinner {
  width: 48px; height: 48px;
  border: 6px solid var(--primary-light);
  border-top: 6px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ── Loading Screen ── */

#loading-screen {
  background-image: url('../assets/bg.webp');
  background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	position: relative;
   min-height: 100vh !important;
}


#loading-screen::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: inherit;
  background-size: inherit;
  background-position: inherit;
  background-repeat: inherit;
  filter: blur(8px);
  z-index: 1;
}

.loading-container {
  background: rgba(27, 171, 90, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-inverse);
  position: relative;
  z-index: 2;
  min-height: 50vh;
  margin-top: 25vh;
  backdrop-filter: blur(2px);
}

.loading-icon {
  font-size: 64px;
  color: var(--text-inverse);
  margin-bottom: 24px;
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-20px); }
  60% { transform: translateY(-10px); }
}

#loading-screen h1 {
  color: var(--text-inverse);
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 12px;
}
#loading-screen p {
  color: var(--text-inverse);
  font-size: 1.1rem;
  opacity: 0.9;
  margin-bottom: 0;
}
#loading-screen .scan-button {
  background: var(--text-inverse);
  color: var(--primary);
  border: 2px solid var(--text-inverse);
  font-weight: 600;
  transition: all 0.3s ease;
}
#loading-screen .scan-button:hover {
  background: transparent;
  color: var(--text-inverse);
  border-color: var(--text-inverse);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(255,255,255,0.2);
}
#loading-screen .scan-button:active {
  transform: translateY(0);
  box-shadow: 0 4px 12px rgba(255,255,255,0.1);
}

.loading-spinner {
  width: 32px; height: 32px;
  border: 4px solid var(--primary-light);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-top: 24px;
}

/* ── Screen Base ── */
.screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  opacity: 0;
  visibility: hidden;
  transform: translateX(30px);
  transition: all 0.35s ease;
  overflow: hidden;
}
.screen.active {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

/* ── Status Bar (Header) ── */
.status-bar {
  height: var(--header-height);
  min-height: var(--header-height);
  max-height: var(--header-height);
  background: var(--primary);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0 16px;
  flex-shrink: 0;
  box-sizing: border-box;
}
.status-bar .title {
  color: var(--text-inverse);
  font-weight: 600;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.status-bar .action {
  color: var(--text-inverse);
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: background-color 0.2s ease;
  margin-left: auto;
}
.status-bar .action:hover {
  background-color: rgba(255,255,255,0.1);
}

/* ── Camera Container ── */
.camera-container {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100% - var(--header-height) - var(--footer-height));
}
.camera-container video {
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
  transform: scale(1.001);
  cursor: crosshairs;
}

/* ── Camera Overlay ── */
.camera-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
  padding-top: var(--header-height);
}

/* ── Scan Frame ── */
.scan-frame {
  width: min(80vw, 350px);
  height: min(60vh, 480px);
  position: relative;
  border: 2px solid var(--success);
  border-radius: var(--radius-md);
  background: rgba(76,175,80,0.1);
  backdrop-filter: blur(1px);
  pointer-events: none;
}
.scan-corners { position: relative; width: 100%; height: 100%; }
.scan-corners .corner {
  position: absolute;
  width: 24px; height: 24px;
  border: 3px solid var(--success);
  border-radius: 4px;
}
.corner.top-left     { top: -3px; left: -3px;  border-right: none; border-bottom: none; }
.corner.top-right    { top: -3px; right: -3px; border-left: none;  border-bottom: none; }
.corner.bottom-left  { bottom: -3px; left: -3px;  border-right: none; border-top: none; }
.corner.bottom-right { bottom: -3px; right: -3px; border-left: none;  border-top: none; }

.scan-line {
  position: absolute;
  top: 50%; left: 10%; right: 10%;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--success) 50%, transparent 100%);
  animation: scanLine 2s ease-in-out infinite;
  transform: translateY(-50%);
}
@keyframes scanLine {
  0%, 100% { opacity: 0.3; transform: translateY(-50%) scaleX(0.5); }
  50%      { opacity: 1;   transform: translateY(-50%) scaleX(1); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Camera Controls ── */
.camera-controls {
  position: fixed;
  bottom: 20px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 15;
  pointer-events: none;
  touch-action: manipulation;
  padding: 0 16px;
}
.camera-buttons {
  background: rgba(0,0,0,0.7);
  padding: 8px 16px;
  border-radius: 24px;
  display: flex;
  gap: 12px;
  align-items: center;
  backdrop-filter: blur(10px);
  pointer-events: auto !important;
  touch-action: manipulation;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.camera-control-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 12px;
  pointer-events: auto !important;
  -webkit-tap-highlight-color: rgba(255,255,255,0.3);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
  touch-action: manipulation;
  transform: translateZ(0);
  will-change: transform;
  min-width: 28px; min-height: 28px;
  position: relative;
  z-index: 20;
}
.camera-control-btn:focus {
  outline: 2px solid rgba(255,255,255,0.5);
  outline-offset: 2px;
}
.camera-control-btn:hover,
.camera-control-btn.active {
  background: rgba(255,255,255,0.3);
  border-color: rgba(255,255,255,0.5);
  transform: scale(1.1);
}
.camera-control-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.camera-control-btn:active {
  background: rgba(255,255,255,0.4);
  transform: scale(0.95);
}

/* ── Capture Button ── */
.capture-button {
  width: 50px; height: 50px;
  border-radius: 50%;
  border: 2px solid white;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  pointer-events: auto !important;
  -webkit-tap-highlight-color: rgba(255,255,255,0.3);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
  touch-action: manipulation;
  transform: translateZ(0);
  will-change: transform;
  min-width: 40px; min-height: 40px;
  z-index: 20;
  margin: 0 4px;
}
.capture-button:focus { outline: 3px solid rgba(255,255,255,0.5); outline-offset: 2px; }
.capture-button:hover { transform: scale(1.1); background: var(--primary-light); }
.capture-button:active { transform: scale(0.9); background: var(--primary-dark); }
.capture-button.disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.capture-button i {
  font-size: 18px;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.capture-ring, .capture-inner { display: none; }

/* ── Preview Container ── */
.preview-container {
  text-align: center;
  margin-bottom: var(--spacing-md);
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
}
.preview-container:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border-color: var(--primary-light);
}
.preview-container img {
  max-width: 100%; max-height: 180px;
  width: auto; height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  object-fit: contain;
}
.preview-container video {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  object-fit: contain;
}

/* ── Text Review Tweaks ── */
#text-review-screen .preview-container { margin-bottom: 0; padding: 12px; }
#text-review-screen .preview-container img { max-height: 150px; }

/* ── Text Input Container ── */
.text-input-container {
  margin-bottom: var(--spacing-md);
  width: 100%;
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
}
.text-input-container:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border-color: var(--primary-light);
  transform: translateY(-1px);
}
.text-input-container:focus-within {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(33,150,243,0.15);
  transform: translateY(-1px);
}
.text-input-container label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.text-input-container label::before {
  content: '';
  width: 4px; height: 16px;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}
.text-input-container .text-input {
  width: 100%;
  min-height: 140px;
  padding: 16px;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-size: 16px;
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  resize: vertical;
  transition: all 0.3s ease;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
  line-height: 1.6;
}
.text-input-container .text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1), 0 0 0 3px rgba(33,150,243,0.1);
  background: #FAFAFA;
  transform: translateY(-1px);
}
.text-input-container .text-input::placeholder {
  color: #9E9E9E;
  font-style: italic;
}

/* ── Content Container ── */
.content-container {
  flex: 1;
  padding: var(--spacing-md);
  overflow-y: auto;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  min-height: calc(100vh - var(--header-height) - var(--footer-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  max-height: calc(100vh - var(--header-height) - var(--footer-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

/* ── Text Review Layout ── */
#text-review-screen .content-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: calc(100vh - var(--header-height) - var(--footer-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  max-height: calc(100vh - var(--header-height) - var(--footer-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}
#text-review-screen .preview-container { flex: 0 0 auto; margin-bottom: 0; }
#text-review-screen .text-input-container {
  flex: 1;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#text-review-screen .text-input-container .text-input {
  flex: 1;
  min-height: 200px;
  max-height: none;
}

/* ── Data Review Layout ── */
#data-review-screen .content-container { padding: 16px; gap: 16px; }
#data-review-screen .form-grid { gap: 16px; }
#data-review-screen .form-group { margin-bottom: 0; }
#data-review-screen .form-group input[type="text"] { min-height: 48px; }
#data-review-screen .form-group textarea { min-height: 100px; }
#data-review-screen .form-group:has(#processed-text) textarea,
#processed-text {
  min-height: 120px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 14px;
  line-height: 1.5;
  background: #F8F9FA;
}

/* ── Form Grid ── */
.form-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
  width: 100%;
}
.form-group {
  display: flex;
  flex-direction: column;
  width: 100%;
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
  margin-bottom: 16px;
}
.form-group:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border-color: var(--primary-light);
  transform: translateY(-1px);
}
.form-group:focus-within {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(33,150,243,0.15);
  transform: translateY(-1px);
}
.form-group label {
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  order: -1;
}
.form-group label::before {
  content: '';
  width: 4px; height: 16px;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}
.form-group input,
.form-group textarea {
  width: 100%;
  padding: 16px;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-size: 16px;
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: all 0.3s ease;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
  flex: 1;
  min-height: 48px;
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1), 0 0 0 3px rgba(33,150,243,0.1);
  transform: translateY(-1px);
  background: #FAFAFA;
}
.form-group input::placeholder,
.form-group textarea::placeholder {
  color: #9E9E9E;
  font-style: italic;
}
.form-group textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

/* ── Field Validation ── */
.form-group input.empty-field,
.form-group textarea.empty-field {
  border-color: var(--danger) !important;
  background-color: rgba(244,67,54,0.08) !important;
  box-shadow: 0 0 0 3px rgba(244,67,54,0.15) !important;
  border-width: 2px !important;
}
.form-group input.empty-field:focus,
.form-group textarea.empty-field:focus {
  border-color: var(--danger) !important;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1), 0 0 0 4px rgba(244,67,54,0.25) !important;
}
.form-group.has-error {
  border-color: var(--danger);
  background: rgba(244,67,54,0.08);
  box-shadow: 0 4px 12px rgba(244,67,54,0.2);
  transform: scale(1.01);
  transition: all 0.3s ease;
}
.form-group.has-error label { color: var(--danger) !important; }
.form-group.has-error label::before { background: var(--danger) !important; animation: pulse 2s infinite; }
.form-group.error { border-color: var(--danger); background: rgba(244,67,54,0.08); box-shadow: 0 4px 12px rgba(244,67,54,0.2); transform: scale(1.01); }
.form-group.error label::before { background: var(--danger); animation: pulse 2s infinite; }
.form-group.error input,
.form-group.error textarea { border-color: var(--danger); background: rgba(244,67,54,0.03); border-width: 2px; }
.form-group.error input:focus,
.form-group.error textarea:focus { border-color: var(--danger); box-shadow: inset 0 1px 3px rgba(0,0,0,0.1), 0 0 0 4px rgba(244,67,54,0.15); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.7; transform: scale(1.1); }
}

/* ── Text Input ── */
.text-input {
  min-height: 140px;
  width: 100%;
  padding: 16px;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-size: 16px;
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  resize: vertical;
  transition: all 0.3s ease;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
  line-height: 1.6;
}
.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1), 0 0 0 3px rgba(33,150,243,0.1);
  background: #FAFAFA;
  transform: translateY(-1px);
}

/* ── Buttons ── */
.btn {
  padding: 16px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
  text-decoration: none;
  min-height: 48px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  min-width: 44px;
}
.btn::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}
.btn:hover::before { left: 100%; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: 2px solid transparent;
  outline: none;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(27,171,90,0.3);
}
.btn-primary:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.btn-primary:focus  { outline: none; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover {
  background: var(--primary);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(33,150,243,0.2);
}

/* ── Typography ── */
h1, h2, h3 { font-weight: 600; color: var(--text-primary); margin-bottom: 16px; line-height: 1.3; }
h2 { font-size: 24px; text-align: center; margin-bottom: 20px; }

/* ── Status Messages ── */
.status-message {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.status-message.success { border-color: var(--success); background: rgba(76,175,80,0.05); }
.status-message.warning { border-color: var(--warning); background: rgba(255,152,0,0.05); }
.status-message.error   { border-color: var(--danger);  background: rgba(244,67,54,0.05); }

/* ── Action Bar (Footer) ── */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  position: sticky;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  padding: 12px 16px;
  height: var(--footer-height);
  min-height: var(--footer-height);
  max-height: var(--footer-height);
  z-index: 100;
  box-sizing: border-box;
  flex-shrink: 0;
  margin-top: auto;
}
.action-bar .btn {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Processing Screen ── */
.processing-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md);
  text-align: center;
}
.processing-spinner {
  width: 64px; height: 64px;
  border: 6px solid var(--primary-light);
  border-top: 6px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 24px;
}

/* ── Success Screen ── */
.success-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md);
  text-align: center;
}
.success-icon {
  width: 80px; height: 80px;
  background: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 32px;
  margin-bottom: 24px;
}
.success-spacer { height: 40px; width: 100%; }
.stats-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  margin: 24px 0;
  box-shadow: var(--shadow-sm);
  width: 100%; max-width: 400px;
}

/* ── Error Screen ── */
.error-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md);
  text-align: center;
}
.error-icon {
  width: 80px; height: 80px;
  background: var(--danger);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 32px;
  margin-bottom: 24px;
}
.error-spacer { height: 40px; width: 100%; }
.error-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%; max-width: 300px;
}
.error-actions .btn { width: 100%; justify-content: center; }

/* ── 404 Not Found Screen ── */
.not-found-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md);
  text-align: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;
}
.not-found-icon {
  width: 100px;
  height: 100px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 42px;
  margin-bottom: 20px;
  box-shadow: 0 8px 32px rgba(27, 171, 90, 0.3);
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.not-found-code {
  font-size: 72px;
  font-weight: 700;
  color: var(--primary-dark);
  line-height: 1;
  margin-bottom: 8px;
}
.not-found-container h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.not-found-container p {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 300px;
}
.not-found-spacer {
  height: 32px;
  width: 100%;
}
#not-found-screen .not-found-container {
  min-height: 100vh;
  max-height: 100vh;
  box-sizing: border-box;
}

/* ── Rotate Button (Circular) ── */
.btn-circular {
  width: 50px; height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6c757d, #5a6268);
  color: white;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 18px; font-weight: 600;
  min-height: 50px; min-width: 50px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
  outline: none;
  flex-shrink: 0;
}
.btn-circular:hover { background: linear-gradient(135deg, #5a6268, #545b62); transform: translateY(-2px) scale(1.05); box-shadow: 0 6px 20px rgba(108,117,125,0.3); }
.btn-circular:active { background: linear-gradient(135deg, #545b62, #4e555b); transform: translateY(0) scale(0.95); }
.btn-circular:focus { outline: none; }
.btn-circular::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}
.btn-circular:hover::before { left: 100%; }

/* ── Screens Without Action Bars ── */
#loading-screen,
#processing-screen .processing-container,
#success-screen .success-container,
#error-screen .error-container {
  min-height: calc(100vh - var(--header-height));
  max-height: calc(100vh - var(--header-height));
  box-sizing: border-box;
}
#processing-screen .processing-container,
#success-screen .success-container,
#error-screen .error-container {
  padding: var(--spacing-md);
}

/* ── Image Preview Screen ── */
.preview-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--spacing-md);
  gap: var(--spacing-md);
  background: var(--bg-secondary);
  min-height: calc(100vh - var(--header-height) - var(--footer-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  max-height: calc(100vh - var(--header-height) - var(--footer-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  box-sizing: border-box;
  position: relative;
}
.preview-image-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  padding: 16px;
  min-height: 300px;
  position: relative;
  overflow: hidden;
}
.preview-image-container img,
.preview-image-container video {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  object-fit: contain;
  display: block;
  margin: 0 auto;
  transition: transform 0.3s ease;
}
.preview-image-container.rotated { display: flex; align-items: center; justify-content: center; }
.preview-image-container.rotated img,
.preview-image-container.rotated video { transform-origin: center center; }

.preview-instructions {
  text-align: center;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}
.preview-instructions p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.5;
}

#image-preview-screen .action-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#image-preview-screen #retake-photo-btn,
#image-preview-screen #process-ocr-btn,
#image-preview-screen #rotate-btn { flex: 1; max-width: 45%; }

/* ── Recording Timer ── */
.recording-timer {
  position: absolute;
  top: calc(var(--header-height) + 10px);
  left: 16px;
  background: rgba(220,53,69,0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 20px;
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 14px; font-weight: 600;
  z-index: 30;
  backdrop-filter: blur(5px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.2);
}
.recording-dot { animation: recordingPulse 1s ease-in-out infinite; }
@keyframes recordingPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

/* ── Toast Notifications ── */
#toast-container {
  position: fixed;
  top: calc(var(--header-height) + 20px);
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: 320px;
  pointer-events: none;
}
.toast {
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  color: #fff;
  opacity: 0.95;
  animation: slide-in-right 0.3s ease-out;
  transform: translateX(0);
  width: auto; max-width: 300px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px; font-weight: 500;
  white-space: nowrap;
  pointer-events: auto;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
}
.toast-info    { background: var(--info); }
.toast-warning { background: var(--warning); }
.toast-error   { background: var(--danger); }
.toast-success { background: var(--success); }

@keyframes slide-in-right {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 0.95; }
}
.toast.fade-out {
  transition: opacity 0.5s ease, transform 0.5s ease;
  opacity: 0 !important;
  transform: translateX(100%);
}

/* ── Modal ── */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1500;
}
.modal.active { display: flex; }
.modal .modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  width: 90%; max-width: 400px; max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
.modal .close-modal {
  position: absolute;
  top: 12px; right: 12px;
  background: none; border: none;
  font-size: 1.4em;
  color: var(--text-primary);
  cursor: pointer;
}

/* ═══════════════════════════════════════
   Responsive
   ═══════════════════════════════════════ */

@media (max-width: 480px) {
  #toast-container {
    top: calc(var(--header-height) + 10px);
    right: 16px; left: auto;
    max-width: 280px;
  }
  .toast { max-width: 280px; width: auto; font-size: 13px; }
  #camera-screen #toast-container { top: calc(var(--header-height) + 20px); }
  .recording-timer { top: calc(var(--header-height) + 8px); left: 12px; font-size: 13px; padding: 6px 10px; }
  .content-container { padding: 12px; }
  .form-group, .text-input-container { padding: 16px; margin-bottom: 12px; }
  .form-group input,
  .form-group textarea,
  .text-input-container .text-input { padding: 14px; font-size: 16px; }
  .form-grid { gap: 12px; }
  #image-preview-screen .action-bar { gap: 8px; padding: 12px; }
  .action-bar .btn { font-size: 14px; padding: 12px 16px; }
  .btn-circular { width: 44px; height: 44px; font-size: 16px; }
}

@media (min-width: 481px) {
  #toast-container { max-width: 320px; right: 20px; }
  .recording-timer { top: 80px; left: 20px; }
}

@media (max-width: 768px) {
  .action-bar { flex-wrap: wrap; gap: 8px; }
  .action-bar .btn { flex: 1; min-width: 120px; }
  .status-bar {
    height: var(--header-height) !important;
    min-height: var(--header-height) !important;
    max-height: var(--header-height) !important;
  }
  .action-bar {
    height: var(--footer-height) !important;
    min-height: var(--footer-height) !important;
    max-height: var(--footer-height) !important;
  }
}
