/* ==========================================================================
   Webcam Validator - styles.css
   A shadcn/ui inspired theme. Neutral surfaces, subtle borders, soft radius,
   with an emerald accent. Light and dark are driven by [data-theme] on <html>.
   No external fonts or resources are loaded. System fonts only.
   ========================================================================== */

/* ----------------------------- Design tokens ---------------------------- */
:root {
  --radius: 0.65rem;

  /* Emerald accent (shared across themes) */
  --accent: 160 84% 39%;          /* emerald-600 */
  --accent-hover: 161 84% 33%;    /* emerald-700 */
  --accent-foreground: 0 0% 100%;
}

html[data-theme="light"] {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --ring: 160 84% 39%;
  --stage: 240 6% 10%;
  --shadow-color: 240 8% 40%;
}

html[data-theme="dark"] {
  --background: 240 10% 5%;
  --foreground: 0 0% 98%;
  --card: 240 7% 9%;
  --card-foreground: 0 0% 98%;
  --muted: 240 4% 16%;
  --muted-foreground: 240 5% 65%;
  --border: 240 4% 18%;
  --input: 240 4% 20%;
  --secondary: 240 4% 14%;
  --secondary-foreground: 0 0% 98%;
  --ring: 160 84% 39%;
  --stage: 240 12% 3%;
  --shadow-color: 240 30% 2%;
}

/* ------------------------------- Reset ---------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

/* The hidden attribute must always win over component display rules. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p { margin: 0; }

button { font-family: inherit; }

.icon { width: 16px; height: 16px; flex: none; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.muted-text { color: hsl(var(--muted-foreground)); font-size: 13px; }

/* ------------------------------- Header --------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: hsl(var(--background) / 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid hsl(var(--border));
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: hsl(var(--accent-foreground));
  background: hsl(var(--accent));
  box-shadow: 0 1px 2px hsl(var(--shadow-color) / 0.4);
}
.brand-mark svg { width: 22px; height: 22px; }

.brand-text h1 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.brand-text p { font-size: 12.5px; color: hsl(var(--muted-foreground)); }

.header-actions { display: flex; align-items: center; gap: 10px; }

/* ------------------------------- Layout --------------------------------- */
.app-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
  align-items: start;
}

.main-col, .side-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* -------------------------------- Card ---------------------------------- */
.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px hsl(var(--shadow-color) / 0.18);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 0;
}
.card-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.card-subtitle { font-size: 13px; color: hsl(var(--muted-foreground)); margin-top: 3px; }
.card-content { padding: 16px 20px 20px; }
.card-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px 20px;
  flex-wrap: wrap;
}
.footer-hint { font-size: 12.5px; color: hsl(var(--muted-foreground)); }

/* ------------------------------- Buttons -------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease,
    border-color 0.15s ease, opacity 0.15s ease;
}
.btn:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.btn-primary:hover:not(:disabled) { background: hsl(var(--accent-hover)); }

.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn-secondary:hover:not(:disabled) { background: hsl(var(--muted)); }

.btn-outline {
  background: transparent;
  border-color: hsl(var(--border));
  color: hsl(var(--foreground));
}
.btn-outline:hover:not(:disabled) { background: hsl(var(--muted)); }

.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover:not(:disabled) { background: hsl(var(--muted)); }

.btn-icon { width: 38px; padding: 0; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }

/* recording glyph inside the primary record button */
.rec-glyph {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: currentColor;
}
.btn.is-recording { background: hsl(0 72% 51%); }
.btn.is-recording:hover:not(:disabled) { background: hsl(0 72% 45%); }
.btn.is-recording .rec-glyph { border-radius: 2px; }

