:root {
    --bg-body: #0f172a;
    --bg-header: #1e293b;
    --bg-panel: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --editor-bg: #1e293b;
    --editor-text: #e2e8f0;

    --scrollbar-track: #0f172a;
    --scrollbar-thumb: #475569;

    --header-height: 60px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* Header */
header {
    height: var(--header-height);
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    z-index: 10;
}

.logo {
    font-weight: 600;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.logo svg {
    width: 24px;
    height: 24px;
    fill: var(--primary-color);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

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

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

.btn-primary:disabled {
    opacity: 0.7;
    cursor: wait;
}

.btn-icon {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px;
}

.btn-icon:hover {
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.05);
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    height: calc(100vh - var(--header-height));
}

.panel {
    width: 50%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.panel-header {
    /* Optional small label if needed, skipping for cleaner look per request */
    display: none;
}

/* Editor */
#editor-container {
    border-right: 1px solid var(--border-color);
    background-color: var(--editor-bg);
}

#markdown-input {
    width: 100%;
    height: 100%;
    padding: 24px;
    resize: none;
    border: none;
    outline: none;
    background-color: var(--editor-bg);
    color: var(--editor-text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.6;
}

#markdown-input::placeholder {
    color: #64748b;
}

/* Preview */
#preview-container {
    background-color: #fff;
    /* PDF viewer bg style */
    overflow-y: auto;
    position: relative;
    padding: 0;
}

#preview-wrapper {
    background-color: white;
    /* Always white for PDF preview context */
    color: black;
    /* Always black text */
    min-height: 100%;
    width: 100%;
    max-width: 210mm;
    /* Approx A4 width visually */
    margin: 0 auto;
    padding: 0;
    /* Visual margin matching PDF export */
    /*box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);*/
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Markdown Content Styles (Github-like) */
.markdown-body {
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
}

.markdown-body h1 {
    font-size: 1.8em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body h2 {
    font-size: 1.4em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
    margin-top: 24px;
    margin-bottom: 16px;
}

.markdown-body h3 {
    font-size: 1.25em;
    margin-top: 24px;
    margin-bottom: 16px;
}

.markdown-body p {
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body code {
    font-family: 'JetBrains Mono', monospace;
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(27, 31, 35, 0.05);
    border-radius: 3px;
}

.markdown-body pre {
    background-color: #f6f8fa;
    border-radius: 3px;
    font-size: 85%;
    line-height: 1.45;
    overflow: auto;
    padding: 16px;
    margin-bottom: 16px;
}

.markdown-body pre code {
    background-color: transparent;
    padding: 0;
}

.markdown-body blockquote {
    margin: 0;
    padding: 0 1em;
    color: #6a737d;
    border-left: 0.25em solid #dfe2e5;
    margin-bottom: 16px;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 2em;
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body img {
    max-width: 100%;
    box-sizing: content-box;
    background-color: #fff;
}

.markdown-body table {
    display: block;
    width: 100%;
    overflow: auto;
    margin-bottom: 16px;
    border-spacing: 0;
    border-collapse: collapse;
}

.markdown-body table th,
.markdown-body table td {
    padding: 6px 13px;
    border: 1px solid #dfe2e5;
}

.markdown-body table tr {
    background-color: #fff;
    border-top: 1px solid #c6cbd1;
}

.markdown-body table tr:nth-child(2n) {
    background-color: #f6f8fa;
}

/* Page Break Helper */
.page-break {
    border-top: 2px dashed #ccc;
    margin: 20px 0;
    position: relative;
    height: 0;
}

.page-break::after {
    content: 'Page Break';
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 0 8px;
    color: #999;
    font-size: 12px;
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s;
}

#loading-overlay.active {
    visibility: visible;
    opacity: 1;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Print Override for native browser print (Ctrl+P) - though we use html2pdf */
@media print {

    header,
    #editor-container {
        display: none;
    }

    #preview-container {
        width: 100%;
        overflow: visible;
        padding: 0;
        margin: 0;
    }

    #preview-wrapper {
        box-shadow: none;
        padding: 0;
        max-width: none;
    }
}