:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --surface-3: #f3f4f6;
    --border: rgba(34, 36, 38, 0.15);
    --border-lite: rgba(34, 36, 38, 0.1);
    --ink: rgba(0, 0, 0, 0.87);
    --muted: rgba(0, 0, 0, 0.6);
    --accent: #2185d0;
    --accent-dark: #1678c2;
    --accent-bg: #dff0ff;
    --ok-bg: #fcfff5;
    --ok-fg: #2c662d;
    --warn-bg: #fffaf3;
    --warn-fg: #573a08;
    --crit-bg: #fff6f6;
    --crit-fg: #9f3a38;
    --crit-border: #e0b4b4;
    --shadow-card: 0 1px 2px 0 rgba(34, 36, 38, 0.15);
    --shadow-shell: 0 20px 48px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

html {
    background: linear-gradient(180deg, #f5f7fa 0%, #ffffff 240px);
}

body {
    margin: 0;
    min-height: 100vh;
    background: transparent;
    color: var(--ink);
    font: 14px/1.5 Lato, "Helvetica Neue", Arial, Helvetica, sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

a {
    color: var(--accent);
}

a:hover {
    color: var(--accent-dark);
}

.page-header {
    background: #1b1c1d;
    padding: 16px 24px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
}

.page-header-brand {
    min-width: 0;
}

.page-eyebrow {
    margin: 0 0 4px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.page-header h1 {
    margin: 0;
    color: rgba(255, 255, 255, 0.92);
    font-size: 22px;
    line-height: 1.15;
}

.page-subtitle {
    margin: 6px 0 0;
    color: rgba(255, 255, 255, 0.68);
    font-size: 13px;
}

.header-domain {
    font-size: 0.72em;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.55);
}

.header-log-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.header-actions button {
    border: none;
}

.header-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    border-radius: 4px;
    padding: 7px 14px;
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.86);
    font-size: 13px;
    font-weight: 700;
    transition: background 0.12s ease, opacity 0.12s ease;
}

.header-action:hover {
    background: rgba(255, 255, 255, 0.2);
}

.header-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-main {
    width: min(1500px, calc(100vw - 48px));
    margin: 28px auto 56px;
}

.control-deck,
#data-section {
    display: grid;
    gap: 20px;
}

.surface-panel,
.job-status,
.viewer-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.surface-panel > h2,
.viewer-panel-header h2 {
    margin: 0;
    padding: 13px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
}

.surface-panel > p,
.viewer-panel-header p {
    margin: 0;
    padding: 12px 16px 0;
    color: var(--muted);
}

.upload-panel {
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
}

.source-switch {
    display: inline-flex;
    gap: 4px;
    width: fit-content;
    margin-bottom: 4px;
    margin-left: auto;
    margin-right: auto;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: var(--shadow-card);
}

.source-switch-btn {
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 700;
    transition: background 0.12s ease, color 0.12s ease;
}

.source-switch-btn:hover {
    background: var(--surface-3);
    color: var(--ink);
}

.source-switch-btn.active {
    background: var(--accent);
    color: #ffffff;
}

.upload-area {
    margin: 12px 16px 0;
    border: 1px dashed var(--border);
    border-radius: 4px;
    padding: 16px;
    text-align: center;
    background: var(--surface-2);
    transition: border-color 0.12s ease, background 0.12s ease;
}

.upload-area.dragover {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.upload-area p {
    margin: 0;
}

.upload-dropzone {
    display: block;
    cursor: pointer;
}

.upload-kicker {
    display: block;
    margin-bottom: 10px;
    color: #6b7280;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.upload-dropzone strong {
    display: block;
    margin-bottom: 8px;
    font-size: 28px;
    font-weight: 700;
    color: var(--ink);
}

.upload-copy {
    display: block;
    color: var(--muted);
    font-size: 15px;
    max-width: 560px;
    margin: 0 auto;
}

.upload-actions {
    margin-top: 22px;
}

.upload-area button,
#api-connect-btn,
#api-collect-btn,
#convert-folder-btn,
#convert-run-btn,
#cancel-job-btn,
#skip-hung-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    border: none;
    border-radius: 4px;
    padding: 8px 18px;
    font-weight: 700;
    transition: background 0.12s ease, opacity 0.12s ease;
}

.upload-area button,
#api-connect-btn,
#convert-folder-btn,
#convert-run-btn,
#cancel-job-btn {
    background: var(--accent);
    color: #ffffff;
    margin-top: 12px;
}

.upload-area button:hover,
#api-connect-btn:hover,
#convert-folder-btn:hover,
#convert-run-btn:hover,
#cancel-job-btn:hover {
    background: var(--accent-dark);
}

#api-collect-btn {
    background: #2c662d;
    color: #ffffff;
}

#api-collect-btn:hover {
    background: #245524;
}

#skip-hung-btn {
    background: #c67c0d;
    color: #ffffff;
}

#skip-hung-btn:hover {
    background: #a8680c;
}

