:root {
    /* Catppuccin Mocha Inspired Theme */
    --clr-bg-base: #11111b;     /* Mantle */
    --clr-bg-surface: #1e1e2e;  /* Base */
    --clr-bg-overlay: #313244;  /* Surface0 */
    --clr-border: #45475a;      /* Surface1 */
    
    --clr-accent: #89b4fa;      /* Blue */
    --clr-accent-hover: #b4befe;/* Lavender */
    --clr-danger: #f38ba8;      /* Red */
    --clr-warning: #f9e2af;     /* Yellow */
    
    --clr-text-main: #cdd6f4;   /* Text */
    --clr-text-muted: #a6adc8;  /* Subtext0 */
    --clr-text-dark: #11111b;   /* For inverted text on accent */
    
    --font-sans: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

/* Utilities */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.ml-2 { margin-left: 0.5rem; }
.w-full { width: 100%; }
.w-auto { width: auto; }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.85rem; }
.text-main { color: var(--clr-text-main); }
.text-muted { color: var(--clr-text-muted); }
.mono { font-family: var(--font-mono); font-variant-ligatures: none; }

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: var(--transition);
}
.btn-primary { background: var(--clr-accent); color: var(--clr-text-dark); }
.btn-primary:hover { background: var(--clr-accent-hover); transform: translateY(-1px); }
.btn-icon { padding: 0.4rem; background: transparent; color: var(--clr-text-muted); border: 1px solid transparent; border-radius: var(--radius-sm); }
.btn-icon:hover { color: var(--clr-text-main); background: var(--clr-bg-overlay); border-color: var(--clr-border); }
.btn-icon.active { color: var(--clr-warning); }
.btn-icon.danger:hover { color: var(--clr-danger); }
.btn-text { background: transparent; border: none; color: var(--clr-text-muted); cursor: pointer; }
.btn-text:hover { color: var(--clr-accent); text-decoration: underline; }

.custom-select {
    background: var(--clr-bg-overlay);
    color: var(--clr-text-main);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    font-family: inherit;
    outline: none;
    cursor: pointer;
}
.custom-select:focus { border-color: var(--clr-accent); }

/* App Layout */
.app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 340px;
    height: 100%;
    background: var(--clr-bg-surface);
    border-right: 1px solid var(--clr-border);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-header {
    padding: 1.25rem 1.25rem 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.brand { display: flex; align-items: center; gap: 0.5rem; color: var(--clr-accent); }
.brand h1 { font-size: 1.1rem; font-weight: 600; color: var(--clr-text-main); }

.sidebar-search {
    padding: 0 1.25rem 1rem 1.25rem;
    border-bottom: 1px solid var(--clr-border);
}

.search-wrapper {
    position: relative;
    width: 100%;
}
.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--clr-text-muted);
}
#search-input {
    width: 100%;
    background: var(--clr-bg-overlay);
    border: 1px solid var(--clr-border);
    color: var(--clr-text-main);
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}
#search-input:focus { border-color: var(--clr-accent); }

.filter-controls select { width: 48%; }

/* Snippet List */
.snippet-list {
    flex-grow: 1;
    overflow-y: auto;
    list-style: none;
}

.snippet-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--clr-border);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}
.snippet-item:hover { background: rgba(255,255,255,0.03); }
.snippet-item.active { background: var(--clr-bg-overlay); border-left: 3px solid var(--clr-accent); }

.snip-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.25rem; }
.snip-title { font-weight: 600; font-size: 0.95rem; color: var(--clr-text-main); word-break: break-all; }
.snip-lang { font-size: 0.7rem; padding: 0.1rem 0.4rem; background: var(--clr-border); border-radius: 4px; color: var(--clr-text-muted); text-transform: uppercase; }

.snip-desc { font-size: 0.8rem; color: var(--clr-text-muted); margin-bottom: 0.5rem; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.snip-tags { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.snip-tag { font-family: var(--font-mono); font-size: 0.65rem; color: var(--clr-accent); background: rgba(137, 180, 250, 0.1); padding: 0.1rem 0.3rem; border-radius: 3px; }

.pin-indicator { color: var(--clr-warning); position: absolute; top: 1rem; right: 1.25rem; }

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--clr-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    position: relative;
    background: var(--clr-bg-base);
    display: flex;
    flex-direction: column;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* Editor State */
.editor-state {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.editor-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--clr-border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: var(--clr-bg-surface);
}

.editor-meta { flex-grow: 1; margin-right: 2rem; }
.title-input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--clr-text-main);
    font-size: 1.5rem;
    font-weight: 600;
    font-family: inherit;
    outline: none;
}
.title-input::placeholder { color: rgba(205, 214, 244, 0.3); }

.meta-row { display: flex; gap: 1rem; align-items: center; }
.tags-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    border-bottom: 1px solid transparent;
    color: var(--clr-accent);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition);
    padding: 0.25rem 0;
}
.tags-input:focus { border-color: var(--clr-accent); }
.tags-input::placeholder { color: rgba(137, 180, 250, 0.3); }

.editor-actions { display: flex; align-items: center; gap: 0.5rem; }
.header-btn { padding: 0.5rem; }

.editor-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.desc-input {
    width: 100%;
    background: var(--clr-bg-surface);
    border: none;
    border-bottom: 1px solid var(--clr-border);
    color: var(--clr-text-muted);
    font-size: 0.9rem;
    font-family: inherit;
    padding: 1rem 2rem;
    resize: none;
    outline: none;
    height: 60px;
    flex-shrink: 0;
}

/* Code Editor / Syntax Highlighter sync layer */
.code-container {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    background: var(--clr-bg-base);
}

.code-wrapper {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    overflow: auto;
}

/* 
   We overlay a transparent textarea on top of a rendered <pre> tag.
   They must have identical typography, padding, and box model.
*/
.code-editor, .code-viewer {
    margin: 0;
    padding: 1.5rem 2rem;
    border: 0;
    width: 100%;
    height: 100%;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.6;
    tab-size: 4;
    white-space: pre;
    overflow-wrap: normal;
    background: transparent;
}

.code-editor {
    position: absolute;
    top: 0; left: 0;
    color: transparent; /* Text is invisible */
    caret-color: var(--clr-text-main); /* Cursor visible */
    z-index: 2;
    resize: none;
    outline: none;
}
.code-editor::selection {
    background: rgba(137, 180, 250, 0.3); /* Selection color */
    color: transparent;
}

.code-viewer {
    position: absolute;
    top: 0; left: 0;
    z-index: 1;
    pointer-events: none; /* Let clicks pass through to textarea */
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--clr-accent);
    color: var(--clr-text-dark);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    pointer-events: none;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Custom Scrollbar for dark theme */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--clr-bg-base); }
::-webkit-scrollbar-thumb { background: var(--clr-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--clr-text-muted); }

@media (max-width: 800px) {
    .app { flex-direction: column; }
    .sidebar { width: 100%; height: 50vh; border-right: none; border-bottom: 1px solid var(--clr-border); }
    .main-content { height: 50vh; }
    .editor-header { padding: 1rem; flex-direction: column; gap: 1rem; }
    .editor-meta { margin-right: 0; }
    .editor-actions { width: 100%; justify-content: space-between; }
    .code-editor, .code-viewer { padding: 1rem; }
}
