:root {
    --builder-bg: #06070d;
    --builder-panel: rgba(13, 16, 27, .94);
    --builder-panel-2: rgba(18, 23, 38, .9);
    --builder-border: rgba(255, 215, 0, .22);
    --builder-border-soft: rgba(255, 255, 255, .09);
    --builder-gold: #ffd700;
    --builder-cyan: #22d3ee;
    --builder-green: #4ade80;
    --builder-red: #fb7185;
    --builder-text: #f8fafc;
    --builder-muted: #94a3b8;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    height: 100dvh;
    margin: 0;
    overflow: hidden;
    color: var(--builder-text);
    background:
        radial-gradient(circle at 20% 0%, rgba(255, 215, 0, .16), transparent 28%),
        radial-gradient(circle at 78% 10%, rgba(34, 211, 238, .12), transparent 26%),
        linear-gradient(180deg, #080a12 0%, var(--builder-bg) 100%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
    position: fixed;
    inset: 0;
    z-index: -1;
    content: "";
    background:
        linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px);
    background-size: 34px 34px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .9), transparent 86%);
}

button,
input,
select {
    font: inherit;
}

button,
select,
input {
    border: 1px solid var(--builder-border-soft);
    border-radius: 12px;
}

button {
    min-height: 38px;
    padding: 0 14px;
    border-color: rgba(255, 215, 0, .32);
    background: linear-gradient(135deg, var(--builder-gold), #f59e0b);
    color: #09090b;
    cursor: pointer;
    font-size: 13px;
    font-weight: 900;
    transition: transform .18s ease, filter .18s ease, box-shadow .18s ease;
}

button:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(255, 215, 0, .13);
}

button.secondary,
.icon-btn {
    border-color: rgba(34, 211, 238, .22);
    background: rgba(15, 23, 42, .86);
    color: #dbeafe;
}

