:root {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1b2740;
  --border: #26334f;
  --text: #e8edf7;
  --text-dim: #9aa7c2;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
  --ok: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

header.topbar h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
}

header.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
}

main {
  flex: 1;
  padding: 16px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

.screen { display: none; }
.screen.active { display: block; }

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

label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  margin-top: 14px;
}
label:first-child { margin-top: 0; }

input[type="text"], input[type="password"], input[type="tel"] {
  width: 100%;
  padding: 14px;
  font-size: 17px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); }

.input-with-btn {
  display: flex;
  gap: 8px;
}
.input-with-btn input { flex: 1; }

button {
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  padding: 14px 18px;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #05202e;
  width: 100%;
}
.btn-primary:active { background: var(--accent-dark); }
.btn-primary:disabled { opacity: .5; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  width: 100%;
}

.btn-icon {
  background: var(--surface-2);
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 14px;
}

.btn-danger { background: var(--error); color: #2b0b0b; width: 100%; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.helper { font-size: 13px; color: var(--text-dim); margin-top: 8px; }

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 14px;
  line-height: 1.4;
}
.alert-error { background: rgba(248,113,113,.12); color: var(--error); border: 1px solid rgba(248,113,113,.3); }
.alert-warn { background: rgba(251,191,36,.12); color: var(--warn); border: 1px solid rgba(251,191,36,.3); }
.alert-ok { background: rgba(52,211,153,.12); color: var(--ok); border: 1px solid rgba(52,211,153,.3); }

.info-list { display: flex; flex-direction: column; gap: 10px; }
.info-item { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; border-bottom: 1px dashed var(--border); padding-bottom: 8px; }
.info-item span:first-child { color: var(--text-dim); }
.info-item span:last-child { font-weight: 600; text-align: right; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-ok { background: var(--ok); }
.status-error { background: var(--error); }
.status-warn { background: var(--warn); }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.status-ok { background: rgba(52,211,153,.15); color: var(--ok); border-color: rgba(52,211,153,.3); }
.badge.status-warn { background: rgba(251,191,36,.15); color: var(--warn); border-color: rgba(251,191,36,.3); }
.badge.status-error { background: rgba(248,113,113,.15); color: var(--error); border-color: rgba(248,113,113,.3); }

.orden-card { cursor: pointer; }
.orden-card:active { background: var(--surface-2); }

/* ------------------------------------------------------------ CHECKLIST */
.checklist-progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.checklist-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .2s ease;
}
.checklist-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 6px;
}
.checklist-tile { cursor: pointer; text-align: center; }
.checklist-thumb {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.checklist-tile.done .checklist-thumb { border: 1px solid var(--ok); }
.checklist-thumb img { width: 100%; height: 100%; object-fit: cover; }
.checklist-plus { font-size: 22px; color: var(--text-dim); }
.checklist-retry { font-size: 11px; color: var(--error); line-height: 1.3; }
.checklist-label { font-size: 11px; color: var(--text-dim); margin-top: 5px; line-height: 1.25; }
.spinner-mini {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* ------------------------------------------------------------- ADMIN UI */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.tabs button {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 10px 14px;
  white-space: nowrap;
}
.tabs button.active { color: var(--accent); border-color: var(--accent); }

select, textarea {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--border); }
table.data-table th { color: var(--text-dim); font-weight: 600; font-size: 12px; }
.table-wrap { overflow-x: auto; }

.evidence-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}
.evidence-thumb-grid figure { margin: 0; text-align: center; }
.evidence-thumb-grid img {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2);
}
.evidence-thumb-grid figcaption { font-size: 10px; color: var(--text-dim); margin-top: 3px; }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.center { text-align: center; }

.history-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-top { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; }
.history-meta { font-size: 12px; color: var(--text-dim); margin-top: 3px; }

nav.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  bottom: 0;
}
nav.tabbar button {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  border-radius: 0;
  padding: 12px 8px;
  font-size: 12px;
}
nav.tabbar button.active { color: var(--accent); }

#scanner-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  flex-direction: column;
}
#scanner-modal.active { display: flex; }
#scanner-modal #qr-reader { flex: 1; }
#scanner-modal .scanner-footer { padding: 14px; background: var(--bg); }

.hidden { display: none !important; }
