/* SIC — skin móvil/tablet. NO aplica en PC (>1024).
   Tokens: --sic-movil-* / --sic-tablet-* (Personalización).
   Grids: marcar th/td con .hide-mobile o .hide-tablet.
   Rollback: quitar el <link> a este archivo. */

/* ── Patrón grids (todos los módulos) ── */
@media (max-width: 767px) {
  .hide-mobile { display: none !important; }
}
@media (min-width: 768px) and (max-width: 1024px) {
  .hide-tablet { display: none !important; }
}

/* ════════════════════════════════════════
   MÓVIL <768 — formularios (cualquier ficha)
   ════════════════════════════════════════ */
@media (max-width: 767px) {
  html, body { overflow-x: hidden; }
  input, select, textarea { font-size: 16px !important; }

  .sic-form-group,
  .login-field,
  .mb-3.login-field {
    gap: 6px;
  }

  .sic-input,
  .sic-select,
  .sic-textarea,
  .form-control,
  .form-select,
  .ts-wrapper .ts-control {
    min-height: calc(var(--sic-movil-input-alto, 48) * 1px) !important;
    font-size: 16px !important;
    padding: 12px 14px !important;
    border-radius: 12px !important;
  }
  /* Login: no aplastar padding de íconos */
  #login-form .input-icon .form-control {
    padding-left: 2.85rem !important;
    padding-right: 1rem !important;
  }
  /* Topbar buscar: el padding 12px 14px !important de .form-control montaba el texto en la lupa */
  .app-topbar .topbar-search .form-control,
  .app-topbar .topbar-search .topbar-search-input {
    padding-left: 2.5rem !important;
    padding-right: 14px !important;
  }
  #login-form .input-icon:has(.login-password-toggle) .form-control {
    padding-right: 2.85rem !important;
  }

  .btn, .sic-btn, .btn-primary, .auth-btn {
    min-height: 48px;
    min-width: 48px;
  }
  .btn-primary.w-100,
  #login-submit {
    width: 100%;
    border-radius: calc(var(--sic-movil-btn-radio, 16) * 1px) !important;
    font-size: 1rem;
  }

  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* ════════════════════════════════════════
   LOGIN móvil — B2 fondo suave, 1 pantalla
   Logo fluido; sin barra de color en header
   ════════════════════════════════════════ */
