/* ─── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
  --accent:       #00adee;
  --accent-dark:  #0090cc;
  --accent-glow:  rgba(0, 173, 238, 0.18);
  --bg:           #ffffff;
  --section-bg:   #f8f9fa;
  --danger:       #e53e3e;
  --danger-glow:  rgba(229, 62, 62, 0.14);
  --success:      #38a169;
  --success-glow: rgba(56, 161, 105, 0.14);
  --text:         #1a202c;
  --text-muted:   #718096;
  --border:       #e2e8f0;
  --radius:       16px;
  --shadow:       0 2px 16px rgba(0,0,0,0.07);
  --shadow-hover: 0 8px 32px rgba(0,0,0,0.12);
}

/* ─── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--bg);
  border-bottom: 1.5px solid var(--border);
  padding: 0 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: var(--shadow);
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 42px; height: 42px;
  background: var(--accent);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.logo-text { font-family: 'Syne', sans-serif; font-weight: 800; font-size: 22px; color: var(--text); }
.logo-text span { color: var(--accent); }

.header-center { display: flex; align-items: center; }
.ai-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px;
  background: var(--section-bg);
  border: 1.5px solid var(--border);
  border-radius: 100px;
  font-size: 13px; font-weight: 500;
}
.ai-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #cbd5e0; transition: background .3s;
  flex-shrink: 0;
}
.ai-dot.ready { background: var(--success); animation: pulse-green 2s infinite; }
.ai-dot.loading { background: var(--accent); animation: pulse-accent 1s infinite; }

.header-status {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px;
  background: var(--section-bg);
  border: 1.5px solid var(--border);
  border-radius: 100px;
  font-size: 13px; font-weight: 500;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #cbd5e0; transition: background .3s; flex-shrink: 0;
}
.status-dot.active  { background: var(--success); animation: pulse-green 2s infinite; }
.status-dot.alert   { background: var(--danger);  animation: pulse-red .8s infinite; }

/* ─── Animations ────────────────────────────────────────────────────────────── */
@keyframes pulse-green {
  0%,100% { box-shadow: 0 0 0 0 rgba(56,161,105,.4); }
  50%     { box-shadow: 0 0 0 6px rgba(56,161,105,0); }
}
@keyframes pulse-red {
  0%,100% { box-shadow: 0 0 0 0 rgba(229,62,62,.5); }
  50%     { box-shadow: 0 0 0 8px rgba(229,62,62,0); }
}
@keyframes pulse-accent {
  0%,100% { box-shadow: 0 0 0 0 rgba(0,173,238,.4); }
  50%     { box-shadow: 0 0 0 6px rgba(0,173,238,0); }
}
@keyframes flash-border {
  0%,100% { border-color: var(--danger); }
  50%     { border-color: transparent; }
}
@keyframes scan {
  0%   { top: 0; }
  100% { top: 100%; }
}
@keyframes blink-led {
  0%,100% { opacity: 1; }
  50%     { opacity: .3; box-shadow: none; }
}
@keyframes shake {
  0%,100% { transform: rotate(-8deg); }
  50%     { transform: rotate(8deg); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes barFill { from { width: 0; } to { width: 100%; } }

/* ─── Main ──────────────────────────────────────────────────────────────────── */
main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ─── Alert Banner ──────────────────────────────────────────────────────────── */
.alert-banner {
  border-radius: var(--radius);
  padding: 20px 28px;
  margin-bottom: 32px;
  align-items: center; gap: 16px;
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 18px;
  transition: all .4s;
  display: none;
}
.alert-banner.show   { display: flex; animation: fadeSlideIn .35s ease; }
.alert-banner.danger { background: var(--danger-glow); border: 2px solid var(--danger); color: var(--danger); animation: flash-border 1s infinite; }
.alert-banner.safe   { background: var(--success-glow); border: 2px solid var(--success); color: var(--success); }
.banner-icon { font-size: 30px; }
.banner-sub  { font-family: 'DM Sans', sans-serif; font-weight: 400; font-size: 14px; opacity: .8; display: block; margin-top: 3px; }

/* ─── Metrics ───────────────────────────────────────────────────────────────── */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.metric {
  background: var(--section-bg);
  border-radius: 14px;
  padding: 22px;
  text-align: center;
  border: 1.5px solid var(--border);
  transition: box-shadow .2s;
}
.metric:hover { box-shadow: var(--shadow-hover); }
.metric-value {
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: 32px;
  color: var(--accent); margin-bottom: 4px;
  transition: color .3s;
}
.metric-value.danger-val { color: var(--danger); }
.metric-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }

/* ─── Grid ──────────────────────────────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .site-header { padding: 0 16px; }
  .header-center { display: none; }
}

/* ─── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 26px 28px;
  border: 1.5px solid var(--border);
  transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow-hover); }
.card-title {
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 13px;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); margin-bottom: 20px;
  display: flex; align-items: center; gap: 8px;
}

/* ─── Camera ────────────────────────────────────────────────────────────────── */
.camera-container {
  position: relative;
  background: #0d1117;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border);
  aspect-ratio: 4/3;
}
#cameraFeed {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 10px;
}
#overlayCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  border-radius: 10px;
}
.camera-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 10px;
  color: #6b7280; font-size: 14px;
  pointer-events: none;
  transition: opacity .4s;
}
.camera-overlay span { font-size: 38px; }
.camera-overlay p    { font-family: 'Syne', sans-serif; font-weight: 600; }
.camera-overlay.hidden { opacity: 0; }

