:root {
    --bg-base: #09090b;
    --bg-surface: #121214;
    --bg-panel: #18181b;
    --bg-input: #27272a;
    --border: #3f3f46;
    --text-main: #f4f4f5;
    --text-muted: #a1a1aa;

    --primary: #3b82f6;
    /* Blue */
    --primary-glow: rgba(59, 130, 246, 0.4);
    --accent: #8b5cf6;
    /* Purple */
    --danger: #ef4444;
    /* Red */
    --danger-glow: rgba(239, 68, 68, 0.2);

    /* Syntax Highlighting Colors */
    --hl-var: #f59e0b;
    /* {{VAR}} */
    --hl-xml: #10b981;
    /* <tag> */
    --hl-md: #eab308;
    /* **bold** */

    --font-sans: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Base Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.sm-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.icon-only {
    padding: 0.6rem;
}

.full-width {
    width: 100%;
}

.primary-btn {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 10px var(--primary-glow);
}

.primary-btn:hover {
    background: #2563eb;
    box-shadow: 0 0 15px var(--primary-glow);
}

.secondary-btn {
    background: var(--bg-input);
    color: var(--text-main);
    border-color: var(--border);
}

.secondary-btn:hover {
    background: #3f3f46;
}

.danger-btn {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}

.danger-btn:hover {
    background: var(--danger-glow);
}

/* Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
    margin-bottom: 2rem;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.vault-section {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

.vault-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 1rem;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
}

.search-box svg {
    position: absolute;
    left: 0.75rem;
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem 0.5rem 0.5rem 2.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

.vault-list {
    list-style: none;
    overflow-y: auto;
    flex-grow: 1;
}

.vault-list::-webkit-scrollbar {
    width: 4px;
}

.vault-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.vault-item {
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 0.25rem;
    border: 1px solid transparent;
}

.vault-item:hover {
    background: var(--bg-panel);
}

.vault-item.active {
    background: var(--bg-input);
    border-color: var(--border);
}

.vault-item-title {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vault-item-category {
    font-size: 0.7rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Workspace */
.workspace {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: radial-gradient(circle at top, rgba(59, 130, 246, 0.05), transparent 40%);
}

.workspace-header {
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    gap: 2rem;
}

.title-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-grow: 1;
}

.title-input {
    background: transparent;
    border: 2px solid transparent;
    color: var(--text-main);
    font-size: 1.5rem;
    font-weight: 600;
    font-family: var(--font-sans);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    width: 100%;
    max-width: 400px;
    transition: border-color 0.2s;
}

.title-input:focus {
    outline: none;
    border-color: var(--border);
    background: var(--bg-surface);
}

.category-select {
    background: var(--bg-input);
    color: var(--accent);
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    cursor: pointer;
}

.category-select:focus {
    outline: none;
    border-color: var(--accent);
}

.action-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stats-counter {
    display: flex;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--bg-surface);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.stats-counter .divider {
    color: var(--border);
}

/* Editor Layout */
.editor-layout {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
}

.pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 2rem;
}

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

.pane-header {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pane-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
}

.pane-header .hint {
    font-size: 0.8rem;
    color: var(--primary);
    font-family: var(--font-mono);
    background: rgba(59, 130, 246, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

/* Syntax Highlighting Editor */
.editor-container {
    flex-grow: 1;
    position: relative;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.highlight-layer,
.editor-textarea {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 1.5rem;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
}

/* The actual textarea is transparent but takes input */
.editor-textarea {
    color: transparent;
    background: transparent;
    caret-color: var(--text-main);
    border: none;
    resize: none;
    z-index: 2;
}

.editor-textarea:focus {
    outline: none;
    box-shadow: inset 0 0 0 1px var(--primary);
}

/* The visual layer underneath */
.highlight-layer {
    color: var(--text-muted);
    z-index: 1;
    pointer-events: none;
}

/* Highlight Tokens */
.hl-xml {
    color: var(--hl-xml);
    font-weight: 500;
}

.hl-var {
    color: var(--hl-var);
    background: rgba(245, 158, 11, 0.15);
    border-radius: 3px;
    padding: 0 2px;
}

.hl-md {
    color: var(--hl-md);
    font-weight: bold;
}

/* Variables & Preview */
.preview-pane {
    background: var(--bg-base);
}

.variables-section {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.variables-section h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.variables-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.var-input-group {
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.var-label {
    background: var(--bg-surface);
    padding: 0.6rem 0.75rem;
    color: var(--hl-var);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
    border-right: 1px solid var(--border);
    min-width: 120px;
}

.var-input {
    flex-grow: 1;
    background: var(--bg-input);
    border: none;
    color: var(--text-main);
    padding: 0.6rem 0.75rem;
    font-size: 0.95rem;
    font-family: var(--font-sans);
}

.var-input:focus {
    outline: none;
    background: #3f3f46;
}

.preview-section {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.preview-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.preview-header-bar h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.preview-container {
    flex-grow: 1;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    overflow: hidden;
}

#prompt-preview {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--text-main);
    padding: 1.5rem;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    line-height: 1.6;
    resize: none;
}

#prompt-preview:focus {
    outline: none;
    box-shadow: inset 0 0 0 1px var(--primary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 30px;
    font-weight: 600;
    box-shadow: 0 10px 25px var(--primary-glow);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

.toast.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}