/* ==========================================================================
   Web Dev Playground - Dark / Modern CSS Design System
   ========================================================================== */

:root {
    /* Color Palette */
    --bg-dark: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-hover: #334155;
    --bg-editor: #0b1329;
    --border-color: #334155;
    --border-accent: #475569;
    
    /* Brand Colors */
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: rgba(59, 130, 246, 0.15);
    
    /* Tech Brand Colors */
    --color-html: #f97316;
    --color-html-bg: rgba(249, 115, 22, 0.15);
    --color-css: #06b6d4;
    --color-css-bg: rgba(6, 182, 212, 0.15);
    --color-js: #eab308;
    --color-js-bg: rgba(234, 179, 8, 0.15);
    
    /* UI Text */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-sub: #64748b;
    
    /* Action Colors */
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    /* Fonts */
    --font-ui: 'Plus Jakarta Sans', 'Noto Sans Lao', system-ui, sans-serif;
    --font-code: 'Fira Code', Consolas, Monaco, monospace;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-ui);
    background-color: var(--bg-dark);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
}

/* App Container Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Header Styles */
.app-header {
    height: 56px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.brand-title h1 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
}

.brand-title span {
    font-size: 11px;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.custom-select {
    background: var(--bg-dark);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-family: var(--font-ui);
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: min(360px, 42vw);
}

.custom-select:hover, .custom-select:focus {
    border-color: var(--primary);
}

.action-divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
}

/* Switch Toggle Button */
.toggle-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
}

.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #475569;
    transition: .3s;
}

.slider.round {
    border-radius: 20px;
}

.slider.round:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(18px);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-ui);
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover {
    background: #059669;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.btn-secondary {
    background: var(--bg-surface-hover);
    color: var(--text-main);
}
.btn-secondary:hover {
    background: #475569;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}
.btn-outline:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-accent);
}

.btn-danger-outline {
    background: transparent;
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}
.btn-danger-outline:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: var(--danger);
    color: #fff;
}

/* Workspace Layout */
.workspace-layout {
    flex: 1;
    display: flex;
    height: calc(100vh - 56px - 28px);
    overflow: hidden;
    position: relative;
}

/* Editor Section */
.editor-section {
    width: 50%;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-editor);
    border-right: none;
}

/* Tabs Header */
.tabs-header {
    height: 42px;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    border-bottom: 1px solid var(--border-color);
}

.tabs-list {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-top: 2px solid transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-ui);
    cursor: pointer;
    border-radius: 4px 4px 0 0;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
    background: var(--bg-editor);
    color: var(--text-main);
}

.tab-btn[data-tab="html"].active {
    border-top-color: var(--color-html);
}
.tab-btn[data-tab="css"].active {
    border-top-color: var(--color-css);
}
.tab-btn[data-tab="js"].active {
    border-top-color: var(--color-js);
}

.icon-html { color: var(--color-html); font-size: 16px; }
.icon-css { color: var(--color-css); font-size: 16px; }
.icon-js { color: var(--color-js); font-size: 16px; }

.badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 500;
}

#badge-html { background: var(--color-html-bg); color: var(--color-html); }
#badge-css { background: var(--color-css-bg); color: var(--color-css); }
#badge-js { background: var(--color-js-bg); color: var(--color-js); }

.tab-actions {
    font-size: 11px;
    color: var(--text-sub);
}

.hint-text {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #60a5fa;
}

/* Quick Snippets Helper Bar */
.quick-snippets-bar {
    height: 36px;
    background: rgba(30, 41, 59, 0.6);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
    overflow-x: auto;
}

.quick-snippets-bar::-webkit-scrollbar {
    height: 3px;
}
.quick-snippets-bar::-webkit-scrollbar-thumb {
    background: var(--border-color);
}

.snippets-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.snippets-list {
    display: flex;
    align-items: center;
    gap: 6px;
}

.snippet-chip {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: #cbd5e1;
    font-family: var(--font-code);
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.snippet-chip:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: #fff;
    transform: translateY(-1px);
}

/* Editors Container */
.editors-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.editor-pane {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
}

.editor-pane.active {
    display: block;
}

/* Loading Overlay */
.editor-loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-editor);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 5;
    color: var(--text-muted);
    font-size: 13px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Resizer Handle — wide hit area, easy to grab */
.layout-resizer {
    width: 10px;
    flex: 0 0 10px;
    background: var(--bg-surface);
    cursor: col-resize;
    position: relative;
    z-index: 40;
    transition: background 0.15s;
    touch-action: none;
}

.layout-resizer::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -6px;
    right: -6px;
    z-index: 1;
}

.layout-resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 40px;
    border-radius: 4px;
    background: var(--border-accent);
    pointer-events: none;
    opacity: 0.7;
    transition: background 0.15s, height 0.15s, opacity 0.15s;
}

.layout-resizer:hover,
.layout-resizer.dragging {
    background: var(--primary-light);
}

.layout-resizer:hover::after,
.layout-resizer.dragging::after {
    background: var(--primary);
    height: 56px;
    opacity: 1;
}

body.is-resizing {
    cursor: col-resize !important;
    user-select: none !important;
}

body.is-resizing iframe {
    pointer-events: none !important;
}

/* Preview Section */
.preview-section {
    flex: 1;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #0f172a;
}

.preview-header {
    height: 42px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
}

.preview-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
}

.viewport-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.view-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
}

.view-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.view-btn.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.view-btn.icon-only {
    padding: 4px 6px;
    font-size: 14px;
}

/* Iframe Wrapper */
.iframe-wrapper {
    flex: 1;
    width: 100%;
    min-height: 0;
    background: #1e293b;
    display: flex;
    justify-content: center;
    align-items: stretch;
    overflow: hidden;
    position: relative;
}

#preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #ffffff;
    transition: width 0.25s ease;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.35);
}

/* Console Drawer Panel */
.console-panel {
    height: 140px;
    background: #0b0f19;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: height 0.25s ease;
}

.console-panel.collapsed {
    height: 32px;
}

.console-header {
    height: 32px;
    background: var(--bg-surface);
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.console-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.console-title code {
    background: rgba(255, 255, 255, 0.1);
    padding: 1px 4px;
    border-radius: 3px;
    color: var(--color-js);
    font-family: var(--font-code);
}

.console-count {
    background: var(--primary);
    color: white;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
}

.console-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-sm {
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
}

.console-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-family: var(--font-code);
    font-size: 12px;
    line-height: 1.5;
}

.console-empty {
    color: var(--text-sub);
    font-style: italic;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.log-entry {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.log-entry.log { color: #e2e8f0; }
.log-entry.info { color: #38bdf8; }
.log-entry.warn { color: #fbbf24; background: rgba(251, 191, 36, 0.08); }
.log-entry.error { color: #f87171; background: rgba(248, 113, 113, 0.1); }

.log-icon { font-size: 13px; margin-top: 2px; }

/* Status Bar Footer */
.app-footer {
    height: 28px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    font-size: 11px;
    color: var(--text-muted);
}

.footer-left, .footer-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-badge {
    color: var(--success);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.security-badge {
    color: #38bdf8;
    font-weight: 600;
}

.footer-info code {
    color: var(--primary);
    background: var(--primary-light);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: var(--font-code);
}
