:root {
    --bg: #150334;
    --sidebar: #1b0642;
    --surface: #220a50;
    --surface-2: #2c0f65;
    --surface-3: #37157a;
    --border: rgba(255, 255, 255, .08);
    --border-strong: rgba(255, 255, 255, .16);
    --primary: #f2b705;
    --primary-text: #1b0540;
    --text: #ffffff;
    --muted: #a898d0;
    --faint: #7d6ca8;
    --danger: #ff6b81;
    --success: #4ade9b;
    --radius: 10px;
    --radius-sm: 7px;

    --type-link: #a78bfa;
    --type-text: #f2b705;
    --type-image: #34d399;
    --type-video: #ff5a5f;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
[hidden] { display: none !important; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.ui-icon { width: 18px; height: 18px; flex-shrink: 0; }

kbd {
    padding: 1px 6px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--bg);
    font-family: inherit;
    font-size: 12px;
}

/* ---------- App shell ---------- */

.app {
    display: grid;
    grid-template-columns: 250px 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 20px 14px;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px;
    text-decoration: none;
}

.brand img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 0 0 2px var(--primary);
}

.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }

.side-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
}

.side-nav a:hover { color: var(--text); background: rgba(255, 255, 255, .05); }

.side-nav a.active {
    color: var(--text);
    background: var(--surface-2);
    box-shadow: inset 3px 0 0 var(--primary);
}

.account {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    padding: 10px 10px 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, .15);
}

.account-email {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account form { margin: 0; }

.content {
    min-width: 0;
    padding: 32px 40px 64px;
}

/* ---------- Page header ---------- */

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 28px;
}

h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
h2 { margin: 0; font-size: 15px; font-weight: 700; }
.subtitle { margin: 6px 0 0; color: var(--muted); }
.muted { color: var(--muted); }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
}

.back-link:hover { color: var(--text); }
.back-link .ui-icon { width: 16px; height: 16px; }

.stats { display: flex; gap: 10px; margin: 0; }

.stats div {
    min-width: 92px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.stats dt { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stats dd { margin: 2px 0 0; font-size: 22px; font-weight: 700; }

/* ---------- Cards ---------- */

.card {
    margin-bottom: 20px;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.card-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-head p { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 13px; }

.card-head .count {
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.card--list { padding: 18px 18px 14px; }

.narrow { max-width: 780px; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, border-color .15s, filter .15s;
}

.btn:hover { background: var(--surface-3); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(255, 255, 255, .05); color: var(--text); }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.icon-btn:hover { background: rgba(255, 255, 255, .07); color: var(--text); }
.icon-btn--danger:hover { background: rgba(255, 107, 129, .12); color: var(--danger); }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Switch ---------- */

.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, .15);
    cursor: pointer;
    transition: background .2s;
    flex-shrink: 0;
}

.switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    transition: transform .2s;
}

.switch[aria-checked="true"],
.switch-field input:checked + .switch { background: var(--success); }

.switch[aria-checked="true"]::after,
.switch-field input:checked + .switch::after { transform: translateX(16px); }

.switch-field {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    font-weight: 500;
    cursor: pointer;
}

.switch-field input { position: absolute; opacity: 0; pointer-events: none; }
.switch-field input:focus-visible + .switch { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Type icons ---------- */

.type-icon {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.type-link { color: var(--type-link); background: color-mix(in srgb, var(--type-link) 16%, transparent); }
.type-text { color: var(--type-text); background: color-mix(in srgb, var(--type-text) 16%, transparent); }
.type-image { color: var(--type-image); background: color-mix(in srgb, var(--type-image) 16%, transparent); }
.type-video { color: var(--type-video); background: color-mix(in srgb, var(--type-video) 16%, transparent); }

/* ---------- Add block tiles ---------- */

.add-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.add-tile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, .12);
    text-decoration: none;
    transition: border-color .15s, background .15s, transform .15s;
}

.add-tile:hover { border-color: var(--border-strong); background: var(--surface-2); transform: translateY(-1px); }
.add-tile strong { display: block; font-size: 13px; }
.add-tile small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; line-height: 1.35; }

/* ---------- Block list ---------- */

.with-preview {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 28px;
    align-items: start;
}

.block-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 58px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.block-list:not(:has(li)) {
    display: grid;
    place-items: center;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    color: var(--faint);
}

.block-list:not(:has(li))::before { content: attr(data-empty); font-size: 13px; }

.block-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px 9px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    transition: border-color .15s, background .15s, opacity .2s;
}

.block-row:hover { border-color: var(--border-strong); }
.block-row.is-hidden { opacity: .55; }
.block-row.is-hidden .info strong { text-decoration: line-through; text-decoration-color: rgba(255, 255, 255, .35); }

.block-row.is-ghost { opacity: .35; border-style: dashed; }
.block-row.is-chosen { background: var(--surface-3); box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }

.drag-handle {
    display: grid;
    place-items: center;
    width: 26px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--faint);
    cursor: grab;
}

.drag-handle:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
.drag-handle:active { cursor: grabbing; }

.thumb {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
}

.info {
    flex: 1;
    min-width: 0;
    text-decoration: none;
}

.info strong,
.info span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.info strong { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 600; }
.info span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.info:hover strong { color: var(--primary); }


.row-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.row-actions form { display: flex; margin: 0; }
.row-actions .switch { margin-right: 8px; }

/* ---------- Live preview ---------- */

.preview {
    position: sticky;
    top: 24px;
}

.preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.preview-head span { display: flex; align-items: center; gap: 8px; }

