/* NavGeoMX Admin Panel — main.css (responsive: tv / desktop / tablet / mobile) */
:root {
  --blue:    #1565C0;
  --blue-l:  #1976D2;
  --blue-d:  #0D47A1;
  --green:   #2E7D32;
  --red:     #C62828;
  --orange:  #E65100;
  --grey:    #607D8B;
  --bg:      #F0F4F8;
  --card-bg: #FFFFFF;
  --text:    #212121;
  --text-s:  #757575;
  --border:  #E0E0E0;
  --sidebar: #0D2137;
  --sidebar-w: 220px;
  --sidebar-hover: rgba(255,255,255,0.1);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; color: var(--text); }

/* ── Login / Auth ──────────────────────── */
.login-body {
  background: linear-gradient(135deg, var(--blue-d) 0%, var(--blue) 100%);
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.login-container { width: 100%; max-width: 420px; }
.login-card { background: white; border-radius: 16px; padding: 40px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 16px; }
.login-card h1 { text-align: center; font-size: 28px; font-weight: 800; color: var(--blue); letter-spacing: 4px; }
.login-subtitle { text-align: center; color: var(--text-s); font-size: 13px; margin-bottom: 28px; }
.login-footer { text-align: center; color: var(--text-s); font-size: 11px; margin-top: 24px; }

/* ── Forms ─────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-s); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; transition: border-color 0.2s; outline: none; background: white;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--blue); }

/* ── Buttons ───────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 18px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; transition: all 0.15s; text-decoration: none; white-space: nowrap; }
.btn-primary   { background: var(--blue); color: white; }
.btn-primary:hover  { background: var(--blue-d); }
.btn-success   { background: var(--green); color: white; }
.btn-danger    { background: var(--red); color: white; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d0d0d0; }
.btn-full      { width: 100%; justify-content: center; padding: 12px; }

/* ── Alerts ────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.alert-error   { background: #FFEBEE; color: var(--red);   border-left: 4px solid var(--red); }
.alert-success { background: #E8F5E9; color: var(--green); border-left: 4px solid var(--green); }

/* ── App Layout ────────────────────────── */
.app-body { display: flex; min-height: 100vh; background: var(--bg); }

/* ── Hamburger (hidden desktop) ─────────── */
.hamburger-btn {
  display: none;
  position: fixed; top: 10px; left: 10px; z-index: 9999;
  background: var(--sidebar); color: white; border: none;
  border-radius: 8px; width: 46px; height: 46px;
  font-size: 22px; cursor: pointer;
  align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.4); transition: background .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}
.hamburger-btn:hover, .hamburger-btn:active { background: var(--blue); }

/* ── Sidebar overlay ───────────────────── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 9990;
}
.sidebar-overlay.active { display: block; }

/* ── Sidebar ───────────────────────────── */
.sidebar {
  width: var(--sidebar-w); min-height: 100vh;
  background: var(--sidebar); color: white;
  display: flex; flex-direction: column; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto; transition: transform .25s ease; z-index: 9995;
}
.sidebar-logo { padding: 24px 20px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,0.1); flex-shrink: 0; }
.logo-icon { font-size: 22px; }
.logo-text  { font-size: 18px; font-weight: 800; letter-spacing: 3px; color: white; white-space: nowrap; }
.sidebar-nav { list-style: none; padding: 12px 0; flex: 1; overflow-y: auto; }
.sidebar-nav li a { display: flex; align-items: center; gap: 8px; padding: 10px 20px; color: rgba(255,255,255,0.75); text-decoration: none; border-radius: 6px; margin: 1px 8px; transition: all 0.15s; font-size: 13px; white-space: nowrap; }
.sidebar-nav li a:hover, .sidebar-nav li.active a { background: var(--sidebar-hover); color: white; }
.sidebar-sep { height: 1px; background: rgba(255,255,255,0.1); margin: 8px 16px; list-style: none; }
.sidebar-ws-status { padding: 12px 20px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: rgba(255,255,255,0.5); border-top: 1px solid rgba(255,255,255,0.1); flex-shrink: 0; white-space: nowrap; }
.ws-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ws-dot.online  { background: #4CAF50; box-shadow: 0 0 6px #4CAF50; }
.ws-dot.offline { background: #757575; }

/* ── Main content ──────────────────────── */
.main-content { flex: 1; padding: 24px; overflow-x: hidden; min-width: 0; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 22px; font-weight: 700; color: var(--blue); }
.header-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-s); flex-wrap: wrap; }
.sep { opacity: 0.4; }

