:root {
    --primary: #0077CC;
    --primary-light: #4FC3F7;
    --bg: #ffffff;
    --bg-light: #f8fafc;
    --bg-dark: #0A0A0A;
    --text: #1a1a1a;
    --text-light: #6b7280;
    --border: #e2e8f0;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --radius: 6px;
    --header-h: 52px;
    --footer-h: 50px;
    --sidebar-w: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: Inter, -apple-system, sans-serif; background: var(--bg-light); color: var(--text); font-size: 13px; overflow: hidden; height: 100vh; }

/* Header */
.header { height: var(--header-h); background: var(--bg); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; }
.header-left { display: flex; align-items: center; gap: 8px; }
.logo { font-family: 'JetBrains Mono', monospace; font-size: 18px; font-weight: 700; color: var(--bg-dark); }
.logo-sub { font-size: 11px; color: var(--text-light); }
.header-right { display: flex; align-items: center; gap: 6px; }
.header-right select { width: 180px; }

/* Buttons */
.btn { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); cursor: pointer; font-size: 12px; transition: all 0.15s; }
.btn:hover { background: var(--bg-light); }
.btn-sm { padding: 4px 8px; font-size: 11px; }
.btn-lg { padding: 10px 24px; font-size: 14px; font-weight: 600; }
.btn-primary { background: var(--bg-dark); color: #fff; border-color: var(--bg-dark); }
.btn-primary:hover { background: #222; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #059669; }
.btn-success:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }

/* Forms */
.form-control { padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 12px; background: var(--bg); }
.form-sm { width: 100%; font-size: 11px; }

/* Panel container */
.panel-container { display: flex; height: calc(100vh - var(--header-h) - var(--footer-h)); position: relative; }

/* Sidebar */
.controls-panel { width: var(--sidebar-w); min-width: var(--sidebar-w); background: var(--bg); border-right: 1px solid var(--border); overflow-y: auto; padding: 0; transition: margin-left 0.2s; }
.controls-panel.collapsed { margin-left: calc(var(--sidebar-w) * -1); }

/* Tabs */
.tabs { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 2; }
.tab { padding: 8px 4px; border: none; background: none; cursor: pointer; font-size: 10px; font-weight: 500; color: var(--text-light); border-bottom: 2px solid transparent; transition: all 0.15s; }
.tab:hover { color: var(--text); background: var(--bg-light); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; padding: 12px; }
.tab-content.active { display: block; }

/* Control groups */
.control-group { margin-bottom: 10px; }
.control-group label { display: block; font-size: 11px; font-weight: 500; color: var(--text-light); margin-bottom: 3px; }
.section-label { font-size: 11px; font-weight: 600; color: var(--text); margin-bottom: 6px; display: block; }

/* Color pickers */
.color-row { display: flex; align-items: center; gap: 6px; }
.color-hex { width: 70px; font-family: monospace; font-size: 11px; text-align: center; }
.pickr { width: 32px; height: 32px; }
.pickr .pcr-button { width: 32px !important; height: 32px !important; border-radius: 4px !important; }

/* Palette grid */
.palette-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.palette-grid .pickr { width: 100%; }
.palette-grid .pcr-button { width: 100% !important; height: 36px !important; }

/* Sliders */
.slider { width: 100%; height: 4px; -webkit-appearance: none; appearance: none; background: var(--border); border-radius: 2px; outline: none; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--primary); cursor: pointer; }

/* Toggle switches */
.toggle-group { display: flex; align-items: center; justify-content: space-between; }
.toggle-group label { margin-bottom: 0; }
.toggle { appearance: none; width: 36px; height: 20px; background: var(--border); border-radius: 10px; cursor: pointer; position: relative; transition: background 0.2s; }
.toggle:checked { background: var(--primary); }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform 0.2s; }
.toggle:checked::after { transform: translateX(16px); }

/* Toggle panel button */
.btn-toggle { position: absolute; left: var(--sidebar-w); top: 50%; transform: translateY(-50%); z-index: 10; width: 20px; height: 40px; border: 1px solid var(--border); border-left: none; background: var(--bg); border-radius: 0 var(--radius) var(--radius) 0; cursor: pointer; font-size: 10px; color: var(--text-light); transition: left 0.2s; display: flex; align-items: center; justify-content: center; }
.btn-toggle.collapsed { left: 0; }

/* Main area: editor + preview */
.main-area { flex: 1; display: flex; overflow: hidden; }

/* Editor panel */
.editor-panel { flex: 1; min-width: 300px; display: flex; flex-direction: column; padding: 0; overflow: hidden; }

/* Resizer */
.resizer { width: 5px; cursor: col-resize; background: var(--border); transition: background 0.15s; flex-shrink: 0; }
.resizer:hover, .resizer.active { background: var(--primary-light); }

