/* ============================================================
   CQ Web Builder — Matte Black Theme
   ============================================================ */

:root {
    /* Core Palette — Matte Black */
    --bg-void:      #0a0a0a;
    --bg-base:      #111111;
    --bg-surface:   #181818;
    --bg-elevated:  #1f1f1f;
    --bg-hover:     #252525;
    --bg-active:    #2a2a2a;

    /* Borders */
    --border-subtle:  rgba(255,255,255,0.06);
    --border-default: rgba(255,255,255,0.10);
    --border-strong:  rgba(255,255,255,0.16);

    /* Text */
    --text-primary:   #f0f0f0;
    --text-secondary: #a0a0a0;
    --text-dim:       #606060;

    /* Accent — electric amber for edge, not soft purple */
    --accent:         #f0a500;
    --accent-dim:     rgba(240, 165, 0, 0.12);
    --accent-hover:   #f7b731;

    /* Status Colors */
    --success:  #3ddc84;
    --error:    #ff4d4d;
    --warn:     #f7b731;
    --info:     #64b5f6;

    /* Tab Language Colors */
    --html-color: #e8674a;
    --css-color:  #5b9cf6;
    --js-color:   #f7b731;

    /* Layout */
    --sidebar-width: 52px;
    --header-height: 52px;
    --status-height: 26px;
    --pane-header-height: 42px;

    /* Typography */
    --font-ui:   'DM Sans', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', 'Fira Code', monospace;

    /* Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;

    /* Transitions */
    --transition-fast: 100ms ease;
    --transition-base: 180ms ease;
}

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

body {
    font-family: var(--font-ui);
    background: var(--bg-void);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
}

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-base);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
    z-index: 100;
    flex-shrink: 0;
}

.sidebar-logo {
    width: 100%;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    width: 100%;
}

.side-icon {
    color: var(--text-dim);
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast);
    padding: 9px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    position: relative;
}

.side-icon:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.side-icon.active {
    color: var(--accent);
    background: var(--accent-dim);
}

/* ══════════════════════════════════════════
   MAIN WRAPPER
══════════════════════════════════════════ */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ══════════════════════════════════════════
   HEADER
══════════════════════════════════════════ */
.app-header {
    height: var(--header-height);
    background: var(--bg-base);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 9px;
    letter-spacing: 0.01em;
}

