:root {
    --cx-bg: #edf3f9;
    --cx-bg-alt: #f7fbff;
    --cx-surface: #ffffff;
    --cx-surface-soft: #f5f9fd;
    --cx-line: #d7e1eb;
    --cx-line-strong: #c2cfdd;
    --cx-text: #172b3d;
    --cx-muted: #66788c;
    --cx-accent: #2f6fb7;
    --cx-accent-soft: rgba(47, 111, 183, 0.12);
    --cx-success: #287448;
    --cx-danger: #c53a2f;
    --cx-warn: #b7791f;
    --cx-shadow: 0 20px 56px rgba(20, 36, 56, 0.1);
    --cx-radius-xl: 26px;
    --cx-radius-lg: 18px;
    --cx-radius-md: 14px;
    --cx-radius-sm: 12px;
}

* {
    box-sizing: border-box;
}

body.cx-app-page {
    margin: 0;
    min-height: 100vh;
    font-family: "IBM Plex Sans", sans-serif;
    color: var(--cx-text);
    background:
        radial-gradient(circle at top left, rgba(47, 111, 183, 0.08), transparent 24%),
        linear-gradient(180deg, var(--cx-bg-alt) 0%, var(--cx-bg) 100%);
}

body.cx-app-page h1,
body.cx-app-page h2,
body.cx-app-page h3,
body.cx-app-page h4,
body.cx-app-page h5,
body.cx-app-page h6,
body.cx-app-page p {
    margin: 0;
}

body.cx-app-page p {
    color: var(--cx-muted);
    line-height: 1.6;
}

body.cx-app-page button,
body.cx-app-page input,
body.cx-app-page textarea,
body.cx-app-page select {
    font: inherit;
}

body.cx-app-page a {
    color: inherit;
}

.cx-app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.cx-shell-header {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 1.15rem 1.1rem 0.95rem;
    background: rgba(247, 251, 255, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(194, 207, 221, 0.6);
}

.cx-shell-header-top,
.cx-nav,
.cx-main {
    width: min(1440px, 100%);
    margin: 0 auto;
}

.cx-shell-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.cx-shell-brand {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.cx-sidebar-badge,
.cx-shell-eyebrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    border-radius: 999px;
    font-weight: 700;
}

.cx-sidebar-badge {
    padding: 0.72rem 0.95rem;
    background: linear-gradient(135deg, #2f6fb7, #4d8fd1);
    color: #ffffff;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.8rem;
    box-shadow: 0 12px 28px rgba(47, 111, 183, 0.2);
}

.cx-shell-eyebrow {
    padding: 0.28rem 0.55rem;
    background: var(--cx-accent-soft);
    color: var(--cx-accent);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 0.72rem;
}

.cx-shell-brand-copy h1 {
    margin-top: 0.5rem;
    font-size: clamp(2rem, 3vw, 2.9rem);
    line-height: 1.05;
    color: var(--cx-text);
}

.cx-shell-brand-copy p {
    margin-top: 0.45rem;
}

.cx-shell-header-actions {
    display: grid;
    gap: 0.8rem;
    justify-items: end;
}

.cx-topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(160px, 1fr));
    gap: 0.75rem;
}

.cx-topbar-card,
.cx-panel,
.cx-kpi-card,
.cx-suite-card,
.cx-list-item,
.cx-row-card,
.cx-detail-empty,
.cx-inline-stat {
    border: 1px solid var(--cx-line);
    border-radius: var(--cx-radius-xl);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(245, 249, 253, 0.98));
    box-shadow: var(--cx-shadow);
}

.cx-topbar-card {
    padding: 0.9rem 1rem;
}

