/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0a0a0a;
  --surface: #1a1a1a;
  --surface-hover: #222;
  --border: #333;
  --accent: #f0c000;
  --accent-dim: #c09800;
  --text: #e0e0e0;
  --text-muted: #888;
  --green: #4caf50;
  --yellow: #f0c000;
  --orange: #ff9800;
  --red: #e53935;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", Consolas, "Courier New", monospace;
  --max-width: 600px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== HAZARD STRIPE ===== */
.hazard-stripe {
  height: calc(6px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--surface);
  background-image: repeating-linear-gradient(
    -45deg,
    var(--accent) 0,
    var(--accent) 10px,
    var(--bg) 10px,
    var(--bg) 20px
  );
  background-position: bottom;
  background-size: 100% 6px;
  background-repeat: no-repeat;
}

/* ===== NAVIGATION ===== */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.nav-bar::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  flex: 1;
  min-width: 0;
  padding: 14px 8px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

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

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

/* ===== LAYOUT ===== */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 16px;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* ===== VIEWS ===== */
.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

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

/* ===== SCAN VIEW ===== */
.hero {
  text-align: center;
  padding: 40px 0 30px;
}

.app-title {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.08em;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 6px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.scan-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 320px;
  margin: 0 auto;
}

.scan-status {
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.scan-status.error {
  border-color: var(--red);
  color: var(--red);
}

/* ===== CAMERA / LIVE SCAN ===== */
.camera-container {
  margin-top: 20px;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  border: 2px solid var(--accent);
}

#camera-viewfinder {
  width: 100%;
  min-height: 300px;
}

#camera-viewfinder video {
  width: 100% !important;
  max-height: 60vh;
  object-fit: cover;
  border-radius: 8px;
}

/* Hide html5-qrcode's default UI cruft */
#camera-viewfinder img[alt="Info icon"],
#camera-viewfinder span,
#camera-viewfinder br {
  display: none !important;
}

#qr-shaded-region {
  border-color: var(--accent) !important;
}

.camera-stop-btn {
  margin-top: 10px;
  width: 100%;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
}

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

.btn-large {
  padding: 16px 24px;
  font-size: 1.1rem;
  border-radius: 10px;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-danger {
  border-color: var(--red);
  color: var(--red);
  background: transparent;
  margin-top: 20px;
}

.btn-danger:hover {
  background: rgba(229, 57, 53, 0.1);
}

/* ===== SECTION TITLES ===== */
.section-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 16px;
}

/* ===== RESULTS VIEW ===== */
.report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.report-row {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

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

.report-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.report-value {
  font-size: 0.95rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.badge-format {
  background: rgba(224, 224, 224, 0.1);
  color: var(--text);
}

.badge-type {
  background: rgba(240, 192, 0, 0.15);
  color: var(--accent);
}

.badge-unknown {
  background: rgba(240, 192, 0, 0.15);
  color: var(--yellow);
}

.badge-caution {
  background: rgba(240, 192, 0, 0.15);
  color: var(--yellow);
}

.badge-warning {
  background: rgba(255, 152, 0, 0.15);
  color: var(--orange);
}

.badge-danger {
  background: rgba(229, 57, 53, 0.15);
  color: var(--red);
}

/* Risk factors */
.risk-factors-list {
  list-style: none;
  padding: 0;
}

.risk-factors-list li {
  padding: 4px 0;
  font-size: 0.9rem;
  color: var(--text);
}

.risk-factors-list li::before {
  content: "\26A0\FE0E ";
  color: var(--orange);
  margin-right: 4px;
}

/* Raw payload */
.report-row-payload {
  background: rgba(0, 0, 0, 0.3);
}

.raw-payload {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
  line-height: 1.5;
  user-select: all;
  -webkit-user-select: all;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.result-actions .btn {
  width: 100%;
}

/* ===== HISTORY VIEW ===== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s;
}

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

.history-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.history-timestamp {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-preview {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-sm {
  font-size: 0.65rem;
  padding: 2px 6px;
}

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

.empty-state p:first-child {
  font-size: 1.2rem;
}

.empty-hint {
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ===== ABOUT VIEW ===== */
.about-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.about-card h3 {
  color: var(--accent);
  font-size: 1.05rem;
  margin: 20px 0 8px;
}

.about-card h3:first-child {
  margin-top: 0;
}

.about-card p {
  line-height: 1.6;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 0.92rem;
}

.about-card ul {
  list-style: none;
  padding: 0;
}

.about-card ul li {
  padding: 4px 0;
  font-size: 0.92rem;
  line-height: 1.5;
}

.about-card ul li::before {
  content: "\2714\FE0E ";
  color: var(--green);
  margin-right: 6px;
}

/* ===== DONATE VIEW ===== */
.donate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
}

.donate-lead {
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 12px;
}

.donate-card p {
  font-size: 0.92rem;
  line-height: 1.6;
  margin-bottom: 10px;
  color: var(--text);
}

.donate-button-wrap {
  margin: 24px 0;
}

.donate-link {
  font-size: 1.2rem;
  padding: 14px 40px;
}

.donate-warning {
  color: var(--orange);
  font-size: 0.8rem;
  margin-top: 10px;
  font-style: italic;
}

.donate-note {
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* ===== LICENSES VIEW ===== */
.license-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 12px;
}

.license-card h3 {
  color: var(--accent);
  font-size: 1rem;
  margin-bottom: 8px;
}

.license-card p {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
}

.license-card details {
  margin-top: 10px;
}

.license-card summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.85rem;
}

.license-text {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 10px;
  white-space: pre-wrap;
  line-height: 1.5;
}

/* ===== SECTION DIVIDER ===== */
.section-divider {
  height: 1px;
  background: var(--border);
  margin: 28px 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 400px) {
  .app-title {
    font-size: 1.7rem;
  }

  .container {
    padding: 16px 12px;
  }
}