/* ── Stats grid ────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card { background: white; border-radius: 12px; padding: 20px; display: flex; flex-direction: column; align-items: flex-start; box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-top: 4px solid; }
.stat-card.blue   { border-color: var(--blue); }
.stat-card.green  { border-color: var(--green); }
.stat-card.red    { border-color: var(--red); }
.stat-card.orange { border-color: var(--orange); }
.stat-icon  { font-size: 24px; margin-bottom: 8px; }
.stat-value { font-size: 32px; font-weight: 800; line-height: 1; color: var(--text); }
.stat-label { font-size: 11px; color: var(--text-s); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Section header ────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.section-header h2 { font-size: 16px; font-weight: 600; }

/* ── Table ─────────────────────────────── */
.table-container { background: white; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; min-width: 480px; }
.data-table thead th { background: #F5F7FA; padding: 10px 14px; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-s); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tbody td { padding: 10px 14px; border-bottom: 1px solid #FAFAFA; font-size: 13px; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #FAFBFC; }
.empty { text-align: center; color: var(--text-s); padding: 40px !important; }
.mono { font-family: 'Courier New', monospace; font-size: 12px; }

/* ── Badges ────────────────────────────── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; background: var(--border); color: var(--text-s); }
.badge-tipo { padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.badge-entrada { background: #E8F5E9; color: var(--green); }
.badge-salida  { background: #FFEBEE; color: var(--red); }
.badge-rol { display:inline-block; padding:2px 8px; border-radius:10px; font-size:11px; font-weight:700; background:rgba(21,101,192,0.12); color:var(--blue); }
.badge-rol-superadmin { background:#1a237e; color:#fff; }
.badge-rol-admin      { background:#1565c0; color:#fff; }
.badge-rol-gerente    { background:#2e7d32; color:#fff; }
.badge-rol-rrhh       { background:#e65100; color:#fff; }
.badge-rol-supervisor { background:#6a1b9a; color:#fff; }
.badge-rol-readonly   { background:#607d8b; color:#fff; }

/* ── Animated rows ─────────────────────── */
.fila-entrada td { background: rgba(46,125,50,0.03); }
.fila-salida  td { background: rgba(198,40,40,0.03); }
@keyframes fadeIn { from { background: rgba(21,101,192,0.12); } to { background: transparent; } }
.fila-nueva td { animation: fadeIn 2s ease-out; }

/* ── Cards ─────────────────────────────── */
.card { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 700; color: var(--blue); margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }

/* ── Password toggle ───────────────────── */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input[type="password"], .pw-wrap input[type="text"] { flex: 1; padding-right: 44px !important; }
.pw-toggle { position: absolute; right: 10px; background: none; border: none; cursor: pointer; color: #757575; padding: 4px; display: flex; align-items: center; transition: color .15s; }
.pw-toggle:hover { color: #1565C0; }

/* ── Copy button ───────────────────────── */
.btn-copy { background: none; border: 1px solid #e0e0e0; border-radius: 4px; cursor: pointer; font-size: 11px; padding: 2px 8px; color: #666; transition: all .15s; }
.btn-copy:hover { background: #e3f2fd; color: #1565C0; border-color: #1565C0; }

/* ── API Key box ───────────────────────── */
.apikey-box { background: #f5f7fa; border: 1px solid #e0e0e0; border-radius: 8px; padding: 10px 14px; font-family: monospace; font-size: 13px; word-break: break-all; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.apikey-box span { flex: 1; user-select: all; }

/* ── License banner ────────────────────── */
.lic-banner { padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.lic-banner.lic-ok    { background: #E8F5E9; color: #2E7D32; border: 1px solid #A5D6A7; }
.lic-banner.lic-warn  { background: #FFF8E1; color: #E65100; border: 1px solid #FFE082; }
.lic-banner.lic-error { background: #FFEBEE; color: #C62828; border: 1px solid #EF9A9A; }
.lic-banner.lic-trial { background: #E3F2FD; color: #1565C0; border: 1px solid #90CAF9; }

/* ═══════════ RESPONSIVE ══════════════ */

/* Smart TV / 4K (≥ 1600px) */
@media (min-width: 1600px) {
  :root { --sidebar-w: 260px; }
  .main-content { padding: 32px 40px; }
  .stats-grid { gap: 24px; margin-bottom: 36px; }
  .stat-value { font-size: 42px; }
  .stat-icon  { font-size: 32px; }
  .data-table thead th, .data-table tbody td { padding: 14px 18px; font-size: 14px; }
  .page-header h1 { font-size: 28px; }
  .card { padding: 28px; }
  .btn { font-size: 15px; padding: 11px 22px; }
  body { font-size: 15px; }
}

/* Tablet (≤ 1024px) */
@media (max-width: 1024px) {
  :root { --sidebar-w: 200px; }
  .main-content { padding: 18px; }
}

/* Tablet portrait / mobile landscape (≤ 900px) */
@media (max-width: 900px) {
  .hamburger-btn { display: flex; }

  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    transform: translateX(calc(-1 * var(--sidebar-w) - 10px));
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
    z-index: 9995;
  }
  .sidebar.open { transform: translateX(0); }

  .app-body { display: block; }
  .main-content { padding: 16px; padding-top: 68px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .section-header { flex-direction: column; align-items: flex-start; }
}

/* Mobile (≤ 480px) */
@media (max-width: 480px) {
  .stats-grid { gap: 8px; }
  .stat-value { font-size: 26px; }
  .stat-card  { padding: 14px; }
  .main-content { padding: 12px; padding-top: 66px; }
  .page-header h1 { font-size: 18px; }
  .btn { font-size: 12px; padding: 7px 12px; }
  .card { padding: 14px; }
  .login-card { padding: 24px 16px; border-radius: 12px; }
  .login-card h1 { font-size: 22px; letter-spacing: 2px; }
  .data-table thead th { font-size: 10px; padding: 8px 10px; }
  .data-table tbody td { font-size: 12px; padding: 8px 10px; }
  /* Prevent iOS auto-zoom on inputs */
  .form-group input, .form-group select, .form-group textarea { font-size: 16px; }
}

/* Print */
@media print {
  .sidebar, .hamburger-btn, .sidebar-overlay, .btn { display: none !important; }
  .main-content { padding: 0; }
  .app-body { display: block; }
}

/* ═══════════ RESPONSIVE FIXES — v17d ════════════════════════ */

/* ── Grids de 2 columnas inline → 1 columna en móvil ────────── */
/* Aplica a cualquier div con grid-template-columns:1fr 1fr inline */
@media (max-width: 700px) {

  /* Layouts de página principal */
  .two-col   { grid-template-columns: 1fr !important; }
  .three-col { grid-template-columns: 1fr !important; }

  /* Usuarios: lista + formulario apilados */
  .usuarios-layout { grid-template-columns: 1fr !important; }

  /* Empleado detalle: cards de datos en 1 col */
  .det-cols { grid-template-columns: 1fr !important; }

  /* Cabecera de empleado: avatar + datos en columna */
  .det-header { flex-direction: column; align-items: center; text-align: center; }
  .det-title  { min-width: 0 !important; width: 100%; }
  .det-actions { justify-content: center; }
  .det-badges  { justify-content: center; }

  /* Formularios: grids de 2 cols → 1 col */
  .form-grid-2 { grid-template-columns: 1fr !important; }

  /* Rondin detalle: info + mapa apilados */
  .rondin-det-cols { grid-template-columns: 1fr !important; }

  /* GPS row en rondin form: 3 cols → 1 col */
  .gps-row { grid-template-columns: 1fr !important; }

  /* Config: logo + campos apilados */
  .cfg-logo-row { flex-direction: column !important; align-items: flex-start !important; }

  /* Motivos: form inline */
  .form-inline { flex-direction: column; }
  .form-inline .fg { min-width: 0 !important; width: 100%; }

  /* Dispositivos: grid interno */
  .disp-form-grid { grid-template-columns: 1fr !important; }

  /* Sección header: botones no se cortan */
  .section-header { gap: 6px; }
  .section-header .btn { font-size: 11px; padding: 6px 10px; }

  /* Page header botones */
  .page-header .btn { font-size: 11px; padding: 6px 10px; }
  .page-header { gap: 8px; }

  /* Tabs de motivos */
  .mot-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }

  /* Stat cards: 2 cols en 480px ya estaba, aquí reforzamos */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Tabla de usuarios: acciones en columna */
  .user-actions { flex-direction: column; gap: 4px; }

  /* API key box */
  .apikey-box { flex-direction: column; align-items: flex-start; }

  /* Botones de grupos */
  .btn-group { flex-wrap: wrap; }

  /* rep-grid: 1 col */
  .rep-grid { grid-template-columns: 1fr !important; }

  /* emp-grid: 1 col en pantallas muy pequeñas */
  .emp-grid { grid-template-columns: 1fr !important; }

  /* Badges grid gafetes */
  .badges-grid { grid-template-columns: 1fr !important; }

  /* Monitor rondines */
  .monitor-grid { grid-template-columns: 1fr !important; }

  /* Rondin cards en rondines.html */
  .rondines-grid { grid-template-columns: 1fr !important; }

  /* Licencia: tabla info */
  .lic-table td { display: block; width: 100% !important; padding: 4px 8px !important; }
  .lic-table tr { border-bottom: 1px solid #eee; display: block; padding: 4px 0; }

  /* View toggle (lista/grid) */
  .view-toggle { gap: 4px; }

  /* Tab buttons */
  .tab-btns { flex-wrap: wrap; }
}

/* ── Tablas en móvil: scroll horizontal forzado ──────────────── */
@media (max-width: 700px) {
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
  }
  /* Columna de acciones no se rompe */
  .data-table td:last-child { white-space: nowrap; }

  /* Registros: ocultar columna "Registrado por" en móvil muy pequeño */
  .hide-mobile { display: none !important; }
}

/* ── Fix: divs con style inline grid 1fr 1fr ─────────────────── */
/* Selector amplio que captura grids inline en templates sin clase */
@media (max-width: 700px) {
  /* empleado_form, sitio_form, rondin_form, rondin_detalle, empleado_detalle */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* usuarios: sidebar derecho */
  [style*="grid-template-columns:1fr 360px"],
  [style*="grid-template-columns: 1fr 360px"] {
    grid-template-columns: 1fr !important;
  }

  /* rondin form: 3 cols GPS */
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Config logo row */
  [style*="display:flex;align-items:flex-start;gap:20px"],
  [style*="display: flex; align-items: flex-start; gap: 20px"] {
    flex-direction: column !important;
  }
}

/* ── Pantallas muy pequeñas (< 380px) ────────────────────────── */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr 1fr !important; }
  .stat-value { font-size: 22px; }
  .stat-icon  { font-size: 18px; margin-bottom: 4px; }
  .stat-card  { padding: 10px 12px; }
  .btn { font-size: 11px; padding: 6px 10px; }
  .main-content { padding: 10px; padding-top: 64px; }
  .det-avatar { width: 80px; height: 80px; font-size: 32px; }
}


/* ═══════════ PORTRAIT MODE FIX — v19 ════════════════════════════════
   Dispositivos en modo vertical (portrait): ~360–430px de ancho.
   En landscape (~700-900px) las reglas ≤900px y ≤700px ya cubren todo.
   Este bloque cubre lo que se escapa en portrait angosto.
════════════════════════════════════════════════════════════════════════ */

@media (max-width: 600px) {

  /* ── 1. BODY / CONTENIDO PRINCIPAL ──────────────────────────── */
  body { overflow-x: hidden; }
  .main-content { overflow-x: hidden !important; width: 100%; box-sizing: border-box; }

  /* ── 2. PAGE HEADER — siempre columna ───────────────────────── */
  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }
  .page-header h1 { font-size: 18px !important; }
  /* Botones del page-header: wrap */
  .page-header > div { flex-wrap: wrap !important; }

  /* ── 3. SECTION HEADER — wrap ────────────────────────────────── */
  .section-header { flex-wrap: wrap !important; gap: 6px !important; }

  /* ── 4. TODOS LOS GRIDS INLINE → 1 COLUMNA ─────────────────── */
  /* Variante con y sin espacio, con y sin px, con minmax */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns:1fr 360px"],
  [style*="grid-template-columns: 1fr 360px"],
  [style*="grid-template-columns:repeat(auto-fit,minmax(280px"],
  [style*="grid-template-columns: repeat(auto-fit, minmax(280px"],
  [style*="grid-template-columns:repeat(auto-fill,minmax(280px"],
  [style*="grid-template-columns: repeat(auto-fill, minmax(280px"] {
    grid-template-columns: 1fr !important;
    display: grid !important;
  }
  /* minmax(160px) → 2 col (stat cards, no queremos 1 col) */
  [style*="grid-template-columns:repeat(auto-fit,minmax(160px"],
  [style*="grid-template-columns: repeat(auto-fit, minmax(160px"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ── 5. FLEX ROWS → COLUMNA (formularios de filtro/búsqueda) ── */
  /* Cualquier flex sin flex-direction:column que esté dentro de un card  */
  /* y que sirve como fila de inputs necesita colapsar en portrait.       */

  /* Formularios de búsqueda/filtro */
  form[style*="display:flex"][style*="flex-wrap:wrap"],
  form[style*="display:flex"][style*="flex-wrap: wrap"],
  form[style*="display: flex"][style*="flex-wrap:wrap"],
  form[style*="display: flex"][style*="flex-wrap: wrap"] {
    flex-direction: column !important;
  }
  /* Hijos de esos forms: ancho completo */
  form[style*="display:flex"][style*="flex-wrap:wrap"] > *,
  form[style*="display:flex"][style*="flex-wrap: wrap"] > *,
  form[style*="display: flex"][style*="flex-wrap:wrap"] > *,
  form[style*="display: flex"][style*="flex-wrap: wrap"] > * {
    min-width: 0 !important;
    width: 100% !important;
    flex: none !important;
  }

  /* form-group con min-width inline: limpiar */
  .form-group[style*="min-width"] {
    min-width: 0 !important;
    width: 100% !important;
    flex: 1 1 100% !important;
  }
  /* .fg con min-width (motivos.html) */
  .fg, .fg[style*="min-width"] {
    min-width: 0 !important;
    width: 100% !important;
    flex: 1 1 100% !important;
  }

  /* ── 6. FORMULARIOS FORM-INLINE (motivos.html) ───────────────── */
  .form-inline {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .form-inline > * {
    min-width: 0 !important;
    width: 100% !important;
    flex: none !important;
  }

  /* ── 7. CONFIG.HTML — inputs y botones con min-width fijo ─────── */
  input[style*="min-width:260px"],
  input[style*="min-width: 260px"] { min-width: 0 !important; width: 100% !important; }
  button[style*="min-width:180px"],
  button[style*="min-width: 180px"] { min-width: 0 !important; width: 100% !important; }

  /* Logo row en config: columna */
  [style*="display:flex;align-items:flex-start;gap:20px"],
  [style*="display: flex; align-items: flex-start; gap: 20px"] {
    flex-direction: column !important;
  }
  /* Backup/restore form row */
  form[style*="display:flex;gap:8px;align-items:center;flex-wrap:wrap"],
  form[style*="display:flex;gap:8px"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  /* ── 8. EMPLEADO DETALLE ─────────────────────────────────────── */
  .det-header {
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    gap: 16px !important;
  }
  .det-title { min-width: 0 !important; width: 100% !important; }
  .det-actions { justify-content: center !important; flex-wrap: wrap !important; }
  .det-badges { justify-content: center !important; }
  .det-cols { grid-template-columns: 1fr !important; }
  /* QR zone: no fuerza ancho */
  .qr-zone { min-width: 0 !important; width: 100% !important; max-width: 300px; margin: 0 auto; }
  /* Reg-row en registros del empleado: columna */
  .reg-row { flex-wrap: wrap !important; gap: 6px !important; }
  /* Preview links en la sección de compartir */
  [style*="display:flex;gap:20px;align-items:flex-start;flex-wrap:wrap"] {
    flex-direction: column !important;
  }

  /* ── 9. EMPLEADOS LIST (tarjetas y tabla) ────────────────────── */
  .emp-grid { grid-template-columns: 1fr !important; }
  /* Barra de búsqueda: columna */
  form[style*="display:flex;gap:8px;margin-bottom:16px;flex-wrap:wrap"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  form[style*="display:flex;gap:8px;margin-bottom:16px;flex-wrap:wrap"] > * {
    min-width: 0 !important; width: 100% !important; flex: none !important;
  }
  /* View-toggle + nuevo: en fila pero wrap */
  .page-header [style*="display:flex;gap:8px;align-items:center"] {
    flex-wrap: wrap !important;
  }

  /* ── 10. REGISTROS — filtro de fechas ────────────────────────── */
  form[style*="display:flex;gap:10px;flex-wrap:wrap;align-items:flex-end"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  form[style*="display:flex;gap:10px;flex-wrap:wrap;align-items:flex-end"] > * {
    min-width: 0 !important; width: 100% !important; flex: none !important;
  }

  /* ── 11. TABLAS — reducir min-width para portrait ────────────── */
  .data-table { min-width: 340px; font-size: 12px; }
  .table-container { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  .data-table thead th { padding: 8px 8px; font-size: 10px; }
  .data-table tbody td { padding: 8px 8px; font-size: 12px; }

  /* ── 12. RONDINES ────────────────────────────────────────────── */
  .rondines-grid { grid-template-columns: 1fr !important; }
  .rondin-det-cols { grid-template-columns: 1fr !important; }
  .form-grid-2 { grid-template-columns: 1fr !important; }
  .gps-row { grid-template-columns: 1fr !important; }
  /* Rondin form: botones de agregar punto */
  [style*="display:flex;align-items:center;justify-content:space-between;margin-bottom:12px"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }
  /* Guardar / cancelar en rondin form */
  [style*="margin-top:24px;display:flex;gap:12px"] { flex-wrap: wrap !important; }
  /* Foto punto: columna */
  [style*="display:flex;align-items:center;gap:10px;margin-top:8px"] {
    flex-wrap: wrap !important;
  }

  /* ── 13. USUARIOS ────────────────────────────────────────────── */
  .usuarios-layout { grid-template-columns: 1fr !important; }
  /* Modal editar: ancho casi completo */
  #modal-editar .card,
  [style*="width:360px;max-width:95vw"] { width: 94vw !important; max-width: 94vw !important; }

  /* ── 14. DISPOSITIVOS ────────────────────────────────────────── */
  .disp-form-grid { grid-template-columns: 1fr !important; }
  /* Cabecera dispositivo card */
  [style*="display:flex;justify-content:space-between;align-items:flex-start"] {
    flex-direction: column !important;
    gap: 8px !important;
  }

  /* ── 15. REPORTES ────────────────────────────────────────────── */
  .rep-grid { grid-template-columns: 1fr !important; }
  .rep-form { flex-direction: column !important; }
  .rep-form .form-group { min-width: 0 !important; width: 100% !important; }

  /* ── 16. MONITOR RONDINES / BADGES GRID ─────────────────────── */
  .monitor-grid { grid-template-columns: 1fr !important; }
  .badges-grid  { grid-template-columns: 1fr !important; }

  /* ── 17. SITIO FORM / REGISTRO FORM ─────────────────────────── */
  /* Botones submit al final de forms */
  [style*="display:flex;gap:10px;margin-bottom:32px"] { flex-wrap: wrap !important; }

  /* ── 18. LICENCIA ─────────────────────────────────────────────── */
  .lic-table td { display: block !important; width: 100% !important; padding: 4px 8px !important; }
  .lic-table tr { border-bottom: 1px solid #eee; display: block; padding: 4px 0; }

  /* ── 19. API KEY BOX ──────────────────────────────────────────── */
  .apikey-box { flex-direction: column !important; align-items: flex-start !important; }

  /* ── 20. BTN-GROUP / TAB BTNS / VIEW TOGGLE ─────────────────── */
  .btn-group  { flex-wrap: wrap !important; }
  .tab-btns   { flex-wrap: wrap !important; }
  .view-toggle { gap: 4px !important; }
  .mot-tabs   { overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }

  /* ── 21. MODALES — ancho seguro ─────────────────────────────── */
  /* Cualquier modal card con max-width fijo */
  [style*="max-width:480px;width:94%"],
  [style*="max-width:440px;width:94%"],
  [style*="max-width:400px;width:90%"] {
    width: 94vw !important;
    max-width: 94vw !important;
    padding: 20px 16px !important;
  }

  /* ── 22. GAFETE EDITOR — no afectar (tiene su propio layout) ─── */
  /* Solo evitar que overflow-x se rompa en el wrapper */
  body:not(.gafete-editor-body) .main-content { max-width: 100vw; }

  /* ── 23. RONDIN EJECUCION — panel lateral ────────────────────── */
  #panel { min-width: 0 !important; }
}

/* ── PORTRAIT extra-angosto ≤380px ──────────────────────────────── */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
  .data-table { min-width: 300px; font-size: 11px; }
  .data-table thead th { padding: 6px 6px; font-size: 9px; }
  .data-table tbody td { padding: 6px 6px; font-size: 11px; }
  .main-content { padding: 10px; padding-top: 64px; }
  .btn { font-size: 11px !important; padding: 5px 9px !important; }
  .page-header h1 { font-size: 16px !important; }
  .stat-value { font-size: 24px; }
  .stat-card  { padding: 12px; }
  .det-avatar { width: 80px; height: 80px; font-size: 32px; }
}
