/*
 * EL CABEZAL · POLISH DE PRODUCCIÓN
 * Correcciones finales de desbordamiento, densidad, controles e identidad.
 */

html,
body {
    width: 100%;
    max-width: 100%;
}

[hidden] {
    display: none !important;
}

body {
    overflow-x: clip;
}

img,
video,
canvas,
iframe {
    max-width: 100%;
}

button,
.btn,
input,
select,
textarea {
    min-width: 0;
}

button,
.btn {
    line-height: 1.25;
    text-align: center;
    overflow-wrap: anywhere;
}

p,
li,
dd,
td,
label,
.microcopy {
    overflow-wrap: anywhere;
}

.form-grid > *,
.admin-two-col > *,
.admin-grid-forms > *,
.settings-grid > *,
.cards-grid > * {
    min-width: 0;
}

/* Recuperación de sesión móvil sin afectar otros dispositivos. */
.login-card {
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.login-card[aria-busy="true"] {
    cursor: wait;
}

.login-device-help {
    border: 1px solid rgba(30,30,70,.12);
    border-radius: 12px;
    background: rgba(30,30,70,.035);
    padding: .7rem;
    color: var(--admin-text, #1e293b);
}

.login-device-help summary {
    cursor: pointer;
    font-size: .72rem;
    font-weight: 800;
}

.login-device-help p {
    margin: .6rem 0;
    color: var(--admin-text-muted, #64748b);
    font-size: .66rem;
    line-height: 1.55;
}

.login-device-help .btn {
    width: 100%;
    margin-bottom: .55rem;
}

#login-device-diagnostic {
    display: block;
    color: var(--admin-success, #16a34a);
    font-size: .58rem;
    line-height: 1.45;
}

#login-device-diagnostic[data-tone="warning"] {
    color: var(--admin-warning, #b45309);
}

/* Identidad pública sincronizada */
.brand-mark {
    display: inline-flex;
    min-width: 0;
    max-width: min(270px, 34vw);
    gap: .55rem;
    align-items: center;
}

.brand-logo-img {
    display: block;
    width: auto;
    max-width: clamp(108px, 16vw, 210px);
    max-height: 46px;
    object-fit: contain;
}

.brand-text-label {
    min-width: 0;
    overflow: hidden;
    color: inherit;
    font: 800 clamp(.68rem, 1.1vw, .86rem)/1.15 var(--button-font);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.intro-logo-mark {
    gap: .75rem;
    text-align: center;
}

.intro-brand-text {
    display: block;
    font-size: clamp(1.4rem, 5vw, 2.7rem) !important;
}

/* El bloque azul de la guía deja de comportarse como una portada gigante. */
.cabezal-guide-book {
    width: min(100%, 560px) !important;
    min-height: 0 !important;
    margin: .8rem 0 1rem !important;
    justify-items: start !important;
}

.cabezal-guide-book .guide-book-cover {
    width: min(100%, 430px) !important;
    min-height: 92px;
    aspect-ratio: auto !important;
    grid-template-columns: minmax(0, 1fr) auto;
    align-content: center;
    align-items: center;
    gap: .5rem 1rem;
    margin: 0 !important;
    padding: .85rem 1rem !important;
    border-radius: 16px;
    text-align: left;
    box-shadow: 7px 7px 0 rgba(30,30,70,.1), 0 14px 34px rgba(30,30,70,.13);
}

.cabezal-guide-book .guide-book-cover span {
    font-size: clamp(1.2rem, 3.2vw, 1.8rem);
    line-height: .98;
}

.cabezal-guide-book .guide-book-cover small {
    max-width: 9rem;
    font-size: .62rem;
    line-height: 1.3;
    text-align: right;
}

.cabezal-guide-book .guide-book-pages {
    width: min(100%, 520px) !important;
    margin-inline: 0 !important;
}

.hero-actions,
.form-actions {
    gap: .65rem;
}

.hero-actions .btn {
    min-height: 44px;
    margin: 0;
}

.quote-table-wrap,
.table-wrap {
    max-width: 100%;
    overscroll-behavior-x: contain;
    scrollbar-gutter: stable;
}

/* Panel: menos bloque azul, más área útil y densidad consistente. */
body.admin-body {
    grid-template-columns: 272px minmax(0, 1fr);
}

.admin-sidebar {
    width: 272px;
    height: 100dvh;
    padding: .75rem;
    gap: .48rem;
    overflow-x: hidden;
}

.admin-brand {
    min-height: 48px;
    margin-bottom: .1rem;
    padding: .42rem .5rem;
}

.admin-sidebar .brand-mark {
    flex: 0 1 auto;
    max-width: 138px;
    overflow: hidden;
    font-size: 1.38rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-brand-logo {
    display: block;
    width: auto;
    max-width: 116px;
    max-height: 34px;
    object-fit: contain;
}

.admin-sidebar .brand-mark span {
    overflow: hidden;
    font-size: .56rem !important;
    text-overflow: ellipsis;
}

.admin-app-groups {
    gap: .2rem;
    padding: .22rem;
    border-radius: 12px;
}

.admin-app-group {
    min-height: 42px;
    padding: .28rem .12rem;
}

.admin-app-group small {
    font-size: .45rem;
}

.admin-app-page-head {
    padding: .42rem .25rem .5rem;
}

.admin-app-grid {
    gap: .36rem;
}

.admin-sidebar .admin-tab {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: .45rem !important;
    min-height: 51px;
    padding: .4rem !important;
    border-radius: 12px !important;
    font-size: .56rem !important;
}

.admin-sidebar .admin-tab span {
    width: 34px !important;
    height: 34px;
    border-radius: 10px;
    font-size: .92rem !important;
}

.admin-sidebar-assistant {
    gap: .48rem;
    padding: .52rem;
    border-radius: 12px;
}

.admin-sidebar-assistant > span {
    width: 34px;
    height: 34px;
    border-radius: 10px;
}

.admin-sidebar-assistant strong {
    font-size: .58rem;
}

.admin-sidebar-assistant small {
    font-size: .45rem;
}

.admin-main {
    width: 100%;
    max-width: 1600px;
    min-width: 0;
    padding: clamp(1rem, 2.2vw, 1.75rem);
    overflow-x: hidden;
}

.admin-context-appbar {
    min-width: 0;
    margin-bottom: 1rem;
    padding: .4rem;
    border-radius: 14px;
}

.admin-context-app {
    min-height: 36px;
    padding: .28rem .52rem .28rem .32rem;
}

.admin-context-app span {
    width: 25px;
    height: 25px;
}

.admin-heading {
    gap: .8rem 1rem;
    margin-bottom: 1rem;
}

.admin-heading > * {
    min-width: 0;
}

.admin-heading h1 {
    font-size: clamp(1.35rem, 2.5vw, 1.8rem);
    overflow-wrap: anywhere;
}

.admin-heading-actions,
.builder-studio-actions,
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .55rem;
}

.admin-body .btn {
    min-height: 40px;
    max-width: 100%;
    padding: .58rem .88rem;
    white-space: normal;
}

.admin-card {
    min-width: 0;
    padding: clamp(1rem, 1.8vw, 1.3rem);
}

.admin-card > *,
.admin-panel > *,
.admin-editor-body > *,
.form-stack > * {
    min-width: 0;
}

.admin-table th,
.admin-table td {
    max-width: 280px;
    overflow-wrap: anywhere;
}

.mini-row {
    min-width: 0;
}

.mini-row > div {
    min-width: 0;
}

.mini-row span {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.mini-row.media-mini-row {
    grid-template-columns: 52px minmax(0, 1fr) repeat(4, auto);
}

.media-list-controls {
    display: flex;
    flex: 1 1 320px;
    gap: .45rem;
    justify-content: flex-end;
}

.media-list-controls input,
.media-list-controls select {
    min-height: 40px;
    border: 1px solid var(--admin-border, rgba(30,30,70,.14));
    border-radius: 9px;
    background: rgba(255,255,255,.82);
    padding: .5rem .65rem;
    color: var(--admin-text, #1e293b);
    font: inherit;
    font-size: .72rem;
}

.media-list-controls input {
    min-width: min(210px, 100%);
}

.media-result-summary {
    margin: .6rem 0;
    padding: .55rem .7rem;
    border-radius: 9px;
    background: rgba(37,99,235,.07);
    color: var(--admin-text-muted);
    font-size: .62rem;
}

.builder-studio {
    gap: .8rem;
}

.builder-module-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: .58rem;
}

.builder-module-card {
    min-height: 132px;
    gap: .55rem;
    padding: .72rem;
}

.builder-module-card button,
.builder-row-actions button {
    white-space: normal;
}

.builder-live-preview {
    min-height: 460px;
    height: min(58vh, 620px);
}

.builder-page-nav,
.builder-subtabs,
.email-studio-tabs {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
}

.builder-page-chip,
.builder-subtab,
.email-studio-tabs button {
    flex: 0 0 auto;
    white-space: normal;
}

/* Editor profesional para los tres recursos de identidad. */
.identity-settings-shell {
    grid-column: 1 / -1;
    display: grid;
    gap: 1rem;
    padding: clamp(1rem, 2vw, 1.35rem);
    border: 1px solid rgba(30,30,70,.11);
    border-radius: 16px;
    background: rgba(255,255,255,.58);
}

.identity-settings-head,
.identity-display-controls,
.identity-asset-head {
    display: flex;
    gap: .8rem 1rem;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.identity-settings-head h2,
.identity-asset-head h3,
.identity-settings-head p,
.identity-asset-head p {
    margin: 0;
}

.identity-display-controls {
    justify-content: flex-start;
    padding: .75rem;
    border-radius: 12px;
    background: rgba(30,30,70,.045);
}

.identity-display-controls > label:first-child {
    flex: 0 1 260px;
}

.identity-assets-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .75rem;
}

.identity-asset-card {
    display: grid;
    min-width: 0;
    gap: .72rem;
    align-content: start;
    padding: .85rem;
    border: 1px solid rgba(30,30,70,.1);
    border-radius: 14px;
    background: rgba(255,255,255,.75);
}

.identity-asset-card [data-identity-source-panel] {
    display: none;
}

.identity-asset-card[data-source="upload"] [data-identity-source-panel="upload"],
.identity-asset-card[data-source="url"] [data-identity-source-panel="url"],
.identity-asset-card[data-source="library"] [data-identity-source-panel="library"] {
    display: grid;
}

.identity-preview {
    display: grid;
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
    place-items: center;
    overflow: hidden;
    border: 1px solid rgba(30,30,70,.12);
    border-radius: 15px;
    background:
        linear-gradient(45deg, rgba(30,30,70,.04) 25%, transparent 25%) 0 0 / 12px 12px,
        linear-gradient(45deg, transparent 75%, rgba(30,30,70,.04) 75%) 6px 6px / 12px 12px,
        #fff;
    color: var(--admin-text-muted);
    font-size: .52rem;
    text-align: center;
}

.identity-preview-logo {
    width: 92px;
}

.identity-preview img {
    width: 100%;
    height: 100%;
    padding: .35rem;
    object-fit: contain;
}

.identity-preview-app_icon img {
    border-radius: 14px;
}

.assistant-knowledge-row,
.email-campaign-row {
    min-width: 0;
}

.assistant-knowledge-row > *,
.email-campaign-row > * {
    min-width: 0;
}

/* Navegación semántica: fondo claro, jerarquía legible e iconos que sí describen cada app. */
.admin-icon-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    pointer-events: none;
}

.admin-sidebar {
    border-right: 1px solid rgba(30,30,70,.1);
    background:
        radial-gradient(circle at 15% 0, rgba(79,105,190,.1), transparent 30%),
        rgba(250,251,254,.97);
    color: #1e293b;
    box-shadow: 12px 0 34px rgba(30,30,70,.07);
    -webkit-backdrop-filter: blur(24px) saturate(120%);
    backdrop-filter: blur(24px) saturate(120%);
}

.admin-sidebar svg,
.admin-context-appbar svg {
    width: 1.1rem;
    height: 1.1rem;
    overflow: visible;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.admin-brand {
    border: 1px solid rgba(30,30,70,.09);
    border-radius: 14px;
    background: #fff;
    color: #1e1e46;
    box-shadow: 0 8px 24px rgba(30,30,70,.07);
}

.admin-brand-copy small {
    color: #64748b;
}

.admin-app-groups {
    border-color: rgba(30,30,70,.09);
    background: #eef1f7;
}

.admin-app-group {
    color: #64748b;
}

.admin-app-group span {
    display: grid;
    place-items: center;
}

.admin-app-group span svg {
    width: 1rem;
    height: 1rem;
}

.admin-app-group small {
    font-size: .52rem;
}

.admin-app-group:hover {
    background: rgba(255,255,255,.76);
    color: #253a76;
}

.admin-app-group.active {
    background: #fff;
    color: #253a76;
    box-shadow: 0 6px 16px rgba(30,30,70,.09), inset 0 0 0 1px rgba(57,83,164,.1);
}

.admin-app-pages {
    scrollbar-color: rgba(30,30,70,.18) transparent;
}

.admin-app-page-head strong {
    color: #1e293b;
    font-size: .76rem;
}

.admin-app-page-head small,
.admin-app-page-head > span {
    color: #64748b;
}

.admin-app-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: .42rem;
}

.admin-sidebar .admin-tab {
    grid-template-columns: 38px minmax(0, 1fr);
    min-height: 54px;
    padding: .45rem .52rem !important;
    border: 1px solid rgba(30,30,70,.085) !important;
    background: rgba(255,255,255,.88) !important;
    color: #334155 !important;
    font-size: .64rem !important;
    box-shadow: 0 5px 15px rgba(30,30,70,.045) !important;
}

.admin-sidebar .admin-tab > span:first-child {
    width: 38px !important;
    height: 38px;
    border: 0;
    border-radius: 11px;
    color: #fff;
    background: linear-gradient(145deg, #506fc9, #2c438c);
    box-shadow: 0 6px 14px rgba(44,67,140,.22), inset 0 1px 0 rgba(255,255,255,.28);
}

.admin-sidebar .admin-tab > span:first-child svg {
    width: 1.14rem;
    height: 1.14rem;
}

.admin-sidebar .admin-tab span.admin-tab-copy {
    display: grid !important;
    width: auto !important;
    height: auto;
    min-width: 0;
    gap: .08rem;
    border: 0;
    border-radius: 0;
    background: transparent !important;
    color: inherit !important;
    text-align: left;
    box-shadow: none !important;
}

.admin-tab-copy strong {
    overflow: hidden;
    font-size: .7rem;
    line-height: 1.22;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-tab-copy small {
    overflow: hidden;
    color: #64748b;
    font-size: .58rem;
    font-weight: 650;
    line-height: 1.22;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-sidebar .admin-tab[data-tab="crm"] > span:first-child,
.admin-sidebar .admin-tab[data-tab="subscribers"] > span:first-child {
    background: linear-gradient(145deg, #239b83, #11645f);
}

.admin-sidebar .admin-tab[data-tab="gifts"] > span:first-child,
.admin-sidebar .admin-tab[data-tab="assistant"] > span:first-child {
    background: linear-gradient(145deg, #a95bc1, #60419e);
}

.admin-sidebar .admin-tab[data-tab="magazines"] > span:first-child,
.admin-sidebar .admin-tab[data-tab="news"] > span:first-child {
    background: linear-gradient(145deg, #db765d, #9a4051);
}

.admin-sidebar .admin-tab[data-tab="brand"] > span:first-child,
.admin-sidebar .admin-tab[data-tab="headers"] > span:first-child,
.admin-sidebar .admin-tab[data-tab="templates"] > span:first-child {
    background: linear-gradient(145deg, #d49b2f, #a25e20);
}

.admin-sidebar .admin-tab:hover {
    border-color: rgba(57,83,164,.2) !important;
    background: #fff !important;
    color: #1e1e46 !important;
}

.admin-sidebar .admin-tab.active {
    border-color: rgba(57,83,164,.34) !important;
    background: #eef2ff !important;
    color: #172554 !important;
    box-shadow: 0 8px 20px rgba(42,62,124,.1), inset 3px 0 #405ba8 !important;
}

.admin-sidebar .admin-tab.active > span:first-child {
    box-shadow: 0 8px 18px rgba(32,62,179,.27), inset 0 1px 0 rgba(255,255,255,.32);
}

.admin-sidebar-assistant {
    border-color: rgba(104,64,174,.17);
    background: linear-gradient(135deg, #faf5ff, #eef2ff);
    color: #38246d;
    box-shadow: 0 8px 22px rgba(65,49,122,.08);
}

.admin-sidebar-assistant > span {
    color: #fff;
    font-family: inherit !important;
}

.admin-sidebar-assistant > span svg {
    width: 1.08rem;
    height: 1.08rem;
}

.admin-sidebar-assistant small {
    color: #6b7280;
    font-size: .54rem;
}

.admin-sidebar-assistant strong {
    font-size: .64rem;
}

.admin-sidebar .admin-logout {
    border-color: rgba(30,30,70,.12);
    background: #fff;
    color: #334155;
}

.admin-context-app span {
    display: grid;
    place-items: center;
}

.admin-context-app span svg {
    width: .8rem;
    height: .8rem;
}

.assistant-metrics-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.assistant-glossary-shell {
    margin-bottom: 1rem;
}

.assistant-glossary-shell > .form-title-row {
    align-items: flex-start;
}

.assistant-glossary-shell .admin-heading-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

#assistant-glossary-search {
    width: min(260px, 100%);
    min-height: 40px;
}

.assistant-glossary-row small {
    display: block;
    margin-top: .28rem;
    color: #64748b;
    font-size: .52rem;
    line-height: 1.4;
}

/* Respaldo blanco proporcional para logos e imágenes oscuras. */
.admin-asset-backplate {
    box-sizing: border-box;
    padding: var(--asset-plate-pad, .35rem) !important;
    border: 1px solid rgba(30,30,70,.1);
    border-radius: min(14px, var(--asset-plate-radius, 10px));
    background: #fff !important;
    box-shadow: 0 5px 16px rgba(30,30,70,.06);
    object-fit: contain;
}

/* Corrección selectiva aplicada sólo cuando el contraste calculado es insuficiente. */
.admin-force-light-surface {
    border-color: rgba(30,30,70,.1) !important;
    background: #fff !important;
    color: #1e293b !important;
}

.admin-force-light-surface :is(h1,h2,h3,h4,p,span,small,label,legend,summary):not(.btn):not(button) {
    color: inherit;
}

.admin-force-dark-text {
    color: #172033 !important;
}

@media (max-width: 1180px) {
    .identity-assets-grid {
        grid-template-columns: 1fr;
    }

    .identity-asset-head {
        justify-content: flex-start;
    }

    .assistant-metrics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 980px) {
    body.admin-body {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        width: min(272px, 88vw);
    }

    .builder-live-preview {
        min-height: 320px;
        height: min(50vh, 460px);
    }
}

@media (max-width: 640px) {
    .site-header .brand-mark {
        max-width: 54vw;
    }

    .brand-logo-img {
        max-width: min(150px, 48vw);
        max-height: 38px;
    }

    .brand-mode-combined .brand-text-label {
        display: none;
    }

    .cabezal-guide-book {
        width: 100% !important;
    }

    .cabezal-guide-book .guide-book-cover {
        grid-template-columns: minmax(0, 1fr);
        min-height: 82px;
    }

    .cabezal-guide-book .guide-book-cover small {
        text-align: left;
    }

    .admin-main {
        padding: .75rem;
        padding-bottom: calc(6.5rem + env(safe-area-inset-bottom));
    }

    .admin-heading-actions,
    .builder-studio-actions,
    .form-actions {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }

    .admin-heading-actions .btn,
    .builder-studio-actions .btn,
    .form-actions .btn {
        width: 100%;
    }

    .mini-row,
    .mini-row.media-mini-row {
        grid-template-columns: 44px minmax(0, 1fr);
        gap: .45rem;
    }

    .mini-row:not(.media-mini-row) {
        grid-template-columns: minmax(0, 1fr);
    }

    .mini-row button,
    .mini-row.media-mini-row button {
        grid-column: auto;
        width: 100%;
    }

    .mini-row.media-mini-row button:first-of-type {
        grid-column: 1 / -1;
    }

    .media-list-controls {
        display: grid;
        grid-template-columns: 1fr;
        flex-basis: 100%;
    }

    .media-list-controls input,
    .media-list-controls select {
        width: 100%;
    }

    .builder-page-nav,
    .builder-subtabs {
        display: flex;
        flex-wrap: nowrap;
    }

    .builder-page-chip,
    .builder-subtab {
        width: auto;
        min-width: 118px;
    }

    .project-subtabs {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        overflow-x: visible;
    }

    .project-subtabs .builder-subtab {
        width: 100%;
        min-width: 0;
        padding-inline: .35rem;
    }

    .builder-live-preview {
        min-height: 260px;
        height: 44vh;
    }

    .identity-settings-head,
    .identity-display-controls {
        align-items: stretch;
    }

    .identity-settings-head .btn,
    .identity-display-controls > * {
        width: 100%;
    }

    .identity-asset-card {
        padding: .75rem;
    }

    .assistant-knowledge-actions,
    .email-campaign-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .assistant-metrics-grid {
        grid-template-columns: 1fr;
    }
}

@supports not (overflow: clip) {
    body {
        overflow-x: hidden;
    }
}
