/* ==========================================
   MarkItDown Converter — Design System
   ========================================== */

:root {
    /* Colors */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(18, 18, 26, 0.7);
    --bg-card-hover: rgba(24, 24, 36, 0.8);
    --bg-input: rgba(255, 255, 255, 0.03);

    --text-primary: #e8e8ed;
    --text-secondary: #8b8b9e;
    --text-muted: #5a5a6e;

    --accent-indigo: #818cf8;
    --accent-purple: #c084fc;
    --accent-gradient: linear-gradient(135deg, #818cf8, #c084fc);
    --accent-glow: rgba(129, 140, 248, 0.15);

    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);

    --success: #34d399;
    --error: #f87171;
    --warning: #fbbf24;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --transition-fast: 150ms var(--ease-out);
    --transition-normal: 250ms var(--ease-out);
    --transition-slow: 400ms var(--ease-out);
}

/* ==========================================
   Reset & Base
   ========================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* ==========================================
   Animated Background
   ========================================== */
.bg-gradient {
    position: fixed;
    inset: 0;
    z-index: 0;
    background:
        radial-gradient(ellipse 600px 400px at 20% 20%, rgba(129, 140, 248, 0.08), transparent),
        radial-gradient(ellipse 500px 350px at 80% 80%, rgba(192, 132, 252, 0.06), transparent),
        radial-gradient(ellipse 400px 300px at 50% 50%, rgba(129, 140, 248, 0.03), transparent);
    animation: bgPulse 12s ease-in-out infinite alternate;
}

@keyframes bgPulse {
    0% { opacity: 0.7; }
    100% { opacity: 1; }
}

.bg-grid {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
}

/* ==========================================
   Layout
   ========================================== */
.container {
    position: relative;
    z-index: 1;
    max-width: 760px;
    margin: 0 auto;
    padding: 40px 24px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================
   Header
   ========================================== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 48px;
    animation: fadeDown 0.6s var(--ease-out);
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(129, 140, 248, 0.08);
    border-radius: var(--radius-md);
    border: 1px solid rgba(129, 140, 248, 0.15);
}

.logo h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 2px;
}

.badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: rgba(52, 211, 153, 0.08);
    border: 1px solid rgba(52, 211, 153, 0.15);
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--success);
}

.badge-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

/* ==========================================
   Upload Zone
   ========================================== */
.upload-section {
    animation: fadeUp 0.6s var(--ease-out) 0.15s both;
}

.upload-zone {
    position: relative;
    border: 2px dashed var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: 56px 40px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-xl);
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity var(--transition-normal);
    z-index: 0;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--accent-indigo);
    background: var(--bg-card-hover);
}

.upload-zone:hover::before,
.upload-zone.drag-over::before {
    opacity: 0.03;
}

.upload-zone > * {
    position: relative;
    z-index: 1;
}

.upload-icon {
    margin-bottom: 20px;
    display: inline-block;
    animation: floatUpDown 3s ease-in-out infinite;
}

@keyframes floatUpDown {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.upload-zone h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.upload-zone p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.browse-link {
    color: var(--accent-indigo);
    font-weight: 500;
    cursor: pointer;
    transition: color var(--transition-fast);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.browse-link:hover {
    color: var(--accent-purple);
}

.supported-formats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 28px;
}

.format-tag {
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.03em;
    text-transform: uppercase;
    transition: all var(--transition-fast);
}

.upload-zone:hover .format-tag {
    border-color: var(--border-hover);
    color: var(--text-secondary);
}

/* ==========================================
   Progress
   ========================================== */
.progress-section {
    animation: fadeUp 0.4s var(--ease-out);
}

.progress-card {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 32px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
}

.progress-spinner {
    flex-shrink: 0;
}

.spinner-circle {
    animation: spin 1.2s linear infinite;
    transform-origin: center;
}

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

.progress-info h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.progress-info p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ==========================================
   Result
   ========================================== */
.result-section {
    animation: fadeUp 0.5s var(--ease-out);
}

.result-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.result-meta h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 8px;
    word-break: break-all;
}

