:root {
    color-scheme: light;

    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f0f3f8;
    --text: #18202b;
    --muted: #667085;
    --border: #e3e8ef;
    --primary: #3157d5;
    --primary-strong: #2444ad;
    --danger: #b42318;

    --radius-sm: 12px;
    --radius-md: 18px;
    --radius-lg: 24px;

    --shadow:
        0 12px 36px rgba(20, 32, 56, 0.08);

    --topbar-height: 68px;
    --bottom-nav-height: 72px;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--bg);
}

body {
    margin: 0;

    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    color: var(--text);
    background: var(--bg);
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

a {
    color: inherit;
    text-decoration: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}


/* =========================================================
   MOBILE SHELL
   ========================================================= */

.app-shell {
    min-height: 100dvh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;

    height: var(--topbar-height);

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding:
        env(safe-area-inset-top)
        16px
        0;

    background:
        rgba(255, 255, 255, 0.94);

    border-bottom:
        1px solid var(--border);

    backdrop-filter:
        blur(16px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    width: 40px;
    height: 40px;

    display: grid;
    place-items: center;

    border-radius: 13px;

    background: var(--primary);
    color: white;

    font-weight: 800;
    letter-spacing: -0.04em;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.05;
}

.brand-copy strong {
    font-size: 0.98rem;
}

.brand-copy small {
    margin-top: 4px;

    color: var(--muted);
    font-size: 0.72rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 38px;
    height: 38px;

    display: grid;
    place-items: center;

    border-radius: 999px;

    background: var(--surface-soft);
    border: 1px solid var(--border);

    font-weight: 700;
}

.user-copy {
    display: flex;
    flex-direction: column;
}

.user-copy strong {
    max-width: 190px;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    font-size: 0.85rem;
}

.user-copy small {
    margin-top: 2px;

    color: var(--muted);
    font-size: 0.72rem;
}

.icon-button {
    min-width: 44px;
    min-height: 44px;

    display: inline-grid;
    place-items: center;

    padding: 8px;

    border: 1px solid var(--border);
    border-radius: var(--radius-sm);

    background: var(--surface);
    color: var(--text);

    font-size: 1.25rem;
}

.sidebar {
    position: fixed;

    top: var(--topbar-height);
    left: 0;
    bottom: var(--bottom-nav-height);

    z-index: 40;

    width: min(82vw, 300px);

    padding: 14px;

    background: var(--surface);
    border-right: 1px solid var(--border);

    transform: translateX(-105%);
    transition: transform 180ms ease;
}

.sidebar.is-open {
    transform: translateX(0);
}

.sidebar-nav {
    display: grid;
    gap: 6px;
}

.nav-item {
    width: 100%;
    min-height: 48px;

    display: flex;
    align-items: center;
    gap: 12px;

    padding: 0 14px;

    border: 0;
    border-radius: var(--radius-sm);

    background: transparent;
    color: var(--text);

    text-align: left;
}

.nav-item:hover,
.nav-item:focus-visible {
    background: var(--surface-soft);
}

.nav-item.is-active {
    background: #eaf0ff;
    color: var(--primary-strong);
    font-weight: 700;
}

.sidebar-footer {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 16px;

    display: flex;
    flex-direction: column;

    color: var(--muted);
}

.sidebar-footer small {
    margin-top: 3px;
}

.main-content {
    width: 100%;
    max-width: 1500px;

    margin: 0 auto;

    padding:
        24px
        16px
        calc(
            var(--bottom-nav-height)
            + 28px
            + env(safe-area-inset-bottom)
        );
}

.page-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;

    margin-bottom: 22px;
}

.eyebrow {
    margin: 0 0 7px;

    color: var(--primary);

    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.11em;
}

.page-heading h1 {
    margin: 0;

    font-size:
        clamp(
            1.65rem,
            8vw,
            2.4rem
        );

    letter-spacing: -0.04em;
}

.page-subtitle {
    max-width: 600px;

    margin:
        8px 0 0;

    color: var(--muted);

    line-height: 1.5;
}

.primary-button,
.secondary-button {
    min-height: 46px;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    padding: 0 18px;

    border-radius: 13px;

    font-weight: 700;
}

.primary-button {
    border: 1px solid var(--primary);
    background: var(--primary);
    color: white;
}

.primary-button:hover,
.primary-button:focus-visible {
    background: var(--primary-strong);
}

.secondary-button {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.desktop-create {
    display: none;
}

.toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;

    margin-bottom: 18px;
}

.search-box {
    min-height: 48px;

    display: flex;
    align-items: center;
    gap: 9px;

    padding: 0 14px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.search-box input {
    width: 100%;

    padding: 0;

    border: 0;
    outline: 0;

    background: transparent;
    color: var(--text);
}

.search-icon {
    color: var(--muted);
}

.filter-control {
    min-height: 48px;

    padding: 0 14px;

    border: 1px solid var(--border);
    border-radius: var(--radius-sm);

    background: var(--surface);
    color: var(--text);
}

.paper-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

.paper-card {
    overflow: hidden;

    border: 1px solid var(--border);
    border-radius: var(--radius-md);

    background: var(--surface);

    box-shadow:
        0 4px 14px rgba(20, 32, 56, 0.04);
}

.paper-preview {
    position: relative;

    aspect-ratio: 16 / 10;

    display: grid;
    place-items: center;

    overflow: hidden;

    background:
        linear-gradient(
            135deg,
            #eef2ff,
            #f7f8fc
        );
}

.paper-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.paper-placeholder {
    color: var(--muted);
    font-size: 2rem;
}

.paper-card-body {
    padding: 14px;
}

.template-card-preview {
    min-height: 118px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;

    background:
        linear-gradient(
            135deg,
            #eef2ff,
            #f7f8fc
        );

    color: var(--primary);
}

.template-card-icon {
    font-size: 2rem;
    line-height: 1;
}

.template-card-preview strong {
    font-size: 0.72rem;
    letter-spacing: 0.12em;
}

.template-card-description {
    min-height: 2.8em;

    margin: 12px 0 0;

    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.4;
}

.paper-card h2 {
    margin: 0;

    font-size: 1rem;
    line-height: 1.3;
}

.paper-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;

    margin-top: 9px;
}

.status-badge,
.page-count {
    display: inline-flex;
    align-items: center;

    min-height: 26px;

    padding: 0 9px;

    border-radius: 999px;

    background: var(--surface-soft);

    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
}

.status-badge[data-status="published"] {
    background: #e9f8ef;
    color: #187a3d;
}

.status-badge[data-status="draft"] {
    background: #fff4df;
    color: #946200;
}

.card-actions {
    display: flex;
    gap: 8px;

    margin-top: 14px;
}

.card-actions a {
    flex: 1;
}

.loading-state,
.empty-state,
.error-state {
    min-height: 330px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    padding: 38px 20px;

    text-align: center;

    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
}

.loading-state p,
.empty-state p,
.error-state p {
    max-width: 480px;

    color: var(--muted);
    line-height: 1.55;
}

.empty-state h2,
.error-state h2 {
    margin-bottom: 4px;
}

.empty-illustration {
    width: 74px;
    height: 74px;

    display: grid;
    place-items: center;

    margin-bottom: 10px;

    border-radius: 22px;

    background: var(--surface-soft);

    font-size: 2rem;
}

.loading-spinner {
    width: 36px;
    height: 36px;

    border:
        3px solid var(--border);

    border-top-color:
        var(--primary);

    border-radius: 50%;

    animation:
        spin 700ms linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}


/* =========================================================
   MOBILE NAV
   ========================================================= */

.bottom-nav {
    position: fixed;

    left: 0;
    right: 0;
    bottom: 0;

    z-index: 35;

    min-height:
        calc(
            var(--bottom-nav-height)
            + env(safe-area-inset-bottom)
        );

    display: grid;
    grid-template-columns:
        repeat(4, 1fr);

    padding:
        8px
        8px
        env(safe-area-inset-bottom);

    background:
        rgba(255, 255, 255, 0.97);

    border-top:
        1px solid var(--border);

    backdrop-filter:
        blur(16px);
}

.bottom-nav-item {
    min-height: 54px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    gap: 4px;

    border: 0;
    border-radius: 14px;

    background: transparent;
    color: var(--muted);
}

.bottom-nav-item.is-active {
    color: var(--primary);
}

.bottom-nav-item.create span {
    width: 32px;
    height: 32px;

    display: grid;
    place-items: center;

    border-radius: 50%;

    background: var(--primary);
    color: white;
}


/* =========================================================
   MODAL / MOBILE SHEET
   ========================================================= */

.modal-backdrop {
    position: fixed;
    inset: 0;

    z-index: 100;

    display: flex;
    align-items: flex-end;

    padding: 0;

    background:
        rgba(16, 24, 40, 0.42);
}

.modal-card {
    width: 100%;
    max-height: 92dvh;

    overflow-y: auto;

    padding:
        22px
        18px
        calc(
            20px
            + env(safe-area-inset-bottom)
        );

    background: var(--surface);

    border-radius:
        24px 24px 0 0;

    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 20px;

    margin-bottom: 18px;
}

.modal-header h2 {
    margin: 0;
}

.field {
    display: grid;
    gap: 7px;

    margin-bottom: 15px;
}

.field > span {
    font-size: 0.78rem;
    font-weight: 700;
}

.field input,
.field textarea,
.field select {
    width: 100%;

    padding: 12px 13px;

    border: 1px solid var(--border);
    border-radius: var(--radius-sm);

    background: var(--surface);
    color: var(--text);

    outline: none;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: var(--primary);

    box-shadow:
        0 0 0 3px
        rgba(49, 87, 213, 0.12);
}

.form-message {
    margin-bottom: 14px;

    padding: 11px 13px;

    border-radius: var(--radius-sm);

    background: #fef3f2;
    color: var(--danger);

    font-size: 0.85rem;
}

.modal-actions {
    display: grid;
    grid-template-columns:
        1fr 1fr;

    gap: 10px;

    margin-top: 20px;
}

.desktop-only {
    display: none;
}


/* =========================================================
   TABLET
   ========================================================= */

@media (min-width: 700px) {
    .main-content {
        padding:
            32px
            28px
            calc(
                var(--bottom-nav-height)
                + 30px
            );
    }

    .toolbar {
        grid-template-columns:
            minmax(280px, 1fr)
            190px;
    }

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

        gap: 18px;
    }

    .modal-backdrop {
        align-items: center;
        justify-content: center;

        padding: 24px;
    }

    .modal-card {
        max-width: 560px;

        padding: 26px;

        border-radius: var(--radius-lg);
    }

    .desktop-only {
        display: flex;
    }
}


