:root {
    /* Colors (Slate + Blue Accent) */
    --bg-base: #0f172a;
    --bg-surface: rgba(30, 41, 59, 0.6);
    --bg-surface-hover: rgba(51, 65, 85, 0.8);
    --border-color: rgba(148, 163, 184, 0.15);
    
    --primary: #64748b;
    --secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    
    --danger: #ef4444;

    /* Sizes & Effects */
    --radius: 12px;
    --transition: 250ms ease;
    --font-sans: 'Inter', -apple-system, sans-serif;
    
    --sidebar-width: 260px;
}

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

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

/* Base Components */
.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.875rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-sans);
    outline: none;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.btn-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--bg-surface-hover);
}

.btn-icon {
    background: transparent;
    color: var(--secondary);
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
}

.btn-icon:hover {
    background: var(--bg-surface-hover);
    color: var(--text-main);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.brand-icon {
    color: var(--accent);
    width: 28px;
    height: 28px;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-section {
    margin-top: 2rem;
    flex: 1;
    overflow-y: auto;
}

.sidebar-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--secondary);
    margin-bottom: 1rem;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 0.875rem;
}

.history-item:hover, .history-item.active {
    background: var(--bg-surface-hover);
}

.history-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.history-date {
    font-size: 0.75rem;
    color: var(--secondary);
    margin-left: 0.5rem;
}

.history-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    transform: scale(0.8);
    transition: opacity var(--transition);
}

.history-item:hover .history-delete {
    opacity: 1;
}

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

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-radius: 0;
    border-top: none;
    border-right: none;
    border-left: none;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-left h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.status-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: rgba(148, 163, 184, 0.1);
    color: var(--secondary);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-width: 180px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition);
    z-index: 50;
}

.dropdown.open .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    padding: 0.75rem 1rem;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background var(--transition);
}

.dropdown-item i {
    width: 16px;
    height: 16px;
    color: var(--secondary);
}

.dropdown-item:hover {
    background: var(--bg-surface-hover);
}

.dropdown-item:first-child { border-radius: 8px 8px 0 0; }
.dropdown-item:last-child { border-radius: 0 0 8px 8px; }

/* Editor Layout */
.editor-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 1.5rem;
    gap: 1.5rem;
}

.forms-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 450px;
    overflow: hidden;
}

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 1rem;
    color: var(--secondary);
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
}

.tab-btn:hover {
    color: var(--text-main);
    background: var(--bg-surface-hover);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.tab-content.active {
    display: block;
}

/* Forms */
.form-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.form-group label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group input, 
.form-group select, 
.form-group textarea {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    border-radius: 8px;
    color: var(--text-main);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition);
    width: 100%;
}

.form-group input:focus, 
.form-group select:focus, 
.form-group textarea:focus {
    border-color: var(--accent);
    background: rgba(15, 23, 42, 0.8);
}

/* Switches / Toggles */
.section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all var(--transition);
}

.section-toggle:hover {
    border-color: var(--secondary);
}

.section-info h4 {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.section-info p {
    font-size: 0.75rem;
    color: var(--secondary);
}

/* Toggle Switch CSS */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--primary);
    transition: .3s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.mt-4 { margin-top: 1rem; }
.w-full { width: 100%; }

/* Preview Panel */
.preview-panel {
    flex: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

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

.preview-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 3rem;
    background: #ffffff; /* Typically legal docs are read on light bg, adding light theme preview */
    color: #334155;
}

.markdown-body {
    font-family: Georgia, 'Times New Roman', serif; /* Legal feel */
    line-height: 1.6;
    max-width: 800px;
    margin: 0 auto;
}

.markdown-body h1 {
    font-family: var(--font-sans);
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: #0f172a;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 0.5rem;
}

.markdown-body h2 {
    font-family: var(--font-sans);
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: #1e293b;
}

.markdown-body p {
    margin-bottom: 1rem;
    text-align: justify;
}

.markdown-body ul {
    margin-bottom: 1rem;
    padding-left: 2rem;
}

.markdown-body li {
    margin-bottom: 0.5rem;
}

/* Print Only */
.print-only {
    display: none;
}

@media print {
    body {
        background: white;
        color: black;
    }
    .app-container, .btn, .top-nav, .forms-panel, .sidebar, .preview-header {
        display: none !important;
    }
    .print-only {
        display: block;
        padding: 2cm;
    }
    .print-only .markdown-body {
        max-width: none;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        border-bottom: 1px solid var(--border-color);
    }
    
    .editor-layout {
        flex-direction: column;
    }
    
    .forms-panel {
        max-width: none;
        height: 500px;
    }
    
    .preview-panel {
        height: 600px;
    }
}
