:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-hover: #273549;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #2563eb;
  --green: #2e7d32;
  --green-bright: #4ade80;
  --danger: #dc2626;
  --warn: #d97706;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #0b1222;
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.topbar-officer { font-weight: 700; font-size: 0.95rem; }
.topbar-meta { font-size: 0.78rem; color: var(--muted); }
.topbar-actions { display: flex; gap: 6px; align-items: center; }

/* SCREENS & CARDS */
.screen { max-width: 680px; margin: 0 auto; padding: 14px; }
.center-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin: 0 0 4px; font-size: 1.5rem; text-align: center; }
.subtitle { margin: 0 0 14px; color: var(--muted); font-size: 0.9rem; text-align: center; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f172a;
  color: var(--text);
  font-size: 1rem;
}
.pin-input { letter-spacing: 6px; text-align: center; font-size: 1.3rem; }

/* BUTTONS */
button { cursor: pointer; border: none; border-radius: 10px; font-weight: 700; font-size: 0.95rem; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-full { width: 100%; padding: 13px; }
.btn-primary { background: var(--primary); color: #fff; padding: 12px 16px; }
.btn-green { background: var(--green); color: #fff; padding: 12px 16px; }
.btn-secondary { background: #334155; color: #fff; padding: 10px 14px; }
.btn-secondary-sm { background: #334155; color: #fff; padding: 7px 12px; font-size: 0.82rem; }
.btn-danger-sm { background: var(--danger); color: #fff; padding: 7px 11px; font-size: 0.8rem; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 10px; }
.btn-chip { background: #1e293b; color: #cbd5e1; border: 1px solid var(--border); padding: 6px 9px; font-size: 0.74rem; }
.btn-chip.active { background: var(--warn); color: #fff; border-color: var(--warn); }

.error-msg {
  background: rgba(220, 38, 38, 0.18);
  border: 1px solid var(--danger);
  color: #fecaca;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-top: 10px;
}
.hint { font-size: 0.78rem; color: var(--muted); margin: 8px 0 0; }

/* OFFICE NUMBERS GRID */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-header h2 { margin: 0; font-size: 1.15rem; }

.oficios-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 12px;
}
.oficio-block {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 18px 10px;
  text-align: center;
  transition: transform 0.08s ease, border-color 0.15s;
  color: var(--text);
}
.oficio-block:active { transform: scale(0.97); }
.oficio-block:hover { border-color: var(--primary); background: var(--card-hover); }
.oficio-block.locked { opacity: 0.45; border-color: var(--warn); }
.oficio-block.mine { border-color: var(--green-bright); }
.oficio-num { font-size: 1.65rem; font-weight: 800; letter-spacing: 0.5px; }
.oficio-city { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.oficio-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: #334155;
  color: #e2e8f0;
}

/* ACTIVE MEASUREMENT */
.active-banner {
  background: #172554;
  border: 1px solid #1d4ed8;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.active-title { font-size: 1.15rem; font-weight: 800; }
.active-sub { font-size: 0.8rem; color: #bfdbfe; margin-top: 2px; }
.timer-pill {
  background: #0f172a;
  border: 1px solid #3b82f6;
  padding: 8px 12px;
  border-radius: 10px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.15rem;
  font-weight: 800;
}

.checkpoint-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.badge { background: var(--primary); padding: 3px 9px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
.checkpoint-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cp-pill {
  padding: 9px 4px;
  border-radius: 10px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  background: #0f172a;
  border: 1px solid var(--border);
  color: var(--muted);
}
.cp-pill.ready { border-color: #facc15; color: #fef08a; background: rgba(250, 204, 21, 0.14); }
.cp-pill.done { border-color: var(--green-bright); color: #bbf7d0; background: rgba(34, 197, 94, 0.18); }
.prompt-text { margin: 10px 0 0; font-size: 0.86rem; color: #e2e8f0; }

/* CAMERA */
.gps-bar { font-size: 0.8rem; color: #93c5fd; margin-bottom: 8px; font-family: ui-monospace, Consolas, monospace; }
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #020617;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}
#cameraVideo { width: 100%; height: 100%; object-fit: cover; }
.camera-fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  text-align: center; padding: 16px; color: var(--muted); font-size: 0.85rem;
}

.ext-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* MODALS */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(2, 6, 23, 0.82);
  display: flex; align-items: center; justify-content: center;
  padding: 14px;
}
.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  padding: 18px;
  max-height: 92vh;
  overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-header h3 { margin: 0; font-size: 1.15rem; }
.icon-btn { background: transparent; color: var(--muted); font-size: 1.5rem; padding: 0 6px; }

.detail-list { display: flex; flex-direction: column; gap: 10px; }
.detail-item { background: #0f172a; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); }
.detail-label { display: block; font-size: 0.72rem; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.detail-val { font-size: 0.92rem; font-weight: 600; color: var(--text); }

.modal-actions { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; margin-top: 14px; }

/* RESULT VERDICT */
.verdict-banner {
  padding: 14px;
  border-radius: 12px;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 1px;
  margin-bottom: 14px;
}
.verdict-ok { background: rgba(34, 197, 94, 0.2); border: 2px solid var(--green-bright); color: #bbf7d0; }
.verdict-fail { background: rgba(220, 38, 38, 0.22); border: 2px solid #f87171; color: #fecaca; }

.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric-box { background: #0f172a; border: 1px solid var(--border); border-radius: 10px; padding: 10px; text-align: center; }
.metric-box.full-span { grid-column: 1 / -1; }
.metric-label { display: block; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; }
.metric-val { display: block; font-size: 1.1rem; font-weight: 800; margin-top: 4px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.95rem; }
/* 4-ROW TRACKER SERIALS + SIDE MENU */
.tracker-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}
.tracker-row {
  position: relative;
  display: grid;
  grid-template-columns: 32px 1fr 42px;
  gap: 6px;
  align-items: center;
}
.tracker-num {
  height: 42px;
  display: grid;
  place-items: center;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}
.tracker-row-input {
  padding: 10px 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.row-menu-btn {
  height: 42px;
  background: #334155;
  color: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1.25rem;
  line-height: 1;
  display: grid;
  place-items: center;
}
.row-menu-btn:hover { background: var(--primary); border-color: var(--primary); }

.row-side-menu {
  position: absolute;
  right: 0;
  top: 46px;
  z-index: 70;
  min-width: 215px;
  background: #0b1222;
  border: 1px solid var(--primary);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.row-side-menu.open-up {
  top: auto;
  bottom: 46px;
}
.row-side-menu button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 600;
}
.row-side-menu button:hover { background: #1e293b; }
.row-side-menu button.menu-clear { color: #fca5a5; }