/* =========================================================
   DESKTOP
   ========================================================= */

@media (min-width: 1050px) {
    :root {
        --sidebar-width: 235px;
    }

    .mobile-only,
    .bottom-nav {
        display: none;
    }

    .topbar {
        padding:
            0
            28px;
    }

    .sidebar {
        top: var(--topbar-height);
        bottom: 0;

        width: var(--sidebar-width);

        transform: none;
    }

    .main-content {
        max-width: none;

        margin-left:
            var(--sidebar-width);

        padding:
            38px
            38px
            50px;
    }

    .desktop-create {
        display: inline-flex;
    }

    .paper-grid {
        grid-template-columns:
            repeat(
                3,
                minmax(0, 1fr)
            );
    }
}


/* =========================================================
   LARGE DESKTOP
   ========================================================= */

@media (min-width: 1450px) {
    .paper-grid {
        grid-template-columns:
            repeat(
                4,
                minmax(0, 1fr)
            );
    }
}


/* =========================================================
   ACCESSIBILITY
   ========================================================= */

@media (
    prefers-reduced-motion:
    reduce
) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}


/* =========================================================
   DIGITAL PAPER WORKSPACE — MOBILE FIRST
   ========================================================= */

.workspace-shell {
    min-height: 100dvh;

    display: grid;

    grid-template-areas:
        "topbar"
        "canvas";

    grid-template-rows:
        auto 1fr;

    background: var(--bg);
}

.workspace-topbar {
    grid-area: topbar;

    position: sticky;
    top: 0;

    z-index: 50;

    min-height: 68px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 12px;

    padding:
        env(safe-area-inset-top)
        14px
        0;

    background:
        rgba(255, 255, 255, 0.96);

    border-bottom:
        1px solid var(--border);

    backdrop-filter:
        blur(16px);
}

.workspace-topbar-left,
.workspace-topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.workspace-title {
    min-width: 0;

    display: flex;
    flex-direction: column;
}

.workspace-title .eyebrow {
    margin-bottom: 2px;
}