button.danger {
    border-color: rgba(251, 113, 133, .36);
    background: linear-gradient(135deg, #fb7185, #f97316);
    color: #111827;
}

input,
select {
    width: 100%;
    min-height: 38px;
    outline: none;
    padding: 0 12px;
    background: rgba(2, 6, 23, .84);
    color: #f8fafc;
}

label {
    display: block;
    margin: 12px 0 6px;
    color: var(--builder-muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.builder-sidebar,
.side-drawer {
    background:
        linear-gradient(180deg, rgba(8, 10, 18, .98), rgba(5, 7, 15, .96)),
        linear-gradient(90deg, rgba(255, 215, 0, .08), transparent);
    border-color: var(--builder-border);
}

.builder-sidebar {
    display: flex;
    min-height: 0;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding: 18px;
    border-right: 1px solid var(--builder-border);
}

.builder-brand {
    position: relative;
    padding: 18px;
    overflow: hidden;
    border: 1px solid var(--builder-border-soft);
    border-radius: 22px;
    background: rgba(255, 255, 255, .035);
}

.builder-brand::after {
    position: absolute;
    right: -48px;
    bottom: -58px;
    width: 150px;
    height: 150px;
    content: "";
    border-radius: 999px;
    background: radial-gradient(circle, rgba(34, 211, 238, .18), transparent 64%);
}

.builder-kicker {
    color: var(--builder-gold);
    font-size: 11px;
    font-weight: 950;
    letter-spacing: .16em;
    text-transform: uppercase;
}

.builder-brand h1 {
    margin: 8px 0 8px;
    color: #fff;
    font-size: 30px;
    letter-spacing: 0;
    line-height: 1;
}

.builder-brand p {
    margin: 0;
    color: #cbd5e1;
    font-size: 13px;
    line-height: 1.45;
}

.builder-panel {
    padding: 14px;
    border: 1px solid var(--builder-border-soft);
    border-radius: 18px;
    background: rgba(15, 23, 42, .55);
}

.builder-panel h2,
.side-drawer h2 {
    margin: 0 0 12px;
    color: #fef3c7;
    font-size: 15px;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.backend-panel {
    display: grid;
    gap: 10px;
}

.backend-status-pill {
    display: inline-flex;
    width: fit-content;
    max-width: 100%;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid rgba(34, 211, 238, .22);
    border-radius: 999px;
    background: rgba(2, 6, 23, .6);
    color: #a5f3fc;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.backend-status-pill.is-online {
    border-color: rgba(74, 222, 128, .36);
    color: #bbf7d0;
}

.backend-status-pill.is-offline {
    border-color: rgba(251, 113, 133, .36);
    color: #fecdd3;
}

.backend-routes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.backend-routes a {
    max-width: 100%;
    overflow: hidden;
    padding: 6px 8px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 10px;
    background: rgba(2, 6, 23, .54);
    color: #67e8f9;
    font-size: 11px;
    font-weight: 800;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.component-list {
    display: grid;
    gap: 10px;
}

.component-card {
    width: 100%;
    min-height: 72px;
    padding: 12px;
    border: 1px solid rgba(34, 211, 238, .14);
    border-radius: 16px;
    background: rgba(2, 6, 23, .65);
    color: #f8fafc;
    cursor: pointer;
    text-align: left;
}

.component-card strong {
    display: block;
    color: #fde68a;
    font-size: 13px;
    line-height: 1.2;
}

.component-card span {
    display: block;
    margin-top: 4px;
    color: #94a3b8;
    font-size: 12px;
    line-height: 1.35;
}

.sidebar-actions,
.toolbar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.sidebar-actions {
    margin-top: 12px;
}

.builder-main {
    display: grid;
    min-width: 0;
    grid-template-rows: auto minmax(0, 1fr);
}

.builder-toolbar {
    display: flex;
    min-height: 66px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--builder-border);
    background: rgba(2, 6, 23, .78);
    backdrop-filter: blur(18px);
}

.toolbar-group {
    align-items: center;
}

.toolbar-group select {
    width: 138px;
}

.builder-status {
    min-width: 180px;
    max-width: 280px;
    overflow: hidden;
    color: var(--builder-green);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .08em;
    text-align: right;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.client-ribbon {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(74, 222, 128, .2);
    background: rgba(6, 78, 59, .28);
    color: #bbf7d0;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.client-ribbon button {
    min-height: 34px;
    border-color: rgba(187, 247, 208, .3);
    background: rgba(15, 23, 42, .82);
    color: #dcfce7;
}

.builder-workspace {
    display: grid;
    min-height: 0;
    grid-template-columns: minmax(420px, 1fr) minmax(360px, .85fr);
    gap: 14px;
    padding: 14px;
}

.editor-shell,
.preview-shell {
    position: relative;
    display: grid;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    border: 1px solid var(--builder-border-soft);
    border-radius: 22px;
    background: rgba(2, 6, 23, .62);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
}

.workspace-label {
    padding: 10px 14px;
    border-bottom: 1px solid var(--builder-border-soft);
    color: #fef3c7;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .14em;
    text-transform: uppercase;
}

#editor,
.CodeMirror,
#fallbackEditor,
#preview {
    width: 100%;
    height: 100%;
    min-height: 0;
}

#fallbackEditor {
    display: none;
    resize: none;
    border: 0;
    border-radius: 0;
    padding: 14px;
    background: #111827;
    color: #e5e7eb;
    font-family: Consolas, "Courier New", monospace;
    line-height: 1.45;
}

.CodeMirror {
    font-family: Consolas, "Courier New", monospace;
    font-size: 14px;
}

#preview {
    display: block;
    border: 0;
    background: #fff;
    transition: width .2s ease;
}

.side-drawer {
    position: fixed;
    top: 0;
    z-index: 20;
    display: flex;
    width: min(340px, calc(100vw - 308px));
    height: 100dvh;
    min-width: 280px;
    overflow: hidden;
    flex-direction: column;
    padding: 16px;
    transition: transform .24s ease;
}

.left-drawer {
    left: 280px;
    border-right: 1px solid var(--builder-border);
    transform: translateX(-112%);
}

.right-drawer {
    right: 0;
    border-left: 1px solid var(--builder-border);
    transform: translateX(112%);
}

.side-drawer.open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

.icon-btn {
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
}

.full-btn {
    flex: 0 0 auto;
    width: 100%;
}

.page-list,
.version-list {
    display: grid;
    flex: 1 1 auto;
    gap: 10px;
    min-height: 0;
    overflow-y: auto;
    margin-bottom: 12px;
    padding-right: 4px;
}

.page-list::-webkit-scrollbar,
.version-list::-webkit-scrollbar {
    width: 6px;
}

.page-list::-webkit-scrollbar-thumb,
.version-list::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 215, 0, .32);
}

