/* CKY_LAYOUT_STRUCTURE_FIX_V1
   Repairs page-axis layout, public-page shells, modal/contact stacking,
   restricted-account isolation and mobile operations navigation.
   This file intentionally changes presentation only. */

html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body.cky-dashboard-page,
body.cky-public-page {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    overflow-x: hidden;
}

/* Dashboard pages: keep the dashboard and legal footer on one vertical axis. */
.cky-dashboard-page > .dashboard {
    flex: 0 0 auto;
    width: min(900px, 100%);
    max-width: 900px;
    min-width: 0;
}

.cky-dashboard-page > .cky-ops-footer {
    flex: 0 0 auto;
    width: min(900px, 100%);
    max-width: 900px;
    margin: 18px auto 28px;
    padding: 14px 10px;
}

.cky-dashboard-page .cky-platform-links {
    justify-content: center;
    max-width: 100%;
}

.cky-dashboard-page .cky-dashboard-topbar .cky-logout-button {
    background: #64748b;
    color: #fff;
    padding: 8px 12px;
    border: 0;
}

.cky-dashboard-page .cky-dashboard-topbar .cky-logout-button:hover {
    background: #475569;
}

/* Prevent the floating contact widget from covering application modals. */
.cky-dashboard-page .modal {
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    padding: 16px;
    z-index: 12000 !important;
}

.cky-dashboard-page .modal-content {
    position: relative;
    z-index: 12001;
    width: min(100%, 430px) !important;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
}

.cky-dashboard-page .cky-contact-widget,
.cky-public-page .cky-contact-widget,
.cky-restricted-page .cky-contact-widget {
    z-index: 6000 !important;
}