.workspace-title strong {
    max-width: 42vw;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-pages,
.workspace-properties {
    display: none;
}

.workspace-canvas-area {
    grid-area: canvas;

    min-width: 0;

    padding-bottom:
        calc(
            76px
            + env(safe-area-inset-bottom)
        );
}

.workspace-canvas-toolbar {
    min-height: 54px;

    display: flex;
    align-items: center;
    gap: 7px;

    overflow-x: auto;

    padding: 8px 12px;

    background: var(--surface);

    border-bottom:
        1px solid var(--border);
}

.tool-button {
    flex: 0 0 auto;

    min-height: 38px;

    padding: 0 13px;

    border:
        1px solid var(--border);

    border-radius: 10px;

    background:
        var(--surface);

    color: var(--text);
}

.canvas-stage-wrap {
    min-height:
        calc(
            100dvh
            - 68px
            - 54px
            - 76px
        );

    display: grid;
    place-items: center;

    padding: 0;
}

.canvas-stage {
    width: 100%;
    max-width: 1100px;

    /* DPaper canonical Builder surface: 960 x 540. */
    aspect-ratio: 16 / 9;

    display: grid;
    place-items: center;

    overflow: hidden;

    background: white;

    border:
        1px solid var(--border);

    border-radius:
        var(--radius-md);

    box-shadow:
        0 12px 34px
        rgba(20, 32, 56, 0.10);
}

.canvas-stage-placeholder {
    max-width: 560px;

    padding: 24px;

    text-align: center;
}

.canvas-stage-icon {
    width: 64px;
    height: 64px;

    display: grid;
    place-items: center;

    margin:
        0 auto 12px;

    border-radius: 20px;

    background:
        var(--surface-soft);

    color:
        var(--primary);

    font-size: 1.8rem;
}

.canvas-stage-placeholder h1 {
    margin: 0;

    font-size:
        clamp(
            1.3rem,
            6vw,
            2rem
        );
}

.canvas-stage-placeholder p {
    margin:
        8px 0 4px;

    color:
        var(--muted);
}

.canvas-stage-placeholder small {
    color:
        var(--muted);
}

.workspace-mobile-nav {
    position: fixed;

    left: 0;
    right: 0;
    bottom: 0;

    z-index: 60;

    min-height:
        calc(
            70px
            + env(safe-area-inset-bottom)
        );

    display: grid;

    grid-template-columns:
        repeat(4, 1fr);

    padding:
        6px
        8px
        env(safe-area-inset-bottom);

    background:
        rgba(255, 255, 255, 0.97);

    border-top:
        1px solid var(--border);

    backdrop-filter:
        blur(16px);
}

.workspace-mobile-nav-item {
    min-height: 56px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    gap: 3px;

    border: 0;

    border-radius:
        var(--radius-sm);

    background: transparent;

    color:
        var(--muted);
}

.workspace-mobile-nav-item.is-active {
    color:
        var(--primary);

    background:
        #eef2ff;
}


/* =========================================================
   TABLET WORKSPACE
   ========================================================= */

@media (min-width: 700px) {

    .workspace-shell {
        grid-template-areas:
            "topbar topbar"
            "pages canvas";

        grid-template-columns:
            190px minmax(0, 1fr);

        grid-template-rows:
            auto 1fr;
    }

    .workspace-pages {
        grid-area: pages;

        display: block;

        min-height:
            calc(
                100dvh
                - 68px
            );

        padding: 12px;

        background:
            var(--surface);

        border-right:
            1px solid var(--border);
    }

    .workspace-canvas-area {
        padding-bottom: 0;
    }

    .workspace-mobile-nav {
        display: none;
    }

    .canvas-stage-wrap {
        min-height:
            calc(
                100dvh
                - 68px
                - 54px
            );

        padding: 0;
    }
}


/* =========================================================
   DESKTOP WORKSPACE
   ========================================================= */

@media (min-width: 1100px) {

    .workspace-shell {
        grid-template-areas:
            "topbar topbar topbar"
            "pages canvas properties";

        grid-template-columns:
            220px
            minmax(0, 1fr)
            280px;

        grid-template-rows:
            auto 1fr;
    }

    .workspace-properties {
        grid-area: properties;

        display: block;

        min-height:
            calc(
                100dvh
                - 68px
            );

        padding: 14px;

        background:
            var(--surface);

        border-left:
            1px solid var(--border);
    }

    .workspace-panel-heading {
        min-height: 50px;

        display: flex;
        align-items: center;
        justify-content: space-between;

        gap: 10px;

        padding-bottom: 12px;

        border-bottom:
            1px solid var(--border);
    }

    .workspace-panel-heading > div {
        display: flex;
        flex-direction: column;
    }

    .workspace-page-list {
        padding-top: 12px;
    }

    .workspace-empty-mini,
    .workspace-page-placeholder {
        padding: 16px 10px;

        border:
            1px dashed
            var(--border);

        border-radius:
            var(--radius-sm);

        color:
            var(--muted);

        text-align: center;

        font-size: 0.82rem;
    }

    .properties-stack {
        display: grid;
        gap: 16px;

        padding-top: 14px;
    }

    .property-section {
        padding-bottom: 15px;

        border-bottom:
            1px solid var(--border);
    }

    .property-section h2 {
        margin:
            0 0 6px;

        font-size:
            0.85rem;
    }

    .property-section p {
        margin:
            0 0 10px;

        color:
            var(--muted);

        font-size:
            0.78rem;

        line-height:
            1.45;
    }

    .property-preview {
        width: 100%;

        min-height: 42px;

        border:
            1px solid
            var(--border);

        border-radius:
            11px;

        background:
            var(--surface-soft);
    }

    .property-chip-row {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .property-chip-row button {
        min-height: 34px;

        padding:
            0 10px;

        border:
            1px solid
            var(--border);

        border-radius:
            999px;

        background:
            var(--surface-soft);

        font-size:
            0.75rem;
    }
}


/* =========================================================
   LARGE DESKTOP WORKSPACE
   ========================================================= */

@media (min-width: 1450px) {

    .workspace-shell {
        grid-template-columns:
            250px
            minmax(0, 1fr)
            320px;
    }

    .canvas-stage-wrap {
        padding: 0;
    }
}


/* =========================================================
   8C — REAL PAGE MANAGEMENT
   ========================================================= */

.page-heading-status {
    min-width: 0;

    display: flex;
    align-items: baseline;
    gap: 5px;
}

.page-heading-status strong {
    flex: 0 0 auto;
}

.page-active-name {
    min-width: 0;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    color:
        var(--muted);

    font-size:
        0.72rem;

    font-weight: 700;
}


.workspace-page-list,
.mobile-page-list {
    display: grid;
    gap: 10px;
}

.page-thumb {
    width: 100%;

    display: grid;
    grid-template-columns:
        24px 34px minmax(0, 1fr) auto;

    align-items: center;
    gap: 9px;

    padding: 9px;

    border:
        1px solid var(--border);

    border-radius:
        var(--radius-sm);

    background:
        var(--surface);

    color:
        var(--text);

    text-align: left;
}

.page-thumb:hover,
.page-thumb:focus-visible {
    border-color:
        #b9c6eb;

    background:
        #f8faff;
}

.page-thumb.is-active {
    border-color:
        var(--primary);

    background:
        #eef2ff;

    box-shadow:
        0 0 0 2px
        rgba(49, 87, 213, 0.08);
}

.page-move-handle {
    width: 24px;
    height: 32px;

    display: grid;
    place-items: center;

    padding: 0;

    border:
        1px solid transparent;

    border-radius: 8px;

    background:
        transparent;

    color:
        var(--muted);

    font-size: 1rem;
    font-weight: 800;
    line-height: 1;

    cursor: grab;
}

.page-move-handle:hover,
.page-move-handle:focus-visible {
    border-color:
        var(--border);

    background:
        var(--surface-soft);

    color:
        var(--primary);
}


.page-thumb-number {
    width: 32px;
    height: 32px;

    display: grid;
    place-items: center;

    border-radius: 9px;

    background:
        var(--surface-soft);

    color:
        var(--muted);

    font-size:
        0.75rem;

    font-weight: 800;
}

.page-thumb.is-active
.page-thumb-number {
    background:
        var(--primary);

    color:
        white;
}

.page-thumb-copy {
    min-width: 0;

    display: flex;
    flex-direction: column;
    gap: 3px;
}

.page-thumb-copy strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    font-size:
        0.8rem;
}

.page-thumb-copy small {
    color:
        var(--muted);

    font-size:
        0.68rem;
}

.page-delete-button {
    width: 34px;
    height: 34px;

    display: grid;
    place-items: center;

    border:
        1px solid transparent;

    border-radius:
        9px;

    background:
        transparent;

    color:
        var(--muted);
}

.page-delete-button:hover,
.page-delete-button:focus-visible {
    border-color:
        #f1c5c1;

    background:
        #fff1f0;

    color:
        var(--danger);
}

.page-management-empty {
    padding: 20px 12px;

    border:
        1px dashed
        var(--border);

    border-radius:
        var(--radius-sm);

    text-align: center;

    color:
        var(--muted);

    font-size:
        0.8rem;
}

.page-management-empty p {
    margin:
        5px 0 12px;
}

.mobile-pages-backdrop {
    position: fixed;
    inset: 0;

    z-index: 90;

    display: flex;
    align-items: flex-end;

    background:
        rgba(16, 24, 40, 0.44);
}

.mobile-pages-sheet {
    width: 100%;
    max-height: 82dvh;

    overflow-y: auto;

    padding:
        16px
        16px
        calc(
            18px
            + env(safe-area-inset-bottom)
        );

    background:
        var(--surface);

    border-radius:
        24px 24px 0 0;

    box-shadow:
        var(--shadow);
}

.mobile-pages-actions {
    display: flex;
    gap: 7px;
}

.mobile-page-list {
    margin-top: 14px;
}

@media (min-width: 700px) {

    .mobile-pages-backdrop {
        display: none !important;
    }

}


/* =========================================================
   8C-3 — PAGE ORDER CONTROLS
   ========================================================= */

.page-thumb-actions {
    display: flex;
    align-items: center;
    gap: 3px;
}

.page-order-button,
.page-delete-button {
    width: 32px;
    height: 32px;

    display: grid;
    place-items: center;

    padding: 0;

    border:
        1px solid transparent;

    border-radius: 9px;

    background:
        transparent;

    color:
        var(--muted);
}

.page-order-button:hover:not(:disabled),
.page-order-button:focus-visible:not(:disabled) {
    border-color:
        var(--border);

    background:
        var(--surface-soft);

    color:
        var(--primary);
}

.page-order-button:disabled {
    opacity: 0.28;
}

@media (max-width: 699px) {

    .page-thumb {
        grid-template-columns:
            30px
            34px
            minmax(0, 1fr)
            auto;
    }

    .page-move-handle {
        width: 30px;
        height: 38px;
    }

    .page-thumb-actions {
        gap: 5px;
    }

    .page-order-button,
    .page-delete-button {
        width: 38px;
        height: 38px;
    }

}


/* =========================================================
   8D-5 — FABRIC CANVAS STAGE
   ========================================================= */

.canvas-stage {
    position: relative;

    overflow: hidden;

    display: grid;
    place-items: center;
}

.canvas-container {
    max-width: 100%;
    max-height: 100%;
}

.digital-paper-canvas {
    display: block;
}

/*
 * Fabric owns responsive CSS dimensions through
 * DPaperCanvasAdapter.fitToHost().
 *
 * Do not independently scale lower/upper canvas layers here:
 * both layers and the Fabric wrapper must stay pixel-aligned
 * for touch selection and object transforms.
 */
.canvas-stage .canvas-container,
.canvas-stage .upper-canvas,
.canvas-stage .lower-canvas {
    display: block;
}

.canvas-stage-placeholder {
    position: absolute;

    left: 14px;
    bottom: 14px;

    z-index: 5;

    max-width:
        min(420px, calc(100% - 28px));

    padding: 9px 12px;

    border:
        1px solid
        rgba(152, 162, 179, 0.28);

    border-radius: 10px;

    background:
        rgba(255, 255, 255, 0.88);

    backdrop-filter:
        blur(8px);

    pointer-events:
        none;
}

.canvas-stage-placeholder
.canvas-stage-icon {
    display: none;
}

.canvas-stage-placeholder h1 {
    margin: 0 0 2px;

    font-size: 0.8rem;
}

.canvas-stage-placeholder p,
.canvas-stage-placeholder small {
    margin: 0;

    font-size: 0.68rem;
}

@media (max-width: 699px) {

    .canvas-stage-placeholder {
        left: 8px;
        right: 8px;
        bottom: 8px;

        max-width: none;
    }

}


/* =========================================================
   8D-6B — SHAPE GALLERY
   ========================================================= */

.mobile-pages-backdrop[hidden],
.shape-gallery-backdrop[hidden] {
    display: none !important;
}


.shape-gallery-backdrop {
    position: fixed;
    inset: 0;

    z-index: 140;

    display: flex;
    align-items: flex-end;
    justify-content: center;

    padding: 14px;

    background:
        rgba(16, 24, 40, 0.42);
}


.shape-gallery {
    width: 100%;
    max-width: 760px;

    max-height: 82dvh;
    overflow-y: auto;

    padding: 18px;

    border:
        1px solid var(--border);

    border-radius:
        20px 20px 14px 14px;

    background:
        var(--surface);

    box-shadow:
        var(--shadow);
}


.shape-gallery-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 16px;

    margin-bottom: 16px;
}


