/* Global Custom Properties & Themes */
:root {
    /* Font Families */
    --font-primary: 'Inter', system-ui, -apple-system, sans-serif;
    --font-display: 'Outfit', sans-serif;
    --font-mono: 'Fira Code', monospace;

    /* Transition timings */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --border-radius-lg: 16px;
    --border-radius-md: 10px;
    --border-radius-sm: 6px;
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.3);
}

/* Dark Theme Variables (Default) */
.dark-theme {
    --bg-app: #090d16;
    --bg-panel: rgba(22, 31, 50, 0.6);
    --bg-editor: #0d1527;
    --border-color: rgba(255, 255, 255, 0.08);
    
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary-color: #4f46e5;
    --primary-hover: #6366f1;
    --primary-light: rgba(79, 70, 229, 0.15);
    
    --secondary-color: #1e293b;
    --secondary-hover: #334155;
    --secondary-text: #e2e8f0;

    --danger-color: #ef4444;
    --danger-hover: #f87171;

    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --bg-toast: rgba(15, 23, 42, 0.9);
    
    /* Markdown Specific Styles (Dark) */
    --md-bg-code: #0b0f19;
    --md-text-code: #f1f5f9;
    --md-blockquote-border: #4f46e5;
    --md-table-border: #334155;
    --md-table-stripe: #131b2e;
}

/* Light Theme Variables */
.light-theme {
    --bg-app: #f8fafc;
    --bg-panel: rgba(255, 255, 255, 0.8);
    --bg-editor: #ffffff;
    --border-color: rgba(0, 0, 0, 0.08);
    
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.1);
    
    --secondary-color: #f1f5f9;
    --secondary-hover: #e2e8f0;
    --secondary-text: #334155;

    --danger-color: #ef4444;
    --danger-hover: #dc2626;

    --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #8b5cf6 100%);
    --bg-toast: rgba(15, 23, 42, 0.95);
    
    /* Markdown Specific Styles (Light) */
    --md-bg-code: #f1f5f9;
    --md-text-code: #0f172a;
    --md-blockquote-border: #6366f1;
    --md-table-border: #e2e8f0;
    --md-table-stripe: #f8fafc;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-app);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* App Container Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    padding: 20px;
    gap: 16px;
}

/* Header Styles */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-premium);
    height: 64px;
    flex-shrink: 0;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--accent-gradient);
    color: white;
    border-radius: var(--border-radius-sm);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.logo-area h1 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.logo-area h1 span {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 500;
    font-size: 1.1rem;
    margin: 0 2px;
}

/* Buttons and Inputs Styling */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-primary);
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: var(--transition-smooth);
    user-select: none;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--secondary-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-icon:hover {
    background: var(--secondary-hover);
    transform: scale(1.05);
}

.btn-icon svg {
    transition: var(--transition-smooth);
}

/* Theme Icons Toggle Visibility */
.dark-theme #theme-toggle .sun-icon {
    display: block;
}
.dark-theme #theme-toggle .moon-icon {
    display: none;
}
.light-theme #theme-toggle .sun-icon {
    display: none;
}
.light-theme #theme-toggle .moon-icon {
    display: block;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.85rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
}

.btn-secondary {
    background: var(--secondary-color);
    color: var(--secondary-text);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--secondary-hover);
    transform: translateY(-1px);
}

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

.btn-danger:hover {
    background: var(--danger-color);
    color: white;
    transform: translateY(-1px);
}

.file-label {
    cursor: pointer;
}

/* Workspace Panels */
.workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    flex-grow: 1;
    min-height: 0; /* Important for scroll nested contents */
}

@media (max-width: 960px) {
    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }
}

.panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-premium);
    overflow: hidden;
    min-height: 0; /* Allow panels to shrink and scroll their children */
    transition: border-color 0.3s ease;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.panel-title h2 {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.panel-title svg {
    color: var(--primary-hover);
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 18px;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.02);
    flex-shrink: 0;
}

/* Editor Specific Styles */
.editor-container {
    position: relative;
    flex-grow: 1;
    min-height: 0;
}

#markdown-input {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    background: var(--bg-editor);
    color: var(--text-primary);
    padding: 20px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.6;
    resize: none;
    tab-size: 4;
}

#markdown-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

/* Drag and Drop Overlay Styling */
.drop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 10;
}

.editor-container.dragover .drop-overlay {
    opacity: 1;
}

.overlay-content {
    text-align: center;
    color: white;
    transform: scale(0.9);
    transition: transform 0.25s ease;
}

.editor-container.dragover .overlay-content {
    transform: scale(1);
}

.overlay-content svg {
    color: var(--primary-hover);
    margin-bottom: 12px;
    animation: bounce 1.5s infinite;
}

.overlay-content p {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 600;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* Preview Specific Styles */
.preview-container {
    flex-grow: 1;
    padding: 24px;
    overflow-y: auto;
    background: var(--bg-editor);
    min-height: 0;
}

/* Fallback for empty editor */
.empty-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    gap: 12px;
}

.empty-preview svg {
    opacity: 0.4;
}

.empty-preview p {
    font-size: 0.9rem;
    max-width: 280px;
    line-height: 1.4;
}

/* --- Markdown Rendering Body Theme CSS (Clean & Modern) --- */
.markdown-body {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
    word-wrap: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    font-family: var(--font-display);
}

.markdown-body h1 {
    font-size: 1.8rem;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.markdown-body h2 {
    font-size: 1.4rem;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.markdown-body h3 {
    font-size: 1.2rem;
}

.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body dl,
.markdown-body table,
.markdown-body pre {
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body a {
    color: #6366f1;
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body strong {
    font-weight: 600;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 20px;
}

.markdown-body li + li {
    margin-top: 4px;
}

/* Code Snippets and Blocks */
.markdown-body code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: var(--md-bg-code);
    color: var(--md-text-code);
    border-radius: var(--border-radius-sm);
    font-family: var(--font-mono);
}

.markdown-body pre {
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: var(--md-bg-code);
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
}

.markdown-body pre code {
    padding: 0;
    margin: 0;
    font-size: 100%;
    background-color: transparent;
    color: var(--md-text-code);
    border-radius: 0;
}

/* Blockquotes */
.markdown-body blockquote {
    padding: 0 15px;
    color: var(--text-secondary);
    border-left: 4px solid var(--md-blockquote-border);
    font-style: italic;
    background: rgba(99, 102, 241, 0.05);
    border-top-right-radius: var(--border-radius-sm);
    border-bottom-right-radius: var(--border-radius-sm);
}

/* Tables */
.markdown-body table {
    border-spacing: 0;
    border-collapse: collapse;
    width: 100%;
    overflow: auto;
}

.markdown-body table th {
    font-weight: 600;
    background-color: rgba(0, 0, 0, 0.05);
}

.markdown-body table th,
.markdown-body table td {
    padding: 8px 13px;
    border: 1px solid var(--md-table-border);
}

.markdown-body table tr:nth-child(even) {
    background-color: var(--md-table-stripe);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-toast);
    color: white;
    padding: 12px 20px;
    border-radius: var(--border-radius-md);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.15);
    z-index: 100;
    transform: translateY(100px);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

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

.toast-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #10b981;
}