@media (max-width: 767px) {
  /* Solo páginas auth (minimal_layout): body con auth-main */
  body:has(.auth-main) {
    min-height: 100dvh;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    /* no apagar imagen: overlay más fuerte encima */
    background-color: transparent !important;
    background-image: none !important;
  }

  body:has(.auth-main)::before {
    display: block !important;
    /* overlay más denso para legibilidad (fondo suave B2) */
    filter: none;
    opacity: 1;
  }

  /* Oscurecer un poco más el wallpaper solo móvil auth */
  body:has(.auth-main)::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: rgba(8, 12, 24, 0.22);
  }

  .bg-orb { opacity: 0.06 !important; }

  body:has(.auth-main) > *:not(.bg-orb) {
    position: relative;
    z-index: 1;
  }

  /* Sin bloque de color: header transparente */
  body:has(.auth-main) .auth-header {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 4px !important;
    flex-shrink: 0;
  }

  body:has(.auth-main) .auth-brand {
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    gap: 8px !important;
    width: 100% !important;
  }

  body:has(.auth-main) .auth-brand__logo {
    /* Legible: ~140–200px, baja si pantalla corta */
    width: clamp(8.75rem, 38vmin, 12.5rem) !important;
    max-width: min(12.5rem, 58vw) !important;
    max-height: 28vh !important;
    flex: 0 0 auto !important;
    border-radius: 22px !important;
    filter: drop-shadow(0 6px 16px rgba(0,0,0,.4));
  }

  body:has(.auth-main) .auth-brand__text {
    text-align: center !important;
    color: #fff !important;
  }

  body:has(.auth-main) .auth-brand__programa {
    display: block !important;
    font-size: clamp(0.65rem, 2.6vw, 0.78rem) !important;
    font-weight: 400 !important;
    line-height: 1.25 !important;
    opacity: 0.78 !important;
    color: rgba(255,255,255,.88) !important;
    text-shadow: 0 1px 3px rgba(0,0,0,.35);
    max-width: 16rem;
    margin: 0.15rem auto 0 !important;
  }

  body:has(.auth-main) .auth-brand__sigla {
    font-size: clamp(1.15rem, 4.5vw, 1.45rem) !important;
    font-weight: 800 !important;
    letter-spacing: 0.06em;
    color: #fff !important;
    text-shadow: 0 1px 4px rgba(0,0,0,.4);
  }

  body:has(.auth-main) .auth-brand__subtitulo {
    display: block !important;
    font-size: clamp(0.62rem, 2.4vw, 0.72rem) !important;
    font-weight: 400 !important;
    opacity: 0.7 !important;
    color: rgba(255,255,255,.82) !important;
    margin: 0.1rem 0 0 !important;
    letter-spacing: 0.03em;
  }

  /* Main ocupa el resto y centra el form (sin pozo vacío) */
  body:has(.auth-main) .auth-main {
    flex: 1 1 auto !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px 16px !important;
    min-height: 0 !important;
  }

  body:has(.auth-main) .auth-main .container-tight {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    padding: 0 !important;
  }

  body:has(.auth-main) #login-form.card,
  body:has(.auth-main) .auth-main .card {
    /* Glass real: transparente, se ve el fondo */
    /* alpha=0.16 → ~84% transparente */
    background: rgba(15, 23, 42, 0.16) !important;
    backdrop-filter: blur(22px) saturate(1.35) !important;
    -webkit-backdrop-filter: blur(22px) saturate(1.35) !important;
    border: 1px solid rgba(255,255,255,0.18) !important;
    border-radius: 18px !important;
    box-shadow: 0 16px 48px rgba(0,0,0,0.32) !important;
    color: #fff !important;
  }

  body:has(.auth-main) #login-form .card-body {
    padding: 1.1rem 1.15rem 1.15rem !important;
  }

  body:has(.auth-main) #login-form .card-title {
    text-align: center !important;
    font-size: clamp(1.05rem, 4vw, 1.25rem) !important;
    font-weight: 700 !important;
    letter-spacing: -0.02em !important;
    font-family: inherit !important;
    color: #fff !important;
    margin-bottom: 1rem !important;
  }

  body:has(.auth-main) #login-form .form-label {
    color: rgba(255,255,255,0.78) !important;
    font-size: 0.78rem !important;
  }

  body:has(.auth-main) #login-form .form-control {
    background: rgba(255,255,255,0.12) !important;
    border: 1px solid rgba(255,255,255,0.22) !important;
    color: #fff !important;
    min-height: 48px;
  }

  body:has(.auth-main) #login-form .form-control::placeholder {
    color: rgba(255,255,255,0.5) !important;
  }

  body:has(.auth-main) #login-form .input-icon-addon {
    color: rgba(255,255,255,0.75) !important;
  }

  /* Labels ocultos en móvil → texto va en placeholder */
  body:has(.auth-main) #login-form .login-label,
  body:has(.auth-main) #login-form .form-label.login-label {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0,0,0,0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }
  body:has(.auth-main) #login-form .login-field {
    margin-bottom: 0.75rem !important;
  }
  body:has(.auth-main) #login-form .input-icon {
    width: 100%;
  }
  body:has(.auth-main) #login-form .form-control {
    width: 100% !important;
    min-height: 50px !important;
  }
  body:has(.auth-main) #login-form .form-control::placeholder {
    font-size: 0.82rem !important;
    color: rgba(255,255,255,0.55) !important;
    opacity: 1;
  }
  body:has(.auth-main) #login-form .card-title.mb-4 {
    margin-bottom: 0.85rem !important;
  }
  body:has(.auth-main) #login-form .input-icon .form-control {
    padding-left: 2.85rem !important;
  }
  body:has(.auth-main) #login-form .input-icon:has(.login-password-toggle) .form-control {
    padding-right: 2.85rem !important;
  }

  /* Recordarme switch + label chica */
  body:has(.auth-main) #login-form .form-check {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 40px;
    padding-left: 0;
    margin-bottom: 0.65rem !important;
  }
  body:has(.auth-main) #login-form .form-check-input {
    appearance: none;
    -webkit-appearance: none;
    width: 44px;
    height: 26px;
    min-width: 44px;
    border-radius: 13px;
    background: #cbd5e1;
    border: 0;
    position: relative;
    cursor: pointer;
    float: none;
    margin: 0;
    order: 2;
  }
  body:has(.auth-main) #login-form .form-check-input::after {
    content: '';
    position: absolute;
    top: 3px; left: 3px;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #fff;
    transition: transform .15s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
  }
  body:has(.auth-main) #login-form .form-check-input:checked {
    background: var(--tblr-primary, #6c5ce7);
  }
  body:has(.auth-main) #login-form .form-check-input:checked::after {
    transform: translateX(18px);
  }
  body:has(.auth-main) #login-form .form-check-label {
    order: 1;
    margin: 0;
    font-size: 0.75rem !important;
    color: rgba(255,255,255,0.75) !important;
    text-shadow: none !important;
  }

  body:has(.auth-main) #login-form a,
  body:has(.auth-main) .auth-register-link {
    color: #fbbf24 !important;
    text-shadow: 0 1px 2px rgba(0,0,0,.35) !important;
    font-size: 0.85rem;
  }

  body:has(.auth-main) .auth-main .hr-text {
    color: rgba(255,255,255,0.75) !important;
    margin: 0.65rem 0 !important;
  }
  body:has(.auth-main) .auth-main .hr-text::before,
  body:has(.auth-main) .auth-main .hr-text::after {
    background: rgba(255,255,255,0.28) !important;
  }

  body:has(.auth-main) .btn-outline-secondary.w-100 {
    background: rgba(255,255,255,0.14) !important;
    border: 1px solid rgba(255,255,255,0.35) !important;
    color: #fff !important;
    min-height: 44px;
    backdrop-filter: blur(6px);
  }

  body:has(.auth-main) .auth-footer {
    flex-shrink: 0;
    background: transparent !important;
    border: 0 !important;
    backdrop-filter: none !important;
    max-height: none !important;
    padding: 4px 16px calc(6px + env(safe-area-inset-bottom, 0px)) !important;
  }
  body:has(.auth-main) .auth-footer__line {
    font-size: 11px !important;
    opacity: .7;
    color: rgba(255,255,255,.85) !important;
  }
  body:has(.auth-main) .auth-footer__line:not(:first-child) { display: none; }

  /* Pantallas muy bajas: comprimir logo y gaps */
  @media (max-height: 700px) {
    body:has(.auth-main) .auth-brand__logo {
      width: clamp(6.5rem, 26vmin, 9rem) !important;
      max-height: 22vh !important;
    }
    body:has(.auth-main) .auth-brand__programa {
      font-size: 0.62rem !important;
    }
    body:has(.auth-main) #login-form .card-body {
      padding: 0.85rem 1rem !important;
    }
    body:has(.auth-main) .auth-main { padding: 4px 12px !important; }
  }
}

