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

:root {
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-focus: #93c5fd;
    --success: #10b981;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 680px;
    margin: 0 auto;
    padding: 48px 24px 80px;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

header h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 6px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 15px;
}

/* Mode Switch */
.mode-switch {
    display: flex;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.mode-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 7px;
    transition: all 0.2s;
}

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

.mode-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3);
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.step-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.step-header h2 {
    font-size: 18px;
    font-weight: 600;
}

/* API Key */
.api-key-card {
    margin-bottom: 20px;
}

.api-key-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.api-key-label {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.api-key-input-group {
    display: flex;
    gap: 6px;
    align-items: center;
}

.api-key-input-group .field-input {
    flex: 1;
    font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
    font-size: 13px;
}

.btn-icon {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--bg);
    color: var(--text);
}

.api-key-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.5;
}

.api-key-hint a {
    color: var(--primary);
    text-decoration: none;
}

.api-key-hint a:hover {
    text-decoration: underline;
}

/* Model Status */
.model-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}

.model-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-muted);
}

.model-status.checking .model-status-dot {
    background: #f59e0b;
    animation: pulse-dot 1s ease-in-out infinite;
}

.model-status.downloading .model-status-dot {
    background: var(--primary);
    animation: pulse-dot 1s ease-in-out infinite;
}

.model-status.ready .model-status-dot {
    background: var(--success);
}

.model-status.error .model-status-dot {
    background: var(--danger);
}

.model-status.ready {
    border-color: #a7f3d0;
    background: #ecfdf5;
    color: #065f46;
}

.model-status.error {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.model-progress-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 140px;
}

.model-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    min-width: 80px;
}

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

.model-progress-pct {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 36px;
    text-align: right;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    color: var(--text-muted);
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: #eff6ff;
}

.drop-zone svg {
    margin-bottom: 12px;
    opacity: 0.5;
}

.drop-zone p {
    font-size: 14px;
}

.browse-link {
    color: var(--primary);
    font-weight: 500;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Status Bar */
.status-bar {
    margin-top: 14px;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-bar.success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.status-bar.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Field Rows */
.field-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    align-items: center;
}

.field-input {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.field-key {
    flex: 1;
    min-width: 0;
}

.field-desc {
    flex: 1;
    min-width: 0;
    color: var(--text-muted);
    font-size: 13px;
}

.field-desc::placeholder {
    color: #94a3b8;
}

.field-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn-remove {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.btn-remove:hover {
    background: #fef2f2;
    color: var(--danger);
}

/* Buttons */
.field-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.btn-primary {
    padding: 10px 22px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    margin-left: auto;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    padding: 10px 22px;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-secondary:hover {
    background: var(--bg);
}

/* Multi-match */
.hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.multimatch-group {
    margin-bottom: 18px;
}

.multimatch-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    font-size: 14px;
}

.radio-option:hover {
    border-color: var(--border-focus);
    background: #f8fafc;
}

.radio-option input[type="radio"] {
    accent-color: var(--primary);
    flex-shrink: 0;
}

.radio-option.selected {
    border-color: var(--primary);
    background: #eff6ff;
}

/* JSON Output */
.json-output-wrapper {
    position: relative;
    background: #0f172a;
    border-radius: 8px;
    overflow: hidden;
}

.json-output-wrapper pre {
    padding: 20px;
    margin: 0;
    overflow-x: auto;
    font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.7;
    color: #e2e8f0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.btn-copy {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #94a3b8;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-copy:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.btn-copy.copied {
    color: var(--success);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 16px;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

.loading-overlay p {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Loading Progress Bar (Method 1) */
.loading-progress {
    width: 280px;
    max-width: 80vw;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.loading-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.loading-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), #3b82f6);
    border-radius: 4px;
    transition: width 0.4s ease;
}

.loading-progress-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

#loading-stage {
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#loading-percent {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    font-weight: 600;
}

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

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

    .card {
        padding: 20px;
    }

    header h1 {
        font-size: 22px;
    }

    .field-row {
        flex-wrap: wrap;
    }

    .field-key,
    .field-desc {
        flex: 1 1 100%;
    }

    .field-actions {
        flex-direction: column;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
        text-align: center;
        margin-left: 0;
    }
}
