:root{
  --bg: #111a2f;
  --surface: #0f1b32;
  --card: rgba(16,31,60,0.72);
  --text: #e8eefc;
  --muted: #a9b7d6;
  --line: rgba(255,255,255,0.10);
  --accent: #2dd4bf;
  --accent2: #60a5fa;
  --warn: #fbbf24;
  --danger: #fb7185;
  --ok: #34d399;
}

*{ box-sizing:border-box; }
html, body{ height:100%; overflow-x: hidden; }

body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background:
    radial-gradient(900px 500px at 10% 0%, rgba(96,165,250,0.14), transparent 50%),
    radial-gradient(800px 480px at 95% 15%, rgba(45,212,191,0.16), transparent 55%),
    linear-gradient(180deg, var(--bg), #070d1b);
  color: var(--text);
}

a{ color:inherit; text-decoration:none; }

/* ===== Topbar ===== */
.topbar{
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15,27,50,0.80);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .inner{
  max-width: 1680px;
  margin: 0 auto;
  padding: 14px 24px;
  display:flex;
  align-items:center;
  gap:14px;
}
.brand{
  display:flex;
  align-items:center;
  gap:10px;
  font-weight: 900;
  letter-spacing: 0.2px;
}
.dot{
  width:10px;height:10px;border-radius:6px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(45,212,191,0.10);
}
.badge{
  font-size:12px;
  padding:3px 8px;
  border-radius:999px;
  background: rgba(45,212,191,0.12);
  border: 1px solid rgba(45,212,191,0.30);
  color: var(--accent);
  font-weight: 800;
  display:inline-flex;
  align-items:center;
  gap:8px;
}
.badge .nit{
  color: rgba(232,238,252,0.70);
  font-weight: 700;
  font-size: 11px;
}
.nav{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin-left: 8px;
}
.nav a{
  font-size:14px;
  padding:8px 10px;
  border-radius:12px;
  color: var(--muted);
  border: 1px solid transparent;
  display:inline-flex;
  align-items:center;
  gap:8px;
}
.nav a.active,
.nav a:hover{
  color: var(--text);
  background: rgba(96,165,250,0.10);
  border-color: rgba(96,165,250,0.25);
}
.right{
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:10px;
  color: var(--muted);
  font-size:14px;
}

