/* ══════════════════════════════════════════════════
   DNA BUILDER — VISUAL EDITOR STYLES
   ══════════════════════════════════════════════════ */
:root {
    /* Surface hierarchy */
    --bg-0: #f3f4f6;
    --bg-1: #ffffff;
    --bg-2: #f9fafb;
    --bg-3: #e5e7eb;
    --bg-4: #d1d5db;

    /* Borders */
    --border-1: rgba(0, 0, 0, 0.08);
    --border-2: rgba(0, 0, 0, 0.12);
    --border-3: rgba(0, 0, 0, 0.20);
    --shadow-soft: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);

    /* Text */
    --text-1: #111827;
    --text-2: #4b5563;
    --text-3: #9ca3af;

    /* Brand */
    --brand: #0db4f7;
    --brand-hover: #0284c7;
    --brand-glow: rgba(13, 180, 247, 0.12);
    --brand-text: #ffffff;

    /* Accent */
    --gold: #f59e0b;
    --gold-glow: rgba(245, 158, 11, 0.10);

    /* Semantic */
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;

    /* Layout */
    --toolbar-h: 56px;
    --panel-w: 240px;
    --panel-r-w: 280px;
    --radius: 12px;
    --radius-sm: 8px;
    --ease: cubic-bezier(.25, .8, .25, 1);
    --dur: 180ms;
    --font: 'Poppins', system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    width: 100%;
    font-family: var(--font);
    background: var(--bg-0);
    color: var(--text-1);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    font-size: 13px;
}

.hidden {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* ══════════════════════════════════════
   TOOLBAR
   ══════════════════════════════════════ */
.toolbar {
    height: var(--toolbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border-1);
    z-index: 100;
    position: relative;
}

.toolbar__left,
.toolbar__right,
.toolbar__center {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar__logo {
    width: 22px;
    height: 22px;
    color: var(--brand);
    flex-shrink: 0;
}

.toolbar__brand {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.toolbar__brand-accent {
    color: var(--brand);
}

.toolbar__divider {
    width: 1px;
    height: 20px;
    background: var(--border-2);
    margin: 0 4px;
}

.toolbar__project {
    font-size: 12px;
    color: var(--text-2);
    font-weight: 500;
}

/* Tabs */
.toolbar__tabs {
    display: flex;
    background: var(--bg-2);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
}

.toolbar__tab {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 14px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--text-2);
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--dur) var(--ease);
}

.toolbar__tab:hover {
    color: var(--text-1);
}

.toolbar__tab.active {
    background: var(--bg-4);
    color: var(--text-1);
    font-weight: 600;
}

/* Buttons */
.toolbar__btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--dur) var(--ease);
    line-height: 1;
    white-space: nowrap;
}

.toolbar__btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.toolbar__btn--primary {
    background: var(--brand);
    color: var(--brand-text);
}

.toolbar__btn--primary:hover:not(:disabled) {
    background: var(--brand-hover);
}

.toolbar__btn--outline {
    background: transparent;
    color: var(--text-2);
    border-color: var(--border-2);
}

.toolbar__btn--outline:hover:not(:disabled) {
    color: var(--text-1);
    border-color: var(--border-3);
    background: var(--bg-3);
}

.toolbar__btn--ghost {
    background: transparent;
    color: var(--text-3);
    border: none;
    padding: 6px;
}

.toolbar__btn--ghost:hover:not(:disabled) {
    color: var(--text-1);
    background: var(--bg-3);
}

.toolbar__btn--sm {
    padding: 4px 8px;
    font-size: 11px;
}

/* ══════════════════════════════════════
   WORKSPACE
   ══════════════════════════════════════ */
.workspace {
    display: flex;
    height: calc(100vh - var(--toolbar-h));
    overflow: hidden;
}

/* ══════════════════════════════════════
   PANELS (left + right)
   ══════════════════════════════════════ */
.panel {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-1);
    overflow: hidden;
}

.panel--left {
    width: var(--panel-w);
    border-right: 1px solid var(--border-1);
}

.panel--right {
    width: var(--panel-r-w);
    border-left: 1px solid var(--border-1);
}

.panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 10px;
    flex-shrink: 0;
}

.panel__title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel__count {
    background: var(--bg-3);
    color: var(--text-2);
    font-size: 10px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 99px;
}

/* ── Page List ── */
.page-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 4px 8px;
}

.page-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
    color: var(--text-2);
    font-weight: 500;
    margin-bottom: 1px;
    position: relative;
}

.page-item:hover {
    background: var(--bg-3);
    color: var(--text-1);
}

.page-item.active {
    background: var(--brand-glow);
    color: var(--brand);
}

.page-item__icon {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    opacity: 0.5;
}

.page-item.active .page-item__icon {
    opacity: 1;
}

.page-item__name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

.page-item__dot {
    width: 5px;
    height: 5px;
    border-radius: 99px;
    background: var(--gold);
    opacity: 0;
    flex-shrink: 0;
    transition: opacity var(--dur);
}