.phone {
    width: 320px;
    height: 640px;
    margin: 0 auto;
    overflow: hidden;
    border: 10px solid #0c0120;
    border-radius: 38px;
    background: #250655;
    box-shadow: 0 0 0 1px var(--border-strong), 0 24px 60px rgba(0, 0, 0, .45);
}

.phone iframe {
    display: block;
    width: 375px;
    height: 755px;
    border: 0;
    transform: scale(.8);
    transform-origin: 0 0;
}

/* ---------- Forms ---------- */

.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }

.field > label,
.field > .label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 600;
}

.field .hint { margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.field .error { margin-top: 7px; color: var(--danger); font-size: 12px; font-weight: 500; }

.field input[type=text],
.field input[type=email],
.field input[type=url],
.field input[type=password],
.field select,
.field textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, .2);
    color: var(--text);
    font: inherit;
    transition: border-color .15s, background .15s;
}

.field input:hover,
.field select:hover,
.field textarea:hover { border-color: rgba(255, 255, 255, .26); }

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(0, 0, 0, .28);
    box-shadow: 0 0 0 3px rgba(242, 183, 5, .15);
}

.field textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
.field select option, .field select optgroup { background: var(--surface); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid-2 > .field { margin-bottom: 18px; }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.form-actions--sticky {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 0 0 24px;
    padding: 14px 0;
    background: linear-gradient(transparent, var(--bg) 35%);
}

/* Type picker (block form) */

.type-picker {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.type-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 13px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.type-option:hover { background: rgba(255, 255, 255, .03); }
.type-option input { position: absolute; opacity: 0; pointer-events: none; }
.type-option:has(input:checked) { border-color: var(--primary); background: rgba(242, 183, 5, .08); box-shadow: inset 0 0 0 1px var(--primary); }
.type-option:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Upload box */

.upload {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, .15);
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.upload:hover { border-color: var(--primary); background: rgba(242, 183, 5, .05); }
.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload img { width: 64px; height: 64px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; }
.upload img.round { border-radius: 50%; }
.upload img.wide { width: 110px; }
.upload strong { display: block; font-size: 13px; }
.upload small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.upload .upload-name { color: var(--primary); }
.upload .upload-name:empty { display: none; }

/* Social fields */

.social-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.social-grid .field { margin: 0; }
.social-field label { color: var(--muted); }
.social-field.is-filled label { color: var(--text); }
.social-field .icon { display: inline-flex; }
.social-field .icon svg { width: 16px; height: 16px; fill: currentColor; }
.social-field .icon .play { fill: var(--surface); }

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 1px solid rgba(74, 222, 155, .35);
    border-radius: var(--radius);
    background: #0f3a2c;
    color: #d6ffea;
    font-weight: 600;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
    animation: toast-in .3s ease;
    transition: opacity .4s, transform .4s;
}

.toast .ui-icon { color: var(--success); }
.toast.is-leaving { opacity: 0; transform: translateY(10px); pointer-events: none; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
}

/* ---------- Login ---------- */

.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: radial-gradient(circle at 50% 0%, #2c0f65, var(--bg) 60%);
}

.auth .card { width: 100%; max-width: 400px; margin: 0; padding: 30px; }
.auth .avatar { display: block; width: 80px; height: 80px; margin: 0 auto 16px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 3px var(--primary); }
.auth h1 { margin-bottom: 4px; text-align: center; }
.auth .muted { margin: 0 0 24px; text-align: center; }
.auth .btn-primary { width: 100%; padding: 12px; }
.auth .back { display: block; margin-top: 20px; color: var(--muted); font-size: 13px; text-align: center; }
.checkbox { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.checkbox input { width: 17px; height: 17px; accent-color: var(--primary); }

/* ---------- Responsive ---------- */

@media (max-width: 1280px) {
    .with-preview { grid-template-columns: minmax(0, 1fr); }
    .preview { display: none; }
}

@media (max-width: 1000px) {
    .add-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
    .app { grid-template-columns: minmax(0, 1fr); }

    .sidebar {
        position: sticky;
        z-index: 10;
        height: auto;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 10px 14px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .brand span, .account-email { display: none; }
    .brand img { width: 34px; height: 34px; }
    .side-nav { flex-direction: row; flex: 1; gap: 2px; }
    .side-nav a { padding: 8px 10px; font-size: 13px; }
    .side-nav a.active { box-shadow: inset 0 -2px 0 var(--primary); }
    .account { margin: 0; padding: 0; border: 0; background: none; }
    .content { padding: 24px 16px 48px; }
}

@media (max-width: 640px) {
    .side-nav a { gap: 0; font-size: 0; }
    .side-nav a .ui-icon { width: 20px; height: 20px; }
    .grid-2, .social-grid { grid-template-columns: 1fr; }
    .type-picker { grid-template-columns: 1fr 1fr; }
    .add-grid { grid-template-columns: 1fr; }
    .stats { width: 100%; }
    .stats div { flex: 1; min-width: 0; }
    .block-row { flex-wrap: wrap; }
    .info { flex-basis: calc(100% - 90px); }
    .row-actions { width: 100%; justify-content: flex-end; padding-top: 4px; border-top: 1px solid var(--border); }
}

/* Brand icon or emoji inside a type tile */
.type-icon .icon { display: inline-flex; }
.type-icon .icon svg { width: 18px; height: 18px; fill: currentColor; }
.type-icon .icon .play { fill: var(--surface-2); }
.type-icon .icon--emoji { font-size: 18px; line-height: 1; }
