/* ═══════════════════════════════════════════
   LOGIN SCREEN (full-page overlay)
═══════════════════════════════════════════ */
#login-screen {
  position: fixed; inset: 0; z-index: 100;
  background:
    radial-gradient(900px 600px at 15% 20%, rgba(56,189,248,.12), transparent 60%),
    radial-gradient(700px 500px at 85% 80%, rgba(99,102,241,.12), transparent 55%),
    var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
#login-screen.hidden { display: none; }
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 20px;
  box-shadow: var(--shadow), 0 0 80px rgba(56,189,248,.06);
  padding: 36px 32px 32px;
  animation: fadeIn .35s ease;
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-logo-icon {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--sky), #6366f1);
  display: flex; align-items: center; justify-content: center;
}
.login-logo-icon svg { width: 22px; height: 22px; fill: white; }
.login-logo-text strong { display: block; font-size: 17px; font-weight: 700; }
.login-logo-text span { font-size: 12px; color: var(--text2); }
.login-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.login-card p  { font-size: 13px; color: var(--text2); margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }
.form-input {
  width: 100%; background: rgba(0,0,0,.25); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text); padding: 10px 12px;
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus { border-color: rgba(56,189,248,.4); box-shadow: 0 0 0 3px rgba(56,189,248,.08); }
.login-error {
  font-size: 12px; color: var(--red); background: var(--red-dim);
  border: 1px solid rgba(248,113,113,.25); border-radius: var(--radius-sm);
  padding: 9px 12px; margin-bottom: 16px; display: none;
}
.login-error.show { display: block; }
.btn-login {
  width: 100%; padding: 11px; border: none; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--sky), #6366f1);
  color: white; font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: opacity var(--transition), transform var(--transition);
}
.btn-login:hover { opacity: .9; transform: translateY(-1px); }
.btn-login:active { transform: none; }
.login-hint { text-align: center; font-size: 12px; color: var(--text3); margin-top: 16px; }

/* ═══════════════════════════════════════════
   SHARED COMPONENTS
═══════════════════════════════════════════ */

/* Page header */
.page-header {
  margin-bottom: 24px; display: flex; align-items: flex-start;
  justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -.2px; }
.page-header p  { font-size: 13px; color: var(--text2); margin-top: 4px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Stat cards */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--border2); }
.stat-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.stat-icon.sky   { background: var(--sky-dim);   color: var(--sky);   }
.stat-icon.green { background: var(--green-dim); color: var(--green); }
.stat-icon.red   { background: var(--red-dim);   color: var(--red);   }
.stat-icon.amber { background: var(--amber-dim); color: var(--amber); }
.stat-icon svg { width: 18px; height: 18px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text2); }
.stat-delta { font-size: 11px; color: var(--text3); }

/* Card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-header h3 { font-size: 13px; font-weight: 600; }
.card-header .sub { font-size: 12px; color: var(--text2); }
.card-body { padding: 18px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border: 1px solid var(--border2);
  border-radius: var(--radius-sm); background: rgba(255,255,255,.04);
  color: var(--text); font-size: 13px; font-weight: 500; font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), border-color var(--transition);
  user-select: none; white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,.07); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--sky-dim); border-color: rgba(56,189,248,.3); color: var(--sky); }
.btn.primary:hover { background: rgba(56,189,248,.22); }
.btn.success { background: var(--green-dim); border-color: rgba(52,211,153,.3); color: var(--green); }
.btn.danger  { background: var(--red-dim);   border-color: rgba(248,113,113,.3); color: var(--red); }
.btn.amber   { background: var(--amber-dim); border-color: rgba(251,191,36,.3);  color: var(--amber); }
.btn.sm { padding: 6px 10px; font-size: 12px; }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 99px;
  font-size: 11px; font-weight: 600; border: 1px solid transparent;
}
.badge.sky   { background: var(--sky-dim);   color: var(--sky);   border-color: rgba(56,189,248,.2); }
.badge.green { background: var(--green-dim); color: var(--green); border-color: rgba(52,211,153,.2); }
.badge.red   { background: var(--red-dim);   color: var(--red);   border-color: rgba(248,113,113,.2); }
.badge.amber { background: var(--amber-dim); color: var(--amber); border-color: rgba(251,191,36,.2); }

/* Table */
.table-wrap {
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  overflow: auto; max-height: 520px;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky; top: 0; background: var(--surface2);
  padding: 10px 14px; text-align: left;
  font-size: 11px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
  color: var(--text2); border-bottom: 1px solid var(--border); white-space: nowrap; z-index: 1;
}
tbody td { padding: 11px 14px; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,.025); }