.logo-text {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.logo-sub {
    font-weight: 300;
    color: var(--text-dim);
    margin-left: 1px;
}

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

.divider-v {
    width: 1px;
    height: 22px;
    background: var(--border-default);
    margin: 0 2px;
}

/* ══════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════ */
button {
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: #0a0a0a;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }

.btn-primary kbd {
    background: rgba(0,0,0,0.2);
    color: rgba(0,0,0,0.6);
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    letter-spacing: 0;
    font-weight: 500;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 6px 10px;
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-ghost-sm {
    background: transparent;
    color: var(--text-dim);
    padding: 4px 8px;
    font-size: 11px;
    border-radius: var(--radius-sm);
}
.btn-ghost-sm:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.btn-close {
    background: transparent;
    color: var(--text-dim);
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 20px;
    border-radius: var(--radius-md);
    justify-content: center;
}
.btn-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-icon-text {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    padding: 5px 10px;
    font-size: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
}
.btn-icon-text:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ══════════════════════════════════════════
   WORKSPACE
══════════════════════════════════════════ */
.workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

.pane {
    display: flex;
    flex-direction: column;
    min-width: 180px;
    overflow: hidden;
    background: var(--bg-void);
}

#code-pane { flex: 1; }
#output-pane { width: 38%; flex-shrink: 0; border-left: 1px solid var(--border-subtle); }

.pane-header {
    height: var(--pane-header-height);
    background: var(--bg-base);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
    gap: 8px;
}

.pane-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* ── Tabs ── */
.editor-tabs, .output-tabs {
    display: flex;
    gap: 2px;
}

.tab-btn {
    background: transparent;
    color: var(--text-dim);
    padding: 5px 11px;
    border-radius: var(--radius-sm);
    font-size: 11.5px;
    font-weight: 500;
    font-family: var(--font-ui);
    letter-spacing: 0.02em;
    gap: 6px;
    transition: color var(--transition-fast), background var(--transition-fast);
}
.tab-btn:hover { color: var(--text-secondary); background: var(--bg-hover); }
.tab-btn.active { color: var(--text-primary); background: var(--bg-active); }

/* Language dot indicators */
.tab-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.html-dot { background: var(--html-color); }
.css-dot  { background: var(--css-color); }
.js-dot   { background: var(--js-color); }

/* ══════════════════════════════════════════
   EDITOR
══════════════════════════════════════════ */
#editor-container {
    flex: 1;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.CodeMirror {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 14px;
    height: 100% !important;
    line-height: 1.65;
    background: var(--bg-void) !important;
}

.CodeMirror-gutters {
    background: var(--bg-void) !important;
    border-right: 1px solid var(--border-subtle) !important;
}

.CodeMirror-linenumber {
    color: var(--text-dim) !important;
    font-size: 11px;
}

.CodeMirror-activeline-background {
    background: rgba(255,255,255,0.03) !important;
}

.CodeMirror-selected { background: rgba(240,165,0,0.12) !important; }
.CodeMirror-focused .CodeMirror-selected { background: rgba(240,165,0,0.15) !important; }

.CodeMirror-cursor { border-left: 2px solid var(--accent) !important; }

/* Foldgutter */
.CodeMirror-foldgutter-open,
.CodeMirror-foldgutter-folded { color: var(--text-dim); }

/* ══════════════════════════════════════════
   RESIZER
══════════════════════════════════════════ */
.resizer {
    width: 5px;
    cursor: col-resize;
    background: var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    transition: background var(--transition-fast);
}
.resizer:hover, .resizer.dragging { background: var(--accent); }

.resizer-handle {
    width: 1px;
    height: 40px;
    background: rgba(255,255,255,0.2);
    border-radius: 1px;
}

/* ══════════════════════════════════════════
   OUTPUT / CONSOLE
══════════════════════════════════════════ */
.output-content {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.output-content.active { display: flex; }

#output {
    flex: 1;
    padding: 8px 12px;
    font-family: var(--font-mono);
    overflow-y: auto;
    font-size: 12.5px;
    line-height: 1.6;
    background: var(--bg-void);
    color: var(--text-primary);
}

/* Console Entry Types */
.log-entry {
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    border-left: 2px solid transparent;
    white-space: pre-wrap;
    word-break: break-all;
}
.log-log   { border-left-color: var(--border-default); color: var(--text-primary); }
.log-error { border-left-color: var(--error); background: rgba(255,77,77,0.06); color: var(--error); }
.log-warn  { border-left-color: var(--warn); background: rgba(247,183,49,0.05); color: var(--warn); }
.log-info  { border-left-color: var(--info); color: var(--info); }
.log-debug { border-left-color: var(--text-dim); color: var(--text-dim); }
.log-time  { color: var(--accent); font-size: 10px; font-weight: 600; margin-top: 8px; letter-spacing: 0.05em; }

/* Expandable JSON blocks */
.log-object-toggle {
    cursor: pointer;
    color: var(--info);
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: rgba(100,181,246,0.08);
    border: 1px solid rgba(100,181,246,0.15);
    margin-top: 2px;
}
.log-object-toggle:hover { background: rgba(100,181,246,0.14); }
.log-object-toggle svg { transition: transform var(--transition-fast); }
.log-object-toggle.expanded svg { transform: rotate(90deg); }

.log-object-body {
    display: none;
    margin-top: 4px;
    padding: 8px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: pre;
}
.log-object-body.visible { display: block; }

.console-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-dim);
    gap: 8px;
    font-size: 12px;
}

/* Error badge on console tab */
.error-badge {
    background: var(--error);
    color: white;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 8px;
    min-width: 16px;
    text-align: center;
    line-height: 14px;
}
.error-badge.hidden { display: none; }

/* ══════════════════════════════════════════
   STATUS BAR
══════════════════════════════════════════ */
.status-bar {
    height: var(--status-height);
    background: var(--bg-base);
    border-top: 1px solid var(--border-subtle);
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    font-size: 11px;
    font-family: var(--font-mono);
    flex-shrink: 0;
}

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

.status-sep { color: var(--border-default); }

#autosave-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--success);
}

/* ══════════════════════════════════════════
   SNIPPETS PANEL
══════════════════════════════════════════ */
#snippets-menu {
    position: absolute;
    left: var(--sidebar-width);
    top: 0;
    bottom: 0;
    width: 260px;
    background: var(--bg-base);
    border-right: 1px solid var(--border-default);
    z-index: 80;
    transform: translateX(-110%);
    transition: transform 280ms cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 8px 0 40px rgba(0,0,0,0.6);
}

