/* Portal shell SPA — contenedor de vistas */

/* layout.css fija .container a width: min(1100px, 100%). En app.html el shell debe
   usar el ancho disponible (como las páginas legacy con #portal-content a 1400/1900px). */
body.portal-shell-app > #portal-content.container,
body.portal-shell-app > #portal-content.shell {
  width: 100%;
  max-width: min(1900px, 100%);
  box-sizing: border-box;
}

body.portal-shell-app.fullwidth > #portal-content.container,
body.portal-shell-app.fullwidth > #portal-content.shell {
  max-width: 100% !important;
  width: 100% !important;
}

body.portal-shell-app #app-view :is(.container, .shell) {
  width: 100%;
}

#app-view {
  position: relative;
  min-height: 40vh;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

/* Defensa contra overflow horizontal de vistas en el shell.
   Permite que los items de grids/flex se encojan (evita el min-width:auto que
   empuja recuadros fuera de la hoja, ej. la sección de Deudas en clientes). */
#app-view :where(.two-col, .bottom-row, .grid-3i, .calc-panel, .method-grid, .proof-grid, .grid) > * {
  min-width: 0;
}

/* Tablas anchas: que hagan scroll dentro de su caja en vez de desbordar. */
#app-view .table-wrap,
#app-view .table-container {
  overflow-x: auto;
  max-width: 100%;
}

#app-view table {
  max-width: 100%;
}

/* Solo el contenido de la vista en pausa; header/menú siguen activos */
#app-view.portal-shell-loading {
  pointer-events: none;
  user-select: none;
}

.portal-shell-route-overlay {
  position: absolute;
  inset: 0;
  z-index: 240;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(231, 235, 242, 0.38);
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
  pointer-events: none;
}

.portal-shell-route-overlay[hidden] {
  display: none !important;
}

.portal-shell-route-overlay .portal-shell-route-label {
  margin: 0;
  color: #1e2a49;
  font-size: 15px;
  font-weight: 600;
}

body.portal-shell-app.portal-shell-route-busy::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 100001;
  background: linear-gradient(90deg, #c9a962, #3d5a80, #c9a962);
  background-size: 200% 100%;
  animation: portal-shell-progress 0.9s linear infinite;
  pointer-events: none;
}

@keyframes portal-shell-progress {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.portal-shell-route-aviso {
  margin: 0 0 1rem;
  padding: 12px 16px;
  border-radius: 8px;
  background: rgba(220, 53, 69, 0.12);
  border: 1px solid rgba(220, 53, 69, 0.35);
  color: #f8d7da;
}

body.portal-shell-app .header {
  border-bottom: 3px solid #1d4f91;
  box-shadow: 0 2px 10px rgba(29, 79, 145, 0.12);
}

body.portal-shell-app {
  /* Misma base que portal-fixed-footer */
}

.portal-shell-legacy-only {
  padding: 24px 30px;
}

.portal-shell-legacy-only h3 {
  margin-bottom: 12px;
}

/* Estado "Verificando acceso..." — garantizar contraste sobre cualquier fondo */
#loader-auth:not(.loader-auth--login) {
  background: linear-gradient(135deg, #0f2a4a 0%, #1d4f91 100%);
  color: #fff;
}

#loader-auth:not(.loader-auth--login) h2 {
  margin: 0;
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ============================================================
   LOGIN ELEGANTE — solo para el shell (app.html)
   ============================================================ */
#loader-auth.loader-auth--login {
  display: block;
  min-height: 100vh;
  padding: 0;
  color: var(--text-dark, #1a2744);
}

.login-shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: #0f1730;
  font-family: 'DM Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

/* --- Panel izquierdo (marca) --- */
.login-shell__aside {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px;
  background:
    radial-gradient(120% 120% at 0% 0%, #24365f 0%, rgba(36, 54, 95, 0) 55%),
    linear-gradient(135deg, #1a2744 0%, #0f1730 55%, #0b1226 100%);
}

.login-shell__aside-content {
  position: relative;
  z-index: 2;
  max-width: 420px;
  color: #eef2fb;
}

.login-shell__aside-logo {
  height: 50px;
  width: auto;
  margin-bottom: 28px;
  background: #ffffff;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
}

.login-shell__aside-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 34px;
  line-height: 1.18;
  margin: 0 0 16px;
  color: #ffffff;
}

.login-shell__aside-text {
  font-size: 15.5px;
  line-height: 1.6;
  margin: 0;
  color: rgba(232, 238, 251, 0.78);
}

.login-shell__aside-glow {
  position: absolute;
  width: 460px;
  height: 460px;
  right: -140px;
  bottom: -160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201, 168, 76, 0.32) 0%, rgba(201, 168, 76, 0) 70%);
  z-index: 1;
}

/* --- Panel derecho (formulario) --- */
.login-shell__panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 28px;
  background: #f4f6fb;
  overflow-y: auto;
}

.login-shell__card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: #ffffff;
  border: 1px solid var(--line, #dde4ee);
  border-radius: 18px;
  padding: 38px 36px 30px;
  box-shadow: 0 24px 60px rgba(15, 23, 48, 0.16);
  animation: loginCardIn 0.45s ease both;
}