/* ════════════════════════════════════════
   TABLET 768–1024 — formularios
   ════════════════════════════════════════ */
@media (min-width: 768px) and (max-width: 1024px) {
  .sic-input, .form-control, .ts-wrapper .ts-control {
    min-height: calc(var(--sic-tablet-input-alto, 44) * 1px);
    font-size: 16px;
  }
}

/* ════════════════════════════════════════
   FICHA agente (misDatosAgente) móvil
   ════════════════════════════════════════ */
@media (max-width: 767px) {
  .sic-page-header { margin-bottom: 12px !important; }
  .sic-tabs {
    margin-bottom: 12px !important;
    -webkit-overflow-scrolling: touch;
  }
  .sic-tab { min-height: 44px; }
  .container, .container-tight, .container-fluid {
    padding-left: calc(var(--sic-espacio-pagina-movil, 12) * 1px) !important;
    padding-right: calc(var(--sic-espacio-pagina-movil, 12) * 1px) !important;
  }
}

/* ══ FICHA agente — ajustes presentacion (sep 2026) ══ */
@media (max-width: 767px) {
  #main-content.app-content,
  #main-content.main-content {
    padding-left: 16px !important;
    padding-right: 16px !important;
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }
  .sic-page-title--identity {
    font-size: 1.4rem !important;
    font-weight: 700 !important;
    font-family: inherit !important;
  }
  .ficha-minimos {
    font-size: .68rem !important;
    color: var(--tblr-secondary, #94a3b8) !important;
    font-weight: 400 !important;
  }
  /* Labels con respiro respecto al borde del content */
  #agente-form .form-label,
  #agente-form label.form-label {
    padding-left: 2px;
  }
  #agente-form .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  #agente-form .row > [class*="col"] {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
}

