:root {
    --primary: #8B5CF6;
    --primary-hover: #7C3AED;
    --secondary: #A78BFA;
    --accent: #F59E0B;
    --bg-dark: #0F0A1A;
    --bg-panel: #1A1429;
    --bg-panel-light: #251D3A;
    --text-main: #F3F4F6;
    --text-muted: #9CA3AF;
    --border: rgba(139, 92, 246, 0.2);
    --border-hover: rgba(139, 92, 246, 0.4);
    --border-radius: 12px;
    --glass-bg: rgba(26, 20, 41, 0.6);
    --glass-border: rgba(255, 255, 255, 0.05);
    --danger: #EF4444;
    --danger-hover: #DC2626;
    --success: #10B981;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* Base Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--border-radius);
    border: none;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-icon {
    padding: 8px;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: var(--border-hover);
}

.btn-danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

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

input[type="text"],
.select-input,
textarea {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s ease;
}

input[type="text"]:focus,
.select-input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

/* Layout */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px 20px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.sidebar-controls {
    padding: 0 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-box {
    position: relative;
}

.search-box svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    padding-left: 36px;
}

.template-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    padding: 0 12px;
}

.template-item {
    margin-bottom: 4px;
}

.template-btn {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 16px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.template-btn:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

.template-btn.active {
    background-color: var(--bg-panel-light);
    border-color: var(--border);
}

.template-item-header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 4px;
}

.template-title {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.template-usage {
    font-size: 12px;
    color: var(--accent);
    flex-shrink: 0;
}

.template-category {
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 12px;
}

.sidebar-footer .btn {
    flex: 1;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.welcome-icon {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(167, 139, 250, 0.1));
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    color: var(--primary);
}

.welcome-screen h2 {
    font-size: 28px;
    margin-bottom: 12px;
}

.welcome-screen p {
    color: var(--text-muted);
    margin-bottom: 32px;
    max-width: 400px;
    line-height: 1.5;
}

.editor-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.editor-header {
    padding: 24px 32px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background-color: var(--glass-bg);
    backdrop-filter: blur(10px);
}

.template-meta {
    flex: 1;
    max-width: 600px;
}

.title-input {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    font-size: 24px !important;
    font-weight: 600 !important;
    color: white !important;
    margin-bottom: 8px;
    box-shadow: none !important;
}

.title-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.meta-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.category-input {
    width: 200px !important;
    padding: 6px 10px !important;
}

.usage-badge {
    background-color: rgba(245, 158, 11, 0.15);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.split-pane {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px 32px;
    overflow-y: auto;
}

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

.preview-pane {
    background-color: rgba(0, 0, 0, 0.2);
}

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

.pane-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge {
    background-color: rgba(255, 255, 255, 0.1);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 8px;
    color: var(--text-muted);
}

.subject-input {
    margin-bottom: 16px;
    font-size: 16px !important;
}

.content-textarea {
    flex: 1;
    min-height: 200px;
    resize: none;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 24px;
}

.variables-section {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    padding: 16px;
}

.variables-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.variable-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.variable-label {
    width: 120px;
    font-size: 13px;
    color: var(--secondary);
    font-family: monospace;
    flex-shrink: 0;
}

.variable-input {
    flex: 1;
}

/* Preview Styles */
.preview-container {
    background-color: white;
    border-radius: var(--border-radius);
    overflow: hidden;
    color: #333;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.preview-subject {
    padding: 16px 24px;
    border-bottom: 1px solid #E5E7EB;
    font-weight: 600;
    font-size: 16px;
    background-color: #F9FAFB;
}

.preview-body {
    padding: 24px;
    font-size: 15px;
    line-height: 1.6;
    overflow-y: auto;
}

.preview-body h1, .preview-body h2, .preview-body h3, .preview-body h4 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    color: #111827;
}

.preview-body h1:first-child, .preview-body h2:first-child {
    margin-top: 0;
}

.preview-body p {
    margin-bottom: 1em;
}

.preview-body p:last-child {
    margin-bottom: 0;
}

.preview-body a {
    color: #4F46E5;
    text-decoration: underline;
}

.preview-body ul, .preview-body col {
    margin-bottom: 1em;
    padding-left: 24px;
}

.preview-body blockquote {
    border-left: 4px solid #D1D5DB;
    padding-left: 16px;
    color: #4B5563;
    font-style: italic;
    margin-bottom: 1em;
}

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

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background-color: var(--success);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(16, 185, 129, 0.3);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}