.result-stats {
    display: flex;
    gap: 10px;
}

.stat-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-subtle);
    padding: 4px 10px;
    border-radius: 100px;
}

.stat-chip svg {
    color: var(--success);
}

.result-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ==========================================
   Buttons
   ========================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover {
    box-shadow: 0 4px 20px rgba(129, 140, 248, 0.25);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

/* ==========================================
   Tabs
   ========================================== */
.tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: rgba(255,255,255,0.03);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    margin-bottom: 16px;
    width: fit-content;
}

.tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.tab.active {
    background: rgba(129, 140, 248, 0.12);
    color: var(--accent-indigo);
}

/* ==========================================
   Content Panels
   ========================================== */
.content-panel {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    animation: fadeIn 0.3s var(--ease-out);
}

.content-panel pre {
    padding: 24px;
    margin: 0;
    overflow-x: auto;
    max-height: 60vh;
    overflow-y: auto;
}

.content-panel code {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

/* Scrollbar styling */
.content-panel pre::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.content-panel pre::-webkit-scrollbar-track {
    background: transparent;
}
.content-panel pre::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
}
.content-panel pre::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.15);
}

/* ==========================================
   Markdown Preview
   ========================================== */
.markdown-preview {
    padding: 28px;
    max-height: 60vh;
    overflow-y: auto;
    line-height: 1.75;
    color: var(--text-primary);
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

.markdown-preview h1 { font-size: 1.6rem; }
.markdown-preview h2 { font-size: 1.3rem; border-bottom: 1px solid var(--border-subtle); padding-bottom: 0.4em; }
.markdown-preview h3 { font-size: 1.1rem; }

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

.markdown-preview a {
    color: var(--accent-indigo);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.markdown-preview code {
    font-family: var(--font-mono);
    background: rgba(255,255,255,0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
}

.markdown-preview pre {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    margin-bottom: 1em;
}

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

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

.markdown-preview li {
    margin-bottom: 0.3em;
}

.markdown-preview blockquote {
    border-left: 3px solid var(--accent-indigo);
    padding-left: 16px;
    margin: 1em 0;
    color: var(--text-secondary);
}

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

.markdown-preview th,
.markdown-preview td {
    border: 1px solid var(--border-subtle);
    padding: 8px 12px;
    text-align: left;
    font-size: 0.9rem;
}

.markdown-preview th {
    background: rgba(255,255,255,0.04);
    font-weight: 600;
}

.markdown-preview img {
    max-width: 100%;
    border-radius: var(--radius-sm);
}

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

/* ==========================================
   Error
   ========================================== */
.error-section {
    animation: fadeUp 0.4s var(--ease-out);
}

.error-card {
    text-align: center;
    padding: 48px 32px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(248, 113, 113, 0.15);
    border-radius: var(--radius-lg);
}

.error-icon {
    margin-bottom: 16px;
}

.error-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--error);
}

.error-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

/* ==========================================
   Toast
   ========================================== */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 10px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    opacity: 0;
    transition: all var(--transition-normal);
    z-index: 1000;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================
   Footer
   ========================================== */
.footer {
    margin-top: auto;
    padding-top: 48px;
    text-align: center;
    animation: fadeUp 0.6s var(--ease-out) 0.3s both;
}

.footer p {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.footer a {
    color: var(--accent-indigo);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer a:hover {
    color: var(--accent-purple);
}

/* ==========================================
   Utility
   ========================================== */
.hidden {
    display: none !important;
}

/* ==========================================
   Animations
   ========================================== */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeDown {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 640px) {
    .container {
        padding: 24px 16px;
    }

    .header {
        margin-bottom: 32px;
    }

    .logo h1 {
        font-size: 1.15rem;
    }

    .upload-zone {
        padding: 40px 24px;
    }

    .upload-zone h2 {
        font-size: 1.1rem;
    }

    .result-header {
        flex-direction: column;
    }

    .result-actions {
        width: 100%;
        justify-content: stretch;
    }

    .result-actions .btn {
        flex: 1;
        justify-content: center;
    }
}