.cx-topbar-card span {
    display: block;
    color: var(--cx-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.cx-topbar-card strong {
    display: block;
    margin-top: 0.4rem;
    color: var(--cx-text);
    font-size: 1rem;
}

.cx-shell-session {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.7rem;
}

.cx-role-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.cx-role-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.7rem;
    border-radius: 999px;
    background: var(--cx-accent-soft);
    color: var(--cx-accent);
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: capitalize;
}

.cx-nav {
    margin-top: 1rem;
    display: flex;
    gap: 0.7rem;
    overflow-x: auto;
    padding-bottom: 0.15rem;
}

.cx-nav button {
    flex: 0 0 auto;
    padding: 0.78rem 1rem;
    border: 1px solid var(--cx-line);
    border-radius: 999px;
    background: #ffffff;
    color: var(--cx-muted);
    font-weight: 600;
    cursor: pointer;
}

.cx-nav button.is-active {
    background: linear-gradient(135deg, #2f6fb7, #4d8fd1);
    border-color: transparent;
    color: #ffffff;
    box-shadow: 0 12px 24px rgba(47, 111, 183, 0.18);
}

.cx-nav button.is-locked {
    opacity: 0.48;
}

.cx-main {
    padding: 1.2rem 1.1rem 1.8rem;
}

.cx-page {
    display: none;
}

.cx-page.is-active {
    display: block;
}

.cx-page-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.cx-page-heading h3 {
    font-size: 1.55rem;
    color: var(--cx-text);
}

.cx-kpi-grid,
.cx-two-col,
.cx-three-col,
.cx-suite-grid {
    display: grid;
    gap: 1rem;
}

.cx-kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 1rem;
}

.cx-two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 1rem;
}

.cx-three-col,
.cx-suite-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 1rem;
}

.cx-panel,
.cx-kpi-card,
.cx-suite-card {
    padding: 1.1rem;
}

.cx-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.85rem;
    margin-bottom: 0.9rem;
}

.cx-panel-header h4 {
    color: var(--cx-text);
    font-size: 1rem;
}

