/* ── Reset & Variables ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --surface2: #21262d;
  --border:   #30363d;
  --text:     #e6edf3;
  --muted:    #8b949e;
  --green:    #3fb950;
  --yellow:   #e3b341;
  --red:      #f85149;
  --blue:     #58a6ff;
  --orange:   #ffa657;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Auth Overlay ───────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.94);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  text-align: center;
  width: 360px;
}
.auth-logo { font-size: 3.5rem; margin-bottom: 8px; }
.auth-box h2 { font-size: 1.6rem; font-weight: 700; margin-bottom: 6px; }
.auth-box p  { color: var(--muted); margin-bottom: 24px; }
.auth-box input {
  width: 100%; padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-size: 1rem; margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}
.auth-box input:focus { border-color: var(--blue); }
.auth-box button {
  width: 100%; padding: 12px;
  background: var(--blue); color: #000;
  border: none; border-radius: 8px;
  font-size: 1rem; font-weight: 700;
  cursor: pointer;
}
.auth-error { color: var(--red); margin-top: 10px; display: none; font-size: 0.9rem; }

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-left  { display: flex; align-items: center; gap: 14px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 1.25rem; font-weight: 700; }

.conn-dot { font-size: 1.3rem; line-height: 1; transition: color 0.3s; }
.conn-dot.connected    { color: var(--green); }
.conn-dot.disconnected { color: var(--red); }

/* ── Main Grid ──────────────────────────────────────────────────────────── */
main {
  display: grid;
  grid-template-columns: minmax(320px, 660px) 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
}

/* ── Panel label ────────────────────────────────────────────────────────── */
.panel-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 8px;
}

/* ── Camera Section ─────────────────────────────────────────────────────── */
.camera-section { display: flex; flex-direction: column; }
.canvas-wrapper {
  background: #000;
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}
#video-canvas { display: block; width: 100%; height: auto; }

.camera-controls {
  display: flex; gap: 10px; margin-top: 12px;
}
.camera-source-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
}
.source-label { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em; }
.source-opt {
  display: flex; align-items: center; gap: 5px;
  color: var(--text); cursor: pointer;
}
.source-opt input[type=radio] { accent-color: var(--blue); cursor: pointer; }

/* ── Count Section ──────────────────────────────────────────────────────── */
.count-section {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 24px;
  text-align: center;
  gap: 16px;
}

.count-number {
  font-size: clamp(80px, 14vw, 190px);
  font-weight: 900;
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  line-height: 1;
  letter-spacing: -0.02em;
  transition: color 0.4s, text-shadow 0.4s;
}
.count-number.green  { color: var(--green);  text-shadow: 0 0 40px rgba(63,185,80,0.4); }
.count-number.yellow { color: var(--yellow); text-shadow: 0 0 40px rgba(227,179,65,0.4); }
.count-number.red    { color: var(--red);    text-shadow: 0 0 40px rgba(248,81,73,0.4); }
.count-number.alert  {
  animation: count-pulse 0.65s ease-in-out infinite alternate;
}
@keyframes count-pulse {
  from { color: var(--red);  text-shadow: 0 0 40px rgba(248,81,73,0.5); }
  to   { color: #ff9999;     text-shadow: 0 0 80px rgba(248,81,73,0.9), 0 0 120px rgba(248,81,73,0.5); }
}

.count-meta  { color: var(--muted); font-size: 1rem; }

/* ── Progress Bar ───────────────────────────────────────────────────────── */
.progress-bar-wrap {
  width: 100%;
  height: 10px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--green);
  border-radius: 99px;
  transition: width 0.35s ease, background 0.5s ease;
}
.training-bar { background: var(--orange); }
.progress-pct { font-size: 0.85rem; color: var(--muted); }

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

/* ── Training Section ───────────────────────────────────────────────────── */
.training-section {
  max-width: 1280px; margin: 0 auto;
  padding: 0 24px 40px;
}
.training-section h3 { font-size: 1.1rem; margin-bottom: 16px; }
.training-controls {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 16px;
}
.training-controls input[type=text] {
  padding: 10px 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.95rem;
  min-width: 200px;
}

.training-status-row {
  display: flex; justify-content: space-between;
  font-size: 0.9rem; color: var(--muted);
  margin-bottom: 8px;
}
#training-progress {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.product-card-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px;
}
.product-name  { font-weight: 700; font-size: 0.95rem; }
.product-count { font-size: 0.8rem; color: var(--muted); }
.product-actions { display: flex; gap: 8px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
button, .upload-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px;
  border: none; border-radius: 8px;
  font-size: 0.92rem; font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
button:active, .upload-btn:active { transform: scale(0.96); }
.btn-primary   { background: var(--blue);    color: #000; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--red);     color: #fff; }
.btn-large     { padding: 13px 28px; font-size: 1.05rem; }
.upload-btn    { background: var(--surface2); color: var(--text); border: 1px solid var(--border); cursor: pointer; }

select {
  padding: 8px 12px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.9rem;
  cursor: pointer;
}

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%; max-width: 460px;
}
.modal-box h3 { font-size: 1.15rem; margin-bottom: 22px; }

.modal-box label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 0.88rem; color: var(--muted);
  margin-bottom: 16px;
}
.checkbox-row {
  flex-direction: row !important;
  align-items: center; gap: 10px;
  color: var(--text) !important;
}
.modal-box input[type=number],
.modal-box select {
  width: 100%; padding: 10px 12px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.95rem;
}
.modal-box input[type=range] {
  width: 100%; accent-color: var(--blue); margin-top: 4px;
}

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* Alert modal */
.alert-modal-box { text-align: center; }
.alert-icon  { font-size: 4rem; margin-bottom: 4px; }
.alert-modal-box h2 { font-size: 2rem; margin-bottom: 16px; }
.alert-count {
  font-size: 5.5rem; font-weight: 900;
  font-family: 'SF Mono', monospace;
  color: var(--green);
  text-shadow: 0 0 40px rgba(63,185,80,0.5);
  line-height: 1;
}
.alert-subtitle { color: var(--muted); margin-top: 6px; margin-bottom: 24px; }
.alert-modal-box .modal-actions { justify-content: center; }

/* ── Flash overlay ──────────────────────────────────────────────────────── */
.flash-overlay {
  position: fixed; inset: 0;
  background: var(--red);
  opacity: 0; pointer-events: none;
  z-index: 400;
}
.flash-overlay.flashing {
  animation: flash-anim 0.5s ease-out forwards;
}
@keyframes flash-anim {
  0%   { opacity: 0.65; }
  100% { opacity: 0; }
}