/* Preview panel */
.preview-panel { width: 55%; min-width: 300px; display: flex; flex-direction: column; background: var(--bg-light); overflow: hidden; }
.preview-panel.hidden { display: none; }
.preview-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: var(--bg); border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--text-light); }
.preview-container { flex: 1; position: relative; }
.preview-container iframe { width: 100%; height: 100%; border: none; }
.preview-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text-light); font-size: 14px; text-align: center; padding: 20px; }

/* Snippet toolbar */
.snippet-toolbar { display: flex; align-items: center; gap: 4px; padding: 6px 12px; background: var(--bg); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.snippet-group { display: flex; gap: 2px; }
.snippet-group::after { content: ''; width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.snippet-group:last-of-type::after { display: none; }
.snippet-btn { padding: 3px 8px; border: 1px solid var(--border); border-radius: 3px; background: var(--bg); cursor: pointer; font-size: 10px; font-family: 'JetBrains Mono', monospace; color: var(--text-light); transition: all 0.1s; }
.snippet-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.snippet-actions { margin-left: auto; display: flex; gap: 4px; }

/* Markdown textarea */
#markdown-input { flex: 1; width: 100%; border: none; resize: none; padding: 16px; font-family: 'JetBrains Mono', monospace; font-size: 13px; line-height: 1.6; background: var(--bg); color: var(--text); outline: none; }

/* Info bar */
.info-bar { display: flex; gap: 16px; padding: 4px 16px; background: var(--bg-light); border-top: 1px solid var(--border); font-size: 11px; color: var(--text-light); }

/* Actions bar */
.actions-bar { display: flex; gap: 8px; padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--border); }

/* Contrast errors */
.contrast-errors { margin: 0 16px 8px; padding: 12px; background: #fef3c7; border: 1px solid var(--warning); border-radius: var(--radius); font-size: 12px; }
.contrast-errors h4 { font-size: 13px; color: #92400e; margin-bottom: 6px; }
.contrast-errors ul { margin: 0; padding-left: 18px; }
.contrast-errors li { margin-bottom: 4px; color: #78350f; }
.contrast-errors .hint { margin-top: 8px; font-style: italic; color: #92400e; }
.contrast-errors .dismiss { float: right; cursor: pointer; color: #92400e; font-weight: bold; border: none; background: none; }

/* Footer */
.footer { height: var(--footer-h); background: var(--bg); border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; }
.footer-left { display: flex; align-items: center; gap: 8px; }
.footer-left label { font-size: 11px; color: var(--text-light); white-space: nowrap; }
.footer-left input { font-size: 12px; }
.footer-left input:first-of-type { width: 120px; }
.footer-left input:last-of-type { width: 200px; }
.footer-right { display: flex; align-items: center; gap: 10px; }
.save-status { font-size: 11px; color: var(--success); }
.save-status.unsaved { color: var(--warning); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #cbd5e1; }

/* Chat panel */
.chat-panel { position: fixed; bottom: 0; right: 20px; width: 440px; background: var(--bg); border: 1px solid var(--border); border-bottom: none; border-radius: 10px 10px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,0.1); z-index: 100; display: flex; flex-direction: column; transition: height 0.25s ease; }
.chat-panel.collapsed { height: 42px; overflow: hidden; }
.chat-panel:not(.collapsed) { height: 480px; }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--border); background: var(--bg-dark); color: #fff; border-radius: 10px 10px 0 0; font-size: 13px; font-weight: 600; user-select: none; }
.chat-shortcut { font-size: 10px; opacity: 0.5; font-family: monospace; }
.chat-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 85%; }
.chat-msg.user { align-self: flex-end; }
.chat-msg.assistant { align-self: flex-start; }
.chat-bubble { padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5; word-wrap: break-word; }
.chat-msg.user .chat-bubble { background: var(--bg-dark); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.assistant .chat-bubble { background: var(--bg-light); color: var(--text); border-bottom-left-radius: 4px; border: 1px solid var(--border); }
.chat-msg.typing .chat-bubble { color: var(--text-light); font-style: italic; }
.chat-input-row { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--bg); }
.chat-input-row textarea { flex: 1; resize: none; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; outline: none; }
.chat-input-row textarea:focus { border-color: var(--primary); }
.chat-input-row .btn { align-self: flex-end; padding: 8px 16px; }

/* Responsive */
@media (max-width: 768px) {
    .controls-panel { position: absolute; z-index: 20; height: 100%; }
    .controls-panel.collapsed { margin-left: calc(var(--sidebar-w) * -1); }
    .btn-toggle { z-index: 21; }
    .header-right select { width: 120px; }
    .snippet-toolbar { overflow-x: auto; flex-wrap: nowrap; }
}
