:root {
    --bg: #1e1e1e;
    --surface: #252526;
    --border: #3c3c3c;
    --text: #cccccc;
    --text-muted: #999999;
    --primary: #0e639c;
    --primary-hover: #1177bb;
    --danger: #c53030;
    --danger-hover: #e53e3e;
    --success: #2d8a4e;
    --error-bg: #3b1515;
    --error-border: #c53030;
    --header-height: 48px;
    --pane-header-height: 72px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Toolbar */
#toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#toolbar h1 {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

#token-section {
    display: flex;
    align-items: center;
    gap: 6px;
}

#token-input {
    width: 280px;
    padding: 4px 8px;
    font-size: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 3px;
}

#token-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 3px;
}

#token-status.valid {
    background: var(--success);
    color: white;
}

#token-status.expiring {
    background: #b7791f;
    color: white;
}

#token-status.expired {
    background: var(--danger);
    color: white;
}

/* Buttons */
button {
    cursor: pointer;
    font-size: 12px;
    border: none;
    border-radius: 3px;
    padding: 4px 10px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

button:hover {
    background: var(--border);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.small-btn {
    font-size: 11px;
    padding: 3px 8px;
}

.small-btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.small-btn.primary:hover {
    background: var(--primary-hover);
}

.small-btn.danger {
    color: var(--danger);
}

.small-btn.danger:hover {
    background: var(--danger);
    color: white;
}

.toolbar-btn {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    padding: 5px 12px;
    text-decoration: none;
    display: inline-block;
}

.toolbar-btn:hover {
    background: var(--primary-hover);
}

/* Main layout */
#workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    min-width: 0;
}

.pane:last-child {
    border-right: none;
}

.pane-header {
    padding: 6px 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: var(--pane-header-height);
}

.pane-title {
    font-size: 12px;
    font-weight: 600;
    margin-right: 8px;
}

.template-filters,
.template-actions,
.preview-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.template-filters input {
    width: 110px;
    padding: 3px 6px;
    font-size: 11px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 3px;
}

#template-select {
    max-width: 180px;
    padding: 3px 6px;
    font-size: 11px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 3px;
}

/* Editor containers */
.editor-container {
    flex: 1;
    min-height: 0;
}

/* Drop zone */
.drop-zone {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(14, 99, 156, 0.3);
    border: 2px dashed var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: white;
    z-index: 10;
}

/* Preview */
#preview-container {
    flex: 1;
    position: relative;
    min-height: 0;
}

#preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

#preview-raw {
    position: absolute;
    inset: 0;
}

.error-box {
    padding: 8px 12px;
    font-size: 12px;
    background: var(--error-bg);
    border-top: 1px solid var(--error-border);
    color: #fc8181;
    max-height: 120px;
    overflow-y: auto;
    white-space: pre-wrap;
}

/* Toggle */
.toggle-label {
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    width: 80vw;
    height: 70vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 14px;
    font-weight: 600;
}

.close-btn {
    font-size: 20px;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
}

.modal-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.partials-sidebar {
    width: 200px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.partials-list-header {
    display: flex;
    gap: 4px;
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

#partials-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

#partials-list li {
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

#partials-list li:hover {
    background: var(--border);
}

#partials-list li.active {
    background: var(--primary);
    color: white;
}

.partials-editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.partial-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.partial-name-row label {
    font-size: 12px;
    font-weight: 600;
}

.partial-name-row input {
    flex: 1;
    padding: 4px 8px;
    font-size: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 3px;
}

.partial-actions {
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 6px;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Pane Resizer */
.pane-resizer {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.15s;
}

.pane-resizer:hover,
.pane-resizer.active {
    background: var(--primary);
}

/* Monaco partial reference decoration */
.partial-reference {
    text-decoration: underline;
    text-decoration-color: #4fc1ff;
    cursor: pointer !important;
}
