/* CSS Variables for theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --surface-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --font-mono: 'Fira Code', 'Consolas', 'Monaco', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --border-radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --transition: all 0.2s ease;
}

/* Reset and base styles */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

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

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color) 0%, #a855f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Editor container */
.editor-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    flex: 1;
    min-height: 500px;
}

/* Panels */
.panel {
    display: flex;
    flex-direction: column;
    background-color: var(--surface-color);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--surface-light);
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

/* Textarea */
#markdownInput {
    flex: 1;
    width: 100%;
    padding: 1rem;
    border: none;
    background-color: transparent;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.7;
    resize: none;
    outline: none;
}

#markdownInput::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

/* Output area */
.output-area {
    flex: 1;
    padding: 1rem;
    overflow: auto;
}

.preview-mode {
    background-color: var(--surface-color);
    color: var(--text-primary);
}

.code-mode {
    margin: 0;
    background-color: #0d1117;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.7;
}

.code-mode code {
    background: transparent;
    padding: 0;
}

.hidden {
    display: none !important;
}

/* View toggle */
.output-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.view-toggle {
    display: flex;
    background-color: var(--surface-color);
    border-radius: 6px;
    padding: 2px;
}

.tab-btn {
    padding: 0.375rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition);
}

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

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

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

.btn-secondary:hover {
    background-color: var(--surface-light);
    color: var(--text-primary);
}

/* Actions */
.actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

/* Footer */
footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

footer p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--surface-light);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    z-index: 1000;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--error-color);
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(1rem);
    pointer-events: none;
}

/* Preview content styles */
.preview-mode h1,
.preview-mode h2,
.preview-mode h3,
.preview-mode h4,
.preview-mode h5,
.preview-mode h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
}

.preview-mode h1 { font-size: 2em; }
.preview-mode h2 { font-size: 1.5em; }
.preview-mode h3 { font-size: 1.25em; }
.preview-mode h4 { font-size: 1em; }
.preview-mode h5 { font-size: 0.875em; }
.preview-mode h6 { font-size: 0.85em; }

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

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

.preview-mode a {
    color: var(--primary-color);
    text-decoration: none;
}

.preview-mode a:hover {
    text-decoration: underline;
}

.preview-mode ul,
.preview-mode ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

.preview-mode li {
    margin-bottom: 0.25em;
}

.preview-mode blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 1em;
    margin: 1em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.preview-mode code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background-color: var(--surface-light);
    padding: 0.2em 0.4em;
    border-radius: 4px;
}

.preview-mode pre {
    background-color: #0d1117;
    padding: 1em;
    border-radius: var(--border-radius);
    overflow-x: auto;
    margin: 1em 0;
}

.preview-mode pre code {
    background: transparent;
    padding: 0;
    font-size: 0.875rem;
    line-height: 1.6;
}

.preview-mode img {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
}

.preview-mode table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
}

.preview-mode th,
.preview-mode td {
    border: 1px solid var(--border-color);
    padding: 0.5em 0.75em;
    text-align: left;
}

.preview-mode th {
    background-color: var(--surface-light);
    font-weight: 600;
}

.preview-mode hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2em 0;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .logo {
        width: 36px;
        height: 36px;
    }

    .subtitle {
        font-size: 0.875rem;
    }

    .editor-container {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .panel {
        min-height: 300px;
    }

    .panel-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.75rem;
    }

    header {
        margin-bottom: 1rem;
    }

    .logo-title {
        gap: 0.5rem;
    }

    .logo {
        width: 32px;
        height: 32px;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .panel-header h2 {
        font-size: 0.75rem;
    }

    #markdownInput,
    .output-area {
        font-size: 0.8125rem;
        padding: 0.75rem;
    }

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

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Selection */
::selection {
    background-color: var(--primary-color);
    color: white;
}
