:root {
    --bg: #f8fafc;
    --panel: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --danger: #dc2626;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.muted { color: var(--muted); }
.hidden { display: none !important; }

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    gap: 1rem;
    flex-shrink: 0;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
}
.back-link svg { width: 16px; height: 16px; }
.back-link:hover { color: var(--text); }

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent), #ec4899);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.badge {
    background: #eef2ff;
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.topbar-actions { display: flex; gap: 0.5rem; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: #fff;
    border: none;
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    font-family: inherit;
    box-shadow: 0 4px 12px rgba(99,102,241,0.2);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(99,102,241,0.3); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-danger {
    background: #fff;
    color: var(--danger);
    border: 1px solid #fecaca;
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
}
.btn-danger:hover { background: #fef2f2; border-color: var(--danger); }

.btn-small { padding: 0.35rem 0.7rem; font-size: 0.75rem; border-radius: 6px; }

.btn-icon {
    background: #fff;
    border: 1px solid var(--border);
    width: 32px; height: 32px;
    border-radius: 6px;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text);
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

/* Loader Pane */
.loader-pane {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.loader-card {
    background: var(--panel);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 2.5rem;
    max-width: 600px;
    width: 100%;
    border: 1px solid var(--border);
}

.resume-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, #eef2ff, #fce7f3);
    border: 1px solid #c7d2fe;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}
.resume-info { display: flex; flex-direction: column; gap: 0.15rem; }
.resume-info strong { font-size: 0.95rem; color: var(--text); }
.resume-info .muted { font-size: 0.8rem; }
.resume-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

.loader-card h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.loader-card .muted { margin-bottom: 1.5rem; }

.loader-tabs {
    display: flex;
    gap: 0.25rem;
    background: var(--bg);
    border-radius: 10px;
    padding: 0.25rem;
    margin-bottom: 1.25rem;
}
.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--muted);
    font-family: inherit;
    transition: all 0.15s;
}
.tab-btn.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.tab-panel input[type="url"],
.tab-panel input[type="file"],
.tab-panel textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--bg);
    margin-bottom: 0.75rem;
    outline: none;
}
.tab-panel input:focus, .tab-panel textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.tab-panel textarea { min-height: 180px; font-family: 'Courier New', monospace; font-size: 0.8rem; resize: vertical; }

.hint { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.75rem; }

.loader-variations {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}
.loader-variations-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.loader-variations-header h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.loader-variations-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}
.loader-variation-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.loader-variation-thumb {
    aspect-ratio: 16/10;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border);
}
.loader-variation-thumb img { width: 100%; height: 100%; object-fit: cover; }
.loader-variation-thumb .muted { font-size: 0.7rem; }
.loader-variation-body { padding: 0.5rem 0.6rem; display: flex; flex-direction: column; gap: 0.4rem; }
.loader-variation-name { font-size: 0.85rem; font-weight: 600; word-break: break-all; }
.loader-variation-actions { display: flex; gap: 0.3rem; }
.loader-variation-actions .btn-primary { flex: 1; }
.loader-variation-actions .btn-danger { width: 30px; padding: 0; }

.loader-status { margin-top: 0.75rem; font-size: 0.85rem; min-height: 1.2em; }
.loader-status.err { color: var(--danger); }
.loader-status.info { color: var(--muted); }

/* Editor pane */
.editor-pane {
    flex: 1;
    display: grid;
    grid-template-columns: 240px 1fr 280px;
    overflow: hidden;
    height: calc(100vh - 64px);
}

.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1rem;
}
.right-sidebar { border-right: none; border-left: 1px solid var(--border); }

.sidebar-section {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: none; }
.sidebar-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sidebar-section h4 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.insert-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.insert-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.15s;
}
.insert-btn:hover { border-color: var(--accent); color: var(--accent); background: #eef2ff; }

.theme-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.theme-swatch {
    height: 48px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 600;
}
.theme-swatch span {
    position: absolute;
    bottom: 4px;
    left: 6px;
    background: rgba(255,255,255,0.85);
    padding: 1px 6px;
    border-radius: 4px;
    color: #0f172a;
}
.theme-swatch:hover { transform: scale(1.03); }

#pageBgColor { width: 100%; height: 36px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }

.canvas-wrap {
    display: flex;
    flex-direction: column;
    background: #f1f5f9;
    overflow: hidden;
}

.canvas-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    gap: 0.5rem;
}
.canvas-toolbar-left, .canvas-toolbar-right { display: flex; gap: 0.4rem; align-items: center; }
.canvas-toolbar .divider { width: 1px; height: 20px; background: var(--border); margin: 0 0.25rem; }

#viewportSelect {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    font-family: inherit;
    font-size: 0.8rem;
    background: #fff;
}

.canvas-stage {
    flex: 1;
    overflow: auto;
    padding: 1rem;
    display: flex;
    justify-content: center;
}
#editorFrame {
    width: 100%;
    min-height: 100%;
    border: none;
    background: #fff;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    border-radius: 4px;
}

/* Inspector */
.selection-info {
    font-size: 0.75rem;
    word-break: break-all;
    font-family: 'Courier New', monospace;
    background: var(--bg);
    padding: 0.5rem;
    border-radius: 6px;
}

.inspector label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: 0.5rem;
}
.inspector input[type="text"],
.inspector select {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.55rem;
    font-family: inherit;
    font-size: 0.8rem;
    background: #fff;
    outline: none;
}
.inspector input[type="color"] {
    width: 100%;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}
.inspector input:focus, .inspector select:focus { border-color: var(--accent); }

.elem-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; }

/* Variations */
.variations-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.variation-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.5rem;
}
.variation-thumb {
    width: 100%;
    aspect-ratio: 16/10;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.4rem;
    border: 1px solid var(--border);
}
.variation-thumb img { width: 100%; height: 100%; object-fit: cover; }
.variation-thumb .muted { font-size: 0.7rem; }
.variation-name {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    word-break: break-all;
}
.variation-actions { display: flex; gap: 0.3rem; }
.variation-actions .btn-secondary { flex: 1; }
.variation-actions .btn-danger { width: 32px; padding: 0; }

/* Compare modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-inner {
    background: var(--panel);
    border-radius: 16px;
    width: 100%;
    max-width: 1400px;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    gap: 0.5rem;
}
.modal-header > div { display: flex; gap: 0.5rem; }

.compare-grid {
    flex: 1;
    overflow: auto;
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 1rem;
}
.compare-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
}
.compare-card-header {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg);
}
.compare-card iframe {
    width: 100%;
    height: 500px;
    border: none;
    background: #fff;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #fff;
    padding: 0.7rem 1.25rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 3000;
    animation: toastIn 0.2s ease-out;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Responsive */
@media (max-width: 1100px) {
    .editor-pane { grid-template-columns: 200px 1fr 260px; }
}
@media (max-width: 900px) {
    .editor-pane { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
    .sidebar { max-height: 200px; }
}
