:root {
  color-scheme: dark;
  --bg-dark: #0B0F19;
  --card-bg: rgba(17, 24, 39, 0.86);
  --card-inner: rgba(30, 41, 59, 0.62);
  --card-border: rgba(255, 255, 255, 0.09);
  --gold: #F59E0B;
  --gold-glow: rgba(245, 158, 11, 0.35);
  --emerald: #10B981;
  --emerald-dark: #059669;
  --emerald-glow: rgba(16, 185, 129, 0.32);
  --red: #EF4444;
  --blue: #3B82F6;
  --text-main: #F3F4F6;
  --text-muted: #9CA3AF;
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-stack);
  -webkit-font-smoothing: antialiased;
}

/* Marca de agua sutil Glifo OLLIN */
body::before {
  content: "";
  position: fixed;
  top: 50%;
  left: 50%;
  width: 420px;
  height: 420px;
  transform: translate(-50%, -50%);
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="none" stroke="%23F59E0B" stroke-width="1.6"><circle cx="50" cy="50" r="46" stroke-opacity="0.3"/><path d="M50 15 C35 35, 65 65, 50 85 C65 65, 35 35, 50 15 Z" stroke-opacity="0.4"/><path d="M15 50 C35 35, 65 65, 85 50 C65 35, 35 65, 15 50 Z" stroke-opacity="0.4"/><circle cx="50" cy="50" r="11" stroke-opacity="0.5"/><circle cx="50" cy="50" r="3.5" fill="%2310B981" fill-opacity="0.6"/></svg>');
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0.04;
  pointer-events: none;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 14px 36px;
}

/* Header Glassmorphism estilo Ollinqui */
header.app-header {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 18px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  margin-bottom: 12px;
}

.brand-section { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  box-shadow: 0 0 14px var(--gold-glow);
  background: #0B0F19;
  object-fit: cover;
  flex-shrink: 0;
}

h1 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: #FFFFFF;
}

header strong {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--emerald);
  letter-spacing: 0.04em;
}

.pill-env {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.14);
  color: var(--gold);
  border: 1px solid rgba(245, 158, 11, 0.35);
  white-space: nowrap;
}

.pill-env.prod {
  background: rgba(16, 185, 129, 0.16);
  color: var(--emerald);
  border-color: rgba(16, 185, 129, 0.42);
}

/* Paneles Glass */
#login, .glass-panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 18px;
  padding: 20px 18px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}

#login { margin-top: 18px; }
#login h2 { margin: 0 0 4px; font-size: 1.15rem; font-weight: 700; color: #FFFFFF; }
.login-sub { margin: 0 0 16px; font-size: 0.84rem; color: var(--text-muted); }

h2 { font-size: 0.95rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 18px 0 8px; }

/* Mensajes y alertas */
#message {
  white-space: pre-wrap;
  font-size: 0.84rem;
  font-weight: 500;
  color: #D1FAE5;
  background: rgba(16, 185, 129, 0.10);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0 0 12px;
}
#message:empty { display: none; }

/* Estado compacto del operador */
.status-bar {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.status-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
#identity { margin: 0; font-size: 0.82rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
#network, #queue-count {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-main);
}

/* Inputs */
label { display: block; margin: 10px 0; font-size: 0.84rem; font-weight: 600; color: var(--text-muted); }
input:not([type=checkbox]), select, textarea {
  width: 100%;
  min-height: 46px;
  font: inherit;
  font-size: 0.95rem;
  padding: 10px 12px;
  margin-top: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.85);
  color: #FFFFFF;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:not([type=checkbox]):focus, select:focus, textarea:focus {
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}
input[type=checkbox] { width: 22px; height: 22px; vertical-align: middle; accent-color: var(--emerald); cursor: pointer; }

.controls-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

