@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg-body: #f4f7fb;
  --bg-card: #ffffff;
  
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-indigo: #4f46e5;
  --accent-indigo-hover: #4338ca;
  --bg-secondary: #f1f5f9;
  --bg-secondary-hover: #e2e8f0;
  
  --border-light: #e2e8f0;
  
  --safe-bg: #ecfdf5;
  --safe-text: #059669;
  --safe-border: #10b981;
  
  --caution-bg: #fffbeb;
  --caution-text: #d97706;
  --caution-border: #f59e0b;
  
  --unsafe-bg: #fef2f2;
  --unsafe-text: #dc2626;
  --unsafe-border: #ef4444;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  --radius-md: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Navbar ── */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; padding: 0 2rem; height: 72px;
  border-bottom: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 50;
}
.navbar-left { flex: 1; }
.logo {
  display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.25rem;
}
.navbar-center {
  display: flex; gap: 2rem;
}
.nav-link {
  text-decoration: none; color: var(--text-secondary); font-weight: 500; font-size: 0.9rem;
  padding: 24px 0; border-bottom: 2px solid transparent;
}
.nav-link:hover { color: var(--text-primary); }
.nav-link.active {
  color: var(--accent-indigo); border-bottom-color: var(--accent-indigo);
}
.navbar-right {
  flex: 1; display: flex; justify-content: flex-end; align-items: center; gap: 1.5rem;
}
.user-profile {
  display: flex; align-items: center; gap: 12px;
}
.avatar {
  width: 36px; height: 36px; background: var(--border-light); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary);
}
.user-info { display: flex; flex-direction: column; }
.user-info .name { font-size: 0.85rem; font-weight: 600; line-height: 1.2; }
.user-info .role { font-size: 0.75rem; color: var(--text-muted); }
.nav-btn {
  background: #1e293b; color: white; border: none; padding: 8px 16px;
  border-radius: 8px; font-weight: 500; font-size: 0.9rem; cursor: pointer;
}

/* ── App Container & Cards ── */
@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-4px); }
  100% { transform: translateY(0px); }
}

.app-container {
  max-width: 900px; margin: 3rem auto; padding: 0 1.5rem;
  display: flex; flex-direction: column; gap: 1.5rem;
}
.card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); padding: 2rem;
  border: 1px solid var(--border-light);
  animation: float 6s ease-in-out infinite;
}
.card-title {
  font-size: 1.25rem; font-weight: 600; color: var(--text-primary);
  margin-bottom: 1.5rem;
}
.text-center { text-align: center; }

/* ── Dashboard Grid ── */
.dashboard-grid { display: flex; flex-direction: column; gap: 1.5rem; }

/* ── Scanner Card ── */
.scanner-card { display: flex; flex-direction: column; align-items: center; }
.camera-wrapper {
  position: relative; width: 100%; max-width: 500px; aspect-ratio: 16/10;
  background: #1e293b; border-radius: var(--radius-md); overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.5); margin: 0 auto 1.5rem;
}
#camera-video { width: 100%; height: 100%; object-fit: cover; }
#camera-canvas { display: none; }
.viewfinder {
  position: absolute; inset: 0; pointer-events: none;
}
.vf-corner {
  position: absolute; width: 30px; height: 30px; border: 2px solid rgba(255,255,255,0.7);
}
.vf-tl { top: 20px; left: 20px; border-right: none; border-bottom: none; border-top-left-radius: 8px; }
.vf-tr { top: 20px; right: 20px; border-left: none; border-bottom: none; border-top-right-radius: 8px; }
.vf-bl { bottom: 20px; left: 20px; border-right: none; border-top: none; border-bottom-left-radius: 8px; }
.vf-br { bottom: 20px; right: 20px; border-left: none; border-top: none; border-bottom-right-radius: 8px; }

.vf-text {
  position: absolute; width: 100%; text-align: center; color: rgba(255,255,255,0.7);
  font-size: 0.75rem; font-weight: 600; letter-spacing: 1px;
}
.vf-text-top { top: 25px; }
.vf-text-bottom { bottom: 25px; }

.vf-box {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 220px; height: 160px;
  border: 4px solid var(--safe-border); border-radius: 4px;
  border-left-color: var(--accent-indigo); border-right-color: var(--accent-indigo);
  opacity: 0.8;
}
.vf-line {
  position: absolute; top: 50%; left: -10px; right: -10px; height: 2px;
  background: var(--accent-indigo); box-shadow: 0 0 10px var(--accent-indigo);
}
.camera-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.8);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: white; font-size: 0.9rem; transition: opacity 0.3s;
}
.camera-overlay__icon { font-size: 2rem; margin-bottom: 0.5rem; opacity: 0.5; }
.scan-active .camera-overlay { opacity: 0; pointer-events: none; }

