:root {
  --bg: #0b0f14;
  --panel: #131a23;
  --line: #223041;
  --text: #e6edf5;
  --muted: #8b9bb0;
  --accent: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 32px 20px 64px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.wrap { max-width: 900px; margin: 0 auto; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -0.2px; }
h2 { font-size: 15px; margin: 0 0 12px; color: var(--muted); font-weight: 600;
     text-transform: uppercase; letter-spacing: 0.08em; }

.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .grid { grid-template-columns: 1fr; } }

/* camera */
.stage {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
}
.stage video, .stage canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%; object-fit: cover; display: block;
}
/* Horizontal flip for the preview. Kept in sync by bindFlipToggle() in camera.js. */
.stage video.mirrored, .stage canvas.mirrored { transform: scaleX(-1); }

/* Element rules above set display:block, which would beat the browser's own
   [hidden] rule -- so hiding the video while showing the still had no effect
   and both frames were laid out side by side. */
[hidden] { display: none !important; }
.stage .placeholder { color: var(--muted); font-family: var(--mono); font-size: 13px; padding: 20px; text-align: center; }

.guide {
  position: absolute; inset: 0; pointer-events: none;
  display: grid; place-items: center;
}
.guide::after {
  content: ""; width: 46%; aspect-ratio: 3 / 4;
  border: 1px dashed rgba(255,255,255,0.28); border-radius: 50%;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
/* A steady, well-framed face is in the oval and auto-capture is counting down. */
.guide.ready::after {
  border-style: solid;
  border-color: rgba(74, 222, 128, 0.9);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.14);
}

/* On-screen alignment guidance, drawn over the video. */
.stage-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  max-width: 92%;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(11, 15, 20, 0.82);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  backdrop-filter: blur(4px);
  pointer-events: none;
  transition: border-color 120ms ease, color 120ms ease;
}
.stage-hint.warn { border-color: rgba(251, 191, 36, 0.55); color: var(--warn); }
.stage-hint.ok { border-color: rgba(74, 222, 128, 0.55); color: var(--accent); }
.stage-hint.bad { border-color: rgba(248, 113, 113, 0.55); color: var(--bad); }

/* forms */
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px;
        text-transform: uppercase; letter-spacing: 0.07em; }
input[type="text"] {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: #0e141b; color: var(--text);
  font-size: 15px; font-family: inherit;
}
input[type="text"]:focus { outline: 2px solid rgba(74,222,128,0.35); border-color: var(--accent); }

button {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: #1b2634; color: var(--text);
}
button:hover:not(:disabled) { border-color: #38506b; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06210f; }
button.primary:hover:not(:disabled) { filter: brightness(1.06); }
button.link { background: none; border: none; color: var(--muted); padding: 4px 8px; font-weight: 400; }
button.link:hover { color: var(--bad); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* status + results */
.status {
  font-family: var(--mono); font-size: 13px; margin-top: 14px;
  padding: 10px 12px; border-radius: 8px;
  background: #0e141b; border: 1px solid var(--line); color: var(--muted);
  min-height: 40px; white-space: pre-wrap;
}
.status.ok { color: var(--accent); border-color: rgba(74,222,128,0.35); }
.status.warn { color: var(--warn); border-color: rgba(251,191,36,0.35); }
.status.bad { color: var(--bad); border-color: rgba(248,113,113,0.35); }

.kv { font-family: var(--mono); font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.kv span:last-child { color: var(--text); }

/* match list */
.results { display: grid; gap: 8px; margin-top: 4px; }
.result {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 8px; background: #0e141b; border: 1px solid var(--line);
}
.result.match { border-color: rgba(74,222,128,0.5); background: rgba(74,222,128,0.06); }
.result .who { font-weight: 600; }
.result .code { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.result .score { font-family: var(--mono); font-size: 15px; }
.bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: #1b2634; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* map */
.map {
  height: 260px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0e141b;
  overflow: hidden;
}
.map.tall { height: 360px; }
.leaflet-container {
  background: #0e141b;
  font-family: inherit;
  font-size: 13px;
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: #131a23; color: var(--text);
  border: 1px solid var(--line);
}
.leaflet-control-attribution {
  background: rgba(11,15,20,0.75) !important; color: var(--muted);
}
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-bar a { background: #131a23; color: var(--text); border-bottom-color: var(--line); }
.leaflet-bar a:hover { background: #1b2634; }

/* employee table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }
td.code { font-family: var(--mono); color: var(--muted); }
td:last-child, th:last-child { text-align: right; }

.links { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
@media (max-width: 720px) { .links { grid-template-columns: 1fr; } }
.card-link {
  display: block; padding: 20px; border-radius: 12px; background: var(--panel);
  border: 1px solid var(--line); color: var(--text);
}
.card-link:hover { border-color: var(--accent); text-decoration: none; }
.card-link strong { display: block; font-size: 16px; margin-bottom: 4px; }
.card-link p { margin: 0; color: var(--muted); font-size: 13px; }
.tag { font-family: var(--mono); font-size: 11px; color: var(--warn); }
.muted { color: var(--muted); }

/* Blocking popup for refusals (out of range, no location) */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  background: rgba(4, 7, 10, 0.72);
  backdrop-filter: blur(2px);
  padding: 20px;
}
.modal-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}
.modal-card h3 { margin: 0 0 10px; font-size: 17px; }
.modal-card p {
  margin: 0 0 20px; color: var(--muted);
  line-height: 1.55; font-size: 14.5px;
}

/* Face-ID style capture ring */
.ring {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
  overflow: visible;
}
.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.22);
  stroke-width: 2.2;
  stroke-dasharray: 3 5;
  stroke-linecap: round;
}
.ring-bar {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-dasharray: 270.18;
  stroke-dashoffset: 270.18;
  transition: stroke-dashoffset 160ms linear, stroke-width 140ms ease, filter 140ms ease;
}
.ring-bar.ready {
  stroke-width: 4.6;
  filter: drop-shadow(0 0 7px rgba(74, 222, 128, 0.85));
}

/* Policy notice shown above the capture area */
.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  margin: 0 0 18px;
  border-radius: 10px;
  background: rgba(251, 191, 36, 0.07);
  border: 1px solid rgba(251, 191, 36, 0.42);
  color: #f3dfae;
  font-size: 14px;
  line-height: 1.5;
}
.notice strong { color: var(--warn); }
.notice-icon {
  flex: 0 0 auto;
  width: 18px; height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  border: 1.5px solid var(--warn);
  color: var(--warn);
  font-size: 12px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
}