.page-item.modified .page-item__dot {
    opacity: 1;
}

.page-item__imgs {
    font-size: 10px;
    color: var(--text-3);
    font-weight: 600;
    flex-shrink: 0;
}

.page-item__delete {
    background: transparent;
    border: none;
    color: var(--text-3);
    margin-left: auto;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: all var(--dur);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-item:hover .page-item__delete {
    opacity: 1;
}

.page-item__delete:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

/* ══════════════════════════════════════
   CANVAS
   ══════════════════════════════════════ */
.canvas {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-0);
}

.canvas__visual,
.canvas__code {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Canvas Header / Breadcrumb */
.canvas__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border-1);
    flex-shrink: 0;
}

.canvas__breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.breadcrumb__page {
    font-weight: 600;
    color: var(--text-1);
}

.breadcrumb__sep {
    color: var(--text-3);
}

.breadcrumb__info {
    color: var(--text-2);
}

.canvas__controls {
    display: flex;
    align-items: center;
    gap: 14px;
}

.canvas__hint {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-3);
    font-weight: 500;
}

.canvas__hint--interact {
    color: var(--success);
}

/* Toggle Switch */
.edit-toggle {
    display: flex;
    align-items: center;
    gap: 7px;
}

.edit-toggle__label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-2);
    white-space: nowrap;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    border-radius: 99px;
    background: var(--bg-4);
    cursor: pointer;
    transition: background var(--dur);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 2px;
    width: 14px;
    height: 14px;
    border-radius: 99px;
    background: var(--text-2);
    transition: transform var(--dur), background var(--dur);
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--brand);
}

.toggle-switch input:checked+.toggle-slider::before {
    transform: translateX(14px);
    background: #fff;
}

.canvas__frame {
    flex: 1;
    position: relative;
    overflow: hidden;
    margin: 0 auto;
    transition: width var(--dur) var(--ease);
    width: 100%;
}

.canvas__frame.canvas-desktop {
    width: 100%;
}

.canvas__frame.canvas-tablet {
    width: 768px;
    border-left: 1px solid var(--border-1);
    border-right: 1px solid var(--border-1);
    box-shadow: var(--shadow-soft);
}

.canvas__frame.canvas-mobile {
    width: 375px;
    border-left: 1px solid var(--border-1);
    border-right: 1px solid var(--border-1);
    box-shadow: var(--shadow-soft);
}

.canvas__empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-state {
    text-align: center;
    color: var(--text-3);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-2);
}

.empty-state p {
    font-size: 13px;
}

.canvas__iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

.canvas__code {
    background: #1e1e1e;
}

/* ── Code View ── */
.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #252526;
    border-bottom: 1px solid #333;
}

.code-header__file {
    font-size: 12px;
    font-weight: 600;
    color: #cccccc;
}

.code-header .toolbar__btn--outline {
    color: #cccccc;
    border-color: #444;
}

.code-header .toolbar__btn--outline:hover {
    color: #ffffff;
    border-color: #666;
    background: #333;
}

.code-block {
    flex: 1;
    overflow: auto;
    margin: 0;
    padding: 16px;
    background: #1e1e1e;
    font-size: 13px;
    line-height: 1.6;
    color: #d4d4d4;
    font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    tab-size: 4;
    white-space: pre-wrap;
    word-break: normal;
}