.login-shell__pending-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(2px);
}

.login-shell__pending-overlay[hidden] {
  display: none !important;
}

.login-shell__pending-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  text-align: center;
}

.login-shell__spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(26, 39, 68, 0.15);
  border-top-color: var(--navy, #1a2744);
  border-radius: 50%;
  animation: loginSpinner 0.75s linear infinite;
}

@keyframes loginSpinner {
  to { transform: rotate(360deg); }
}

.login-shell__pending-text {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy, #1a2744);
}

.login-shell__btn:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}

.login-container {
  position: relative;
}

.login-pending-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
}

.login-pending-overlay[hidden] {
  display: none !important;
}

.login-pending-text {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 600;
  color: #1a2744;
}

@keyframes loginCardIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-shell__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.login-shell__logo {
  height: 42px;
  width: auto;
}

.login-shell__brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.login-shell__brand-name {
  font-weight: 600;
  letter-spacing: 0.14em;
  font-size: 15px;
  color: var(--navy, #1a2744);
}

.login-shell__brand-sub {
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: #8893ad;
  text-transform: uppercase;
}

.login-shell__title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 26px;
  margin: 0 0 6px;
  color: var(--navy, #1a2744);
}

.login-shell__lead {
  margin: 0 0 24px;
  font-size: 14px;
  color: #6b7693;
}

.login-shell__form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-shell__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.login-shell__label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #4a5670;
}

.login-shell__input {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  font-size: 14.5px;
  color: var(--text-dark, #1a2744);
  background: #fbfcfe;
  border: 1px solid var(--line, #dde4ee);
  border-radius: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.login-shell__input::placeholder {
  color: #aab2c6;
}

.login-shell__input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--steel, #3d5a80);
  box-shadow: 0 0 0 3px rgba(61, 90, 128, 0.16);
}

.login-shell__turnstile {
  min-height: 65px;
  margin-top: 4px;
}

.login-shell__captcha {
  margin: 0;
  font-size: 11.5px;
  color: #8893ad;
}

.login-shell__error {
  margin: 0;
  padding: 10px 12px;
  font-size: 13px;
  color: #b3261e;
  background: #fdecea;
  border: 1px solid #f7c6c1;
  border-radius: 9px;
}

.login-shell__btn {
  margin-top: 6px;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #ffffff;
  background: linear-gradient(135deg, #1a2744 0%, #3d5a80 100%);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
  box-shadow: 0 10px 24px rgba(26, 39, 68, 0.22);
}

.login-shell__btn:hover {
  filter: brightness(1.07);
  box-shadow: 0 12px 28px rgba(26, 39, 68, 0.3);
}

.login-shell__btn:active {
  transform: translateY(1px);
}

.login-shell__footer {
  margin: 24px 0 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: #aab2c6;
  text-transform: uppercase;
}

@media (max-width: 880px) {
  .login-shell {
    grid-template-columns: 1fr;
  }
  .login-shell__aside {
    display: none;
  }
  .login-shell__panel {
    background:
      radial-gradient(120% 90% at 50% 0%, #1f3057 0%, rgba(31, 48, 87, 0) 60%),
      linear-gradient(160deg, #16223f 0%, #0f1730 100%);
  }
}

@media (max-width: 420px) {
  .login-shell__card {
    padding: 28px 22px 24px;
    border-radius: 14px;
  }
}

.portal-pwa-install-btn {
  white-space: nowrap;
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
}

body.portal-pwa-install-modal-open {
  overflow: hidden;
}

.portal-pwa-install-modal {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.portal-pwa-install-modal.open {
  display: flex;
}

.portal-pwa-install-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.portal-pwa-install-modal-sheet {
  position: relative;
  z-index: 1;
  width: min(100%, 480px);
  max-height: 85vh;
  overflow-y: auto;
  margin: 0;
  padding: 20px 18px 24px;
  background: #fff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.2);
  color: #1a2744;
}

.portal-pwa-install-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  padding: 4px 8px;
}

.portal-pwa-install-modal-sheet h3 {
  margin: 0 2rem 10px 0;
  font-size: 1.1rem;
  font-family: 'Playfair Display', serif;
}

.portal-pwa-install-modal-lead {
  margin: 0 0 12px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: #475569;
}

.portal-pwa-install-steps {
  margin: 0 0 12px;
  padding-left: 1.2rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.portal-pwa-install-steps li + li {
  margin-top: 8px;
}

.portal-pwa-install-note {
  margin: 0 0 16px;
  font-size: 0.82rem;
  color: #64748b;
  line-height: 1.4;
}

.portal-pwa-install-modal-ok {
  width: 100%;
  margin-top: 4px;
}

@media (min-width: 520px) {
  .portal-pwa-install-modal {
    align-items: center;
    padding: 16px;
  }

  .portal-pwa-install-modal-sheet {
    border-radius: 12px;
    max-height: 90vh;
  }
}