/* ------------------------------- Badges --------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
}
.badge-muted { background: hsl(var(--muted)); border-color: transparent; color: hsl(var(--muted-foreground)); }
.badge-soft { background: hsl(var(--accent) / 0.12); border-color: hsl(var(--accent) / 0.25); color: hsl(var(--accent)); }
.badge-pass { background: hsl(var(--accent) / 0.14); border-color: transparent; color: hsl(var(--accent)); }
.badge-warn { background: hsl(38 92% 50% / 0.15); border-color: transparent; color: hsl(38 92% 45%); }
.badge-fail { background: hsl(0 72% 51% / 0.14); border-color: transparent; color: hsl(0 72% 55%); }

.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-emerald { background: hsl(var(--accent)); box-shadow: 0 0 0 3px hsl(var(--accent) / 0.2); }

/* ----------------------------- Diagnostics ------------------------------ */
.diag-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.diag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid hsl(var(--border));
}
.diag-row:last-child { border-bottom: none; }
.diag-name { font-size: 13.5px; }
.diag-note {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: calc(var(--radius) - 2px);
  background: hsl(38 92% 50% / 0.1);
  border: 1px solid hsl(38 92% 50% / 0.25);
  color: hsl(38 60% 40%);
  font-size: 13px;
}
html[data-theme="dark"] .diag-note { color: hsl(38 92% 70%); }

/* ----------------------------- Preview stage ---------------------------- */
.preview-card { overflow: hidden; }
.preview-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  background: hsl(var(--stage));
  display: grid;
  place-items: center;
  overflow: hidden;
}
.preview-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  background: hsl(var(--stage));
}
.preview-stage.has-stream .preview-video { display: block; }
.preview-stage.is-mirrored .preview-video { transform: scaleX(-1); }

.preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  color: hsl(0 0% 70%);
  padding: 24px;
}
.preview-stage.has-stream .preview-empty { display: none; }
.empty-icon svg { width: 46px; height: 46px; opacity: 0.5; }
.empty-title { font-size: 15px; font-weight: 600; color: hsl(0 0% 88%); }
.empty-sub { font-size: 13px; color: hsl(0 0% 62%); max-width: 280px; }

/* Overlays */
.overlay { position: absolute; display: flex; gap: 8px; pointer-events: none; }
.overlay-top { top: 12px; left: 12px; right: 12px; justify-content: space-between; }
.overlay-bottom { bottom: 12px; right: 12px; pointer-events: auto; }

.res-pill {
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: hsl(0 0% 0% / 0.55);
  color: #fff;
  backdrop-filter: blur(4px);
}
.rec-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: hsl(0 0% 0% / 0.55);
  color: #fff;
  backdrop-filter: blur(4px);
}
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: hsl(0 80% 58%); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.ctl-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  border: none;
  cursor: pointer;
  color: #fff;
  background: hsl(0 0% 0% / 0.45);
  backdrop-filter: blur(4px);
  transition: background-color 0.15s ease;
}
.ctl-btn:hover { background: hsl(0 0% 0% / 0.7); }
.ctl-btn.is-active { background: hsl(var(--accent)); }

/* ----------------------------- Control bar ------------------------------ */
.control-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  flex-wrap: wrap;
}
.control-left { min-width: 0; }
.active-cam-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  max-width: 320px;
}
.control-right { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-block { width: 100%; }
.field-label { font-size: 12px; font-weight: 500; color: hsl(var(--muted-foreground)); }

.select {
  height: 38px;
  padding: 0 30px 0 12px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--input));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 13.5px;
  cursor: pointer;
  appearance: none;
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
}
.select:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 1px; }
.select:disabled { opacity: 0.5; cursor: not-allowed; }

