/* ============================================================
   XLSX to CSV — Mobile-first, Dark Theme
   ============================================================ */

/* --- CSS Variables --- */
:root {
    --bg:          #0f0f14;
    --surface:     #1a1a24;
    --surface-2:   #24243a;
    --border:      #2e2e48;
    --border-hover:#6366f1;
    --text:        #e0e0e0;
    --text-light:  #9ca3af;
    --muted:       #6b7280;
    --accent:      #6366f1;
    --accent-hover:#818cf8;
    --accent-glow: rgba(99,102,241,0.15);
    --success:     #22c55e;
    --error:       #ef4444;
    --error-bg:    rgba(239,68,68,0.1);
    --radius:      12px;
    --radius-sm:   8px;
    --max-w:       640px;
    --font:        system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --transition:  0.2s ease;
}

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

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* --- Skip Link (a11y) --- */
.skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    z-index: 1000;
    text-decoration: none;
    font-weight: 600;
    transition: top var(--transition);
}
.skip-link:focus {
    top: 1rem;
}

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.logo-dot { color: var(--accent); }

.header-tag {
    font-size: 0.8rem;
    color: var(--accent);
    background: var(--accent-glow);
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-weight: 600;
    flex-shrink: 0;
}

/* --- Nav --- */
.header-nav {
    display: none;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.header-nav.open {
    display: flex;
}

.nav-link {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    color: var(--text-light);
    text-decoration: none;
    border-radius: 6px;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}
.nav-link:hover {
    background: var(--surface-2);
    color: var(--text);
}
.nav-link.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    transition: border-color var(--transition);
}
.nav-toggle:hover {
    border-color: var(--accent);
}
.nav-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- Main --- */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem;
    max-width: var(--max-w);
    width: 100%;
    margin: 0 auto;
}

/* --- Steps --- */
.converter-step {
    display: none;
    width: 100%;
    animation: fadeIn 0.3s ease;
}
.converter-step.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

/* --- Titles --- */
.converter-title {
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.5rem;
}

.converter-subtitle {
    color: var(--text-light);
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    max-width: 500px;
    line-height: 1.5;
}

/* --- Dropzone --- */
.dropzone {
    width: 100%;
    max-width: var(--max-w);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    background: var(--surface);
    position: relative;
}

.dropzone:hover,
.dropzone.drag-over {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.dropzone:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.dropzone-icon {
    margin-bottom: 1rem;
    opacity: 0.9;
}

.dropzone-text {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.dropzone-hint {
    font-size: 0.85rem;
    color: var(--muted);
}

.file-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* --- Error --- */
.error-message {
    width: 100%;
    max-width: var(--max-w);
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: var(--error-bg);
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: var(--radius);
    color: var(--error);
    font-size: 0.9rem;
    text-align: center;
}

/* --- Sheet Tabs --- */
.sheet-tabs {
    width: 100%;
    max-width: var(--max-w);
    display: flex;
    gap: 0.35rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}

.sheet-tab {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-light);
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    white-space: nowrap;
    font-family: var(--font);
}
.sheet-tab:hover {
    border-color: var(--accent);
    color: var(--text);
}
.sheet-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}
.sheet-tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- Preview --- */
.preview-header {
    width: 100%;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.preview-title {
    font-size: 1.2rem;
    font-weight: 600;
}

.preview-meta {
    font-size: 0.8rem;
    color: var(--muted);
}

.preview-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    max-height: 50vh;
    overflow-y: auto;
    margin-bottom: 1.25rem;
}

.preview-container:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    white-space: nowrap;
}

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

.preview-table th {
    background: var(--surface-2);
    font-weight: 600;
    color: var(--accent);
    position: sticky;
    top: 0;
    z-index: 1;
}

.preview-table tr:hover td {
    background: var(--accent-glow);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform 0.1s;
    text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
    background: var(--surface-2);
    color: var(--muted);
    cursor: not-allowed;
    transform: none;
}

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

.btn-lg {
    padding: 0.85rem 2rem;
    font-size: 1rem;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.preview-actions {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    max-width: var(--max-w);
}
.preview-actions .btn {
    flex: 1;
    justify-content: center;
}

/* --- Progress --- */
.progress-container {
    width: 100%;
    max-width: var(--max-w);
    margin-top: 1.25rem;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.5rem;
}

/* --- Download --- */
.download-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1rem;
    padding: 2rem 1rem;
}

.download-icon {
    margin-bottom: 0.5rem;
}

.download-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.download-filename {
    color: var(--muted);
    font-size: 0.9rem;
    word-break: break-all;
}

.download-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

/* --- How It Works --- */
.how-it-works {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 3rem 1rem 2rem;
}

.how-it-works h2 {
    text-align: center;
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.steps-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.step-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    position: relative;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.step-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.step-card p {
    font-size: 0.85rem;
    color: var(--text-light);
    line-height: 1.5;
}

/* --- Footer --- */
.app-footer {
    text-align: center;
    padding: 1.25rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.app-footer p {
    font-size: 0.8rem;
    color: var(--muted);
    max-width: 500px;
    margin: 0 auto;
}

/* --- Responsive: Tablets+ --- */
@media (min-width: 640px) {
    .converter-title { font-size: 2rem; }
    .dropzone { padding: 4rem 2rem; }
    .app-main { padding: 2.5rem 1.5rem; }
    .steps-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 768px) {
    .header-nav {
        display: flex !important;
    }
    .nav-toggle {
        display: none;
    }
}

/* --- Mobile nav open --- */
@media (max-width: 767px) {
    .app-header {
        padding: 0.75rem 1rem;
    }

    .header-nav.open {
        display: flex;
        flex-basis: 100%;
        border-top: 1px solid var(--border);
        padding-top: 0.5rem;
    }
}

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

/* --- Print --- */
@media print {
    .app-header, .app-footer, .how-it-works, .skip-link, .nav-toggle {
        display: none !important;
    }
    body { background: #fff; color: #000; }
}