.cx-kpi-card {
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.cx-kpi-label {
    color: var(--cx-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.8rem;
}

.cx-kpi-value {
    font-size: clamp(1.8rem, 3vw, 2.4rem);
    line-height: 1.1;
    color: var(--cx-text);
}

.cx-kpi-meta {
    color: var(--cx-muted);
    font-size: 0.92rem;
}

.cx-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

.cx-form-grid .cx-form-span {
    grid-column: 1 / -1;
}

.cx-form-grid label {
    display: grid;
    gap: 0.38rem;
}

.cx-form-grid label span {
    color: #42586d;
    font-size: 0.84rem;
    font-weight: 700;
}

.cx-form-grid input,
.cx-form-grid textarea,
.cx-form-grid select {
    width: 100%;
    min-height: 44px;
    padding: 0.78rem 0.88rem;
    border: 1px solid var(--cx-line-strong);
    border-radius: var(--cx-radius-sm);
    background: #ffffff;
    color: var(--cx-text);
}

.cx-form-grid input:focus,
.cx-form-grid textarea:focus,
.cx-form-grid select:focus {
    outline: none;
    border-color: rgba(47, 111, 183, 0.52);
    box-shadow: 0 0 0 4px rgba(47, 111, 183, 0.12);
}

.cx-form-grid textarea {
    min-height: 110px;
    resize: vertical;
}

.cx-primary-btn,
.cx-secondary-btn,
.cx-action-btn {
    border-radius: var(--cx-radius-sm);
    cursor: pointer;
    font-weight: 700;
}

.cx-primary-btn,
.cx-secondary-btn {
    min-height: 44px;
    padding: 0.78rem 1rem;
    border: 1px solid transparent;
}

.cx-primary-btn {
    background: linear-gradient(135deg, #2f6fb7, #4d8fd1);
    color: #ffffff;
}

.cx-secondary-btn {
    background: #ffffff;
    color: var(--cx-text);
    border-color: var(--cx-line);
}

.cx-list-stack {
    display: grid;
    gap: 0.75rem;
}

.cx-list-item,
.cx-row-card {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 0.95rem;
    border-radius: var(--cx-radius-lg);
}

.cx-list-item strong,
.cx-row-card strong {
    display: block;
    color: var(--cx-text);
    margin-bottom: 0.2rem;
}

.cx-list-item span,
.cx-row-card span {
    color: var(--cx-muted);
    font-size: 0.9rem;
}

.cx-table {
    width: 100%;
    border-collapse: collapse;
}

.cx-table th,
.cx-table td {
    text-align: left;
    padding: 0.8rem 0.7rem;
    border-bottom: 1px solid var(--cx-line);
    vertical-align: top;
}

.cx-table th {
    color: var(--cx-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.cx-table td {
    color: var(--cx-text);
}

.cx-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.66rem;
    border-radius: 999px;
    font-size: 0.82rem;
    text-transform: capitalize;
}

.cx-pill.is-good {
    background: rgba(40, 116, 72, 0.12);
    color: var(--cx-success);
}

.cx-pill.is-warn {
    background: rgba(183, 121, 31, 0.12);
    color: var(--cx-warn);
}

.cx-pill.is-risk {
    background: rgba(197, 58, 47, 0.12);
    color: var(--cx-danger);
}

.cx-table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.cx-action-btn {
    border: 1px solid var(--cx-line);
    background: var(--cx-surface-soft);
    color: var(--cx-text);
    padding: 0.55rem 0.7rem;
}

.cx-detail-empty {
    padding: 1rem;
    border-radius: var(--cx-radius-lg);
    background: var(--cx-surface-soft);
    border: 1px dashed var(--cx-line-strong);
    color: var(--cx-muted);
}

.cx-takeoff-detail-grid {
    display: grid;
    gap: 1rem;
}

.cx-inline-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.cx-inline-stat {
    padding: 0.7rem 0.8rem;
    border-radius: var(--cx-radius-md);
}

.cx-suite-card {
    min-height: 210px;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.cx-suite-card strong {
    font-size: 1rem;
    color: var(--cx-text);
}

.cx-suite-status {
    margin-top: auto;
    color: var(--cx-muted);
}

.cx-status-message {
    min-height: 1.25rem;
    margin-top: 0.25rem;
    color: var(--cx-accent);
    font-size: 0.92rem;
}

@media (max-width: 1280px) {
    .cx-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .cx-three-col,
    .cx-suite-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 1040px) {
    .cx-shell-header-top,
    .cx-page-heading {
        flex-direction: column;
    }

    .cx-shell-header-actions {
        width: 100%;
        justify-items: stretch;
    }

    .cx-topbar-actions,
    .cx-two-col,
    .cx-three-col,
    .cx-suite-grid,
    .cx-form-grid {
        grid-template-columns: 1fr;
    }

    .cx-shell-session {
        justify-content: flex-start;
    }
}

@media (max-width: 720px) {
    .cx-shell-header {
        padding: 0.9rem 0.65rem 0.85rem;
    }

    .cx-shell-header-top,
    .cx-nav,
    .cx-main {
        width: min(100%, calc(100% - 0.1rem));
    }

    .cx-main {
        padding: 0.9rem 0.65rem 1.2rem;
    }

    .cx-kpi-grid {
        grid-template-columns: 1fr;
    }

    .cx-panel,
    .cx-kpi-card,
    .cx-suite-card,
    .cx-topbar-card,
    .cx-list-item,
    .cx-row-card,
    .cx-detail-empty,
    .cx-inline-stat {
        border-radius: 20px;
    }

    .cx-list-item,
    .cx-row-card {
        flex-direction: column;
    }
}

/* ERP-style construction shell (thin top bars + compact icon rail) */
body.cx-app-page {
    background: #edf1f6;
}

.cx-app-shell {
    background: #edf1f6;
}

.cx-app-frame {
    min-height: 100vh;
    display: flex;
    align-items: stretch;
}

.cx-side-rail {
    width: 62px;
    background: #0b5ca6;
    border-right: 1px solid rgba(5, 33, 66, 0.2);
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    padding: 0.72rem 0.4rem;
    z-index: 40;
}

.cx-side-rail button {
    width: 42px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 700;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.cx-side-rail button:hover,
.cx-side-rail button.is-active {
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.cx-side-rail button.is-locked {
    opacity: 0.45;
}

.cx-workspace {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.cx-shell-header {
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 0;
    backdrop-filter: none;
    background: transparent;
    border-bottom: none;
}

.cx-shell-header-top {
    width: 100%;
    max-width: none;
    min-height: 44px;
    padding: 0.35rem 1rem;
    background: #ffffff;
    border-bottom: 1px solid #d2dbe8;
    align-items: center;
}

.cx-shell-brand {
    gap: 0.65rem;
    align-items: center;
}

.cx-sidebar-badge {
    min-width: 58px;
    padding: 0.35rem 0.45rem;
    border-radius: 6px;
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    box-shadow: none;
}

.cx-shell-eyebrow {
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: #5a6f88;
    letter-spacing: 0.04em;
    font-size: 0.62rem;
}

.cx-shell-brand-copy h1 {
    margin-top: 0.08rem;
    font-size: 1rem;
    line-height: 1.2;
    font-weight: 600;
    color: #1f2d3d;
}

.cx-shell-brand-copy p {
    margin-top: 0.08rem;
    font-size: 0.72rem;
    color: #5f7084;
}

.cx-shell-header-actions {
    gap: 0.35rem;
}

.cx-topbar-actions {
    gap: 0.45rem;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
}

.cx-topbar-card {
    border: none;
    box-shadow: none;
    border-radius: 0;
    background: transparent;
    padding: 0.15rem 0.4rem;
}

.cx-topbar-card span {
    font-size: 0.64rem;
    color: #6d7d92;
}

.cx-topbar-card strong {
    margin-top: 0.08rem;
    font-size: 0.76rem;
    color: #22334a;
}

.cx-shell-session {
    gap: 0.5rem;
}

.cx-role-badge {
    padding: 0.3rem 0.45rem;
    border-radius: 999px;
    font-size: 0.7rem;
}

.cx-secondary-btn {
    min-height: 30px;
    padding: 0.3rem 0.55rem;
    border-radius: 6px;
    border-color: #cdd8e5;
    font-size: 0.74rem;
}

.cx-nav {
    width: 100%;
    max-width: none;
    margin-top: 0;
    gap: 0.1rem;
    padding: 0.1rem 0.7rem;
    background: #0059a8;
    border-bottom: 1px solid #0a4e8f;
    overflow-x: auto;
}

.cx-nav button {
    padding: 0.45rem 0.7rem;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.76rem;
    font-weight: 600;
    box-shadow: none;
}

.cx-nav button:hover,
.cx-nav button.is-active {
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
}

.cx-main {
    width: 100%;
    max-width: none;
    padding: 0.8rem 0.8rem 1.2rem;
    overflow-y: auto;
}

.cx-panel,
.cx-kpi-card,
.cx-suite-card,
.cx-list-item,
.cx-row-card,
.cx-detail-empty,
.cx-inline-stat {
    border-radius: 8px;
    border: 1px solid #d8e0eb;
    background: #ffffff;
    box-shadow: none;
}

.cx-panel,
.cx-kpi-card,
.cx-suite-card {
    padding: 0.82rem;
}

.cx-kpi-card {
    min-height: 118px;
}

.cx-kpi-value {
    font-size: clamp(1.35rem, 2vw, 1.8rem);
}

.cx-table th,
.cx-table td {
    padding: 0.56rem 0.55rem;
}

@media (max-width: 1040px) {
    .cx-app-frame {
        flex-direction: column;
    }

    .cx-side-rail {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        justify-content: flex-start;
        overflow-x: auto;
        padding: 0.45rem 0.5rem;
        gap: 0.35rem;
    }

    .cx-side-rail button {
        width: auto;
        min-width: 46px;
        padding: 0 0.52rem;
    }
}
