/*
 * CGB CONTROL — mobile/tablet product system.
 * This layer is intentionally responsive-only: desktop composition remains intact.
 */
.topbar-mobile-brand,
.mobile-product-nav {
    display: none;
}

@media (max-width: 1100px) {
    :root {
        --cgb-mobile-navy: #062b46;
        --cgb-mobile-navy-deep: #031f35;
        --cgb-mobile-cyan: #11b7c8;
        --cgb-mobile-line: #dce8ef;
        --cgb-mobile-card: rgba(255, 255, 255, .97);
    }

    html {
        scroll-padding-top: 94px;
    }

    body.has-app-navigation.cgb-responsive-app {
        min-width: 0;
        background:
            radial-gradient(circle at 92% 4%, rgba(17, 183, 200, .2), transparent 22rem),
            linear-gradient(180deg, var(--cgb-mobile-navy) 0 250px, #eef5f8 520px, #eef5f8 100%);
    }

    body.has-app-navigation.cgb-responsive-app .page {
        min-width: 0;
        background: transparent;
    }

    body.has-app-navigation.cgb-responsive-app .topbar {
        min-height: 72px;
        border-bottom: 1px solid rgba(255, 255, 255, .12);
        background: linear-gradient(115deg, rgba(3, 31, 53, .98), rgba(5, 55, 82, .96));
        box-shadow: 0 12px 32px rgba(1, 24, 41, .16);
        color: #fff;
    }

    body.has-app-navigation.cgb-responsive-app .mobile-nav-toggle {
        border-color: rgba(255, 255, 255, .18);
        background: rgba(255, 255, 255, .08);
        box-shadow: none;
        color: #fff;
    }

    body.has-app-navigation.cgb-responsive-app .topbar-title-copy h1,
    body.has-app-navigation.cgb-responsive-app .topbar-title-copy .brand-kicker {
        color: #fff;
    }

    body.has-app-navigation.cgb-responsive-app .topbar-title-copy .brand-kicker {
        opacity: .68;
    }

    .topbar-mobile-brand {
        display: none;
        align-items: center;
        gap: 9px;
        color: #fff;
        font-size: 15px;
        font-weight: 900;
        letter-spacing: .035em;
        text-decoration: none;
        white-space: nowrap;
    }

    .topbar-mobile-brand img {
        width: 34px;
        height: 34px;
        border: 2px solid rgba(255, 255, 255, .16);
        border-radius: 50%;
        object-fit: cover;
        box-shadow: 0 0 0 3px rgba(17, 183, 200, .12);
    }

    .topbar-mobile-brand b {
        color: #2ad4df;
    }

    body.has-app-navigation.cgb-responsive-app .topbar-account-actions .btn {
        border-color: rgba(255, 255, 255, .18);
        background: rgba(255, 255, 255, .1);
        color: #fff;
    }

    body.has-app-navigation.cgb-responsive-app .page-content {
        width: min(100%, 1500px);
        margin: 0 auto;
        padding: 18px;
    }

    /* Cards keep a recognisable page hierarchy on tablet. */
    body.cgb-responsive-app .page-content :is(.panel-card, .hero-card, .module-card, .stat-card) {
        border-color: rgba(202, 221, 232, .92);
        box-shadow: 0 12px 30px rgba(6, 43, 70, .075);
    }

    /* Reusable dashboards remain dashboards: 2/3 columns instead of one long list. */
    body.cgb-responsive-app .page-content :is(
        .stats-grid,
        .billing-summary-stats,
        .billing-control-grid,
        .billing-decision-grid,
        .op2-kpi-grid,
        .direction-kpi-grid,
        .ecosystem-grid,
        .portal-kpi-grid,
        .cgb-kpis,
        .rt-kpis,
        .et-decision-grid,
        .vi-executive-grid
    ) {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    body.cgb-responsive-app .page-content :is(
        .billing-control-card-main,
        .hero-card
    ) {
        grid-column: 1 / -1;
    }

    /* Forms and controls use available tablet width instead of becoming a button list. */
    body.cgb-responsive-app .page-content :is(
        .company-form-grid,
        .filter-grid,
        .billing-entry-form,
        .op2-context,
        .provider-form-grid
    ) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body.cgb-responsive-app .page-content :is(.section-tabs, .workspace-tabs, .op2-tabs, .billing-client-nav, [role="tablist"]) {
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
        scroll-snap-type: x proximity;
    }

    body.cgb-responsive-app .page-content :is(.section-tabs, .workspace-tabs, .op2-tabs, .billing-client-nav, [role="tablist"])::-webkit-scrollbar {
        display: none;
    }

    body.cgb-responsive-app .page-content :is(.section-tabs, .workspace-tabs, .op2-tabs, .billing-client-nav, [role="tablist"]) > * {
        flex: 0 0 auto;
        scroll-snap-align: start;
    }

    body.cgb-responsive-app .table-wrap {
        border-radius: 14px;
        background: #fff;
    }

    /* Financial command area keeps contrast and hierarchy throughout tablet widths. */
    body.route-facturacion .billing-page-hero {
        display: grid;
        gap: 18px;
        padding: 22px;
        border: 1px solid rgba(255, 255, 255, .14);
        border-radius: 22px;
        background: linear-gradient(145deg, #07304d, #07566d);
        color: #fff;
    }

    body.route-facturacion .billing-page-hero :is(h2, .section-kicker, .muted-copy) {
        color: #fff;
    }

    body.route-facturacion .billing-page-hero .muted-copy {
        opacity: .78;
    }

    body.route-facturacion .billing-hero-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
        gap: 8px;
    }

    body.route-facturacion .billing-hero-actions .btn,
    body.route-facturacion .billing-hero-actions .btn:nth-child(3) {
        grid-column: auto;
    }

    body.route-facturacion .billing-hero-actions .btn:first-child {
        background: linear-gradient(135deg, #10b9c9, #08a9b7);
    }

    body.route-facturacion .billing-hero-actions .btn-soft {
        border-color: rgba(255, 255, 255, .2);
        background: rgba(255, 255, 255, .1);
        color: #fff;
    }
}

@media (max-width: 900px) {
    body.has-app-navigation.cgb-responsive-app .topbar {
        display: grid;
        grid-template-columns: 46px minmax(0, 1fr) auto;
        align-items: center;
    }

    body.has-app-navigation.cgb-responsive-app .topbar-mobile-brand {
        display: inline-flex;
        grid-column: 2;
        justify-self: start;
    }

    body.has-app-navigation.cgb-responsive-app .topbar-title-copy {
        display: none;
    }

    body.has-app-navigation.cgb-responsive-app .topbar-account-actions {
        grid-column: 3;
    }

    body.has-app-navigation.cgb-responsive-app .topbar-account-actions form {
        display: none;
    }

    body.has-app-navigation.cgb-responsive-app .topbar-account-actions .btn {
        min-height: 38px;
        padding: 8px 12px;
        font-size: 11px;
    }

    body.has-app-navigation.cgb-responsive-app .page-content {
        padding-bottom: calc(94px + env(safe-area-inset-bottom));
    }

    .mobile-product-nav {
        position: fixed;
        right: max(10px, env(safe-area-inset-right));
        bottom: max(9px, env(safe-area-inset-bottom));
        left: max(10px, env(safe-area-inset-left));
        z-index: 950;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        min-height: 67px;
        padding: 6px;
        border: 1px solid rgba(7, 46, 71, .12);
        border-radius: 22px;
        background: rgba(255, 255, 255, .96);
        box-shadow: 0 16px 42px rgba(2, 30, 50, .22);
        backdrop-filter: blur(18px);
    }

    .mobile-product-nav__item {
        display: flex;
        min-width: 0;
        min-height: 54px;
        padding: 6px 3px;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border: 0;
        border-radius: 16px;
        background: transparent;
        color: #62758a;
        font: inherit;
        font-size: 9px;
        font-weight: 850;
        line-height: 1.15;
        text-align: center;
        text-decoration: none;
        cursor: pointer;
    }

    .mobile-product-nav__item svg {
        width: 21px;
        height: 21px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.9;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .mobile-product-nav__item.is-active {
        background: linear-gradient(145deg, #e5fafa, #edf8fb);
        color: #009eae;
    }

    body.cgb-responsive-app .page-content :is(
        .stats-grid,
        .billing-summary-stats,
        .billing-control-grid,
        .billing-decision-grid,
        .op2-kpi-grid,
        .direction-kpi-grid,
        .ecosystem-grid,
        .portal-kpi-grid,
        .cgb-kpis,
        .rt-kpis,
        .et-decision-grid,
        .vi-executive-grid
    ) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body.cgb-responsive-app .page-content :is(
        [class$="-kpis"],
        [class$="-kpi-grid"],
        [class$="-stats-grid"],
        [class$="-quick-grid"]
    ) {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    body.cgb-responsive-app .page-content :is(.billing-control-card-main, .hero-card) {
        grid-column: 1 / -1;
    }

    body.cgb-responsive-app .page-content :is(.section-head, .action-row, .table-actions) {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-start;
    }

    body.cgb-responsive-app .page-content :is(.action-row, .table-actions) {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body.cgb-responsive-app .page-content :is(.action-row, .table-actions) :is(.btn, form, form .btn) {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 760px) {
    html {
        scroll-padding-top: 80px;
    }

    body.has-app-navigation.cgb-responsive-app {
        background:
            radial-gradient(circle at 90% 2%, rgba(17, 183, 200, .24), transparent 18rem),
            linear-gradient(180deg, var(--cgb-mobile-navy-deep) 0 210px, #edf4f7 430px, #edf4f7 100%);
    }

    body.has-app-navigation.cgb-responsive-app .topbar {
        min-height: 64px;
        padding: 8px 12px;
        grid-template-columns: 42px minmax(0, 1fr);
        gap: 10px;
    }

    body.has-app-navigation.cgb-responsive-app .mobile-nav-toggle {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
        border-radius: 13px;
    }

    body.has-app-navigation.cgb-responsive-app .topbar-mobile-brand {
        justify-self: center;
        transform: translateX(-26px);
    }

    body.has-app-navigation.cgb-responsive-app .topbar-account-actions {
        display: none;
    }

    body.has-app-navigation.cgb-responsive-app .page-content {
        padding: 12px 12px calc(92px + env(safe-area-inset-bottom));
    }

    body.cgb-responsive-app .global-request-alert {
        margin-bottom: 12px;
        padding: 12px;
        border-radius: 15px;
    }

    body.cgb-responsive-app .global-request-alert b {
        display: none;
    }

    body.cgb-responsive-app .page-content :is(.panel-card, .hero-card, .module-card, .stat-card) {
        border-radius: 17px;
    }

    body.cgb-responsive-app .page-content :is(.panel-card, .hero-card) {
        padding: 15px;
    }

    body.cgb-responsive-app .page-content :is(.section-head, .billing-client-workspace > .section-head) {
        margin: -15px -15px 15px;
        padding: 15px;
    }

    body.cgb-responsive-app .page-content :is(h2, .hero-card h2) {
        font-size: clamp(25px, 8vw, 34px);
        line-height: 1.04;
    }

    body.cgb-responsive-app .page-content h3 {
        line-height: 1.16;
    }

    body.cgb-responsive-app .page-content :is(
        .stats-grid,
        .billing-summary-stats,
        .billing-control-grid,
        .billing-decision-grid,
        .op2-kpi-grid,
        .direction-kpi-grid,
        .ecosystem-grid,
        .portal-kpi-grid,
        .cgb-kpis,
        .rt-kpis,
        .et-decision-grid,
        .vi-executive-grid
    ) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
    }

    body.cgb-responsive-app .page-content :is(.stat-card, .billing-control-card, .op2-kpi) {
        min-height: 118px;
        padding: 14px;
    }

    body.cgb-responsive-app .page-content :is(.stat-card strong, .billing-control-card h3, .op2-kpi strong) {
        font-size: clamp(20px, 6vw, 25px);
    }

    body.cgb-responsive-app .page-content :is(
        .company-form-grid,
        .filter-grid,
        .billing-entry-form,
        .provider-form-grid
    ) {
        grid-template-columns: 1fr;
    }

    /* Billing gets a compact, app-like command surface. */
    body.route-facturacion .billing-page-hero {
        gap: 16px;
    }

    body.route-facturacion .billing-page-hero :is(h2, .section-kicker, .muted-copy) {
        color: #fff;
    }

    body.route-facturacion .billing-page-hero .muted-copy {
        opacity: .76;
    }

    body.route-facturacion .billing-hero-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    body.route-facturacion .billing-hero-actions .btn:first-child {
        grid-column: 1 / -1;
        background: linear-gradient(135deg, #10b9c9, #08a9b7);
    }

    body.route-facturacion .billing-hero-actions .btn:nth-child(n + 2) {
        grid-column: auto !important;
    }

    body.route-facturacion .billing-hero-actions .btn-soft {
        border-color: rgba(255, 255, 255, .2);
        background: rgba(255, 255, 255, .1);
        color: #fff;
    }

    body.route-facturacion .billing-control-card-main {
        min-height: 0;
    }

    body.route-facturacion .billing-attention-list {
        grid-template-columns: 1fr;
    }

    body.route-facturacion .billing-decision-block {
        padding: 13px;
    }

    /* Operational panel: compact controls, KPIs visible before long analysis. */
    body.route-operational-panel .op2-shell {
        gap: 10px;
    }

    body.route-operational-panel .op2-header {
        padding: 17px;
        border-radius: 18px;
        background: linear-gradient(145deg, #07304d, #07566d);
        color: #fff;
    }

    body.route-operational-panel .op2-header :is(h1, h2, p, span, strong) {
        color: inherit;
    }

    body.route-operational-panel .op2-header-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
    }

    body.route-operational-panel .op2-context {
        padding: 13px;
        border-radius: 16px;
    }

    body.route-operational-panel .op2-tabs {
        top: 64px;
        margin-inline: -12px;
        padding: 8px 12px;
        border-radius: 0;
        background: rgba(255, 255, 255, .96);
        box-shadow: 0 8px 18px rgba(5, 40, 64, .08);
    }

    body.route-operational-panel .op2-tech-grid,
    body.route-operational-panel .op2-reading-grid,
    body.route-operational-panel .op2-admin-grid,
    body.route-operational-panel .op2-finance-grid {
        padding: 12px;
    }

    body.route-operational-panel .op2-import-card {
        order: 90;
    }

    body.route-operational-panel .op2-planning-entry {
        order: 91;
    }

    /* Direction and Novedades already have strong heroes; retain them and compact their navigation. */
    body.route-direccion-cgb :is(.direction-tabs, .dirx-tabs),
    body.route-novedades-cgb :is(.sector-admin-nav, .sector-provider-nav) {
        position: sticky;
        top: 64px;
        z-index: 20;
        overflow-x: auto;
        scrollbar-width: none;
        box-shadow: 0 8px 18px rgba(5, 40, 64, .08);
    }

    body.route-direccion-cgb :is(
        .dirx-quick-grid,
        .dirx-kpis,
        .dirx-dimensions,
        .dirx-alerts,
        .dirx-trends,
        .dirx-client-grid,
        .dirx-decision-grid,
        .dirx-agenda-kpis
    ) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
    }

    body.route-direccion-cgb .dirx-quick {
        min-height: 118px;
        padding: 14px;
    }

    body.route-direccion-cgb .dirx-tabs {
        top: 64px;
        margin-inline: 0;
    }

    body.route-ecosistema-cgb :is(.eco-command-overview, .eco-command-module__facts),
    body.route-novedades-cgb :is(.sector-admin-kpi-grid, .sector-partner-stats--pro) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body.route-ecosistema-cgb .eco-command-overview__intro {
        grid-column: 1 / -1;
    }

    body.route-novedades-cgb :is(.sector-admin-nav, .sector-provider-nav) {
        display: flex;
        flex-wrap: nowrap;
    }

    body.route-novedades-cgb :is(.sector-admin-nav, .sector-provider-nav) > * {
        flex: 0 0 min(180px, 48vw);
    }

    /* Keep charts readable and horizontally contained. */
    body.cgb-responsive-app .page-content :is(.chart-card, .op2-chart-wrap, .observatory-chart, canvas, svg) {
        max-width: 100%;
    }

    body.cgb-responsive-app .page-content :is(.chart-card, .op2-chart-wrap) {
        overflow: hidden;
    }
}

@media (max-width: 430px) {
    .mobile-product-nav {
        right: 7px;
        bottom: max(7px, env(safe-area-inset-bottom));
        left: 7px;
        border-radius: 20px;
    }

    .mobile-product-nav__item {
        font-size: 8.5px;
    }

    body.cgb-responsive-app .page-content :is(.billing-control-card, .billing-decision-block, .stat-card, .op2-kpi) {
        overflow-wrap: anywhere;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mobile-product-nav,
    .mobile-product-nav__item {
        scroll-behavior: auto;
        transition: none;
    }
}