.scan-line {
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scan 2.2s linear infinite;
  display: none;
}
.scan-line.active { display: block; }

.cam-badge {
  position: absolute; top: 10px; left: 10px;
  background: var(--danger); color: white;
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 11px;
  padding: 4px 12px; border-radius: 100px;
  display: none; align-items: center; gap: 5px;
  animation: pulse-red 1s infinite;
}
.cam-badge.show { display: flex; }

.cam-status-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 12px; font-size: 13px; color: var(--text-muted);
}
.cam-dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e0; transition: background .3s; }
.cam-dot.live  { background: var(--danger);  animation: pulse-red 1s infinite; }
.cam-dot.ready { background: var(--success); }

.cam-interval-row {
  display: flex; align-items: center; gap: 10px;
}
.cam-interval-row label  { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.cam-interval-row input  { flex: 1; accent-color: var(--accent); }
.cam-interval-row span   { font-family: 'Syne', sans-serif; font-weight: 700; font-size: 13px; color: var(--accent); min-width: 32px; }

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px;
  border-radius: 10px;
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 15px;
  cursor: pointer; border: none;
  transition: all .2s;
}
.btn-primary {
  background: var(--accent); color: white;
  width: 100%; margin-top: 14px;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-outline {
  background: transparent; color: var(--accent);
  border: 2px solid var(--accent);
  padding: 10px 20px; font-size: 14px;
}
.btn-outline:hover:not(:disabled) { background: var(--accent-glow); }
.btn-outline:disabled { opacity: .4; cursor: not-allowed; }
.btn-stop {
  background: var(--danger); color: white;
  width: 100%; margin-top: 10px;
}
.btn-stop:hover { opacity: .88; transform: translateY(-1px); }

.controls-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── Result Box ────────────────────────────────────────────────────────────── */
.result-box {
  background: var(--bg);
  border-radius: 12px; padding: 20px;
  border: 1.5px solid var(--border);
  min-height: 150px;
  display: flex; flex-direction: column; justify-content: center;
}
.result-empty {
  text-align: center; color: var(--text-muted); font-size: 14px;
}
.result-empty span { font-size: 32px; display: block; margin-bottom: 8px; }
.result-status { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.result-badge {
  padding: 6px 16px; border-radius: 100px;
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 12px;
  text-transform: uppercase; letter-spacing: .05em;
}
.badge-danger  { background: var(--danger-glow);  color: var(--danger);  }
.badge-safe    { background: var(--success-glow); color: var(--success); }
.result-confidence { font-size: 13px; color: var(--text-muted); }
.confidence-bar {
  height: 6px; background: var(--border);
  border-radius: 100px; margin: 8px 0 14px;
  overflow: hidden;
}
.confidence-fill {
  height: 100%; border-radius: 100px;
  transition: width .8s cubic-bezier(.4,0,.2,1), background .4s;
}
.fill-danger { background: var(--danger); }
.fill-safe   { background: var(--success); }
.result-details { font-size: 14px; color: var(--text); line-height: 1.65; margin-bottom: 10px; }
.result-recommendation {
  font-size: 13px; padding: 10px 14px;
  border-radius: 8px; background: var(--section-bg);
  color: var(--text-muted); border-left: 3px solid var(--accent);
}

/* ─── LED Panel ─────────────────────────────────────────────────────────────── */
.led-display {
  display: flex; gap: 24px;
  justify-content: center; align-items: center;
  margin: 18px 0;
}
.led { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.led-bulb {
  width: 52px; height: 52px;
  border-radius: 50%; border: 3px solid;
  position: relative; transition: all .3s;
}
.led-bulb::after {
  content: '';
  position: absolute; top: 8px; left: 10px;
  width: 14px; height: 8px;
  background: rgba(255,255,255,.5);
  border-radius: 50%;
  transform: rotate(-30deg);
}
.led-red  .led-bulb { background: #fbd3d3; border-color: #fc8181; }
.led-red.active  .led-bulb {
  background: var(--danger); border-color: #c53030;
  box-shadow: 0 0 24px rgba(229,62,62,.7), 0 0 48px rgba(229,62,62,.3);
  animation: blink-led .6s ease-in-out infinite;
}
.led-green .led-bulb { background: #c6f6d5; border-color: #68d391; }
.led-green.active .led-bulb {
  background: var(--success); border-color: #276749;
  box-shadow: 0 0 24px rgba(56,161,105,.7), 0 0 48px rgba(56,161,105,.3);
}
.led-label {
  font-family: 'Syne', sans-serif; font-weight: 700; font-size: 10px;
  text-transform: uppercase; letter-spacing: .1em; color: var(--text-muted);
}
.buzzer-icon {
  font-size: 28px; text-align: center;
  padding: 14px; border-radius: 50%;
  background: var(--section-bg); border: 2px solid var(--border);
  transition: all .3s;
}
.buzzer-icon.active {
  background: rgba(229,62,62,.1); border-color: var(--danger);
  animation: shake .4s ease-in-out infinite;
}

/* ─── Log ───────────────────────────────────────────────────────────────────── */
.log-area {
  background: #1a202c; border-radius: 12px;
  padding: 16px; font-family: 'Courier New', monospace;
  font-size: 12px; color: #a0aec0;
  max-height: 180px; overflow-y: auto;
  line-height: 1.65;
}
.log-entry    { margin-bottom: 2px; }
.log-time     { color: #4a5568; }
.log-info     { color: var(--accent); }
.log-warn     { color: #f6ad55; }
.log-error    { color: #fc8181; }
.log-success  { color: #68d391; }

/* ─── Loading Overlay ───────────────────────────────────────────────────────── */
#loadingOverlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.96);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity .5s;
}
#loadingOverlay.hidden { opacity: 0; pointer-events: none; }
.loading-card {
  text-align: center; padding: 48px 40px;
  background: var(--section-bg);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.1);
  max-width: 340px; width: 90%;
}
.loading-spinner {
  width: 52px; height: 52px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 22px;
}
.loading-title {
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: 22px;
  color: var(--text); margin-bottom: 8px;
}
.loading-sub  { font-size: 13px; color: var(--text-muted); margin-bottom: 22px; }
.loading-bar  { height: 5px; background: var(--border); border-radius: 100px; overflow: hidden; }
.loading-fill {
  height: 100%; background: var(--accent); border-radius: 100px;
  width: 0; transition: width .5s ease;
}

/* ─── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--text); color: white;
  padding: 12px 22px; border-radius: 10px; font-size: 14px;
  transform: translateY(80px); opacity: 0;
  transition: all .35s; z-index: 999;
  pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }

/* ─── Utility ───────────────────────────────────────────────────────────────── */
.mt-2 { margin-top: 10px; }
.mt-3 { margin-top: 18px; }
.w-100 { width: 100%; }
.ms-auto { margin-left: auto; }
.d-none { display: none !important; }
/* ─── Image Upload Panel ─────────────────────────────────────────────────── */
.upload-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .upload-layout { grid-template-columns: 1fr; }
}

/* Drop Zone */
.upload-dropzone {
  border: 2.5px dashed var(--border);
  border-radius: 14px;
  background: var(--bg);
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color .25s, background .25s, box-shadow .25s;
  position: relative;
  overflow: hidden;
}
.upload-dropzone:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 0 4px rgba(0,173,238,0.08);
}
.upload-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(0,173,238,0.12);
  box-shadow: 0 0 0 6px rgba(0,173,238,0.14);
  transform: scale(1.01);
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 32px 20px;
  pointer-events: none;
  text-align: center;
}
.dropzone-icon {
  font-size: 42px;
  line-height: 1;
  filter: grayscale(0.3);
}
.dropzone-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.dropzone-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* Preview inside dropzone */
.dropzone-preview {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.dropzone-preview img {
  width: 100%;
  height: 190px;
  object-fit: contain;
  display: block;
  background: #0d1117;
}
.dropzone-preview-overlay {
  background: rgba(26,32,44,0.85);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.upload-filename {
  font-size: 11px;
  color: #a0aec0;
  font-family: 'Courier New', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

/* Result panel (right side) */
.upload-result-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 200px;
  justify-content: flex-start;
}

/* Canvas wrap — shows the image with detection overlay */
.upload-canvas-wrap {
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #0d1117;
  line-height: 0;
}
.upload-canvas-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
  max-height: 260px;
  object-fit: contain;
}

/* Empty state */
.upload-result-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 32px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  flex: 1;
}
.upload-result-empty span { font-size: 32px; }

/* Actions row */
.upload-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Spinner */
.upload-spinner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  color: var(--text-muted);
}