/* ============================================
   MD File Viewer - Modern Stylesheet
   Matching ConvertICO design system (Watermark Maker style)
   ============================================ */

/* CSS Variables */
:root {
    --primary: #0EA5E9;
    --primary-light: #BAE6FD;
    --primary-dark: #0284C7;
    --accent: #FF6B6B;
    --success: #10B981;
    --success-light: #D1FAE5;
    --warning: #F59E0B;
    --danger: #EF4444;
    --purple: #8B5CF6;
    --purple-light: #EDE9FE;
    
    --bg: #f8fafc;
    --bg-elevated: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1);
    
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    /* Markdown specific */
    --md-bg: #ffffff;
    --md-text: #24292f;
    --md-border: #d0d7de;
    --md-code-bg: #f6f8fa;
    --md-link: #0969da;
    --md-heading: #1f2328;
    --md-blockquote: #656d76;
    --md-table-border: #d0d7de;
    --md-table-alt: #f6f8fa;
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --bg: #0f172a;
    --bg-elevated: #1e293b;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    
    --md-bg: #0d1117;
    --md-text: #c9d1d9;
    --md-border: #30363d;
    --md-code-bg: #161b22;
    --md-link: #58a6ff;
    --md-heading: #f0f6fc;
    --md-blockquote: #8b949e;
    --md-table-border: #30363d;
    --md-table-alt: #161b22;
}

/* Base */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, var(--bg) 0%, #f1f5f9 100%);
    color: var(--text);
    line-height: 1.6;
    margin: 0;
    padding: 0;
}

[data-theme="dark"] body {
    background: linear-gradient(135deg, var(--bg) 0%, #1e293b 100%);
}

/* Container */
.tool-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
}

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

.tool-title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.tool-icon-inline {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    color: var(--primary);
}

.tool-title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.tool-description {
    font-size: 1.15rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.7;
}

/* Main Tool Area */
.tool-main {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    border: 1px solid var(--border);
}

/* Upload Section */
.upload-section {
    padding: 3rem;
}

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: linear-gradient(135deg, #fafafa 0%, #f5f5f5 100%);
    position: relative;
    overflow: hidden;
}

.upload-area::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.05), rgba(2, 132, 199, 0.05));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.upload-area:hover,
.upload-area.dragover,
.upload-area.active {
    border-color: var(--primary);
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.upload-area:hover::before,
.upload-area.dragover::before,
.upload-area.active::before {
    opacity: 1;
}

.upload-content {
    position: relative;
    z-index: 1;
}

.upload-icon {
    color: var(--primary);
    margin-bottom: 1.5rem;
    transition: transform 0.3s ease;
}

.upload-area:hover .upload-icon {
    transform: translateY(-5px);
}

.upload-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 0.5rem;
}

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

.upload-hint {
    display: inline-block;
    background: var(--bg);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.875rem;
}

.file-types {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.file-type-badge {
    background: linear-gradient(135deg, var(--purple-light), #ddd6fe);
    color: var(--purple);
    padding: 0.35rem 0.85rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
}

/* Editor Section */
.editor-section {
    padding: 0;
    animation: fadeIn 0.4s ease;
}

/* File Info Bar */
.file-info-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    padding: 1.25rem 2rem;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .file-info-bar {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

.file-info-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.file-info-item svg {
    color: var(--primary);
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

/* Toolbar */
.viewer-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 1rem;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* View Toggle */
.view-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg);
}

.view-toggle button {
    padding: 0.6rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.view-toggle button:not(:last-child) {
    border-right: 1px solid var(--border);
}

.view-toggle button:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

.view-toggle button.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.view-toggle button svg {
    width: 16px;
    height: 16px;
}

/* Toolbar Buttons */
.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

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

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

.toolbar-btn svg {
    width: 18px;
    height: 18px;
}

/* Content Area */
.viewer-content {
    display: flex;
    min-height: 450px;
    max-height: 65vh;
    border-bottom: 1px solid var(--border);
}

.source-panel,
.preview-panel {
    flex: 1;
    overflow: auto;
    transition: all 0.3s ease;
}

.source-panel {
    background: var(--md-code-bg);
    border-right: 1px solid var(--border);
    display: none;
}

.source-panel.active {
    display: block;
}

.preview-panel {
    background: var(--md-bg);
}

.preview-panel.active {
    display: block;
}

.viewer-content.split-view .source-panel,
.viewer-content.split-view .preview-panel {
    display: block;
    flex: 1;
}

.viewer-content.source-only .source-panel {
    display: block;
    flex: 1;
}

.viewer-content.source-only .preview-panel {
    display: none;
}

.viewer-content.preview-only .source-panel {
    display: none;
}

.viewer-content.preview-only .preview-panel {
    display: block;
    flex: 1;
}

/* Source Code Display */
.source-code {
    margin: 0;
    padding: 1.5rem;
    font-family: 'SF Mono', 'Fira Code', 'Monaco', monospace;
    font-size: 14px;
    line-height: 1.7;
    color: var(--md-text);
    white-space: pre-wrap;
    word-wrap: break-word;
    counter-reset: line;
}

.source-code .line {
    display: block;
    padding-left: 3.5rem;
    position: relative;
}

.source-code .line::before {
    content: counter(line);
    counter-increment: line;
    position: absolute;
    left: 0;
    width: 2.5rem;
    text-align: right;
    color: var(--text-muted);
    font-size: 12px;
    user-select: none;
    opacity: 0.7;
}

/* Markdown Preview Styles */
.markdown-body {
    padding: 2rem;
    color: var(--md-text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.7;
}

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

.markdown-body h1 {
    font-size: 2em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--md-border);
}

.markdown-body h2 {
    font-size: 1.5em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--md-border);
}

.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }
.markdown-body h5 { font-size: 0.875em; }
.markdown-body h6 { font-size: 0.85em; color: var(--md-blockquote); }

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

.markdown-body a {
    color: var(--md-link);
    text-decoration: none;
}

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

.markdown-body code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 85%;
    padding: 0.2em 0.4em;
    background: var(--md-code-bg);
    border-radius: 6px;
}

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

