:root {
  --azul: #0099ff;
  --azul-oscuro: #0077cc;
  --azul-claro: #e6f5ff;
  --gris-fondo: #f4f6f9;
  --gris-borde: #dde3ea;
  --texto: #1c2733;
  --texto-suave: #64748b;
  --verde: #16a34a;
  --rojo: #dc2626;
  --amarillo: #d97706;
  --blanco: #ffffff;
  --radio: 10px;
  --sombra: 0 2px 10px rgba(15, 30, 60, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--gris-fondo);
  color: var(--texto);
  font-size: 14px;
}
a { color: var(--azul); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ===== Pantalla de login ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--azul) 0%, #005fa3 100%);
  padding: 20px;
}
.login-card {
  background: var(--blanco);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.login-logo {
  width: 56px; height: 56px;
  background: var(--azul);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 800; font-size: 22px;
  margin: 0 auto 16px;
}
.login-card h1 { text-align: center; font-size: 18px; margin: 0 0 4px; }
.login-card .empresa { text-align: center; color: var(--texto-suave); font-size: 12px; margin-bottom: 24px; }
.campo { margin-bottom: 16px; }
.campo label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: var(--texto-suave); }
.campo input, .campo select, .campo textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--gris-borde); border-radius: 8px; font-size: 14px;
  outline: none; transition: border-color .15s;
}
.campo input:focus, .campo select:focus, .campo textarea:focus { border-color: var(--azul); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; border: none; font-weight: 600; font-size: 14px;
  transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(0.98); }
.btn-primario { background: var(--azul); color: white; width: 100%; }
.btn-primario:hover { background: var(--azul-oscuro); }
.btn-secundario { background: var(--azul-claro); color: var(--azul-oscuro); }
.btn-outline { background: transparent; border: 1.5px solid var(--gris-borde); color: var(--texto); }
.btn-peligro { background: #fee2e2; color: var(--rojo); }
.btn-exito { background: #dcfce7; color: var(--verde); }
.btn-chico { padding: 6px 12px; font-size: 12.5px; }
.error-msg { background: #fee2e2; color: var(--rojo); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.ok-msg { background: #dcfce7; color: #15803d; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.demo-usuarios { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--gris-borde); font-size: 11.5px; color: var(--texto-suave); }
.demo-usuarios code { background: var(--gris-fondo); padding: 1px 5px; border-radius: 4px; }

/* ===== Layout principal ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: #0b2540; color: #cfe4f7; flex-shrink: 0;
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
  transition: transform .2s;
}
.sidebar-header { padding: 20px 18px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-header .logo { width: 34px; height: 34px; background: var(--azul); border-radius: 9px; display:flex; align-items:center; justify-content:center; font-weight:800; color:white; flex-shrink:0; }
.sidebar-header .titulo { font-weight: 700; font-size: 14.5px; color: white; line-height:1.2; }
.sidebar-header .subtitulo { font-size: 10.5px; color: #7fa8cc; }
.nav-menu { flex: 1; overflow-y: auto; padding: 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; margin-bottom: 2px;
  color: #b9d4ea; text-decoration: none; font-size: 13.5px; font-weight: 500; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-item.activo { background: var(--azul); color: white; }
.nav-icon { width: 18px; text-align: center; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.usuario-chip { display: flex; align-items: center; gap: 10px; }
.usuario-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--azul); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink:0; }
.usuario-info .nombre { font-size: 12.5px; font-weight: 600; color: white; }
.usuario-info .rol { font-size: 10.5px; color: #7fa8cc; }
.btn-salir { margin-top: 10px; width: 100%; background: rgba(255,255,255,0.08); color: #dfeeff; border:none; padding: 8px; border-radius: 7px; font-size: 12px; }

.main { flex: 1; margin-left: 230px; min-width: 0; }
.topbar {
  height: 60px; background: white; border-bottom: 1px solid var(--gris-borde);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 30;
}
.topbar h2 { font-size: 17px; margin: 0; }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; }
.contenido { padding: 24px; max-width: 1300px; }

.card {
  background: white; border-radius: var(--radio); padding: 20px; box-shadow: var(--sombra); margin-bottom: 20px;
  border: 1px solid var(--gris-borde);
}
.card h3 { margin: 0 0 16px; font-size: 15px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { background: white; border-radius: var(--radio); padding: 18px; box-shadow: var(--sombra); border-left: 4px solid var(--azul); }
.kpi .label { font-size: 12px; color: var(--texto-suave); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .valor { font-size: 24px; font-weight: 800; margin-top: 6px; }
.kpi.alerta { border-left-color: var(--amarillo); }
.kpi.rojo { border-left-color: var(--rojo); }
.kpi.verde { border-left-color: var(--verde); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; background: var(--gris-fondo); color: var(--texto-suave); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
td { padding: 10px 12px; border-bottom: 1px solid var(--gris-borde); }
tr:hover td { background: #fafcff; }
.tabla-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-gris { background: #eef1f5; color: #55606b; }
.badge-azul { background: var(--azul-claro); color: var(--azul-oscuro); }
.badge-verde { background: #dcfce7; color: #15803d; }
.badge-rojo { background: #fee2e2; color: var(--rojo); }
.badge-amarillo { background: #fef3c7; color: #b45309; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-derecha { display: flex; gap: 8px; flex-wrap: wrap; }
.buscador { padding: 9px 12px; border: 1.5px solid var(--gris-borde); border-radius: 8px; min-width: 220px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 20, 35, 0.5); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal {
  background: white; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  padding: 24px;
}
.modal.ancho { max-width: 780px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-header h3 { margin: 0; }
.cerrar-x { background: none; border: none; font-size: 20px; color: var(--texto-suave); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.items-factura { border: 1px solid var(--gris-borde); border-radius: 8px; overflow: hidden; margin: 12px 0; }
.items-factura table { font-size: 12.5px; }
.totales-factura { margin-left: auto; width: 260px; }
.totales-factura .fila { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.totales-factura .fila.total { font-weight: 800; font-size: 16px; border-top: 1px solid var(--gris-borde); margin-top: 4px; padding-top: 10px; }

.vacio { text-align: center; padding: 40px 20px; color: var(--texto-suave); }
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--gris-borde); flex-wrap: wrap; }
.tab { padding: 10px 16px; font-size: 13px; font-weight: 600; color: var(--texto-suave); border-bottom: 2px solid transparent; cursor: pointer; }
.tab.activo { color: var(--azul); border-bottom-color: var(--azul); }

.aviso {
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; padding: 12px 14px; border-radius: 8px; font-size: 12.5px; margin-bottom: 16px;
}
.aviso.info { background: var(--azul-claro); border-color: #bfe4ff; color: var(--azul-oscuro); }
.aviso.exito { background: #dcfce7; border-color: #bbf7d0; color: var(--verde); }

.clave-acceso { font-family: monospace; font-size: 11px; word-break: break-all; color: var(--texto-suave); }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.abierto { transform: translateX(0); box-shadow: 8px 0 30px rgba(0,0,0,.2); }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
}