.side-info { display: none; } /* Used in mock layout, hidden here for simpler mobile-friendly stacking */
.text-muted { color: var(--text-muted); font-size: 0.85rem; }

.action-buttons {
  display: flex; gap: 12px; justify-content: center; width: 100%; max-width: 400px;
}
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: 8px; font-weight: 500; font-size: 0.95rem;
  cursor: pointer; border: none; transition: all 0.2s; flex: 1;
}
.btn-primary { background: var(--accent-indigo); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-indigo-hover); }
.btn-primary:disabled { opacity: 0.7; cursor: not-allowed; }
.btn-secondary { background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border-light); }
.btn-secondary:hover { background: var(--bg-secondary-hover); }

/* ── Metrics Card ── */
.metrics-card { padding: 1.5rem 2rem; }
.card-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;
}
.card-header .card-title { margin-bottom: 0; font-size: 1.1rem; }
.card-meta { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

.slider-container { position: relative; padding: 10px 0; margin-bottom: 1rem; }
input[type=range] {
  -webkit-appearance: none; width: 100%; background: transparent;
  --val: 0%;
}
input[type=range]:disabled { opacity: 0.5; cursor: not-allowed; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; height: 16px; width: 16px; border-radius: 50%;
  background: var(--accent-indigo); cursor: pointer; margin-top: -6px;
  box-shadow: 0 0 0 3px white, 0 0 0 4px var(--border-light);
}
input[type=range]:disabled::-webkit-slider-thumb { cursor: not-allowed; background: #94a3b8; }
input[type=range]::-webkit-slider-runnable-track {
  width: 100%; height: 4px; background: linear-gradient(to right, var(--accent-indigo) var(--val), var(--border-light) var(--val));
  border-radius: 2px;
}
input[type=range]:disabled::-webkit-slider-runnable-track {
  background: linear-gradient(to right, #94a3b8 var(--val), var(--border-light) var(--val));
}

/* ── Sandbox Controls ── */
.sandbox-controls { display: flex; flex-direction: column; gap: 1.2rem; }
.control-group { display: flex; flex-direction: column; }
.control-header { display: flex; justify-content: space-between; font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }

/* ── Toggle Switch ── */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider.round {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border-light); transition: .2s; border-radius: 24px;
}
.slider.round:before {
  position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px;
  background-color: white; transition: .2s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
input:checked + .slider.round { background-color: var(--accent-indigo); }
input:checked + .slider.round:before { transform: translateX(20px); }

/* ── Summary & Results ── */
.summary-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.5rem;
}
.data-group { display: flex; flex-direction: column; }
.data-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; margin-bottom: 4px; }
.data-value { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.data-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.biofilm-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

.result-panel { display: flex; flex-direction: column; align-items: center; }
.status-badge {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 120px; height: 120px; border-radius: 50%; margin-bottom: 2rem;
  border: 4px solid; font-size: 1.25rem; font-weight: 800; text-transform: uppercase;
}
.status-badge--safe { border-color: var(--safe-border); color: var(--safe-text); background: var(--safe-bg); }
.status-badge--caution { border-color: var(--caution-border); color: var(--caution-text); background: var(--caution-bg); }
.status-badge--unsafe { border-color: var(--unsafe-border); color: var(--unsafe-text); background: var(--unsafe-bg); }

.confidence-container { width: 100%; max-width: 500px; margin-bottom: 1.5rem; }
.confidence-title { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 1rem; text-align: center; }
.bar-row { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.75rem; }
.bar-label { width: 80px; font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); text-align: right; }
.bar-track { flex: 1; height: 8px; background: var(--border-light); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 1s; }
.bar-fill--safe { background: var(--safe-border); }
.bar-fill--caution { background: var(--caution-border); }
.bar-fill--unsafe { background: var(--unsafe-border); }
.bar-value { width: 45px; font-size: 0.75rem; font-weight: 600; color: var(--text-primary); }

.recommendation {
  background: var(--bg-secondary); padding: 1rem 1.5rem; border-radius: var(--radius-md);
  border-left: 4px solid var(--accent-indigo); font-size: 0.9rem; color: var(--text-secondary);
}

/* ── Toasts & Utils ── */
.hidden { display: none !important; }
.error-toast, .info-toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%) translateY(100px);
  padding: 14px 24px; border-radius: var(--radius-md); font-size: 0.9rem; font-weight: 600;
  z-index: 1000; opacity: 0; transition: all 0.3s; max-width: 500px; text-align: center;
  box-shadow: var(--shadow-lg);
}
.error-toast { background: var(--unsafe-bg); color: var(--unsafe-text); border: 1px solid var(--unsafe-border); }
.info-toast { background: var(--safe-bg); color: var(--safe-text); border: 1px solid var(--safe-border); }
.error-toast--visible, .info-toast--visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .navbar-center, .navbar-right { display: none; }
  .card-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .action-buttons { flex-direction: column; }
}