/* ===== Layout ===== */
.container{ max-width: 1680px; margin: 0 auto; padding: 18px 24px; }
.page-head{
  margin: 10px 0 14px;
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.h1{ font-size: 22px; font-weight: 950; margin:0; }
.subhead{ color: var(--muted); font-size: 13px; margin-top: 4px; }
.actions{ display:flex; gap:10px; flex-wrap:wrap; align-items:center; justify-content:flex-end; }

/* ===== Cards / grids ===== */
.card{
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.20);
  min-width: 0;
}
.grid{ display:grid; gap:14px; }
.grid.kpis{ grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.split{ grid-template-columns: 1.2fr 0.8fr; }

@media (max-width: 980px){
  .grid.kpis{ grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.split{ grid-template-columns: 1fr; }
}
@media (max-width: 520px){
  .grid.kpis{ grid-template-columns: 1fr; }
}

.kpi{ display:flex; flex-direction:column; gap:6px; }
.kpi .label{ color: var(--muted); font-size: 13px; }
.kpi .value{ font-size: 30px; font-weight: 950; letter-spacing: -0.5px; }
.kpi .hint{ color: var(--muted); font-size: 12px; }
.kpi .icon{ font-size: 16px; opacity: 0.9; }

/* ===== Buttons / pills ===== */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding:10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  cursor:pointer;
  font-weight: 700;
}
.btn:hover{ background: rgba(255,255,255,0.06); }
.btn.primary{
  border-color: rgba(45,212,191,0.32);
  background: rgba(45,212,191,0.12);
  color: var(--accent);
}
.btn.primary:hover{ background: rgba(45,212,191,0.18); }
.btn.ghost{ background: transparent; }
.btn.small{ padding:7px 10px; font-size: 13px; }

.pill{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.tag{
  display:inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  white-space: nowrap;
}
.tag.ok{ color: var(--ok); border-color: rgba(52,211,153,0.35); background: rgba(52,211,153,0.10); }
.tag.warn{ color: var(--warn); border-color: rgba(251,191,36,0.35); background: rgba(251,191,36,0.10); }
.tag.danger{ color: var(--danger); border-color: rgba(251,113,133,0.35); background: rgba(251,113,133,0.10); }
.tag.accent{ color: var(--accent2); border-color: rgba(96,165,250,0.35); background: rgba(96,165,250,0.10); }

/* ===== Forms ===== */
label{ font-size: 12px; color: var(--muted); display:block; margin-bottom: 6px; }
input, select{
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(5,9,20,0.30);
  color: var(--text);
  outline: none;
}
input::placeholder{ color: rgba(169,183,214,0.55); }
.form-row{ display:flex; gap:10px; flex-wrap:wrap; align-items:end; }
.field{ min-width: 190px; flex:1; }

/* ===== Tables ===== */
.table-wrap{
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border: 1px solid var(--line);
  max-width: 100%;
  position: relative;
}
.table-scroll{
  /* solo aire abajo para el scrollbar */
  padding-bottom: 6px;
}

table{ width:100%; border-collapse: collapse; }
th, td{ padding: 10px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
th{
  color: var(--muted);
  font-weight: 800;
  text-align:left;
  background: rgba(255,255,255,0.02);
  position: sticky;
  top: 0;
  z-index: 2;
}
tbody tr:hover td{ background: rgba(255,255,255,0.03); }
tr.row-warn td{ background: rgba(251,191,36,0.07); }

.mono{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.muted{ color: var(--muted); }

/* ===== Messages / footer ===== */
.msg{ border-color: rgba(96,165,250,0.25); }

/* ===== Footer PRO ===== */
.footer{
  margin-top: 18px;
  padding: 14px 0 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.footer .inner{
  display:flex;
  gap:12px;
  align-items:center;
  justify-content:space-between;
  flex-wrap:wrap;
}
.footer .left{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
}
.footer .mini-dot{
  width:8px;height:8px;border-radius:999px;
  background: var(--accent2);
  box-shadow: 0 0 0 4px rgba(96,165,250,0.10);
}
.footer .links{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:center;
}
.footer .links a{
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: rgba(232,238,252,0.78);
  font-size: 12px;
}
.footer .links a:hover{ background: rgba(255,255,255,0.06); }

/* ===== Focus / accesibilidad ===== */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible{
  outline: 2px solid rgba(96,165,250,0.55);
  outline-offset: 2px;
  border-radius: 12px;
}

/* ===== Tablets ===== */
@media (max-width: 980px){
  .topbar .inner{ flex-wrap: wrap; }
  .nav{
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    margin-left: 0;
    padding-bottom: 6px;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar{ display:none; }
  .nav a{ white-space: nowrap; }
}

/* ===== Mobile: bottom nav ===== */
.mobile-nav{ display:none; }

@media (max-width: 560px){
  body{ padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .container{ padding: 14px; }
  .page-head{ gap: 10px; }
  .btn{ padding: 11px 13px; border-radius: 14px; }
  th, td{ padding: 12px 10px; }

  .nav{ display:none; }
  .right .pill{ display:none; }

  .topbar .inner{ padding: 12px 14px; gap: 10px; }
  .brand{ flex: 1 1 100%; font-size: 18px; line-height: 1.1; }
  .badge{
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .right{
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
    gap: 8px;
  }

  .right a.btn.small[href*="choose_empresa"],
  .right a.btn.small[href*="choose-empresa"],
  .right a.btn.small[href*="choose"]{
    font-size: 0;
    padding: 9px 12px;
    border-radius: 14px;
    white-space: nowrap;
  }
  .right a.btn.small[href*="choose_empresa"]::before,
  .right a.btn.small[href*="choose-empresa"]::before,
  .right a.btn.small[href*="choose"]::before{
    content: "Empresa";
    font-size: 13px;
    font-weight: 800;
  }

  .right form .btn.small{
    font-size: 0;
    padding: 9px 12px;
    border-radius: 14px;
    white-space: nowrap;
  }
  .right form .btn.small::before{
    content: "Salir";
    font-size: 13px;
    font-weight: 800;
  }

  .footer{
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .footer .inner{
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
  }
  .footer .left{ justify-content: center; }
  .footer .links{ display:none; }

  .mobile-nav{
    display:flex;
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    padding: 10px;
    gap: 8px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(15,27,50,0.86);
    backdrop-filter: blur(10px);
    z-index: 30;
  }
  .mobile-nav a{
    flex: 1;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap: 4px;
    padding: 8px 6px;
    border-radius: 14px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    border: 1px solid transparent;
  }
  .mobile-nav a .ico{ font-size: 18px; line-height: 1; }
  .mobile-nav a.active{
    color: var(--text);
    background: rgba(96,165,250,0.12);
    border-color: rgba(96,165,250,0.25);
  }
}

/* ===== Mobile header extra ===== */
@media (max-width: 560px){
  .right form{ display: inline-flex; margin: 0; }
  .right{ width: 100%; margin-left: 0; justify-content: center; gap: 10px; }
  .right a.btn.small, .right form .btn.small{
    padding: 8px 10px;
    border-radius: 14px;
    min-height: 36px;
  }
  .right a.btn.small[href*="choose_empresa"],
  .right a.btn.small[href*="choose-empresa"],
  .right a.btn.small[href*="choose"]{
    font-size: 0;
  }
  .right a.btn.small[href*="choose_empresa"]::before,
  .right a.btn.small[href*="choose-empresa"]::before,
  .right a.btn.small[href*="choose"]::before{
    content: "🏢 Empresa";
    font-size: 13px;
    font-weight: 800;
  }
  .right form .btn.small{ font-size: 0; }
  .right form .btn.small::before{
    content: "🚪 Salir";
    font-size: 13px;
    font-weight: 800;
  }
}

@media (min-width: 420px) and (max-width: 560px){
  .brand{ flex: 1 1 auto; }
  .right{
    width: auto;
    margin-left: auto;
    justify-content: flex-end;
  }
}

/* -----------------------------
   Filtros - helpers
------------------------------ */
.field-grow{ min-width:260px; flex:2; }
.form-actions{ display:flex; gap:10px; align-items:flex-end; }
.form-quick{ display:flex; gap:8px; align-items:flex-end; }

/* -----------------------------
   Mobile responsive (filtros)
------------------------------ */
@media (max-width: 720px){
  input, select, textarea{ font-size:16px; }

  .page-head{
    flex-direction:column;
    align-items:stretch;
    gap:12px;
  }
  .page-head .actions{
    width:100%;
    flex-wrap:wrap;
  }
  .page-head .actions .btn{
    flex:1 1 140px;
    justify-content:center;
  }

  .form-row{
    flex-direction:column;
    align-items:stretch;
    gap:12px;
  }
  .form-row .field{ width:100%; min-width:0; }
  .field-grow{ min-width:0; }

  .form-actions{
    display:grid;
    grid-template-columns: 1fr 1fr;
    gap:10px;
  }
  .form-actions .btn{
    width:100%;
    justify-content:center;
  }

  .form-quick{
    display:grid;
    grid-template-columns: repeat(3, 1fr);
    gap:8px;
  }
  .form-quick .btn{
    width:100%;
    justify-content:center;
  }
}

.form-row input,
.form-row select{
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

@media (max-width: 800px){
  .form-row{ flex-wrap: wrap; }
  .form-row .field{ flex: 1 1 100%; }
}

.form-row > * { min-width: 0; }

input[type="date"] {
  width: 100%;
  max-width: 100%;
}

@media (max-width: 640px){
  .form-row{
    flex-wrap: wrap;
    gap: 10px;
  }
  .form-row .field{ width: 100%; }
}

/* FIX iPhone Safari (no afecta Chrome) */
@media (hover: none) and (pointer: coarse) {
  .form-row{
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .form-row .field{
    width: 100%;
    min-width: 0;
  }
  .form-row > div:not(.field){ width: 100%; }
  .form-row .btn{
    width: 100%;
    justify-content: center;
  }
  input[type="date"]{
    width: 100%;
    max-width: 100%;
  }
}

/* =========================================
   ✅ Scroll espejo (ÚNICO sistema)
   Usa IDs #topScroll y #bottomScrollWrap
   ========================================= */

/* Arriba */
#topScroll{
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  height: 20px;
  margin-bottom: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
}
#topScrollInner{ height:1px; }

/* Abajo (el real) */
#bottomScrollWrap{
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding-bottom: 6px;
}

/* Grosor (Chrome/Edge/Safari) */
#topScroll::-webkit-scrollbar,
#bottomScrollWrap::-webkit-scrollbar{ height: 16px; }

#topScroll::-webkit-scrollbar-thumb,
#bottomScrollWrap::-webkit-scrollbar-thumb{
  border-radius: 999px;
  border: 4px solid rgba(0,0,0,0);
  background-clip: padding-box;
  background-color: rgba(255,255,255,0.25);
}

#topScroll::-webkit-scrollbar-track,
#bottomScrollWrap::-webkit-scrollbar-track{
  background: rgba(255,255,255,0.07);
  border-radius: 999px;
}

/* ===== FIX header desktop lineal ===== */
@media (min-width: 981px){
  .topbar .inner{
    flex-wrap: nowrap;
    align-items: center;
  }

  .brand{
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .nav{
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    margin-left: 14px;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar{
    display: none;
  }

  .nav a{
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .right{
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

/* ===== FIX header desktop marca + nav lineales ===== */
@media (min-width: 981px){
  .topbar .inner{
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
  }

  .brand{
    flex: 0 0 auto;
    min-width: 0;
    gap: 8px;
  }

  .brand > span:nth-child(2){
    white-space: nowrap;
    display: inline-block;
    line-height: 1;
    font-size: 14px;
  }

  .badge{
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .nav{
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    margin-left: 10px;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar{
    display: none;
  }

  .nav a{
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .right{
    flex: 0 0 auto;
    white-space: nowrap;
  }
}