.markdown-body pre code {
    padding: 0;
    background: transparent;
    font-size: 100%;
}

.markdown-body blockquote {
    margin: 0 0 16px 0;
    padding: 0 1em;
    color: var(--md-blockquote);
    border-left: 4px solid var(--primary-light);
}

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

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

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

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

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

.markdown-body th {
    background: var(--md-table-alt);
    font-weight: 600;
}

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

.markdown-body hr {
    height: 0.25em;
    padding: 0;
    margin: 24px 0;
    background-color: var(--md-border);
    border: 0;
    border-radius: var(--radius-sm);
}

.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
}

.markdown-body input[type="checkbox"] {
    margin-right: 8px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1.5rem;
    opacity: 0.5;
    color: var(--primary);
}

.empty-state h3 {
    margin: 0 0 0.5rem;
    color: var(--text-secondary);
    font-size: 1.25rem;
}

.empty-state p {
    margin: 0;
    font-size: 0.95rem;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

[data-theme="dark"] .stats-bar {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.stat-item svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
    color: var(--primary);
}

.stat-item strong {
    color: var(--text);
    font-weight: 600;
}

/* Action Bar */
.action-bar {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1.75rem;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.btn svg {
    width: 20px;
    height: 20px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

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

.btn-secondary:hover {
    background: var(--bg-elevated);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #DC2626);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* Info Sections */
.info-sections {
    display: grid;
    gap: 2rem;
    margin-top: 3rem;
}

.info-card {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.info-card h2 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.35rem;
    color: var(--text);
    margin: 0 0 1.5rem;
}

.info-card h2 svg {
    color: var(--primary);
    width: 24px;
    height: 24px;
}

/* Steps List */
.steps-list {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: step;
}

.steps-list li {
    position: relative;
    padding-left: 3.5rem;
    padding-bottom: 1.25rem;
    margin-left: 1rem;
    counter-increment: step;
}

.steps-list li:not(:last-child) {
    border-left: 2px solid var(--primary-light);
}

.steps-list li:last-child {
    padding-bottom: 0;
}

.steps-list li::before {
    content: counter(step);
    position: absolute;
    left: -1rem;
    top: 0;
    width: 2rem;
    height: 2rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
}

/* Features Grid */
.features-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.feature-item {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.feature-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.feature-icon svg {
    width: 24px;
    height: 24px;
}

.feature-icon.blue { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); }
.feature-icon.green { background: linear-gradient(135deg, var(--success), #059669); }
.feature-icon.purple { background: linear-gradient(135deg, var(--purple), #7C3AED); }
.feature-icon.orange { background: linear-gradient(135deg, var(--warning), #D97706); }

.feature-content h3 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.feature-content p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* FAQ */
.faq-list {
    display: grid;
    gap: 0.75rem;
}

.faq-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.faq-question {
    width: 100%;
    padding: 1rem 1.25rem;
    background: var(--bg);
    border: none;
    text-align: left;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.faq-question:hover {
    background: var(--bg-elevated);
}

.faq-question svg {
    color: var(--primary);
    transition: transform 0.3s ease;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.faq-item.open .faq-question svg {
    transform: rotate(180deg);
}

.faq-answer {
    display: none;
    padding: 0 1.25rem 1rem;
    background: var(--bg-elevated);
}

.faq-item.open .faq-answer {
    display: block;
}

.faq-answer p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.7;
}

/* Syntax Badge */
.syntax-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.syntax-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.syntax-badge:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.syntax-badge svg {
    width: 16px;
    height: 16px;
    color: var(--primary);
}

/* Responsive */
@media (max-width: 900px) {
    .viewer-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .toolbar-left,
    .toolbar-right {
        justify-content: center;
    }
    
    .viewer-content {
        flex-direction: column;
        max-height: none;
    }
    
    .viewer-content.split-view .source-panel,
    .viewer-content.split-view .preview-panel {
        min-height: 300px;
    }
    
    .source-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .features-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .tool-container {
        padding: 1rem;
    }
    
    .upload-section {
        padding: 2rem 1.5rem;
    }
    
    .upload-area {
        padding: 3rem 1.5rem;
    }
    
    .viewer-toolbar {
        padding: 1rem;
    }
    
    .markdown-body {
        padding: 1.5rem;
    }
    
    .stats-bar {
        gap: 1rem;
        padding: 1rem;
    }
    
    .action-bar {
        flex-direction: column;
        padding: 1.5rem;
    }
    
    .btn {
        width: 100%;
    }
    
    .file-info-bar {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .tool-title {
        font-size: 1.75rem;
    }
    
    .tool-title-row {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .file-info-bar {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }
    
    .view-toggle {
        width: 100%;
    }
    
    .view-toggle button {
        flex: 1;
        justify-content: center;
    }
    
    .toolbar-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .stats-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .feature-item {
        flex-direction: column;
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Print Styles */
@media print {
    .upload-section,
    .viewer-toolbar,
    .action-bar,
    .stats-bar,
    .source-panel,
    .info-sections {
        display: none !important;
    }
    
    .tool-main {
        box-shadow: none;
        border: none;
    }
    
    .editor-section {
        display: block !important;
    }
    
    .preview-panel {
        display: block !important;
    }
    
    .markdown-body {
        padding: 0;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