body:has(.modal[style*="display: flex"]) .cky-contact-widget {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Public platform pages: header and content share the same centered column. */
.cky-public-page {
    padding: 20px;
}

.cky-public-page > .cky-dashboard-topbar,
.cky-public-page > .cky-legal-shell,
.cky-public-page > .cky-case-shell,
.cky-public-page > .cky-promotion-shell {
    width: min(980px, 100%);
    max-width: 980px;
    min-width: 0;
    margin-left: auto;
    margin-right: auto;
}

.cky-public-page > .cky-dashboard-topbar {
    flex: 0 0 auto;
    margin-top: 0;
    margin-bottom: 16px;
}

.cky-public-page > .cky-legal-shell,
.cky-public-page > .cky-case-shell,
.cky-public-page > .cky-promotion-shell {
    flex: 0 0 auto;
    margin-top: 0;
    margin-bottom: 42px;
}

.cky-public-page .cky-public-card,
.cky-public-page .cky-legal-body,
.cky-public-page .cky-case-response,
.cky-public-page td,
.cky-public-page th {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.cky-public-page .cky-public-card h1 {
    font-size: clamp(1.65rem, 5vw, 2.25rem);
    line-height: 1.15;
}

.cky-public-page .cky-public-card h2 {
    font-size: clamp(1.25rem, 3.6vw, 1.65rem);
}

.cky-public-page .cky-lang-always {
    display: block !important;
}

.cky-public-page .cky-promotion-history {
    min-width: 640px;
}

/* Account-restricted page must not inherit the interactive registration card. */
body.cky-restricted-page {
    width: 100%;
    min-height: 100vh;
    display: grid !important;
    place-items: center !important;
    padding: 20px;
    background: #f8fafc;
    overflow-x: hidden;
}

.cky-restricted-card {
    width: min(100%, 560px);
    max-width: 560px;
    margin: 0;
    padding: 32px;
    border: 1px solid #e2e8f0;
    border-top: 6px solid #dc2626;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 16px 50px rgba(15, 23, 42, .12);
    cursor: default;
    transform: none;
}

.cky-restricted-card:hover {
    border-color: #e2e8f0;
    border-top-color: #dc2626;
    background: #fff;
    transform: none;
    box-shadow: 0 16px 50px rgba(15, 23, 42, .12);
}

.cky-restricted-card .cky-platform-links {
    margin-top: 18px;
}

/* Operations admin: eliminate duplicated mobile navigation and make wide data safe. */
.cky-admin-ops-page {
    display: block !important;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.cky-admin-ops-page .table-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
}

.cky-admin-ops-page .table-scroll table {
    margin: 0;
}

@media (max-width: 760px) {
    body.cky-dashboard-page,
    body.cky-public-page {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .cky-dashboard-page > .dashboard,
    .cky-dashboard-page > .cky-ops-footer {
        width: 100%;
        max-width: 100%;
    }

    .cky-dashboard-page .cky-ops-quick-actions {
        display: flex;
        flex-wrap: nowrap;
        gap: 8px;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        padding: 1px 1px 5px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .cky-dashboard-page .cky-ops-quick-actions::-webkit-scrollbar {
        display: none;
    }

    .cky-dashboard-page .cky-ops-quick-actions .cky-ops-action-link {
        flex: 0 0 auto;
        min-height: 40px;
        padding: 8px 11px;
        font-size: .82rem;
        white-space: nowrap;
    }

    .cky-dashboard-page .cky-contact-widget,
    .cky-public-page .cky-contact-widget,
    .cky-restricted-page .cky-contact-widget {
        left: auto !important;
        right: 16px !important;
        top: auto !important;
        bottom: calc(84px + env(safe-area-inset-bottom)) !important;
        transform: none !important;
    }

    .cky-dashboard-page .cky-contact-panel,
    .cky-public-page .cky-contact-panel,
    .cky-restricted-page .cky-contact-panel {
        left: 10px !important;
        right: 10px !important;
        bottom: calc(12px + env(safe-area-inset-bottom)) !important;
        width: auto !important;
    }

    .cky-dashboard-page {
        padding-bottom: calc(132px + env(safe-area-inset-bottom)) !important;
    }

    .cky-public-page {
        padding: 8px 8px calc(28px + env(safe-area-inset-bottom)) !important;
    }

    .cky-public-page > .cky-dashboard-topbar {
        width: 100%;
        margin-bottom: 10px;
        padding: 10px 11px;
        gap: 8px;
    }

    .cky-public-page > .cky-legal-shell,
    .cky-public-page > .cky-case-shell,
    .cky-public-page > .cky-promotion-shell {
        width: 100%;
        margin: 0 auto 28px;
    }

    .cky-public-page .cky-topbar-brand {
        flex: 1 1 auto;
        min-width: 0;
    }

    .cky-public-page .cky-topbar-actions {
        flex: 0 0 auto;
        gap: 6px;
    }

    .cky-public-page .cky-topbar-actions .cky-ops-action-link {
        min-height: 38px;
        padding: 7px 9px;
        font-size: .78rem;
        white-space: nowrap;
    }

    .cky-public-page .cky-public-card {
        padding: 16px;
        border-radius: 14px;
    }

    .cky-public-page .cky-case-meta,
    .cky-public-page .cky-case-grid,
    .cky-public-page .cky-promotion-plans {
        grid-template-columns: 1fr;
    }

    .cky-public-page .cky-platform-links {
        justify-content: center;
        gap: 8px 12px;
        padding: 4px 6px;
    }

    .cky-restricted-card {
        padding: 24px 18px;
    }

    .cky-admin-ops-page .topbar {
        position: relative;
        flex-wrap: wrap;
        align-items: flex-start;
        padding: 12px 14px;
    }

    .cky-admin-ops-page .topbar > div:last-child {
        width: 100%;
        display: flex !important;
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .cky-admin-ops-page .layout {
        display: block !important;
        min-height: 0;
    }

    .cky-admin-ops-page .sidebar {
        display: none !important;
    }

    .cky-admin-ops-page .main {
        padding: 12px;
    }

    .cky-admin-ops-page .ops-tabs {
        position: sticky;
        top: 0;
        z-index: 15;
        margin: 0 -12px 14px;
        padding: 9px 12px;
        background: rgba(241, 245, 249, .97);
        border-bottom: 1px solid #e2e8f0;
        backdrop-filter: blur(8px);
    }

    .cky-admin-ops-page .ops-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
    }

    .cky-admin-ops-page .ops-card {
        padding: 14px;
    }

    .cky-admin-ops-page table {
        min-width: 720px;
    }
}

@media (max-width: 380px) {
    .cky-public-page .cky-topbar-brand small {
        display: none;
    }

    .cky-public-page .cky-topbar-mark {
        flex-basis: 32px;
        width: 32px;
        height: 32px;
    }

    .cky-public-page .cky-lang-mobile select,
    .cky-public-page .cky-lang-always select {
        min-width: 58px;
        padding-left: 7px;
        padding-right: 21px;
    }

    .cky-public-page .cky-topbar-actions .cky-ops-action-link {
        max-width: 88px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .cky-admin-ops-page .ops-stats {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cky-dashboard-page .cky-contact-widget,
    .cky-public-page .cky-contact-widget,
    .cky-restricted-page .cky-contact-widget {
        transition: none !important;
    }
}