.shape-gallery-header > div {
    display: flex;
    flex-direction: column;
    gap: 3px;
}


.shape-gallery-header small,
.shape-gallery-note {
    color: var(--muted);
}


.shape-gallery-close {
    width: 38px;
    height: 38px;

    border:
        1px solid var(--border);

    border-radius: 10px;

    background:
        var(--surface);

    font-size: 1.4rem;
    line-height: 1;

    cursor: pointer;
}


.shape-gallery-grid {
    display: grid;

    grid-template-columns:
        repeat(3, minmax(0, 1fr));

    gap: 10px;
}


.shape-gallery-grid button {
    min-height: 88px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    gap: 7px;

    padding: 10px;

    border:
        1px solid var(--border);

    border-radius: 14px;

    background:
        var(--surface);

    color:
        var(--text);

    cursor: pointer;
}


.shape-gallery-grid button:hover,
.shape-gallery-grid button:focus-visible {
    border-color:
        #3157d5;

    outline: none;

    box-shadow:
        0 0 0 3px
        rgba(49, 87, 213, 0.12);
}


.shape-gallery-grid button span {
    font-size: 2rem;
    line-height: 1;
}


.shape-gallery-note {
    margin:
        14px 2px 0;

    font-size: 0.78rem;
}


@media (min-width: 700px) {

    .shape-gallery-backdrop {
        align-items: center;

        padding: 24px;
    }


    .shape-gallery {
        border-radius: 18px;
    }


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

}


/* =========================================================
   8D-7B — SHAPE APPEARANCE INSPECTOR
   ========================================================= */

.shape-inspector[hidden],
.shape-range-control[hidden] {
    display: none !important;
}


.shape-inspector {
    display: grid;
    gap: 15px;
}


.shape-inspector-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 12px;
}


.shape-inspector-heading h2 {
    margin: 0;
}


.shape-inspector-heading p {
    margin: 3px 0 0;
}


.shape-inspector-badge {
    width: 34px;
    height: 34px;

    flex: 0 0 auto;

    display: grid;
    place-items: center;

    border-radius: 10px;

    background:
        var(--surface-soft);

    color:
        var(--primary);

    font-size: 1.15rem;
}


.shape-control-group {
    display: grid;
    gap: 10px;

    padding-top: 4px;
}


.shape-control-group + .shape-control-group {
    padding-top: 13px;

    border-top:
        1px solid var(--border);
}


.shape-control-group h3 {
    margin: 0;

    font-size: 0.76rem;

    color:
        var(--muted);

    text-transform: uppercase;

    letter-spacing: 0.07em;
}