/* Botones estilo Ollinqui Minimalista */
button {
  min-height: 46px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(16, 185, 129, 0.4);
  background: linear-gradient(135deg, var(--emerald), var(--emerald-dark));
  color: #FFFFFF;
  cursor: pointer;
  transition: transform .1s, opacity .15s, box-shadow .15s;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.22);
}
button:active:not(:disabled) { transform: scale(0.98); }
button.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: none;
}
button.btn-gold {
  background: linear-gradient(135deg, #F59E0B, #D97706);
  border-color: rgba(245, 158, 11, 0.5);
  color: #111827;
  box-shadow: 0 4px 14px var(--gold-glow);
}
button.btn-danger-ghost {
  background: rgba(239, 68, 68, 0.10);
  color: #FCA5A5;
  border: 1px solid rgba(239, 68, 68, 0.28);
  box-shadow: none;
}
button:disabled {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

nav { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
nav button { margin: 0; padding: 10px 12px; font-size: 0.84rem; }

#batch, #login-form button { width: 100%; margin-top: 8px; }
#update { width: 100%; margin-bottom: 12px; }

/* Tarjetas de Guías minimalistas */
article {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--emerald);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 14px;
  margin: 10px 0;
  border-radius: 16px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
}
article.card-closed { border-left-color: #64748B; opacity: 0.82; }
article label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 0.96rem;
  font-weight: 800;
  color: #FFFFFF;
}
article p { margin: 4px 0; font-size: 0.86rem; color: var(--text-muted); line-height: 1.35; }
article p.dest-name { font-size: 0.94rem; font-weight: 700; color: var(--text-main); }
article p.pid-line { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.74rem; color: #64748B; }
article button { width: 100%; margin-top: 8px; }

.badge-multi {
  display: inline-block;
  background: rgba(245, 158, 11, 0.18);
  color: var(--gold);
  border: 1px solid rgba(245, 158, 11, 0.45);
  font-size: 0.70rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: auto;
}

.links { display: flex; gap: 8px; margin: 10px 0 4px; }
.links a {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  min-height: 42px;
  padding: 6px 8px;
}

/* Modales Glass Oscuro */
dialog {
  max-width: 460px;
  width: calc(100% - 20px);
  max-height: 92dvh;
  background: #111827;
  color: var(--text-main);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 20px;
  overflow-y: auto;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75);
}
dialog::backdrop { background: rgba(5, 8, 15, 0.82); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 8px; color: #FFFFFF; text-transform: none; letter-spacing: 0; font-size: 1.1rem; }

.voice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
.voice-row button { margin: 0; font-size: 0.82rem; padding: 10px 8px; }
#audio-status { font-size: 0.78rem; color: var(--gold); margin: 4px 0 10px; }

#close-error {
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #FECACA;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 600;
  margin: 10px 0;
}
#close-error.info {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(59, 130, 246, 0.45);
  color: #BFDBFE;
}

.dialog-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.dialog-actions button { width: 100%; margin: 0; }
.sup-panel { margin-top: 16px; }
.sup-block { border-top: 1px solid var(--card-border); padding-top: 12px; margin-top: 12px; }
.sup-block h3 { margin: 0 0 8px; font-size: 0.92rem; color: #FFFFFF; }
.sup-block button { width: 100%; margin: 4px 0; }
.radar-chip { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 0.74rem; font-weight: 700; margin-right: 6px; background: rgba(255, 255, 255, 0.07); }
.radar-warn { border-left-color: var(--red); }

/* Canvas de firma táctil */
.sig-box { margin: 12px 0; }
.sig-label { display: block; font-size: 0.84rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
#signature-canvas {
  width: 100%;
  height: 140px;
  background: #FFFFFF;
  border: 1.5px dashed var(--gold);
  border-radius: 12px;
  touch-action: none;
  display: block;
}
.sig-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.sig-actions button { min-height: 38px; padding: 6px 12px; font-size: 0.8rem; }
.sig-status { font-size: 0.78rem; color: var(--text-muted); }

video, img, audio { max-width: 100%; border-radius: 10px; margin-top: 8px; }
[hidden] { display: none !important; }

/* Animación orbital Pulso León (estilo Ollin / Tlapoualli) */
.len-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 11, 20, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 20px;
}
.len-loader-card {
  background: rgba(17, 24, 39, 0.95);
  color: #FFFFFF;
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: 22px;
  padding: 26px 28px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.65), 0 0 32px rgba(16, 185, 129, 0.14);
}
.len-orb { position: relative; width: 72px; height: 72px; margin: 0 auto 16px; }
.len-ring { position: absolute; inset: 0; border-radius: 50%; border: 3px solid transparent; }
.len-ring-outer {
  border-top-color: var(--emerald);
  border-right-color: rgba(16, 185, 129, 0.35);
  box-shadow: 0 0 14px var(--emerald-glow);
  animation: len-spin 1.15s linear infinite;
}
.len-ring-inner {
  inset: 10px;
  border-bottom-color: var(--gold);
  border-left-color: rgba(245, 158, 11, 0.35);
  animation: len-spin-rev 1.6s linear infinite;
}
.len-core {
  position: absolute;
  inset: 25px;
  border-radius: 50%;
  background: radial-gradient(circle, #F59E0B 0%, #10B981 80%);
  box-shadow: 0 0 16px var(--gold-glow);
  animation: len-pulse 1.4s ease-in-out infinite;
}
.len-loader-title { margin: 0 0 6px; font-weight: 800; font-size: 1rem; color: #FFFFFF; }
.len-loader-sub { margin: 0; font-size: 0.82rem; color: var(--text-muted); }

@keyframes len-spin { to { transform: rotate(360deg); } }
@keyframes len-spin-rev { to { transform: rotate(-360deg); } }
@keyframes len-pulse { 0%, 100% { transform: scale(0.82); opacity: 0.75; } 50% { transform: scale(1.12); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .len-ring-outer, .len-ring-inner, .len-core { animation: none; }
}
