:root {
  --azul: #2856c9;
  --azul-oscuro: #1c3d8f;
  --gris-fondo: #f4f6fb;
  --gris-borde: #e1e5ee;
  --texto: #1e2433;
  --texto-suave: #6b7280;
  --verde: #16a34a;
  --rojo: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--gris-fondo);
  color: var(--texto);
}

/* --- Layout --- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: #12172b;
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-brand {
  font-size: 1.2rem;
  font-weight: 700;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-nav { flex: 1; padding: 14px 10px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #cdd3e6;
  text-decoration: none;
  font-size: 0.94rem;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-icon { width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.usuario-nombre { font-weight: 600; font-size: 0.9rem; }
.usuario-email { font-size: 0.78rem; color: #9aa3bd; margin-bottom: 10px; }

.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--gris-borde);
  padding: 18px 28px;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.page-content { padding: 28px; position: relative; isolation: isolate; }
/* Logo de la empresa de fondo: muy suave, fijo, detrás de todo y sin recibir clics */
.marca-agua { position: fixed; top: 54%; left: calc(50% + 120px); width: min(42vw, 520px); height: min(56vh, 600px); transform: translate(-50%, -50%);
              background: no-repeat center / contain; opacity: .07; pointer-events: none; z-index: -1; }
@media (max-width: 900px) { .marca-agua { left: 50%; width: 78vw; height: 50vh; opacity: .06; } }
@media print { .marca-agua { display: none; } }