.shape-control-row,
.shape-check-row,
.shape-select-control {
    min-height: 38px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 10px;
}


.shape-control-row > span,
.shape-check-row > span,
.shape-select-control > span,
.shape-range-control > span {
    font-size: 0.78rem;
    font-weight: 650;
}


.shape-control-row input[type="color"] {
    width: 44px;
    height: 34px;

    padding: 2px;

    border:
        1px solid var(--border);

    border-radius: 9px;

    background:
        var(--surface);
}


.shape-check-row {
    justify-content: flex-start;
}


.shape-check-row input {
    width: 18px;
    height: 18px;
}


.shape-range-control {
    display: grid;
    gap: 7px;
}


.shape-range-control > span {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 8px;
}


.shape-range-control output {
    color:
        var(--muted);

    font-size: 0.72rem;
}


.shape-range-control input[type="range"] {
    width: 100%;
}


.shape-select-control select {
    min-width: 112px;

    padding:
        8px 10px;

    border:
        1px solid var(--border);

    border-radius: 9px;

    background:
        var(--surface);

    color:
        var(--text);
}


/* =========================================================
   8D-7C — SHAPE GRADIENT CONTROLS
   ========================================================= */

.shape-gradient-controls[hidden],
.shape-control-row[hidden] {
    display: none !important;
}

.shape-gradient-controls {
    display: grid;
    gap: 9px;

    padding:
        10px;

    border:
        1px solid var(--border);

    border-radius:
        10px;

    background:
        var(--surface-soft);
}


/* =========================================================
   8D-8C — IMAGE FILL CONTROLS
   ========================================================= */

.shape-image-fill-controls[hidden] {
    display: none !important;
}

.shape-image-fill-controls {
    display: grid;
    gap: 10px;

    padding: 10px;

    border:
        1px solid var(--border);

    border-radius: 10px;

    background:
        var(--surface-soft);
}

.shape-select-stack {
    display: grid;
    gap: 7px;
}

.shape-select-stack > span {
    font-size: 0.78rem;
    font-weight: 650;
}

.shape-select-stack select {
    width: 100%;

    padding: 9px 10px;

    border:
        1px solid var(--border);

    border-radius: 9px;

    background:
        var(--surface);

    color:
        var(--text);
}

.shape-image-fill-status {
    margin: 0 !important;

    font-size: 0.72rem !important;

    line-height: 1.4 !important;
}


/* =========================================================
   8D-8C-C — IMAGE CROP / PAN / ZOOM
   ========================================================= */

.shape-image-transform-controls {
    display: grid;
    gap: 10px;

    padding-top: 4px;
}

/* Studio create-paper modal must respect the hidden attribute. */
[data-create-modal][hidden] {
    display: none !important;
}


/* Shape image uploader */
.shape-image-upload-control {
    display: grid;
    gap: 7px;
}

.shape-image-upload-control > span {
    font-size: 0.78rem;
    font-weight: 650;
}

.shape-image-upload-control input[type="file"] {
    width: 100%;
    font-size: 0.78rem;
}

/* Studio list states must respect the hidden attribute. */
.loading-state[hidden],
.empty-state[hidden],
.error-state[hidden],
.paper-grid[hidden] {
    display: none !important;
}


/* My Papers card actions */
.card-actions > a,
.card-actions > button {
    flex: 1;
}

.paper-trash-button {
    color: #a42b2b;
    border-color: #efcaca;
    background: #fffafa;
}

.paper-trash-button:hover,
.paper-trash-button:focus-visible {
    background: #fff0f0;
    border-color: #e5aaaa;
}


/* =========================================================
   STUDIO — COMPACT DESKTOP
   Keeps mobile/tablet comfortable while making desktop
   behave like a dense dashboard instead of stretched cards.
   ========================================================= */

@media (min-width: 1050px) {
    :root {
        --sidebar-width: 205px;
    }

    .sidebar {
        padding: 10px;
    }

    .nav-item {
        min-height: 42px;
        gap: 10px;
        padding: 0 12px;
        font-size: 0.92rem;
    }

    .sidebar-footer {
        left: 12px;
        right: 12px;
        bottom: 12px;
        font-size: 0.82rem;
    }

    .main-content {
        padding:
            26px
            28px
            42px;
    }

    .page-heading {
        gap: 16px;
        margin-bottom: 16px;
    }

    .page-heading h1 {
        font-size: 2rem;
    }

    .page-subtitle {
        margin-top: 5px;
        font-size: 0.94rem;
    }

    .main-content .primary-button {
        min-height: 40px;
        padding: 0 14px;
        border-radius: 11px;
        font-size: 0.9rem;
    }

    .toolbar {
        grid-template-columns:
            minmax(260px, 1fr)
            170px;

        gap: 10px;
        margin-bottom: 14px;
    }

    .search-box,
    .filter-control {
        min-height: 42px;
    }

    /*
     * Important:
     * Do not use 1fr columns here.
     * A small number of Papers must not stretch
     * into giant cards across the entire viewport.
     */
    .paper-grid {
        grid-template-columns:
            repeat(
                auto-fill,
                minmax(220px, 280px)
            );

        justify-content: start;
        align-items: start;

        gap: 14px;
    }

    .paper-card {
        width: 100%;
    }

    .paper-preview {
        aspect-ratio: 16 / 9;
    }

    .paper-placeholder {
        font-size: 1.55rem;
    }

    .paper-card-body {
        padding: 11px;
    }

    .paper-card h2 {
        font-size: 0.93rem;
    }

    .paper-meta {
        gap: 5px;
        margin-top: 7px;
    }

    .status-badge,
    .page-count {
        min-height: 22px;
        padding: 0 7px;
        font-size: 0.68rem;
    }

    .card-actions {
        gap: 6px;
        margin-top: 10px;
    }

    .card-actions .secondary-button {
        min-height: 38px;
        padding: 0 10px;
        border-radius: 10px;
        font-size: 0.86rem;
    }
}



/* =========================================================
   STUDIO — DESKTOP WIDTH FIX
   Main content must occupy only the space remaining after
   the fixed sidebar. Never viewport width + sidebar width.
   ========================================================= */

@media (min-width: 1050px) {
    .main-content {
        width:
            calc(
                100% - var(--sidebar-width)
            );

        max-width: none;

        margin-left:
            var(--sidebar-width);

        min-width: 0;
        box-sizing: border-box;
    }

    .toolbar,
    .paper-area,
    .paper-grid {
        min-width: 0;
        max-width: 100%;
    }
}


/* Keep compact cards on larger desktop screens too. */
@media (min-width: 1450px) {
    .paper-grid {
        grid-template-columns:
            repeat(
                auto-fill,
                minmax(220px, 280px)
            );
    }
}


/* Trash restore action */
.paper-restore-button {
    color: #176c3a;
    border-color: #bfe3cd;
    background: #f6fff9;
}

.paper-restore-button:hover,
.paper-restore-button:focus-visible {
    background: #eaf9f0;
    border-color: #9fd1b2;
}


/* =========================================================
   DIGITAL PAPER — OBJECT ACTIONS + LAYERS
   ========================================================= */

.shape-action-grid,
.shape-layer-grid {
    display: grid;
    gap: 8px;
}

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

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