.side-drawer > .full-btn {
    position: sticky;
    bottom: 0;
    min-height: 44px;
    box-shadow: 0 -12px 28px rgba(6, 7, 13, .85);
}

.page-card,
.version-card {
    padding: 12px;
    border: 1px solid var(--builder-border-soft);
    border-radius: 16px;
    background: rgba(15, 23, 42, .72);
}

.page-card.active {
    border-color: rgba(255, 215, 0, .58);
    box-shadow: 0 0 24px rgba(255, 215, 0, .1);
}

.page-card strong,
.version-card strong {
    display: block;
    margin-bottom: 8px;
    color: #fff;
    font-size: 14px;
}

.page-actions,
.version-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.version-card time {
    display: block;
    margin-bottom: 10px;
    color: var(--builder-muted);
    font-size: 12px;
}

body.preview-hidden .preview-shell {
    display: none;
}

body.preview-hidden .builder-workspace {
    grid-template-columns: 1fr;
}

body.client-mode {
    display: block;
    height: 100dvh;
}

body.client-mode .builder-sidebar,
body.client-mode .side-drawer,
body.client-mode .admin-only,
body.client-mode .editor-shell,
body.client-mode .workspace-label {
    display: none !important;
}

body.client-mode .builder-main {
    display: grid;
    min-height: 100dvh;
    grid-template-rows: auto auto minmax(0, 1fr);
}

body.client-mode .builder-toolbar {
    position: fixed;
    right: 18px;
    bottom: 18px;
    left: auto;
    z-index: 40;
    min-height: 0;
    width: auto;
    max-width: calc(100vw - 36px);
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 999px;
    background: rgba(2, 6, 23, .84);
    box-shadow: 0 18px 56px rgba(0, 0, 0, .45), 0 0 32px rgba(34, 211, 238, .12);
}

body.client-mode .builder-toolbar .toolbar-group {
    display: contents;
}

body.client-mode #runBtn {
    display: none;
}

body.client-mode .builder-status {
    display: none;
}

body.client-mode .client-ribbon {
    display: flex;
}

body.client-mode .builder-workspace {
    min-height: 0;
    grid-template-columns: 1fr;
    padding: 0;
}

body.client-mode .preview-shell {
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: #fff;
}

body.client-mode #preview {
    width: 100% !important;
    height: 100%;
    margin: 0 !important;
}

body.focus-mode:not(.client-mode) {
    grid-template-columns: 1fr;
}

body.focus-mode:not(.client-mode) .builder-sidebar,
body.focus-mode:not(.client-mode) .editor-shell,
body.focus-mode:not(.client-mode) .admin-only,
body.focus-mode:not(.client-mode) .side-drawer {
    display: none !important;
}

body.focus-mode:not(.client-mode) .builder-workspace {
    grid-template-columns: 1fr;
}

body.focus-mode:not(.client-mode) .preview-shell {
    min-height: calc(100dvh - 96px);
}

@media (max-width: 1100px) {
    body {
        grid-template-columns: 240px minmax(0, 1fr);
    }

    .builder-workspace {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(360px, 1fr) minmax(300px, .9fr);
    }

    .left-drawer {
        left: 240px;
        width: min(330px, calc(100vw - 258px));
    }
}

@media (max-width: 760px) {
    body {
        display: block;
        height: auto;
        min-height: 100dvh;
        overflow: auto;
    }

    .builder-sidebar {
        min-height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--builder-border);
    }

    .builder-main {
        min-height: 100dvh;
    }

    .builder-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .builder-status {
        max-width: none;
        text-align: left;
    }

    .builder-workspace {
        min-height: 900px;
        padding: 10px;
    }

    .left-drawer {
        left: 0;
        width: min(360px, calc(100vw - 18px));
        min-width: 0;
    }

    .right-drawer {
        width: min(360px, calc(100vw - 18px));
        min-width: 0;
    }

    body.client-mode .builder-toolbar {
        right: 10px;
        bottom: 10px;
        left: 10px;
        justify-content: center;
        border-radius: 18px;
    }

    body.client-mode .client-ribbon {
        align-items: flex-start;
        flex-direction: column;
    }
}