/* Topbar móvil: luna y A± salen de la fila (no caben). Viven en el menú del avatar. */
@media (max-width: 767.98px) {
  .topbar-access-pc { display: none !important; }
  .topbar-access-movil { display: block; }
  .topbar-access-movil__font {
    display: flex !important;
    align-items: center;
    gap: 8px;
    min-height: 48px;
  }
  .topbar-access-movil__font .topbar-btn {
    width: 44px;
    height: 44px;
  }
}
@media (min-width: 768px) {
  .topbar-access-movil { display: none !important; }
}

/* Config / personalización: usable en móvil, sin tocar PC */
@media (max-width: 767.98px) {
  html[data-sic-modulo="personalizacion"] .page-wrapper {
    margin-left: 0 !important;
    margin-right: 0 !important;
    min-height: 0 !important;
  }
  html[data-sic-modulo="personalizacion"] .page-header {
    padding: 0 0 8px !important;
    margin: 0 !important;
  }
  html[data-sic-modulo="personalizacion"] .page-title {
    font-size: 1.05rem !important;
  }
  html[data-sic-modulo="personalizacion"] .page-header .btn-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }
  html[data-sic-modulo="personalizacion"] .page-header .btn-list .btn {
    flex: 1 1 auto;
    min-height: 44px;
  }
  html[data-sic-modulo="personalizacion"] #theme-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0;
  }
  html[data-sic-modulo="personalizacion"] #theme-tabs .nav-item {
    flex: 0 0 auto;
  }
  html[data-sic-modulo="personalizacion"] #theme-tabs .nav-link {
    white-space: nowrap;
    font-size: 0.8rem;
    padding: 10px 12px;
  }
  html[data-sic-modulo="personalizacion"] .card-header-tabs {
    margin-bottom: 0;
  }
  html[data-sic-modulo="personalizacion"] .col-lg-4 .sticky-top {
    position: static !important;
  }
  html[data-sic-modulo="personalizacion"] #preview-frame {
    min-height: 180px;
  }
  html[data-sic-modulo="personalizacion"] .page-body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
  html[data-sic-modulo="personalizacion"] .position-fixed.bottom-0 {
    bottom: 64px !important;
  }
}

/* SIC — drawer móvil: bloqueo scroll y compensación */
@media (max-width: 768px) {
  body.drawer-open { overflow: hidden; }
  .app-sidebar.drawer-open { box-shadow: 0 18px 60px rgba(0,0,0,.45); }
}

/* Historial/ticker: nunca en móvil ni tablet (la raya de color es el panel cerrado) */
@media (max-width: 1024px) {
  .sic-ticker,
  #sic-ticker-bar,
  .sic-panel,
  #sic-log-panel {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    max-height: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
  }
}