.shape-action-grid button,
.shape-layer-grid button {
    min-width: 0;
    width: 100%;
    box-sizing: border-box;

    min-height: 38px;

    padding: 7px 9px;

    border:
        1px solid var(--border);

    border-radius:
        10px;

    background:
        var(--surface);

    color:
        var(--text);

    font-size:
        0.78rem;

    font-weight:
        700;
}

.shape-action-grid button:hover,
.shape-action-grid button:focus-visible,
.shape-layer-grid button:hover,
.shape-layer-grid button:focus-visible {
    background:
        var(--surface-soft);
}

.shape-action-grid button[aria-pressed="true"] {
    background:
        #eef2ff;

    border-color:
        #b9c7f5;

    color:
        var(--primary-strong);
}

.shape-action-grid button.danger {
    color:
        #a42b2b;

    border-color:
        #efcaca;

    background:
        #fffafa;
}


/* =========================================================
   DIGITAL PAPER — TEXT INSPECTOR V1
   ========================================================= */

.text-content-control {
    display: grid;
    gap: 7px;
}

.text-content-control > span {
    font-size: 0.78rem;
    font-weight: 650;
}

.text-content-control textarea {
    width: 100%;
    min-height: 90px;

    resize: vertical;

    padding: 10px 11px;

    border:
        1px solid var(--border);

    border-radius:
        10px;

    background:
        var(--surface);

    color:
        var(--text);

    font: inherit;
    line-height: 1.4;
}

