/* assets/styles/main.css */
:root {
  --navy: #10264b;
  --navy-dark: #09172f;
  --navy-light: #1a3a6f;
  --wine: #7a2638;
  --gold: #c5a46d;
  --gold-hover: #b49258;
  --ink: #202938;
  --muted: #697586;
  --line: #e6e9ef;
  --bg: #f4f5f7;
  --white: #ffffff;
  --green: #18794e;
  --green-bg: #e8f5ee;
  --red: #b42318;
  --red-bg: #fdebea;
  --amber: #a15c07;
  --amber-bg: #fff3df;
  --blue-bg: #eaf0fa;
  --shadow: 0 8px 28px rgba(16, 38, 75, 0.07);
  --shadow-lg: 0 20px 70px rgba(0, 0, 0, 0.18);
  --radius: 10px;
  --radius-lg: 14px;

  /* Safe Area Insets para dispositivos Apple (iPad, iPhone) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

body {
  margin: 0;
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

/* Evitar scroll del fondo cuando el drawer lateral está abierto en móvil o tablet */
body.menu-open {
  overflow: hidden;
  touch-action: none;
}

/* Cuando un modal está abierto: bloquear scroll del fondo y ocultar footer nav para evitar solapamiento */
body.modal-open {
  overflow: hidden !important;
  touch-action: none !important;
}
body.modal-open .mobile-bottom-nav {
  display: none !important;
}

/* Ocultar elementos institucionales en páginas de autenticación o durante la carga inicial */
body.is-auth-page .topbar,
body.is-auth-page .sidebar,
body.is-auth-page .mobile-bottom-nav,
body.is-auth-page #bottomSheet,
body.is-auth-page #bottomSheetBackdrop,
body.is-loading .topbar,
body.is-loading .sidebar,
body.is-loading .mobile-bottom-nav,
body.is-loading #bottomSheet,
body.is-loading #bottomSheetBackdrop {
  display: none !important;
}

/* Pantalla de carga inicial suave */
.initial-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
  text-align: center;
}

.loader-logo {
  max-height: 52px;
  max-width: 210px;
  object-fit: contain;
}

.loader-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--wine);
  border-radius: 50%;
  animation: spinLoader 0.75s linear infinite;
}

@keyframes spinLoader {
  to { transform: rotate(360deg); }
}

.loader-text {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

button, input, select, textarea {
  font: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  position: relative;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

/* ==========================================================================
   SIDEBAR (Menú Lateral / Drawer)
   ========================================================================== */
.sidebar {
  width: 260px;
  background: var(--navy);
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 100;
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1), box-shadow 0.28s ease;
}

.sidebar.auth-hidden {
  display: none !important;
}

.brand {
  padding: 6px 10px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 18px;
}

.brand-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-logo-white {
  width: 100%;
  max-width: 195px;
  max-height: 60px;
  object-fit: contain;
  object-position: left center;
  display: block;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.28));
  transition: opacity 0.2s ease;
}

.brand-logo-white:hover {
  opacity: 0.95;
}

.brand small {
  display: block;
  color: var(--gold);
  letter-spacing: 2.2px;
  font-size: 9px;
  margin: 10px 0 0 2px;
  font-weight: 700;
}

/* Botón cerrar sidebar (solo visible en móvil/iPad portrait) */
.sidebar-close-btn {
  display: none;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 17px;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease;
}

.sidebar-close-btn:hover,
.sidebar-close-btn:active {
  background: rgba(255, 255, 255, 0.22);
}

.nav-label {
  color: #8fa0ba;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  padding: 10px 12px 6px;
  font-weight: 700;
}

.nav button {
  width: 100%;
  border: 0;
  background: transparent;
  color: #dce4f1;
  text-align: left;
  padding: 11px 13px;
  border-radius: 8px;
  margin: 2px 0;
  display: flex;
  gap: 12px;
  align-items: center;
  font-weight: 500;
  font-size: 13.5px;
  min-height: 44px;
  transition: all 0.15s ease;
}

.nav button:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav button.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 4px 0 var(--gold);
}

.nav .ico {
  width: 20px;
  text-align: center;
  font-size: 16px;
  opacity: 0.95;
  flex-shrink: 0;
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px 10px;
  color: #aebbd0;
  font-size: 11px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  line-height: 1.45;
}

/* Backdrop para Drawer en pantallas táctiles */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 18, 36, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 990;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   MAIN CONTENT AREA & TOPBAR
   ========================================================================== */
.main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  padding: 10px 16px;
  position: sticky;
  top: 10px;
  z-index: 900;
  margin: 12px 18px 14px;
  border-radius: 18px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 4px 20px rgba(16, 38, 75, 0.06);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

