:root {
    /* Indigo Cyan Palette */
    --bg-base: #0F172A;
    --bg-surface: rgba(30, 41, 59, 0.7);
    --bg-surface-solid: #1e293b;
    --bg-hover: rgba(99, 102, 241, 0.1);

    --border-light: rgba(99, 102, 241, 0.2);
    --border-subtle: rgba(255, 255, 255, 0.05);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --primary: #6366F1;
    --primary-hover: #4f46e5;
    --accent: #22D3EE;

    --error: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;

    --font-ui: 'Inter', system-ui, sans-serif;
    --font-code: 'JetBrains Mono', monospace;

    --radius-sm: 6px;
    --radius-md: 12px;

    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

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

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-ui);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Glassmorphism */
.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-light);
}

/* Typography Utils */
.text-sm {
    font-size: 0.85rem;
}

.text-muted {
    color: var(--text-muted);
}

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

.text-accent {
    color: var(--accent);
}

.text-success {
    color: var(--success);
}

.text-error {
    color: var(--error);
}

.font-medium {
    font-weight: 500;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-3 {
    margin-bottom: 0.75rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 0.75rem;
}

.mr-2 {
    margin-right: 0.5rem;
}

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

.hidden {
    display: none !important;
}

.relative {
    position: relative;
}

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

/* Header */
.app-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-light);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.15rem;
    font-weight: 500;
}

.logo strong {
    font-weight: 700;
    color: #FFF;
}

.select-glass {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border-light);
    padding: 0.4rem 2rem 0.4rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.85rem;
    appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

.select-glass option {
    background: var(--bg-surface-solid);
    color: #fff;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.btn-primary {
    background: var(--primary);
    color: #FFF;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
    border: 1px solid var(--border-light);
}

.btn-outline:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-icon {
    padding: 0.35rem;
    background: transparent;
    color: var(--text-muted);
}

.btn-icon:hover {
    color: var(--text-main);
    background: var(--bg-hover);
    border-radius: 4px;
}

/* Workspace Layout */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Panes */
.pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    position: relative;
}

.pane-editor {
    border-right: 1px solid var(--border-light);
    flex: 1;
}

.pane-preview {
    flex: 1.2;
    background: var(--bg-base);
}

.pane-header {
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    background: var(--bg-surface-solid);
    height: 46px;
    display: flex;
    align-items: center;
}

.compact-header {
    padding: 0 1rem;
    height: 36px;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(0, 0, 0, 0.2);
}

.pane-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pane-content {
    padding: 1.5rem;
    flex: 1;
    overflow-y: auto;
}

.pane-content.no-pad {
    padding: 0;
    overflow: hidden;
}

/* Code Editor */
.code-editor {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    color: #a5d6ff;
    border: none;
    padding: 1.5rem;
    font-family: var(--font-code);
    font-size: 0.85rem;
    line-height: 1.6;
    resize: none;
    outline: none;
    white-space: pre;
    overflow: auto;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.code-editor.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 5;
}

.code-editor.sm {
    position: relative;
    height: 120px;
    border: 1px solid var(--border-subtle);
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
}

.code-editor::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.code-editor::-webkit-scrollbar-corner {
    background: transparent;
}

.code-editor::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* Tabs */
.view-tabs {
    display: flex;
    gap: 1rem;
    height: 100%;
}

.view-tabs.sm {
    gap: 0.5rem;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: 0.2s;
    height: 100%;
    display: flex;
    align-items: center;
}

.view-tabs.sm .tab-btn {
    font-size: 0.8rem;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.badge {
    background: rgba(99, 102, 241, 0.2);
    color: var(--accent);
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
    font-size: 0.7rem;
    margin-left: 0.25rem;
}

/* Right Pane Topology */
.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.inspector-section {
    height: 40%;
    min-height: 250px;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
}

/* Iframe Sandbox */
.iframe-container {
    width: 100%;
    flex: 1;
    overflow: hidden;
    background: #FFF;
    position: relative;
}

.check-bg {
    background-image:
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#preview-frame {
    width: 100%;
    height: 100%;
    border: none;
}

/* Inspector Tabs */
.inspector-header {
    height: 40px;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
}

.inspector-content {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.insp-tab {
    display: none;
    height: 100%;
}

.insp-tab.active {
    display: block;
}

.empty-state {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius-sm);
}

/* Attr Grid */
.attr-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.attr-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.attr-name {
    flex: 0 0 120px;
    font-family: var(--font-code);
    font-size: 0.8rem;
    color: var(--accent);
}

.attr-input {
    flex: 1;
    background: var(--bg-surface-solid);
    border: 1px solid var(--border-subtle);
    color: #FFF;
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    outline: none;
}

.attr-input:focus {
    border-color: var(--primary);
}

/* Events Log */
.events-log {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.event-item {
    background: rgba(0, 0, 0, 0.3);
    border-left: 3px solid var(--primary);
    padding: 0.75rem 1rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-family: var(--font-code);
    font-size: 0.8rem;
}

.event-item .detail {
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-size: 0.75rem;
    word-break: break-all;
}

/* Markdown Docs */
.markdown-body {
    font-size: 0.85rem;
    line-height: 1.6;
}

.markdown-body h3 {
    color: var(--text-main);
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.25rem;
    margin-bottom: 0.75rem;
    margin-top: 1rem;
}

.markdown-body h3:first-child {
    margin-top: 0;
}

.markdown-body ul {
    padding-left: 1.5rem;
    color: var(--text-muted);
}

.markdown-body code {
    font-family: var(--font-code);
    background: rgba(0, 0, 0, 0.3);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    color: var(--accent);
    font-size: 0.8rem;
}

/* Toasts */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    color: #000;
    padding: 0.75rem 1.5rem;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.warning {
    background: var(--warning);
}

.toast.error {
    background: var(--error);
    color: #FFF;
}

@media (max-width: 900px) {
    .workspace {
        flex-direction: column;
    }

    .pane {
        flex: none;
        height: 50vh;
    }

    .pane-editor {
        border-right: none;
        border-bottom: 1px solid var(--border-light);
    }
}