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

:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --text-primary: #333333;
    --text-secondary: #7f8c8d;
    --border-color: #e0e0e0;
    --header-bg: #2c3e50;
    --header-text: #ffffff;
    --output-bg: #f8f8f8;
    --btn-primary: #3498db;
    --btn-primary-hover: #2980b9;
    --btn-success: #27ae60;
    --btn-success-hover: #229954;
    --btn-danger: #e74c3c;
    --btn-danger-hover: #c0392b;
    --preview-bg: #ffffff;
    --preview-border: #e1e5e9;
    --code-bg: #f6f8fa;
    --code-border: #e1e5e9;
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #404040;
    --header-bg: #1f1f1f;
    --header-text: #e0e0e0;
    --output-bg: #1f1f1f;
    --preview-bg: #2d2d2d;
    --preview-border: #404040;
    --code-bg: #1f1f1f;
    --code-border: #404040;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 1.5rem 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

main {
    flex: 1;
    width: 100%;
}


.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    gap: 2rem;
    align-items: center;
    justify-content: space-between;
}

.header-content > div:first-child {
    flex: 0 1 auto;
}

header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

header p {
    font-size: 1rem;
    opacity: 0.9;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.fixit-link {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 0.4rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: var(--header-text);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;
    line-height: 1.2;
}

.fixit-link .more-tools {
    font-size: 0.7rem;
    opacity: 0.8;
    margin-bottom: 0.1rem;
    display: block;
    text-align: center;
}

.fixit-link .fixit-name {
    font-size: 0.95rem;
    font-weight: 600;
}

.fixit-link:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--header-text);
    padding: 0.8rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 20px;
}

.mode-selector {
    display: flex;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
}

.mode-btn {
    flex: 1;
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.mode-btn.active {
    background: var(--btn-primary);
    color: white;
    box-shadow: 0 2px 4px rgba(52, 152, 219, 0.3);
}

.mode-btn:hover:not(.active) {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.mode-content {
    display: none;
}

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

.editor-container {
    display: flex;
    gap: 1.5rem;
    height: 70vh;
}

.input-section,
.output-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.file-section {
    margin-bottom: 2rem;
}

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

.section-header h2 {
    font-size: 1.2rem;
    color: var(--text-primary);
    font-weight: 600;
}

.button-group {
    display: flex;
    gap: 0.5rem;
}

button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.history-btn {
    background: #3498db;
    color: white;
}

.history-btn:hover {
    background: #2980b9;
    transform: translateY(-1px);
}

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

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

.copy-btn, .download-btn, .process-btn {
    background: var(--btn-success);
    color: white;
}

.copy-btn:hover, .download-btn:hover, .process-btn:hover {
    background: var(--btn-success-hover);
    transform: translateY(-1px);
}

.copy-btn:disabled, .download-btn:disabled, .process-btn:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
}

#markdownInput, #fileContent {
    flex: 1;
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    transition: border-color 0.3s ease;
}

#markdownInput:focus, #fileContent:focus {
    outline: none;
    border-color: var(--btn-primary);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.preview-content {
    flex: 1;
    padding: 1rem;
    border: 2px solid var(--preview-border);
    border-radius: 8px;
    background: var(--preview-bg);
    overflow-y: auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
}

.preview-placeholder {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    margin-top: 2rem;
}

/* Markdown Preview Styles */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    color: var(--text-primary);
    margin: 1rem 0 0.5rem 0;
    font-weight: 600;
}

.preview-content h1 { font-size: 2rem; }
.preview-content h2 { font-size: 1.5rem; }
.preview-content h3 { font-size: 1.25rem; }
.preview-content h4 { font-size: 1.1rem; }
.preview-content h5 { font-size: 1rem; }
.preview-content h6 { font-size: 0.9rem; }

.preview-content p {
    margin: 0.75rem 0;
    color: var(--text-primary);
}

.preview-content ul, .preview-content ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

.preview-content li {
    margin: 0.25rem 0;
}

.preview-content blockquote {
    border-left: 4px solid var(--btn-primary);
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    background: var(--code-bg);
    color: var(--text-secondary);
    font-style: italic;
}

.preview-content code {
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.9em;
}

.preview-content pre {
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 6px;
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.preview-content pre code {
    background: none;
    border: none;
    padding: 0;
}

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

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

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

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

.preview-content th {
    background: var(--code-bg);
    font-weight: 600;
}

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

/* File Upload Styles */
.file-upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    transition: all 0.3s ease;
    background: var(--bg-secondary);
    margin-bottom: 1rem;
}

.file-upload-area.dragover {
    border-color: var(--btn-primary);
    background: rgba(52, 152, 219, 0.05);
}

.file-upload-label {
    cursor: pointer;
    display: block;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.file-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.file-info-display {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--code-bg);
    border-radius: 6px;
    display: none;
}

.file-info-display.active {
    display: block;
}

.file-action-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80%;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

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

.modal-header h2 {
    font-size: 1.3rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.5rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 2rem;
}

.history-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.history-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.clear-history-btn {
    background: var(--btn-danger);
    color: white;
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.clear-history-btn:hover {
    background: var(--btn-danger-hover);
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.history-item:hover {
    background: var(--code-bg);
}

.history-item-preview {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item-time {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

footer {
    background-color: var(--header-bg);
    color: var(--header-text);
    text-align: center;
    padding: 2rem 0;
    margin-top: auto;
}

footer p {
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

footer a {
    color: var(--header-text);
    text-decoration: none;
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

footer a:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .editor-container {
        flex-direction: column;
        height: auto;
    }
    
    .input-section,
    .output-section {
        height: 50vh;
        min-height: 300px;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .header-actions {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .container {
        padding: 1rem 15px;
    }
    
    .button-group {
        flex-wrap: wrap;
    }
    
    .section-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }
    
    .input-section,
    .output-section {
        height: 40vh;
        min-height: 250px;
    }
    
    .modal-content {
        width: 95%;
        margin: 1rem;
    }
    
    .modal-body {
        padding: 1.5rem;
    }
    
    .history-controls {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }
    
    .fixit-link {
        padding: 0.3rem 0.8rem;
    }
    
    .theme-toggle {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .input-section,
    .output-section {
        height: 35vh;
        min-height: 200px;
    }
    
    #markdownInput, #fileContent {
        font-size: 13px;
    }
}