/* Botón Hamburguesa Estilo Móvil */
.topbar-hamburger-btn {
  width: 38px;
  height: 38px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: all 0.15s ease;
  touch-action: manipulation;
  pointer-events: auto;
}

.topbar-hamburger-btn:active {
  background: #f1f5f9;
  transform: scale(0.95);
}

.topbar-hamburger-btn .bar {
  display: block;
  width: 18px;
  height: 2px;
  background: #334155;
  border-radius: 2px;
  pointer-events: none;
}

.topbar-brand-title {
  font-size: 15px;
  font-weight: 750;
  color: #7a1f33;
  white-space: nowrap;
  letter-spacing: -0.2px;
  line-height: 1.2;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e9eef7;
  color: var(--navy);
  display: grid;
  place-items: center;
  font-weight: 750;
  font-size: 12px;
  border: 1px solid #cbd5e1;
  flex-shrink: 0;
  user-select: none;
}

.topbar-bell-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #334155;
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
  padding: 0;
  transition: all 0.15s ease;
  touch-action: manipulation;
  flex-shrink: 0;
}

.topbar-bell-btn:active {
  background: #e2e8f0;
  transform: scale(0.95);
}

.bell-badge-dot {
  position: absolute;
  top: 6px;
  right: 7px;
  width: 7px;
  height: 7px;
  background: #ef4444;
  border: 1.5px solid #ffffff;
  border-radius: 50%;
  pointer-events: none;
}

.topbar-logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
  flex-shrink: 0;
}

.topbar-logout-btn:active {
  background: #fee2e2;
  color: #dc2626;
  border-color: #fecaca;
  transform: scale(0.96);
}

.content {
  padding: 28px 32px;
  max-width: 1550px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 24px;
}

.eyebrow {
  color: var(--wine);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.h1 {
  font-size: 24px;
  color: var(--navy);
  font-weight: 750;
  margin: 4px 0;
}

.sub {
  color: var(--muted);
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

/* ==========================================================================
   OPTIMIZACIONES PARA TABLET (iPAD Y TABLETS 768px - 1024px)
   ========================================================================== */
@media (max-width: 1024px) {
  .app {
    display: flex;
    flex-direction: column;
  }

  /* El sidebar se convierte en drawer deslizable para no restar espacio a la pantalla del iPad */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    max-width: 82vw;
    height: 100%;
    height: 100dvh;
    z-index: 1000;
    transform: translateX(-100%);
    box-shadow: none;
    padding-top: calc(18px + var(--safe-top));
    padding-bottom: calc(18px + var(--safe-bottom));
    padding-left: calc(16px + var(--safe-left));
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 12px 0 45px rgba(0, 0, 0, 0.45);
  }

  .sidebar-backdrop {
    display: block;
  }

  .sidebar-close-btn {
    display: grid;
  }

  .menu-toggle-btn {
    display: flex;
  }

  .topbar {
    min-height: 62px;
    padding: 10px 20px;
    padding-top: calc(10px + var(--safe-top));
    padding-left: calc(20px + var(--safe-left));
    padding-right: calc(20px + var(--safe-right));
  }

  .content {
    padding: 22px 20px;
    padding-bottom: calc(30px + var(--safe-bottom));
  }

  .brand-logo-white {
    max-height: 48px;
    max-width: 170px;
  }

  .nav button {
    padding: 12px 14px;
    min-height: 48px;
    font-size: 14px;
  }
}

/* ==========================================================================
   OPTIMIZACIONES PARA MÓVIL (SMARTPHONES <= 768px)
   ========================================================================== */
@media (max-width: 768px) {
  .topbar {
    margin: 8px 12px 6px;
    padding: 8px 12px;
    border-radius: 16px;
    top: calc(6px + var(--safe-top));
  }

  .content {
    padding: 14px 12px;
    padding-bottom: calc(84px + var(--safe-bottom)) !important;
  }

  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 18px;
  }

  .page-head > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  .page-head > div:last-child .btn {
    flex: 1 1 auto;
    min-height: 44px;
    justify-content: center;
  }

  .h1 {
    font-size: 21px;
  }
}

/* Móviles muy compactos (< 420px) */
@media (max-width: 420px) {
  .top-user-name {
    display: none;
  }
}


/* ==========================================================================
   BARRA DE NAVEGACIÓN INFERIOR (Estilo App Android / iPad Nativo Permanente)
   ========================================================================== */