/* attached photo format select + button */
.capture-group { display: flex; align-items: stretch; }
.capture-group .field-label { display: none; }
.select-attached {
  height: 38px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
  padding-right: 28px;
}
.btn-attached {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* ---------------------------- Thumbnail strip --------------------------- */
.thumb-section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-title { font-size: 14px; font-weight: 600; }

.thumb-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.thumb-empty {
  width: 100%;
  padding: 22px;
  text-align: center;
  font-size: 13px;
  color: hsl(var(--muted-foreground));
  border: 1px dashed hsl(var(--border));
  border-radius: var(--radius);
}
.thumb {
  position: relative;
  flex: 0 0 auto;
  width: 168px;
  border-radius: calc(var(--radius) - 1px);
  border: 2px solid hsl(var(--border));
  background: hsl(var(--stage));
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
  text-align: left;
  padding: 0;
}
.thumb:hover { transform: translateY(-1px); }
.thumb.is-active { border-color: hsl(var(--accent)); }
.thumb-media { position: relative; aspect-ratio: 16 / 9; background: hsl(var(--stage)); }
.thumb-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.is-mirrored .thumb-media video { transform: scaleX(-1); }
.thumb-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: hsl(0 0% 55%);
  font-size: 12px;
  text-align: center;
  padding: 8px;
}
.thumb-label {
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 500;
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thumb-live {
  position: absolute;
  top: 7px; left: 7px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: hsl(0 0% 0% / 0.55);
  color: #fff;
}
.thumb-live .dot { background: hsl(var(--accent)); }

/* ----------------------------- Device info ------------------------------ */
.info-grid { margin: 0; display: grid; gap: 2px; }
.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid hsl(var(--border));
}
.info-row:last-child { border-bottom: none; }
.info-row dt { color: hsl(var(--muted-foreground)); font-size: 13px; flex: none; }
.info-row dd {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

/* ------------------------------- Meter ---------------------------------- */
.meter {
  height: 12px;
  border-radius: 999px;
  background: hsl(var(--muted));
  overflow: hidden;
  margin: 6px 0 8px;
}
.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, hsl(var(--accent)), hsl(140 70% 55%));
  transition: width 0.06s linear;
}
.meter-caption { font-size: 12.5px; color: hsl(var(--muted-foreground)); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid hsl(var(--border));
}
.switch-text { font-size: 13px; }
.switch {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: hsl(var(--muted));
  transition: background-color 0.15s ease;
  flex: none;
}
.switch[aria-checked="true"] { background: hsl(var(--accent)); }
.switch-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.switch[aria-checked="true"] .switch-thumb { transform: translateX(18px); }

/* ------------------------------ Captures -------------------------------- */
.captures-empty { font-size: 13px; color: hsl(var(--muted-foreground)); }
.captures-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.capture-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
}
.capture-thumb {
  width: 56px; height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: hsl(var(--stage));
  flex: none;
}
.capture-meta { min-width: 0; flex: 1; }
.capture-name { font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.capture-sub { font-size: 11.5px; color: hsl(var(--muted-foreground)); }
.capture-actions { display: flex; gap: 4px; }
.icon-btn {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 7px;
  border: 1px solid hsl(var(--border));
  background: transparent;
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.icon-btn:hover { background: hsl(var(--muted)); }
.icon-btn.danger:hover { background: hsl(0 72% 51% / 0.12); color: hsl(0 72% 55%); }

/* ------------------------------- Toast ---------------------------------- */
.toast-wrap {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 220px;
  max-width: 360px;
  padding: 11px 14px;
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  color: hsl(var(--foreground));
  box-shadow: 0 8px 24px hsl(var(--shadow-color) / 0.35);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.18s ease;
}
.toast.toast-error { border-color: hsl(0 72% 51% / 0.5); }
.toast.toast-success { border-color: hsl(var(--accent) / 0.5); }
.toast .toast-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.toast-error .toast-dot { background: hsl(0 72% 55%); }
.toast-success .toast-dot { background: hsl(var(--accent)); }
.toast-info .toast-dot { background: hsl(var(--muted-foreground)); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ------------------------- Theme toggle icons --------------------------- */
.icon-sun { display: none; }
.icon-moon { display: block; }
html[data-theme="dark"] .icon-sun { display: block; }
html[data-theme="dark"] .icon-moon { display: none; }

/* ----------------------------- Responsive ------------------------------- */
@media (max-width: 980px) {
  .app-main { grid-template-columns: 1fr; }
  .side-col { order: 2; }
}

@media (max-width: 620px) {
  .app-header { padding: 12px 16px; }
  .brand-text p { display: none; }
  .app-main { padding: 16px; gap: 16px; }
  .control-bar { flex-direction: column; align-items: stretch; }
  .control-right { justify-content: space-between; }
  .btn-label { display: inline; }
  .badge-soft { display: none; }
  .active-cam-name { max-width: none; }
}

@media (max-width: 420px) {
  .field-label { display: none; }
  .control-right { gap: 8px; }
  .control-right .field, .capture-group, #recordBtn { flex: 1; }
  .select, .btn { width: 100%; }
  .capture-group .select-attached { flex: 1; }
}
