:root {
    --primary: #1a73e8;
    /* Modern Blue */
    --primary-dark: #1557b0;
    --secondary: #5f6368;
    --success: #2da44e;
    --success-hover: #2c974b;
    --bg-body: #f6f8fa;
    --bg-card: #ffffff;
    --border: #d1d5db;
    --border-light: #e5e7eb;
    --text-main: #111827;
    --text-muted: #6b7280;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    /* Prevent body scroll */
}

.container {
    max-width: 95%;
    /* Increased slightly to accommodate 40-40 split comfortably */
    margin: 0 auto;
    padding: 0 16px;
    /* Reduced padding */
    width: 100%;
}

/* Navbar */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-light);
    padding: 12px 0;
    /* Reduced padding */
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(8px);
    background-color: rgba(255, 255, 255, 0.9);
}

.navbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.brand img {
    height: 48px;
    display: block;
}

.navbar-title {
    text-align: center;
    flex: 1;
    /* Take up available space */
}

.navbar-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: #1f2937;
    line-height: 1.2;
}

.navbar-title p {
    font-size: 0.85rem;
    margin: 0;
    color: var(--text-muted);
}

.badge {
    background: #e0f2fe;
    color: #0369a1;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Page Wrapper */
.page-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 24px;
    /* Reduced vertical spacing */
    padding-bottom: 24px;
}


/* App Card */
.app-card {
    background: var(--bg-card);
    width: 100%;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Upload Area */
.upload-area {
    padding: 64px 32px;
    text-align: center;
    position: relative;
    transition: background 0.2s;
}

.upload-area.dragover {
    background: #f0f9ff;
    box-shadow: inset 0 0 0 2px var(--primary);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.icon-wrapper {
    width: 64px;
    height: 64px;
    background: #eef2ff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    margin-bottom: 8px;
}

.icon {
    width: 32px;
    height: 32px;
}

.upload-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.upload-content p {
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: white;
    border-color: var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: var(--success-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    color: var(--text-main);
    fill: var(--text-main);
}

/* Loader */
.loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    z-index: 10;
}

.loader-overlay[hidden] {
    display: none !important;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

/* Result Area */
.result-area {
    display: flex;
    flex-direction: column;
    height: 100%;
    /* No padding here, handled by children */
}

.result-area[hidden] {
    display: none !important;
}

.toolbar {
    padding: 16px 24px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.file-info {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    background: #e5e7eb;
    padding: 4px 12px;
    border-radius: 99px;
}

.actions {
    display: flex;
    gap: 8px;
}

.split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border-top: 1px solid var(--border-light);
    height: 600px;
    /* Fixed height */
    width: 100%;
    overflow: hidden;
    /* Prevent container itself from causing scroll */
}

.editor-pane,
.preview-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* CRITICAL for Grid: allows item to shrink below content size */
    height: 100%;
    overflow: hidden;
    /* internal scroll handled by children */
}

.editor-pane {
    border-right: 1px solid var(--border-light);
    background: #f8fafc;
}

.pane-header {
    background: #f1f5f9;
    padding: 8px 16px;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    flex-shrink: 0;
}

.markdown-editor {
    flex: 1;
    width: 100%;
    border: none;
    resize: none;
    padding: 24px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-main);
    background: transparent;
    outline: none;
    overflow-y: auto;

    /* Aggressive wrapping */
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    /* Chrome/Firefox modern wrap */
}

.markdown-editor:focus {
    background: white;
}

.preview-pane {
    background: white;
}

.markdown-body {
    height: 100%;
    padding: 24px;
    overflow-y: auto;
    overflow-x: auto;
    /* Restore scroll as safety net */

    /* Aggressive wrapping for all content */
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: normal;
    /* varied content needs normal flow, strict break only on anywhere */
}

/* Force elements to respect container width */
.markdown-body img {
    max-width: 100%;
    height: auto;
    display: block;
}

.markdown-body pre,
.markdown-body code {
    white-space: pre-wrap;
    /* Wrap code blocks */
    word-break: break-all;
    max-width: 100%;
}

.markdown-body table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: collapse;
    margin-bottom: 16px;
}

/* Mobile Split Stack */
@media (max-width: 768px) {
    .split-view {
        flex-direction: column;
        height: auto;
    }

    .editor-pane {
        border-right: none;
        border-bottom: 1px solid var(--border-light);
        height: 400px;
    }

    .preview-pane {
        height: 400px;
    }
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px;
    color: #9ca3af;
    font-size: 0.875rem;
    border-top: 1px solid var(--border-light);
    background: white;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Mobile */
@media (max-width: 640px) {
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .actions {
        flex-direction: column;
    }
}