:root {
  --app-version: "6.0.0";
  --bg: #08101f;
  --panel: #101a2e;
  --panel2: #0c1526;
  --text: #f6f8ff;
  --muted: #aebbd5;
  --line: rgba(255,255,255,.12);
  --yellow: #ffcb05;
  --blue: #2a75bb;
  --red: #ff6b6b;
  --green: #68e6a2;
  --orange: #ffb86b;
  --radius: 22px;
  --shadow: 0 22px 60px rgba(0,0,0,.32);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  background:
    radial-gradient(circle at 0 0, rgba(42,117,187,.45), transparent 32rem),
    radial-gradient(circle at 100% 0, rgba(255,203,5,.20), transparent 28rem),
    linear-gradient(180deg, #08101f, #050915 70%);
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 14px;
  padding: .9rem 1rem;
  background: rgba(255,255,255,.09);
  color: var(--text);
  font-weight: 850;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, opacity .15s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: rgba(255,255,255,.15);
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(135deg, var(--yellow), #ffe890);
  color: #172033;
}

button.danger {
  background: rgba(255,107,107,.17);
  color: #ffd2d2;
}

.hero {
  max-width: 1220px;
  margin: 0 auto;
  padding: 2rem 1rem 1rem;
}

.eyebrow {
  margin: 0 0 .5rem;
  color: var(--yellow);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: .76rem;
  font-weight: 950;
}

h1 {
  margin: 0 0 .8rem;
  font-size: clamp(2.2rem, 7vw, 5rem);
  line-height: .94;
}

h2 {
  margin: 0 0 .25rem;
  font-size: 1.12rem;
}

p {
  margin-top: 0;
}

.sub {
  max-width: 840px;
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 0;
}

.shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr);
  gap: 1rem;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.035));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 1rem;
  overflow: hidden;
}

.db-panel,
.test-panel,
.history-panel,
.help-panel {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head p {
  margin: .15rem 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: .94rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: .45rem .7rem;
  font-size: .78rem;
  font-weight: 950;
}

.badge.muted {
  color: var(--muted);
  background: rgba(255,255,255,.055);
}

.badge.good {
  color: #07160d;
  background: var(--green);
  border-color: transparent;
}

.badge.warn {
  color: #251702;
  background: var(--orange);
  border-color: transparent;
}

.badge.bad {
  color: #280506;
  background: var(--red);
  border-color: transparent;
}

.db-status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
}

.stat {
  background: rgba(0,0,0,.22);
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: .9rem;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.stat strong {
  display: block;
  font-size: 1.35rem;
  margin-top: .25rem;
}

.actions {
  display: flex;
  gap: .65rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.note {
  margin: 1rem 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.camera-box {
  position: relative;
  width: 100%;
  min-height: 420px;
  height: min(72vh, 760px);
  background: #02060f;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* The yellow guide is now an actual card-ratio crop box.
   JS maps this visible box back to the camera pixels before OCR. */
.overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 86%;
  width: auto;
  aspect-ratio: 63 / 88;
  max-width: 84%;
  transform: translate(-50%, -50%);
  border: 3px dashed rgba(255,203,5,.92);
  border-radius: 18px;
  pointer-events: none;
  box-shadow:
    0 0 0 999px rgba(0,0,0,.16),
    inset 0 0 0 1px rgba(0,0,0,.25);
}

.corner {
  position: absolute;
  width: 34px;
  height: 34px;
  border-color: var(--yellow);
  border-style: solid;
}

.tl { top: -3px; left: -3px; border-width: 4px 0 0 4px; border-radius: 16px 0 0 0; }
.tr { top: -3px; right: -3px; border-width: 4px 4px 0 0; border-radius: 0 16px 0 0; }
.bl { bottom: -3px; left: -3px; border-width: 0 0 4px 4px; border-radius: 0 0 0 16px; }
.br { bottom: -3px; right: -3px; border-width: 0 4px 4px 0; border-radius: 0 0 16px 0; }

.overlay-text {
  position: absolute;
  left: 50%;
  bottom: .75rem;
  transform: translateX(-50%);
  background: rgba(8,16,31,.88);
  color: var(--yellow);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .48rem .75rem;
  font-size: .82rem;
  font-weight: 950;
  max-width: calc(100% - 1rem);
  text-align: center;
  white-space: nowrap;
}

.drop {
  display: grid;
  gap: .25rem;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px dashed rgba(255,255,255,.24);
  background: rgba(255,255,255,.045);
  border-radius: 16px;
  color: var(--muted);
  cursor: pointer;
}

.drop strong {
  color: var(--text);
}

.drop input {
  margin-top: .5rem;
  max-width: 100%;
}

.progress {
  margin-top: 1rem;
}

.progress-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 900;
  margin-bottom: .45rem;
}

.track {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255,255,255,.10);
}

.track > div {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--yellow));
  transition: width .2s ease;
}

.preview {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
}

.preview.empty {
  min-height: 290px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 1rem;
  border-style: dashed;
}

.preview canvas,
.preview img {
  display: block;
  width: 100%;
  height: auto;
}

#reviewForm {
  margin-top: 1rem;
}

.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
}

label {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 850;
}

input, select {
  width: 100%;
  margin-top: .34rem;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.26);
  color: var(--text);
  padding: .8rem .85rem;
  border-radius: 13px;
  outline: 0;
}

input:focus, select:focus {
  border-color: rgba(255,203,5,.75);
  box-shadow: 0 0 0 4px rgba(255,203,5,.10);
}

.audit {
  margin-top: 1rem;
  color: var(--muted);
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow: auto;
  background: rgba(0,0,0,.30);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .9rem;
  color: #dce6ff;
}

.candidates {
  display: grid;
  gap: .7rem;
  margin-top: 1rem;
}

.candidate {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: .8rem;
  align-items: center;
  padding: .7rem;
  border-radius: 16px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
}

.candidate img {
  width: 58px;
  height: 81px;
  object-fit: cover;
  border-radius: 8px;
  background: rgba(0,0,0,.25);
}

.candidate strong {
  display: block;
}

.candidate span {
  display: block;
  color: var(--muted);
  font-size: .84rem;
  margin-top: .15rem;
}

.candidate small {
  display: block;
  color: var(--yellow);
  margin-top: .22rem;
  font-weight: 900;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 1rem;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 760px;
}

th, td {
  padding: .85rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .78rem;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.help-panel ul {
  color: var(--muted);
  line-height: 1.65;
  margin-bottom: 0;
}

code {
  color: var(--yellow);
  background: rgba(255,203,5,.08);
  padding: .1rem .25rem;
  border-radius: 6px;
}

.hidden {
  display: none !important;
}

@media (max-width: 880px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .db-status-grid,
  .fields {
    grid-template-columns: 1fr;
  }

  .panel-head {
    flex-direction: column;
  }

  .candidate {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .candidate button {
    grid-column: 1 / -1;
  }
}


@media (max-width: 520px) {
  .camera-box {
    min-height: 470px;
    height: 64vh;
  }

  .overlay {
    height: 82%;
    max-width: 78%;
  }

  .actions button {
    flex: 1 1 145px;
  }
}


.test-summary {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
}

.test-summary .metric {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0,0,0,.22);
  padding: .9rem;
}

.test-summary .metric span {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 900;
}

.test-summary .metric strong {
  display: block;
  margin-top: .25rem;
  font-size: 1.35rem;
}

.pass { color: var(--green); font-weight: 950; }
.fail { color: var(--red); font-weight: 950; }
.warn-text { color: var(--orange); font-weight: 950; }

@media (max-width: 720px) {
  .test-summary { grid-template-columns: 1fr 1fr; }
}
