*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #06170D;
  --bg2:       #0E2E1B;
  --card:      #123725;
  --border:    rgba(47,168,79,.35);
  --green:     #2E8B57;
  --green-lt:  #8EE6A8;
  --cream:     #F6F3EA;
  --muted:     rgba(246,243,234,.65);

  --ok:        #22c55e;
  --warn:      #f97316;
  --err:       #ef4444;
  --ok-bg:     rgba(34,197,94,.12);
  --warn-bg:   rgba(249,115,22,.12);
  --err-bg:    rgba(239,68,68,.12);
}

html, body {
  height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
}

/* ── Login ─────────────────────────────────────────────────────────────── */

.login-wrap {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  background: linear-gradient(180deg, #06170D 0%, #0E2E1B 60%, #06170D 100%);
}

.login-logo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(145deg, #F6F3EA, #fff);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}
.login-logo img { width: 52px; height: auto; display: block; }

.login-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 24px;
  color: var(--green-lt);
  margin-bottom: 6px;
  text-align: center;
}
.login-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 32px;
  text-align: center;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
}

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--green-lt);
  margin-bottom: 8px;
}
.field input {
  width: 100%;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--cream);
  outline: none;
  -webkit-appearance: none;
}
.field input:focus { border-color: var(--green); }
.field input::placeholder { color: rgba(246,243,234,.3); }

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: .02em;
  transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn:disabled { opacity: .5; cursor: default; }

.login-error {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--err-bg);
  border: 1px solid var(--err);
  border-radius: 8px;
  font-size: 13px;
  color: #fca5a5;
  display: none;
}
.login-error.show { display: block; }

/* ── Layout con header ─────────────────────────────────────────────────── */

.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  height: 56px;
  background: rgba(6,23,13,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.app-header .h-logo img { width: 32px; height: 32px; border-radius: 50%; background: var(--cream); }
.app-header .h-title { font-family: Georgia, serif; font-size: 15px; color: var(--green-lt); }
.app-header .h-right { display: flex; gap: 8px; align-items: center; }

.btn-sm {
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.btn-sm:active { background: rgba(255,255,255,.05); }
.btn-sm.active { border-color: var(--green); color: var(--green-lt); }

.main-content {
  padding-top: 56px;
  min-height: 100svh;
}

/* ── Scanner ────────────────────────────────────────────────────────────── */

.scanner-wrap {
  position: relative;
  width: 100%;
  height: calc(100svh - 56px);
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#scanner-canvas { display: none; }

.scan-frame {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -55%);
  width: min(70vw, 260px);
  height: min(70vw, 260px);
  border: 2px solid rgba(255,255,255,.5);
  border-radius: 16px;
  pointer-events: none;
}
.scan-frame::before,
.scan-frame::after,
.scan-frame .c3,
.scan-frame .c4 {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--green-lt);
  border-style: solid;
}
.scan-frame::before  { top: -2px; left: -2px;  border-width: 3px 0 0 3px; border-radius: 14px 0 0 0; }
.scan-frame::after   { top: -2px; right: -2px; border-width: 3px 3px 0 0; border-radius: 0 14px 0 0; }
.scan-frame .c3      { bottom: -2px; left: -2px;  border-width: 0 0 3px 3px; border-radius: 0 0 0 14px; }
.scan-frame .c4      { bottom: -2px; right: -2px; border-width: 0 3px 3px 0; border-radius: 0 0 14px 0; }

.scan-hint {
  position: absolute;
  bottom: 32px;
  left: 0; right: 0;
  text-align: center;
  font-size: 13px;
  color: rgba(255,255,255,.6);
  pointer-events: none;
}

/* ── Resultado overlay ─────────────────────────────────────────────────── */

.result-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.result-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.result-overlay.ok    { background: rgba(0,0,0,.82); }
.result-overlay.warn  { background: rgba(0,0,0,.82); }
.result-overlay.error { background: rgba(0,0,0,.82); }

.result-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin-bottom: 20px;
}
.ok    .result-icon { background: var(--ok-bg);   border: 2px solid var(--ok);   color: var(--ok);   }
.warn  .result-icon { background: var(--warn-bg);  border: 2px solid var(--warn);  color: var(--warn);  }
.error .result-icon { background: var(--err-bg);   border: 2px solid var(--err);   color: var(--err);   }

.result-label {
  font-family: Georgia, serif;
  font-size: 26px;
  font-weight: bold;
  margin-bottom: 8px;
  text-align: center;
}
.ok    .result-label { color: var(--ok);   }
.warn  .result-label { color: var(--warn);  }
.error .result-label { color: var(--err);   }

.result-name {
  font-size: 18px;
  color: var(--cream);
  margin-bottom: 16px;
  text-align: center;
  font-weight: bold;
}

.result-detail {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
  max-width: 300px;
}
.result-detail strong { color: var(--cream); }

.result-times {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
}

.result-dismiss {
  margin-top: 28px;
  padding: 12px 36px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 10px;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

/* ── Historial ─────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky;
  top: 56px;
  z-index: 90;
}
.tab-btn {
  flex: 1;
  padding: 14px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--green-lt); border-bottom-color: var(--green); }

.tab-panel { display: none; padding: 16px; }
.tab-panel.active { display: block; }

/* Tabla historial */
.scan-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.scan-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--green-lt);
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.scan-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,.05);
  color: var(--cream);
  vertical-align: middle;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: .02em;
  white-space: nowrap;
}
.badge-ok_primero  { background: var(--ok-bg);   color: var(--ok);   border: 1px solid var(--ok);   }
.badge-ok_reingreso { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.badge-invalido    { background: var(--err-bg);  color: var(--err);  border: 1px solid var(--err);  }
.badge-bloqueado   { background: var(--err-bg);  color: var(--err);  border: 1px solid var(--err);  }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 0 8px;
}
.pagination button {
  padding: 8px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--cream);
  font-size: 14px;
  cursor: pointer;
}
.pagination button:disabled { opacity: .35; cursor: default; }
.pagination span { font-size: 13px; color: var(--muted); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; border: 1px solid var(--border); }

/* Operadores */
.op-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.op-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.op-info .op-name { font-size: 15px; font-weight: bold; }
.op-info .op-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.toggle-btn {
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  background: transparent;
}
.toggle-btn.active   { border-color: var(--err);   color: var(--err);   }
.toggle-btn.inactive { border-color: var(--green);  color: var(--green-lt); }

.section-title {
  font-family: Georgia, serif;
  font-size: 17px;
  color: var(--green-lt);
  margin-bottom: 14px;
}

.create-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
.create-form .field { margin-bottom: 14px; }

.form-row { display: flex; gap: 10px; }
.form-row .field { flex: 1; }

select {
  width: 100%;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--cream);
  outline: none;
  -webkit-appearance: none;
}
select:focus { border-color: var(--green); }

.form-msg {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
}
.form-msg.ok    { background: var(--ok-bg);  border: 1px solid var(--ok);  color: #86efac; display: block; }
.form-msg.error { background: var(--err-bg); border: 1px solid var(--err); color: #fca5a5; display: block; }

/* ── Misc ─────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; }

.nombre-operador {
  font-size: 13px;
  color: var(--muted);
  margin-left: 8px;
}

@media (max-width: 400px) {
  .scan-table th:nth-child(3),
  .scan-table td:nth-child(3) { display: none; }
}