/* Syntax Highlighting */
.code-tag { color: #ff79c6; }
.code-attr { color: #ffb86c; }
.code-string { color: #f1fa8c; }
.code-comment { color: #6272a4; font-style: italic; }

.code-css-selector { color: #50fa7b; }
.code-css-prop { color: #8be9fd; }
.code-css-val { color: #f8f8f2; }

.code-js-kw { color: #ff79c6; }
.code-js-func { color: #50fa7b; }
.code-js-num { color: #bd93f9; }

/* ══════════════════════════════════════
   IMAGE PANEL (right sidebar)
   ══════════════════════════════════════ */
.img-panel {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.img-panel__empty {
    text-align: center;
    padding: 40px 12px;
    color: var(--text-3);
    font-size: 12px;
}

.img-card {
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-1);
    margin-bottom: 6px;
    background: var(--bg-2);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
}

.img-card:hover {
    border-color: var(--border-3);
    transform: translateY(-1px);
}

.img-card.active {
    border-color: var(--brand);
    box-shadow: 0 0 0 1px var(--brand);
}

.img-card__thumb {
    width: 100%;
    height: 80px;
    object-fit: cover;
    display: block;
    background: var(--bg-3);
}

.img-card__info {
    padding: 6px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.img-card__label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.img-card__swap {
    background: var(--brand-glow);
    border: none;
    color: var(--brand);
    font: inherit;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--dur);
    flex-shrink: 0;
}

.img-card__swap:hover {
    background: var(--brand);
    color: #fff;
}

/* ══════════════════════════════════════
   REPLACE POPOVER
   ══════════════════════════════════════ */
.replace-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.replace-popover {
    background: var(--bg-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    width: 380px;
    max-width: 90vw;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    animation: pop-in 180ms var(--ease);
    overflow: hidden;
}

@keyframes pop-in {
    from {
        transform: scale(0.96) translateY(8px);
        opacity: 0;
    }
}

.replace-popover__close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 99px;
    cursor: pointer;
    font-size: 16px;
    display: grid;
    place-items: center;
    transition: background var(--dur);
}

.replace-popover__close:hover {
    background: rgba(0, 0, 0, 0.8);
}

.replace-popover__preview {
    position: relative;
}

.replace-popover__preview img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
    background: var(--bg-3);
}

.replace-popover__badge {
    position: absolute;
    bottom: 8px;
    left: 8px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 3px 8px;
    border-radius: 4px;
    backdrop-filter: blur(4px);
}

.replace-popover__body {
    padding: 16px;
}

.replace-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
    margin-bottom: 6px;
    display: block;
}

.replace-input-group {
    display: flex;
    gap: 4px;
}

.replace-input {
    flex: 1;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--bg-0);
    color: var(--text-1);
    font: inherit;
    font-size: 12px;
    outline: none;
    transition: border-color var(--dur);
}

.replace-input:focus {
    border-color: var(--brand);
}

.replace-apply-btn {
    width: 36px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    background: var(--brand);
    border: none;
    color: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background var(--dur);
}

.replace-apply-btn:hover {
    background: var(--brand-hover);
}

.replace-or {
    text-align: center;
    margin: 12px 0;
    position: relative;
    font-size: 11px;
    color: var(--text-3);
}

.replace-or::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    border-top: 1px solid var(--border-1);
}

.replace-or span {
    background: var(--bg-2);
    padding: 0 10px;
    position: relative;
}

.replace-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    border: 1.5px dashed var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all var(--dur);
}

.replace-upload:hover {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-glow);
}

/* ══════════════════════════════════════
   TOAST
   ══════════════════════════════════════ */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius);
    background: var(--bg-3);
    color: var(--text-1);
    border: 1px solid var(--border-2);
    font-size: 12px;
    font-weight: 600;
    z-index: 600;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    animation: toast-up 250ms var(--ease);
}

.toast__icon {
    color: var(--success);
    flex-shrink: 0;
}

.toast--error .toast__icon {
    color: var(--error);
}

@keyframes toast-up {
    from {
        transform: translateX(-50%) translateY(12px);
        opacity: 0;
    }
}

/* ══════════════════════════════════════
   IFRAME IMAGE HIGHLIGHT (injected)
   ══════════════════════════════════════ */
/* These styles are injected into the iframe via JS */

/* ══════════════════════════════════════
   POPOVER SHARED EXTRAS
   ══════════════════════════════════════ */
.popover-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-1);
    font-size: 13px;
    font-weight: 700;
}

.popover-tag {
    background: var(--bg-4);
    color: var(--text-2);
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Cascadia Code', monospace;
    margin-left: auto;
}

.replace-textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--bg-0);
    color: var(--text-1);
    font: inherit;
    font-size: 12px;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    min-height: 80px;
    transition: border-color var(--dur);
}

.replace-textarea:focus {
    border-color: var(--success);
}

.popover-apply-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--success);
    color: #fff;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--dur);
    margin-top: 14px;
}

.popover-apply-btn:hover {
    background: var(--success);
}

.ai-btn {
    background: var(--bg-1);
    border: 1px solid var(--border-2);
    color: var(--text-2);
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 99px;
    cursor: pointer;
    transition: all var(--dur);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ai-btn:hover {
    background: var(--bg-3);
    color: var(--text-1);
    border-color: var(--border-3);
}

.ai-btn.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
    color: transparent;
}
.ai-btn.loading::after {
    content: "⏳";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-1);
}

.popover-apply-btn--purple {
    background: #a855f7;
}

.popover-apply-btn--purple:hover {
    background: #9333ea;
}

/* Text popover green accent */
.replace-popover--text .replace-popover__close {
    background: rgba(52, 211, 153, 0.2);
}

.replace-popover--text .replace-input:focus,
.replace-popover--text .replace-textarea:focus {
    border-color: var(--success);
}

/* Button popover purple accent */
.replace-popover--btn .replace-popover__close {
    background: rgba(192, 132, 252, 0.2);
}

.replace-popover--btn .replace-input:focus {
    border-color: #c084fc;
}

/* ══════════════════════════════════════
   DROP ZONE
   ══════════════════════════════════════ */
.drop-zone {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity var(--dur) var(--ease);
}

.drop-zone.hidden {
    opacity: 0;
    pointer-events: none;
}

.drop-zone__content {
    border: 2px dashed var(--brand);
    border-radius: var(--radius);
    padding: 60px 100px;
    text-align: center;
    color: var(--brand);
    background: var(--brand-glow);
}

.drop-zone__content svg {
    margin-bottom: 20px;
}

.drop-zone__content h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-1);
    margin-bottom: 8px;
}

.drop-zone__content p {
    font-size: 14px;
    color: var(--text-2);
}