.mobile-bottom-nav {
  display: flex !important;
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  background: #ffffff !important;
  border-top: 1px solid #e8ecf1 !important;
  box-shadow: 0 -4px 22px rgba(16, 38, 75, 0.08) !important;
  z-index: 99999 !important;
  padding: 6px 14px calc(6px + var(--safe-bottom)) !important;
  justify-content: space-around !important;
  align-items: center !important;
  min-height: 56px !important;
  width: 100% !important;
  max-width: 100vw !important;
  transition: transform 0.25s cubic-bezier(0.2, 0, 0, 1), opacity 0.25s ease;
}

@media (min-width: 1025px) {
  .mobile-bottom-nav {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: 100% !important;
    max-width: 620px !important;
    border-radius: 20px 20px 0 0 !important;
    border-left: 1px solid #e8ecf1 !important;
    border-right: 1px solid #e8ecf1 !important;
    border-bottom: 0 !important;
  }
}

.bottom-nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: 0;
  color: #64748b;
  padding: 4px 6px;
  cursor: pointer;
  flex: 1;
  max-width: 90px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.15s ease;
  position: relative;
}

.bottom-nav-tab * {
  pointer-events: none;
}

.bottom-nav-tab:active {
  transform: scale(0.92);
}

.bottom-nav-tab .tab-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: #64748b;
  transition: color 0.2s ease;
}

.bottom-nav-tab.active .tab-icon {
  color: #10264b;
}

.bottom-nav-tab .tab-label {
  font-size: 11px;
  font-weight: 550;
  color: #64748b;
  line-height: 1.2;
  transition: color 0.2s ease, font-weight 0.2s ease;
  white-space: nowrap;
}

.bottom-nav-tab.active .tab-label {
  color: #10264b;
  font-weight: 750;
}

.tab-active-dot {
  display: block;
  width: 4px;
  height: 4px;
  background: #10264b;
  border-radius: 50%;
  margin-top: 2px;
}

/* Asegurar que el contenido nunca quede tapado por la barra inferior */
.content {
  padding-bottom: calc(90px + var(--safe-bottom)) !important;
}

.toast {
  bottom: calc(90px + var(--safe-bottom)) !important;
}


/* ==========================================================================
   ANDROID BOTTOM SHEET (Hoja Desplegable Inferior Estilo Android Nativo)
   ========================================================================== */
body.sheet-open {
  overflow: hidden;
  touch-action: none;
}

.bottom-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 24, 48, 0.62);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

.bottom-sheet-backdrop.open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet {
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 580px;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -12px 48px rgba(16, 38, 75, 0.28);
  z-index: 100001;
  transform: translateY(105%);
  transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1);
  max-height: 86vh;
  max-height: 86dvh;
  padding: 12px 18px calc(24px + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  pointer-events: none;
  visibility: hidden;
}

.bottom-sheet.open {
  transform: translateY(0);
  pointer-events: auto;
  visibility: visible;
}

.bottom-sheet-drag-handle {
  width: 42px;
  height: 5px;
  background: #cbd5e1;
  border-radius: 4px;
  margin: 2px auto 14px;
  flex-shrink: 0;
}

.bottom-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.bottom-sheet-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bottom-sheet-user-name {
  font-weight: 750;
  font-size: 14.5px;
  color: var(--navy);
  line-height: 1.2;
}

.bottom-sheet-user-role {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 4px;
}

.bottom-sheet-close-btn {
  border: 0;
  background: #f1f5f9;
  color: var(--muted);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.bottom-sheet-close-btn:active {
  background: #e2e8f0;
  color: var(--ink);
}

/* Grilla de Opciones en el Bottom Sheet */
.bottom-sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

@media (min-width: 480px) {
  .bottom-sheet-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.bottom-sheet-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 16px 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--navy);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: all 0.15s ease;
}

.bottom-sheet-item:active {
  background: #eef3f9;
  transform: scale(0.96);
  border-color: #cbd5e1;
}

.bottom-sheet-item.active {
  background: #eaf0fa;
  border-color: var(--navy-light);
  color: var(--navy);
  font-weight: 750;
}

.bottom-sheet-item-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #fff;
  display: grid;
  place-items: center;
  color: var(--navy);
  box-shadow: 0 2px 6px rgba(16, 38, 75, 0.06);
}

.bottom-sheet-item.active .bottom-sheet-item-icon {
  background: var(--navy);
  color: #fff;
}

.bottom-sheet-logout-btn {
  width: 100%;
  border: 1px solid #fecaca;
  background: var(--red-bg);
  color: var(--red);
  padding: 13px;
  border-radius: 12px;
  font-weight: 750;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 48px;
  touch-action: manipulation;
}

.bottom-sheet-logout-btn:active {
  background: #fee2e2;
  transform: scale(0.98);
}
