:root {
    --bg: #0f172a;
    --surface: #111827;
    --surface-alt: #1e293b;
    --border: #1f2937;
    --border-strong: #334155;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #1d4ed8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow: rgba(15, 23, 42, 0.32);
}

[data-theme="light"] {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-alt: #f1f5f9;
    --border: #e2e8f0;
    --border-strong: #cbd5f5;
    --text: #0f172a;
    --muted: #475569;
    --primary: #2563eb;
    --primary-hover: #1e3a8a;
    --shadow: rgba(15, 23, 42, 0.14);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #f8fafc;
        --surface: #ffffff;
        --surface-alt: #f1f5f9;
        --border: #e2e8f0;
        --border-strong: #cbd5f5;
        --text: #0f172a;
        --muted: #475569;
        --primary: #2563eb;
        --primary-hover: #1e3a8a;
        --shadow: rgba(15, 23, 42, 0.14);
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: linear-gradient(180deg, var(--bg) 0%, rgba(15, 23, 42, 0.92) 50%, var(--bg) 100%);
    color: var(--text);
    min-height: 100vh;
}

.container {
    max-width: 1160px;
    margin: 0 auto;
    padding: 32px 18px 48px;
}

.tool-header {
    text-align: center;
    margin-bottom: 32px;
}

.header-top {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 8px;
}

.tool-header h1 {
    font-size: clamp(1.75rem, 3vw, 2.4rem);
    margin: 0;
}

.theme-toggle {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--border);
    transform: translateY(-1px);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.theme-icon {
    font-size: 18px;
    transition: transform 0.2s ease;
}

.theme-toggle:hover .theme-icon {
    transform: rotate(10deg);
}

.subtitle {
    color: var(--muted);
    font-size: 1.05rem;
    margin: 0;
}

.hint {
    color: var(--muted);
    margin-top: 16px;
    font-size: 0.95rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 24px;
    box-shadow: 0 18px 40px -28px var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel h2 {
    margin: 0 0 4px;
    font-size: 1.35rem;
}

.panel-description {
    color: var(--muted);
    font-size: 0.95rem;
    margin: 0;
}

.upload {
    border: 2px dashed var(--border);
    border-radius: 14px;
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
    outline: none;
}

.upload p {
    margin: 0;
    font-weight: 600;
}

.upload.is-hovered,
.upload:focus-visible {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.12);
    transform: translateY(-2px);
}

.file-info {
    margin: 0;
    font-size: 0.9rem;
    color: var(--muted);
}

.file-list {
    margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-alt);
    max-height: 200px;
    overflow-y: auto;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.file-item:last-child {
    border-bottom: none;
}

.file-info-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-details {
    font-size: 0.85rem;
    color: var(--muted);
}

.file-status {
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

.file-status.pending {
    background: rgba(249, 115, 22, 0.2);
    color: var(--warning);
}

.file-status.converting {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primary);
}

.file-status.completed {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.file-status.error {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.file-actions {
    display: flex;
    gap: 8px;
}

.file-remove {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.file-remove:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.batch-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
}

.batch-actions .btn {
    flex: 1;
}

@media (max-width: 640px) {
    .file-item {
        flex-direction: column;
        align-items: stretch;
        text-align: left;
    }

    .file-actions {
        justify-content: flex-end;
        margin-top: 8px;
    }
}

.options {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 16px 4px;
    background: var(--surface-alt);
}

.options legend {
    padding: 0 6px;
    font-weight: 600;
    color: var(--muted);
    font-size: 0.85rem;
}

.row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin: 10px 0;
}

.field {
    min-width: 160px;
    font-weight: 600;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}

.toggle input {
    accent-color: var(--primary);
    cursor: pointer;
}

.input {
    min-height: 40px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.35);
    color: inherit;
    font: inherit;
    flex: 1 1 auto;
}

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

.input.small {
    max-width: 96px;
    text-align: center;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.btn {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 18px;
    font-weight: 600;
    cursor: pointer;
    background: rgba(15, 23, 42, 0.4);
    color: inherit;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.btn:hover:not([disabled]) {
    transform: translateY(-1px);
}

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

.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--primary);
    border-color: transparent;
    color: #fff;
}

.btn-primary:hover:not([disabled]) {
    background: var(--primary-hover);
}

.btn.ghost {
    background: transparent;
}

.preview {
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.preview-header h3 {
    margin: 0;
    font-size: 1rem;
}

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

.preview-table {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.35);
    max-height: 300px;
}

.preview-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.preview-table th,
.preview-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.preview-table th {
    background: rgba(37, 99, 235, 0.08);
    font-weight: 600;
}

.preview-table tr:last-child td {
    border-bottom: none;
}

.preview-more {
    text-align: center;
    font-style: italic;
    color: var(--muted);
}

.panel-wide {
    margin-top: 28px;
}

.guides-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 12px;
}

.guides-list li {
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px dashed var(--border);
    background: var(--surface-alt);
    font-size: 0.95rem;
}

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 14px 22px;
    border-radius: 12px;
    font-weight: 600;
    color: #fff;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 1010;
    pointer-events: none;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.toast[data-type="success"] {
    background: var(--success);
}

.toast[data-type="info"] {
    background: var(--primary);
}

.toast[data-type="warning"] {
    background: var(--warning);
    color: #0f172a;
}

.toast[data-type="error"] {
    background: var(--danger);
}

.loading-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
    background: rgba(15, 23, 42, 0.55);
    z-index: 2000;
    flex-direction: column;
    gap: 14px;
    color: #fff;
}

.loading-spinner {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    animation: spin 1s linear infinite;
}

.loading-text {
    font-weight: 600;
}

.progress-bar {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 280px;
}

.progress-bar-fill {
    width: 200px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.progress-bar-fill::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    animation: progress-slide 1.5s ease-in-out infinite;
}

.progress-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

@keyframes progress-slide {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

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

@media (max-width: 720px) {
    .container {
        padding: 24px 14px 36px;
    }

    .header-top {
        flex-direction: column;
        gap: 16px;
    }

    .tool-header h1 {
        font-size: 1.8rem;
        text-align: center;
    }

    .theme-toggle {
        position: fixed;
        top: 20px;
        right: 20px;
        z-index: 100;
    }

    .grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .panel {
        padding: 20px;
    }

    .row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .field {
        min-width: auto;
        font-size: 0.95rem;
    }

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

    .btn {
        width: 100%;
        text-align: center;
        padding: 12px 18px;
    }

    .upload {
        padding: 24px 16px;
    }

    .preview-table {
        font-size: 0.8rem;
    }

    .preview-table th,
    .preview-table td {
        padding: 6px 8px;
    }

    .progress-bar {
        top: 10px;
        left: 10px;
        right: 10px;
        transform: none;
        min-width: auto;
        margin: 0 10px;
    }

    .toast {
        top: 10px;
        right: 10px;
        left: 10px;
        transform: none;
        margin: 0;
    }
}

.upload:focus-within {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.08);
}

.input:focus,
.btn:focus,
select:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn:focus {
    outline-offset: 3px;
}

.toggle input:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border: #000;
        --border-strong: #000;
        --text: #000;
        --bg: #fff;
        --surface: #fff;
    }

    [data-theme="dark"] {
        --border: #fff;
        --border-strong: #fff;
        --text: #fff;
        --bg: #000;
        --surface: #000;
    }
}

/* Animation preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .progress-bar-fill::before {
        animation: none;
        left: 0;
    }
}