.upload-area button:disabled,
#api-connect-btn:disabled,
#api-collect-btn:disabled,
#convert-folder-btn:disabled,
#convert-run-btn:disabled,
#cancel-job-btn:disabled,
#skip-hung-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.upload-area .hint {
    margin-top: 18px;
    color: #6b7280;
    font-size: 12px;
    letter-spacing: 0.01em;
}

.notice-panel {
    margin-bottom: 4px;
}

#upload-status,
.parsers-info,
#api-connect-form,
#convert-source-content > p,
.convert-progress,
#convert-folder-summary,
#convert-status {
    margin-left: 16px;
    margin-right: 16px;
}

#convert-source-content > p {
    margin-top: 12px;
}

#api-connect-form,
#convert-source-content {
    padding-bottom: 16px;
}

.api-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px 16px;
    margin-top: 12px;
}

.api-form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 700;
}

.api-form-field input,
.api-form-field select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 12px;
    background: #ffffff;
    color: var(--ink);
}

.api-form-field input:focus,
.api-form-field select:focus {
    outline: 2px solid var(--accent-bg);
    border-color: var(--accent);
}

.api-form-field.has-error input,
.api-form-field.has-error select {
    border-color: var(--crit-border);
    background: var(--crit-bg);
}

.field-error {
    min-height: 1rem;
    font-size: 12px;
    color: var(--crit-fg);
    font-weight: 400;
}

.form-errors {
    margin-top: 12px;
    border: 1px solid var(--crit-border);
    border-radius: 4px;
    padding: 10px 14px;
    background: var(--crit-bg);
    color: var(--crit-fg);
}

.form-errors ul {
    margin: 6px 0 0;
    padding-left: 18px;
}

.api-form-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 14px;
}

#api-connect-form.is-disabled {
    opacity: 0.6;
    pointer-events: none;
}

.api-probe-options {
    display: grid;
    gap: 10px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-lite);
}

.api-form-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-size: 13px;
    cursor: pointer;
}

.api-form-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.api-host-off-warning {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(228, 156, 52, 0.45);
    border-radius: 4px;
    padding: 9px 12px;
    background: var(--warn-bg);
    color: var(--warn-fg);
    font-size: 13px;
    font-weight: 700;
}

.api-connect-status {
    margin-top: 12px;
    border-radius: 4px;
    padding: 0;
    color: var(--muted);
    font-size: 13px;
}

.api-connect-status.success,
.api-connect-status.error,
.api-connect-status.info,
.api-connect-status.warning {
    padding: 9px 12px;
    border: 1px solid var(--border);
}

.api-connect-status.success {
    background: var(--ok-bg);
    border-color: rgba(44, 102, 45, 0.25);
    color: var(--ok-fg);
}

.api-connect-status.error {
    background: var(--crit-bg);
    border-color: var(--crit-border);
    color: var(--crit-fg);
}

.api-connect-status.info {
    background: var(--accent-bg);
    border-color: rgba(33, 133, 208, 0.2);
    color: #0f4d7d;
}

.api-connect-status.warning {
    background: var(--warn-bg);
    border-color: rgba(228, 156, 52, 0.45);
    color: var(--warn-fg);
}

.job-status {
    margin: 16px;
    padding: 16px;
    background: var(--surface);
}

.job-status-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.job-status-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.job-status-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.job-status-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px 12px;
    margin-bottom: 14px;
}

.meta-label {
    color: var(--muted);
    font-weight: 700;
}

.job-status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
}

.job-status-badge.status-queued,
.job-status-badge.status-running {
    background: var(--accent-bg);
    color: #0f4d7d;
}

.job-status-badge.status-success {
    background: var(--ok-bg);
    color: var(--ok-fg);
}

.job-status-badge.status-failed {
    background: var(--crit-bg);
    color: var(--crit-fg);
}

.job-status-badge.status-canceled {
    background: var(--surface-3);
    color: #4b5563;
}

.job-progress,
.convert-progress-track {
    height: 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}

.job-progress {
    margin-bottom: 14px;
}

.job-progress-bar,
.convert-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #4cb5ff);
    transition: width 0.2s ease;
}

.job-progress-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
}

.convert-progress {
    margin-top: 16px;
}

.convert-progress-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.job-active-modules,
.job-debug-info,
.job-status-logs {
    margin-top: 14px;
}

.job-module-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.job-module-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    border: 1px solid rgba(33, 133, 208, 0.2);
    background: var(--accent-bg);
    padding: 6px 10px;
    line-height: 1;
}

.job-module-chip-name {
    font-size: 12px;
    font-weight: 700;
    color: #17466b;
}