.text-style-buttons {
    display: grid;
    grid-template-columns:
        repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.text-style-buttons button {
    min-height: 38px;

    border:
        1px solid var(--border);

    border-radius:
        10px;

    background:
        var(--surface);

    color:
        var(--text);

    font-weight: 800;
}

.text-style-buttons button[aria-pressed="true"] {
    background:
        #eef2ff;

    border-color:
        #b9c7f5;

    color:
        var(--primary-strong);
}

.text-style-buttons
button[data-text-italic] {
    font-style: italic;
}


/* =========================================================
   DPAPER PROPERTY TABS + COMPACT DESKTOP INSPECTOR
   ========================================================= */

[data-property-pane][data-property-tab-hidden="true"] {
    display: none !important;
}


.property-tabs {
    display: grid;
    grid-template-columns:
        repeat(3, minmax(0, 1fr));

    gap: 5px;

    padding: 8px 0;

    background:
        var(--surface);

    border-bottom:
        1px solid var(--border);
}


.property-tabs button {
    min-width: 0;
    min-height: 34px;

    padding: 0 8px;

    border:
        1px solid transparent;

    border-radius: 9px;

    background:
        transparent;

    color:
        var(--muted);

    font-size: 0.76rem;
    font-weight: 700;

    cursor: pointer;
}


.property-tabs button:hover {
    background:
        var(--surface-soft);

    color:
        var(--text);
}


.property-tabs button[aria-pressed="true"] {
    background:
        var(--surface-soft);

    border-color:
        var(--border);

    color:
        var(--text);
}


.property-group-toggle {
    position: relative;

    padding-right: 22px;

    cursor: pointer;

    user-select: none;
}


.property-group-toggle::after {
    content: "⌄";

    position: absolute;

    top: 50%;
    right: 2px;

    transform:
        translateY(-50%);

    font-size: 1rem;
    line-height: 1;

    transition:
        transform 0.16s ease;
}


.shape-control-group.is-collapsed
.property-group-toggle::after {
    transform:
        translateY(-50%)
        rotate(-90deg);
}


.shape-control-group.is-collapsed
> :not(h3) {
    display: none !important;
}


.shape-control-group.is-collapsed {
    gap: 0;
}


@media (min-width: 1100px) {

    .workspace-shell {
        grid-template-columns:
            220px
            minmax(0, 1fr)
            340px;
    }


    .workspace-properties {
        height:
            calc(
                100dvh
                - 68px
            );

        min-height: 0;

        overflow-y: auto;

        padding:
            0 14px 18px;
    }


    .workspace-properties
    > .workspace-panel-heading {
        position: sticky;

        top: 0;

        z-index: 20;

        padding-top: 14px;

        background:
            var(--surface);
    }


    .workspace-properties
    > .property-tabs {
        position: sticky;

        top: 64px;

        z-index: 19;
    }


    .properties-stack {
        gap: 10px;

        padding-top: 10px;
    }


    .property-section {
        padding-bottom: 10px;
    }


    .shape-control-group
    + .shape-control-group {
        padding-top: 10px;
    }
}


/* =========================================================
   DPAPER DESKTOP BUILDER SHELL
   ========================================================= */

.desktop-builder-menubar,
.desktop-builder-ribbon {
    display: none;
}


.touch-builder-toolbar {
    display: flex;
    align-items: center;
    gap: 7px;
}


@media (min-width: 1100px) {

    .workspace-shell {
        grid-template-areas:
            "topbar topbar topbar"
            "menubar menubar menubar"
            "pages canvas properties";

        grid-template-rows:
            auto
            auto
            1fr;
    }


    .workspace-topbar {
        min-height: 54px;
    }


    .desktop-builder-menubar {
        grid-area: menubar;

        display: flex;
        align-items: center;

        min-height: 34px;

        padding:
            0 10px;

        background:
            var(--surface);

        border-bottom:
            1px solid var(--border);
    }


    .desktop-builder-menubar button {
        height: 33px;

        padding:
            0 11px;

        border: 0;

        background:
            transparent;

        color:
            var(--text);

        font-size:
            0.78rem;

        cursor: pointer;
    }


    .desktop-builder-menubar button:hover,
    .desktop-builder-menubar button[aria-pressed="true"] {
        background:
            var(--surface-soft);
    }


    .workspace-canvas-toolbar {
        min-height: 72px;

        padding:
            0;

        overflow: visible;
    }


    .touch-builder-toolbar {
        display: none;
    }


    .desktop-builder-ribbon {
        width: 100%;

        min-height: 72px;

        display: block;

        background:
            var(--surface);
    }


    .desktop-ribbon-panel {
        min-height: 72px;

        display: flex;
        align-items: stretch;

        padding:
            7px 10px;
    }


    .desktop-ribbon-panel[hidden] {
        display: none !important;
    }


    .desktop-ribbon-group {
        display: flex;
        align-items: center;
        gap: 7px;

        padding:
            0 12px;

        border-right:
            1px solid var(--border);
    }


    .desktop-ribbon-group > span {
        align-self: flex-end;

        padding-bottom: 2px;

        color:
            var(--muted);

        font-size:
            0.62rem;

        font-weight: 700;

        text-transform: uppercase;

        letter-spacing:
            0.06em;
    }


    .desktop-ribbon-group
    .tool-button {
        min-height: 38px;
    }


    .workspace-pages,
    .workspace-properties {
        min-height:
            calc(
                100dvh
                - 54px
                - 34px
            );
    }


    .workspace-properties {
        height:
            calc(
                100dvh
                - 54px
                - 34px
            );
    }


    .canvas-stage-wrap {
        min-height:
            calc(
                100dvh
                - 54px
                - 34px
                - 72px
            );
    }
}


/* =========================================================
   DPAPER DESKTOP BUILDER MENU V2
   ========================================================= */

@media (min-width: 1100px) {

    /*
     * Desktop menu owns navigation.
     * Do not show a second tab navigator in Properties.
     */
    .workspace-properties
    > .property-tabs {
        display: none;
    }


    .workspace-properties
    > .workspace-panel-heading {
        padding-bottom: 10px;
    }


    .desktop-builder-menubar {
        overflow-x: auto;

        scrollbar-width: thin;
    }


    .desktop-builder-menubar button {
        white-space: nowrap;
    }


    .desktop-builder-ribbon {
        overflow-x: auto;

        overflow-y: hidden;
    }


    .desktop-ribbon-panel {
        width: max-content;
        min-width: 100%;
    }


    .desktop-ribbon-shape-group {
        gap: 10px;
    }


    .desktop-ribbon-shapes {
        display: flex;
        align-items: center;
        gap: 5px;
    }


    .desktop-ribbon-shapes button {
        width: 38px;
        height: 38px;

        flex: 0 0 auto;

        display: grid;
        place-items: center;

        padding: 0;

        border:
            1px solid var(--border);

        border-radius: 9px;

        background:
            var(--surface);

        color:
            var(--text);

        font-size: 1.15rem;

        cursor: pointer;
    }


    .desktop-ribbon-shapes button:hover {
        background:
            var(--surface-soft);

        border-color:
            #b7c4de;

        transform:
            translateY(-1px);
    }


    .desktop-ribbon-panel
    button:disabled {
        opacity: 0.46;

        cursor: not-allowed;
    }
}

/* ==========================================================
   DPAPER · EXPLICIT BUILDER BACK LINK
   ========================================================== */

.workspace-back-link {
    width:
        auto;

    min-width:
        0;

    min-height:
        40px;

    padding:
        0 13px;

    display:
        inline-flex;

    align-items:
        center;

    justify-content:
        center;

    gap:
        6px;

    text-decoration:
        none;

    white-space:
        nowrap;

    font-size:
        .78rem;

    font-weight:
        800;
}



/* =========================================================
   GLOBAL TRASH · HARD HIDDEN CREATE ACTIONS

   Author display rules such as .desktop-create and
   .bottom-nav-item must never override the hidden state.
   ========================================================= */

[data-create-paper][hidden] {
    display: none !important;
}


/* ==========================================================
   DPAPER · PHASE 5 RECOVERY
   TABLET BUILDER · 700px — 1099px

   Mobile keeps its sheet UI below 700px.
   Desktop keeps the full three-column ribbon at 1100px+.
   Tablet gets pages + canvas + properties without pretending
   to be either phone or wide desktop.
   ========================================================== */

@media (min-width: 700px) and (max-width: 1099px) {

    .workspace-topbar {
        flex-wrap: wrap;
        align-content: center;
        row-gap: 8px;
        padding-bottom: 8px;
    }

    .workspace-topbar-left {
        min-width: 0;
        flex: 1 1 auto;
    }

    .workspace-topbar-actions {
        flex: 0 1 auto;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .workspace-navigation-control {
        flex: 0 0 auto;
    }

    .workspace-navigation-control select {
        min-height: 36px;
    }

    .workspace-shell {
        grid-template-areas:
            "topbar topbar"
            "pages canvas"
            "properties properties";

        grid-template-columns:
            180px minmax(0, 1fr);

        grid-template-rows:
            auto
            minmax(0, 1fr)
            auto;
    }


    .workspace-pages {
        grid-area:
            pages;

        display:
            block;

        min-width:
            0;

        max-height:
            calc(
                100dvh
                - 68px
            );

        overflow-y:
            auto;

        border-right:
            1px solid
            var(--border);

        background:
            var(--surface);
    }


    .workspace-canvas-area {
        grid-area:
            canvas;

        min-width:
            0;

        padding-bottom:
            0;
    }


    .workspace-properties {
        grid-area:
            properties;

        display:
            block;

        max-height:
            42dvh;

        overflow-y:
            auto;

        border-top:
            1px solid
            var(--border);

        background:
            var(--surface);
    }


    .workspace-properties
    > .workspace-panel-heading {
        padding:
            12px 14px 6px;
    }


    .property-tabs {
        position:
            sticky;

        top:
            0;

        z-index:
            12;

        background:
            var(--surface);
    }


    .properties-stack {
        padding:
            10px 14px 18px;
    }


    .canvas-stage-wrap {
        min-height:
            calc(
                100dvh
                - 68px
                - 54px
            );
    }


    .touch-builder-toolbar {
        width:
            100%;

        overflow-x:
            auto;

        scrollbar-width:
            thin;
    }


    .touch-builder-toolbar
    .tool-button {
        min-height:
            42px;

        padding:
            0 16px;
    }
}

/* ==========================================================
   DPAPER · SHAPE INSPECTOR COLOR PICKER VIEWPORT FIX

   Firefox positions its native <input type="color"> popup
   relative to the swatch. Keeping the swatch at the extreme
   right edge of the Properties panel can place part of that
   native popup outside the viewport.

   Keep this scoped to the Shape inspector. Do not alter the
   general Properties layout or other editor color controls.
   ========================================================== */

@media (min-width: 1100px) {

    [data-shape-inspector]
    .shape-control-row:has(input[type="color"]) {
        justify-content:
            flex-start;

        display:
            grid;

        grid-template-columns:
            minmax(74px, 96px)
            44px;

        column-gap:
            12px;
    }


    [data-shape-inspector]
    .shape-control-row
    input[type="color"] {
        margin:
            0;

        justify-self:
            start;
    }
}

/* =========================================================
   DPAPER · PERSONAL TEMPLATES MODALS
   hidden must override modal-backdrop display:flex.
   ========================================================= */

[data-template-use-modal][hidden],
[data-template-rename-modal][hidden],
[data-save-template-modal][hidden] {
    display: none;
}

/* =========================================================
   UX-2B1 — PAGE ACTION MENU
   ========================================================= */

.page-thumb-actions {
    position: relative;
}

.page-more-button {
    width: 34px;
    height: 34px;

    display: grid;
    place-items: center;

    padding: 0;

    border:
        1px solid transparent;

    border-radius: 9px;

    background:
        transparent;

    color:
        var(--muted);

    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1;
}

.page-more-button:hover,
.page-more-button:focus-visible {
    border-color:
        var(--border);

    background:
        var(--surface-soft);

    color:
        var(--primary);
}

.page-action-menu {
    position: absolute;

    z-index: 30;

    top:
        calc(100% + 6px);

    right: 0;

    min-width: 168px;

    padding: 6px;

    border:
        1px solid var(--border);

    border-radius: 12px;

    background:
        var(--surface);

    box-shadow:
        0 12px 30px
        rgba(16, 24, 40, 0.16);
}

.page-action-menu[hidden] {
    display: none;
}

.page-action-item {
    width: 100%;

    display: block;

    padding:
        9px 10px;

    border: 0;

    border-radius: 8px;

    background:
        transparent;

    color:
        var(--text);

    text-align: left;

    font-size:
        0.78rem;

    font-weight: 700;
}

.page-action-item:hover:not(:disabled),
.page-action-item:focus-visible:not(:disabled) {
    background:
        var(--surface-soft);

    color:
        var(--primary);
}

.page-action-item:disabled {
    opacity: 0.38;
    cursor: default;
}

.page-action-item.is-danger {
    color:
        var(--danger);
}

.page-action-item.is-danger:hover,
.page-action-item.is-danger:focus-visible {
    background:
        #fff1f0;
}

@media (max-width: 699px) {

    .page-more-button {
        width: 38px;
        height: 38px;
    }

    .page-action-menu {
        min-width: 180px;
    }
}

/* =========================================================
   UX-2B2 — PAGE DIALOG
   Reuses DPaper modal-backdrop / modal-card.
   ========================================================= */

[data-page-dialog][hidden],
[data-physics-connection-dialog][hidden] {
    display: none !important;
}

.page-dialog-card {
    max-width: 520px;
}

.page-dialog-description {
    margin:
        -4px 0 18px;

    color:
        var(--muted);

    font-size:
        0.88rem;

    line-height: 1.5;
}

.page-dialog-warning {
    display: grid;
    gap: 8px;

    padding: 14px;

    border:
        1px solid #f1c5c1;

    border-radius:
        var(--radius-sm);

    background:
        #fff8f7;
}

.page-dialog-warning[hidden] {
    display: none !important;
}

.page-dialog-warning strong {
    color:
        var(--text);

    font-size:
        0.92rem;
}

.page-dialog-warning p {
    margin: 0;

    color:
        var(--muted);

    font-size:
        0.82rem;

    line-height: 1.45;
}

.page-dialog-danger-button {
    background:
        var(--danger) !important;

    border-color:
        var(--danger) !important;

    color:
        white !important;
}

@media (max-width: 699px) {

    .page-dialog-card {
        max-width: none;
    }

    .page-dialog-card
    .modal-actions {
        grid-template-columns:
            1fr;
    }

    .page-dialog-card
    .primary-button {
        order: -1;
    }
}

/* UX-2B2 · hidden rename field must override .field display:grid */
[data-page-dialog-name-field][hidden] {
    display: none !important;
}


/* ==========================================================
   UX-2D1 · CONTEXTUAL EMPTY STATE
   ========================================================== */

.contextual-empty-state {
    padding: 28px 18px;
    text-align: center;
}

.contextual-empty-state[hidden] {
    display: none !important;
}

.contextual-empty-state__icon {
    margin-bottom: 10px;
    font-size: 32px;
    line-height: 1;
}

.contextual-empty-state h2 {
    margin: 0 0 6px;
    font-size: 18px;
}

.contextual-empty-state p {
    margin: 0;
    line-height: 1.45;
    opacity: 0.72;
}


/* ==========================================================
   UX-2D2 · CONTEXTUAL PANEL NAVIGATION
   Internal property tabs remain available to JavaScript.
   Navigation is driven by Página / Avanzado / selection.
   ========================================================== */

[data-property-tabs][hidden] {
    display: none !important;
}

/* =========================================================
   UX-4D1A.2 — COMPACT PAGE MOVE ROW
   Give the page title more usable horizontal space.
   ========================================================= */

.page-thumb {
    grid-template-columns:
        18px 30px minmax(0, 1fr) 30px;

    gap: 5px;

    padding:
        8px 7px;
}

.page-move-handle {
    width: 18px;
    height: 32px;

    border-radius: 6px;

    font-size: 0.9rem;
}

.page-thumb-number {
    width: 30px;
    height: 32px;
}

.page-more-button {
    width: 30px;
    height: 32px;
}

@media (max-width: 699px) {

    .page-thumb {
        grid-template-columns:
            22px 34px minmax(0, 1fr) 38px;

        gap: 6px;
    }

    .page-move-handle {
        width: 22px;
        height: 38px;
    }
}


/* =========================================================
   UX-4D1B — PAGE REORDER INTERACTION
   ========================================================= */

.page-move-handle {
    touch-action: none;
    user-select: none;
}

.page-move-handle.is-reordering {
    cursor: grabbing;
}

body.is-page-reordering {
    cursor: grabbing;
    user-select: none;
}

.page-thumb.is-reordering {
    opacity: 0.48;
}

.page-thumb.is-drop-before,
.page-thumb.is-drop-after {
    position: relative;
}

.page-thumb.is-drop-before::before,
.page-thumb.is-drop-after::after {
    content: "";

    position: absolute;
    left: 6px;
    right: 6px;

    height: 3px;

    border-radius: 999px;

    background:
        var(--primary);

    pointer-events: none;
}

.page-thumb.is-drop-before::before {
    top: -6px;
}

.page-thumb.is-drop-after::after {
    bottom: -6px;
}


/* =========================================================
   TEMPLATES UX-2C — CARD ACTION MENU
   ========================================================= */

.template-card-actions {
    align-items: stretch;
}

.template-card-actions > .secondary-button {
    flex: 1;
}

.template-card-menu {
    position: relative;
    flex: 0 0 auto;
}

.template-card-menu-button {
    width: 44px;
    min-width: 44px;
    height: 100%;

    padding: 0;

    display: grid;
    place-items: center;

    font-size: 1.25rem;
    line-height: 1;
}

.template-card-menu-popover {
    position: absolute;
    right: 0;
    bottom: calc(100% + 7px);

    z-index: 20;

    width: 190px;

    padding: 6px;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.template-card-menu-popover[hidden] {
    display: none !important;
}

.template-card-menu-item {
    width: 100%;

    padding: 10px 11px;

    border: 0;
    border-radius: 8px;

    background: transparent;
    color: var(--text);

    text-align: left;
    font: inherit;
    font-size: 0.84rem;

    cursor: pointer;
}

.template-card-menu-item:hover,
.template-card-menu-item:focus-visible {
    background: var(--surface-soft);
}

.template-card-menu-danger {
    color: var(--danger);
}


/* Digital Paper · navigation mode */

.workspace-navigation-control {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 4px 8px 4px 11px;
    border: 1px solid #d9e0ea;
    border-radius: 10px;
    background: #ffffff;
    color: #4d596b;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.workspace-navigation-control select {
    min-height: 28px;
    max-width: 150px;
    border: 0;
    border-radius: 7px;
    background: #f3f5f8;
    color: #18202b;
    padding: 3px 7px;
    font: inherit;
    cursor: pointer;
}

.workspace-navigation-control select:focus {
    outline: 2px solid currentColor;
    outline-offset: 1px;
}

.workspace-navigation-control select:disabled {
    cursor: wait;
    opacity: .65;
}

/* STUDIO APP DIALOG · SHARED HOTFIX */

.studio-app-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.48);
    backdrop-filter: blur(6px);
}

.studio-app-dialog-backdrop.is-open {
    display: flex;
}

.studio-app-dialog-card {
    width: min(460px, 100%);
    padding: 24px;
    border: 1px solid rgba(148, 163, 184, 0.30);
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.studio-app-dialog-card h2 {
    margin: 0 0 10px;
    font-size: 1.2rem;
}

.studio-app-dialog-card p {
    margin: 0;
    line-height: 1.55;
    color: #475569;
    white-space: pre-line;
}

.studio-app-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
    flex-wrap: wrap;
}

.studio-app-dialog-actions button {
    min-height: 42px;
}

.studio-app-dialog-danger {
    background: #b91c1c !important;
    border-color: #b91c1c !important;
    color: #fff !important;
}