/* Input / textarea */
.input, .textarea {
  width: 100%; background: rgba(0,0,0,.25); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text); padding: 9px 12px;
  font-size: 13px; font-family: inherit; outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  appearance: none; -webkit-appearance: none;
}
.input:hover { background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.18); }
.input:focus, .textarea:focus {
  border-color: rgba(56,189,248,.45);
  box-shadow: 0 0 0 3px rgba(56,189,248,.09);
  background: rgba(56,189,248,.04);
}
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a97bf' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 30px; cursor: pointer;
}
select.input:focus { border-color: rgba(56,189,248,.45); box-shadow: 0 0 0 3px rgba(56,189,248,.09); }
select.input option { background: #0f1929; color: #dce8f8; }
.textarea { min-height: 100px; resize: vertical; }
.label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 5px; }

/* Search bar */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.2); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: 8px 12px;
}
.search-bar svg { width: 15px; height: 15px; color: var(--text3); flex-shrink: 0; }
.search-bar input {
  border: none; background: transparent; outline: none;
  color: var(--text); font-size: 13px; font-family: inherit;
  flex: 1; min-width: 120px;
}

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text2); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 14px; opacity: .35; }
.empty-state p { font-size: 14px; }
.empty-state small { font-size: 12px; color: var(--text3); }

/* Toast */
#toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 12px 16px; min-width: 260px;
  box-shadow: var(--shadow); animation: slideUp .2s ease; display: none;
}
#toast.show { display: block; }
#toast strong { font-size: 13px; font-weight: 600; }
#toast p { font-size: 12px; color: var(--text2); margin-top: 2px; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════
   MODAL — scroll controlado en todas las modales
═══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-overlay.show { display: flex; }

.modal {
  width: min(600px, 100%);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: fadeIn .2s ease;
  /* ── Scroll controlado ── */
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;   /* no se comprime */
}
.modal-header h3 { font-size: 14px; font-weight: 600; }

.modal-body {
  padding: 18px;
  display: grid;
  gap: 14px;
  overflow-y: auto;   /* scroll cuando el contenido es largo */
  flex: 1;            /* ocupa el espacio restante */
  min-height: 0;      /* necesario para que flex+overflow funcione en todos los browsers */
}

.modal-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
  flex-shrink: 0;   /* no se comprime */
}

/* Divider */
.hr { height: 1px; background: var(--border); margin: 16px 0; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.toolbar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* Mono */
.mono { font-family: 'DM Mono', monospace; }


/* ═══════════════════════════════════════════
   MODAL DESTINOS / INTEGRACIONES
   (generada dinámicamente en _openDestModalBase)
═══════════════════════════════════════════ */
.dest-modal-shell {
  width: min(940px, 96vw);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  display: flex;
  flex-direction: column;
  max-height: 88vh;
  overflow: hidden;
  animation: fadeIn .2s ease;
}
.dest-modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 12px;
}
.dest-modal-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.dest-modal-sidebar {
  width: 200px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dest-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  min-width: 0;
}

/* Botones del sidebar */
.dest-sidebar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  transition: background var(--transition), border-color var(--transition);
}
.dest-sidebar-btn:hover {
  background: rgba(255,255,255,.04);
  border-color: var(--border);
}
.dest-sidebar-btn.active {
  background: var(--sky-dim);
  border-color: rgba(56,189,248,.2);
}
.dest-sidebar-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  flex-shrink: 0;
}
.dest-sidebar-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dest-sidebar-count {
  font-size: 11px;
  color: var(--text3);
  flex-shrink: 0;
}

/* Stats del detalle */
.dest-detail-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.dest-stat-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.dest-stat-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 5px;
}
.dest-stat-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.dest-stat-sub {
  font-size: 12px;
  color: var(--sky);
  margin-top: 3px;
}

/* ═══════════════════════════════════════════
   TABLA DE CAMPOS GPS (orgs.js)
═══════════════════════════════════════════ */
.field-row-grid {
  display: grid;
  grid-template-columns: 22px 1fr 1fr 1fr 68px 30px;
  gap: 6px;
  align-items: center;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.field-row-grid:hover {
  background: rgba(255,255,255,.025);
}
.drag-handle {
  color: var(--text3);
  cursor: grab;
  font-size: 14px;
  text-align: center;
  padding-top: 1px;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle:hover { color: var(--text2); }

/* Select de fuente GPS — colores por categoría */
.src-gps    { background: var(--sky-glow)   !important; border-color: rgba(56,189,248,.2)  !important; }
.src-unit   { background: var(--green-dim)  !important; border-color: rgba(52,211,153,.2)  !important; }
.src-fixed  { background: var(--amber-dim)  !important; border-color: rgba(251,191,36,.2)  !important; }

/* Required toggle */
.req-toggle {
  font-size: 11px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  width: 100%;
  font-family: inherit;
  transition: background var(--transition), color var(--transition);
  text-align: center;
}
.req-toggle.on {
  background: var(--sky-dim);
  border-color: rgba(56,189,248,.3);
  color: var(--sky);
}

/* Vista previa del payload */
.payload-preview {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  line-height: 1.7;
  color: var(--sky);
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0;
}

/* Leyenda de fuentes */
.source-legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}
.source-legend-item {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