.job-module-chip-score {
    border: 1px solid rgba(33, 133, 208, 0.2);
    border-radius: 999px;
    background: #ffffff;
    padding: 2px 7px;
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.job-debug-info {
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
    padding: 12px;
}

.job-debug-summary {
    margin-top: 8px;
    color: #374151;
    font-size: 12px;
}

.job-phase-telemetry {
    display: grid;
    gap: 6px;
    margin-top: 10px;
}

.job-phase-row {
    display: grid;
    grid-template-columns: minmax(120px, 180px) repeat(4, minmax(70px, auto));
    gap: 8px;
    align-items: center;
    font-size: 12px;
}

.job-phase-name {
    font-weight: 700;
    color: var(--ink);
}

.job-phase-metric,
.log-time,
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.job-phase-metric {
    color: #4b5563;
}

.job-status-logs ul {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    border-top: 1px solid var(--border-lite);
}

.job-status-logs li {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-lite);
    font-size: 13px;
}

.log-time {
    color: var(--muted);
}

.log-message {
    color: var(--ink);
}

#upload-status {
    margin-top: 12px;
    min-height: 22px;
    color: var(--muted);
    text-align: center;
}

#upload-status.success {
    color: var(--ok-fg);
}

#upload-status.error {
    color: var(--crit-fg);
}

.parsers-info {
    margin-top: 28px;
    padding: 18px 0 2px;
    text-align: center;
    border-top: 1px solid var(--border-lite);
}

.parsers-title {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.parsers-summary {
    margin: 8px 0 0;
    color: var(--ink);
    font-size: 18px;
    font-weight: 700;
}

.parsers-text {
    max-width: 760px;
    margin: 10px auto 0;
    color: #6b7280;
    font-size: 13px;
    line-height: 1.7;
}

.viewer-panel {
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: visible;
}

.viewer-panel-header {
    background: transparent;
    margin-bottom: 10px;
}

.viewer-panel-header h2 {
    border-radius: 4px 4px 0 0;
}

.viewer-panel-header p {
    padding-bottom: 0;
}

.audit-viewer-shell {
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: var(--shadow-shell);
    overflow: hidden;
    background: #ffffff;
}

.audit-viewer-frame {
    display: block;
    width: 100%;
    min-height: 60vh;
    border: none;
    background: #ffffff;
}

.page-footer {
    width: min(1500px, calc(100vw - 48px));
    margin: -20px auto 36px;
    padding-top: 10px;
}

.footer-info {
    color: var(--muted);
    font-size: 12px;
}

.footer-info p {
    margin: 0;
}

.footer-info a {
    text-decoration: none;
}

code {
    border-radius: 3px;
    background: #f3f4f6;
    padding: 0.1em 0.3em;
    font-size: 0.92em;
}

.hidden {
    display: none !important;
}

@media (max-width: 900px) {
    .page-main,
    .page-footer {
        width: calc(100vw - 24px);
    }

    .page-header {
        padding: 14px 16px;
    }

    .page-main {
        margin-top: 18px;
        margin-bottom: 42px;
    }

    .job-phase-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .source-switch {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }

    .source-switch-btn {
        justify-content: center;
    }

    .upload-area {
        padding: 18px 14px;
    }

    .upload-dropzone strong {
        font-size: 22px;
    }

    .upload-copy {
        font-size: 14px;
    }

    .job-status,
    #api-connect-form,
    #convert-source-content,
    #upload-status,
    .parsers-info,
    #convert-folder-summary,
    #convert-status,
    .convert-progress {
        margin-left: 12px;
        margin-right: 12px;
    }

    .job-status-header,
    .header-actions,
    .api-form-actions,
    .job-status-actions {
        align-items: stretch;
    }

    .job-status-header,
    .header-actions {
        flex-direction: column;
    }

    .header-actions button,
    .header-action,
    #api-connect-btn,
    #api-collect-btn,
    #convert-folder-btn,
    #convert-run-btn,
    #cancel-job-btn,
    #skip-hung-btn,
    .upload-area button {
        width: 100%;
    }

    .job-status li {
        grid-template-columns: 1fr;
    }
}

/* ── Parse / collection errors panel ───────────────────────────────────── */
.parse-errors-section {
    overflow: hidden;
}

.parse-errors-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .55rem .75rem;
    background: var(--warn-bg);
    border: 1px solid #f0e0c0;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    font-size: .85rem;
    color: var(--warn-fg);
}

.parse-errors-toggle {
    font-size: .75rem;
    opacity: .7;
}

.parse-errors-body {
    border: 1px solid #f0e0c0;
    border-top: none;
    border-radius: 0 0 6px 6px;
    overflow-x: auto;
}

.parse-errors-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
}

.parse-errors-table th {
    background: var(--surface-3);
    padding: .4rem .65rem;
    text-align: left;
    font-weight: 600;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.parse-errors-table td {
    padding: .38rem .65rem;
    border-bottom: 1px solid var(--border-lite);
    vertical-align: top;
}

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

.parse-error-row.parse-error-error td:first-child {
    color: var(--crit-fg);
    font-weight: 600;
}

.parse-error-row.parse-error-warning td:first-child {
    color: #7a5200;
    font-weight: 600;
}