#snippets-menu.open { transform: translateX(0); }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.panel-title {
    font-weight: 600;
    font-size: 12.5px;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

#snippets-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 10px;
}

.snippet-item {
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: 6px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12.5px;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}
.snippet-item:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    background: var(--bg-elevated);
}
.snippet-item .snippet-delete {
    color: var(--text-dim);
    background: none;
    border: none;
    padding: 2px 5px;
    cursor: pointer;
    border-radius: 3px;
    font-size: 16px;
    line-height: 1;
}
.snippet-item .snippet-delete:hover { color: var(--error); background: rgba(255,77,77,0.08); }

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-dim);
    gap: 12px;
    font-size: 12px;
    line-height: 1.6;
}

/* ══════════════════════════════════════════
   MODALS
══════════════════════════════════════════ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}
.modal.open { display: flex; }

.modal-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    width: 520px;
    max-width: 92vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.7);
    animation: modal-in 180ms ease;
    overflow: hidden;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(-12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-body { padding: 20px; }

.modal-hint {
    color: var(--text-dim);
    font-size: 12px;
    margin-bottom: 16px;
}

/* Resources */
.resource-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

#resource-url {
    flex: 1;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
    background: var(--bg-void);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    transition: border-color var(--transition-fast);
}
#resource-url:focus { outline: none; border-color: var(--accent); }
#resource-url::placeholder { color: var(--text-dim); }

#resource-type {
    padding: 8px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
    background: var(--bg-void);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 12px;
    cursor: pointer;
}
#resource-type:focus { outline: none; }

.resource-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    margin-bottom: 6px;
    border: 1px solid var(--border-subtle);
    transition: border-color var(--transition-fast);
}
.resource-item:hover { border-color: var(--border-default); }

.resource-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
}

.resource-url {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 360px;
}

.resource-badge {
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    width: fit-content;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.resource-badge.css { background: rgba(91,156,246,0.12); color: var(--css-color); }
.resource-badge.js  { background: rgba(247,183,49,0.12); color: var(--js-color); }

.delete-resource {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-size: 16px;
    line-height: 1;
}
.delete-resource:hover { color: var(--error); background: rgba(255,77,77,0.1); }

/* ══════════════════════════════════════════
   SETTINGS MODAL
══════════════════════════════════════════ */
.settings-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-subtle);
}
.settings-group:last-child { border-bottom: none; }

.settings-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.settings-select {
    padding: 6px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 12px;
    cursor: pointer;
    min-width: 130px;
}
.settings-select:focus { outline: none; border-color: var(--accent); }

.font-size-control {
    display: flex;
    align-items: center;
    gap: 12px;
}
.font-size-control button {
    width: 26px;
    height: 26px;
    padding: 0;
    justify-content: center;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-size: 16px;
    line-height: 1;
}
.font-size-control button:hover { background: var(--bg-hover); }
#font-size-display { font-family: var(--font-mono); font-size: 12px; color: var(--text-secondary); min-width: 36px; text-align: center; }

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
    cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-hover);
    border-radius: 20px;
    border: 1px solid var(--border-default);
    transition: background var(--transition-base);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--text-dim);
    border-radius: 50%;
    transition: transform var(--transition-base), background var(--transition-base);
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent-dim); border-color: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translate(18px, -50%); background: var(--accent); }

/* ══════════════════════════════════════════
   SCROLLBARS
══════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-active); }

/* ══════════════════════════════════════════
   AUTOSAVE FLASH
══════════════════════════════════════════ */
@keyframes saved-flash {
    0%   { opacity: 0.4; }
    50%  { opacity: 1; }
    100% { opacity: 0.4; }
}
.saving { animation: saved-flash 0.8s ease; }

/* ══════════════════════════════════════════
   CODE MIRROR DIALOG (Search)
══════════════════════════════════════════ */
.CodeMirror-dialog {
    background: var(--bg-elevated) !important;
    border-bottom: 1px solid var(--border-default) !important;
    color: var(--text-primary) !important;
    padding: 6px 12px !important;
    font-family: var(--font-ui) !important;
    font-size: 12px !important;
}
.CodeMirror-dialog input {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 4px 8px;
    font-size: 12px;
    outline: none;
}
.CodeMirror-dialog input:focus { border-color: var(--accent); }