/* --- Cards --- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}
.card {
  background: #fff;
  border: 1px solid var(--gris-borde);
  border-radius: 12px;
  padding: 22px;
}
.card h3 { margin-top: 0; }
.card-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.empty-state { text-align: center; padding: 50px 20px; }
.empty-icon { font-size: 2.4rem; margin-bottom: 10px; }

/* --- Botones --- */
.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn-primary { background: var(--azul); color: #fff; }
.btn-primary:hover { background: var(--azul-oscuro); }
.btn-secondary { background: #eef1fb; color: var(--azul-oscuro); }
.btn-secondary:hover { background: #dfe5fa; }
.btn-link { background: none; border: none; color: var(--azul); cursor: pointer; font-size: 0.86rem; padding: 0; }

/* --- Formularios --- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field-full { grid-column: 1 / -1; }
.form-card { max-width: 760px; }

label { font-size: 0.85rem; font-weight: 600; color: var(--texto-suave); }
input, select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--gris-borde);
  border-radius: 8px;
  font-size: 0.94rem;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--azul); }

.permisos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 8px; }
.permiso-check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--texto); }
.permiso-check input { width: auto; }

/* --- Tabla --- */
.tabla { width: 100%; border-collapse: collapse; }
.tabla th, .tabla td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--gris-borde); font-size: 0.92rem; }
.tabla th { color: var(--texto-suave); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; }

/* --- Alertas --- */
.alert { padding: 12px 14px; border-radius: 8px; font-size: 0.88rem; margin-bottom: 16px; }
.alert-error { background: #fdeaea; color: var(--rojo); }
.alert-success { background: #e9f9ee; color: var(--verde); }

/* --- Pantallas de autenticación --- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #12172b, #2856c9);
}
.auth-card {
  background: #fff;
  padding: 36px 34px;
  border-radius: 14px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.auth-brand { font-weight: 700; color: var(--azul); margin-bottom: 6px; }
.auth-card h2 { margin-top: 0; }
.auth-text { color: var(--texto-suave); font-size: 0.88rem; }
.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.auth-link { display: block; text-align: center; margin-top: 16px; font-size: 0.85rem; color: var(--azul); text-decoration: none; }

/* RESPONSIVE MOBILE FIX */
@media screen and (max-width: 900px) {
  .app-shell, .layout, body {
    display: block !important;
    overflow-x: hidden !important;
  }
  .sidebar, aside {
    display: none !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 260px !important;
    z-index: 99999 !important;
  }
  .sidebar.open, aside.open {
    display: flex !important;
  }
  .main-content, main {
    width: 100% !important;
    min-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .btn-mobile-toggle {
    display: inline-block !important;
  }
}

/* Menú en móvil (botón ☰ y velo) */
.btn-mobile-toggle { display: none; background: none; border: 1px solid var(--gris-borde); border-radius: 8px; font-size: 1.2rem; padding: 4px 10px; margin-right: 10px; cursor: pointer; color: var(--texto); }
.menu-velo { display: none; }
@media screen and (max-width: 900px) {
  .topbar { display: flex; align-items: center; }
  .topbar h1 { font-size: 1.05rem; }
  .menu-velo.on { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 99998; }
  .sidebar.open { overflow-y: auto; }
  .page-content { padding: 14px !important; }
}

/* ---- Ancho: todas las pantallas de los módulos ocupan todo el ancho, igual en todos (sin cajas estrechas centradas) ---- */
.page-content > div[style*="max-width"][style*="margin: 0 auto"], .page-content > .em, .page-content > form.em { max-width: none !important; }
/* ---- Cabecera del menú: nombre de la empresa, logo, bienvenida y sede (o Central) con su ubicación ---- */
.sb-cab { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 18px 16px 16px; border-bottom: 1px solid rgba(255,255,255,0.08); gap: 6px; }
.sb-cab .sidebar-brand { padding: 0; border: 0; font-size: 1.1rem; line-height: 1.25; }
.sb-logo { width: 92px; height: 92px; border-radius: 18px; background: #fff; display: flex; align-items: center; justify-content: center; padding: 8px; box-sizing: border-box; margin: 6px 0 4px; box-shadow: 0 6px 16px rgba(0,0,0,.25); }
.sb-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sb-hola { font-size: .68rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; opacity: .7; margin-top: 4px; }
.sb-nombre { font-weight: 800; font-size: 1rem; }
.sb-sede { margin-top: 6px; width: 100%; box-sizing: border-box; padding: 8px 10px; border-radius: 999px; background: rgba(255,255,255,.1); color: inherit; text-decoration: none;
           font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
a.sb-sede:hover { background: rgba(255,255,255,.18); opacity: 1; }

/* Menú de módulos plegable (botón junto al título): más espacio para trabajar. Se recuerda en el navegador. */
.btn-plegar { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--gris-borde); border-radius: 8px;
              background: #fff; color: #475569; cursor: pointer; margin-right: 12px; flex-shrink: 0; padding: 0; }
.btn-plegar:hover { background: #f1f5f9; color: #0f172a; }
.topbar { display: flex; align-items: center; }
html.menu-plegado .sidebar { display: none; }
html.menu-plegado .btn-plegar .bp-flecha { transform: rotate(180deg); transform-origin: 12.5px 10px; }
html.menu-plegado .marca-agua { left: 50%; }
@media screen and (max-width: 900px) { .btn-plegar { display: none !important; } }

/* Cabecera: usuario, Portal del empleado y Cerrar sesión arriba a la derecha (en PC). En el móvil ya están en la barra de abajo. */
.tb-der { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; padding-left: 12px; }
.tb-der form { margin: 0; }
.tb-usu { font-size: .84rem; font-weight: 700; color: #334155; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; margin-right: 4px; }
.tb-root { font-style: normal; background: #ef4444; color: #fff; font-size: 10px; padding: 2px 5px; border-radius: 4px; }
.tb-bt { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--gris-borde); border-radius: 8px; background: #fff;
         color: #1e293b; font: inherit; font-size: .82rem; font-weight: 700; text-decoration: none; cursor: pointer; white-space: nowrap; }
.tb-bt:hover { background: #f1f5f9; border-color: #cbd5e1; }
.tb-salir:hover { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
@media screen and (max-width: 1200px) { .tb-usu { display: none; } }
@media screen and (max-width: 900px) { .tb-der { display: none !important; } }
/* En PC el menú de módulos se queda quieto: solo se mueve la parte de la derecha al hacer scroll */
@media screen and (min-width: 901px) {
  .sidebar { position: sticky; top: 0; height: 100vh; align-self: flex-start; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
  .sidebar::-webkit-scrollbar { width: 6px; }
  .sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 6px; }
  .sidebar-footer { display: none; }
}
