/* ==========================================================================
   AlphaCorr — Shared Design System
   Common CSS for all portals (CIM, ARD, IPD, PackOps).
   Hand-written CSS, no frameworks.
   ========================================================================== */

:root {
    /* Brand — AlphaCorr red, matched from alphacorr.com */
    --brand:        #961c1f;
    --brand-light:  #b82528;
    --brand-bg:     #fef2f2;

    /* Grays */
    --gray-900: #111827;
    --gray-700: #374151;
    --gray-500: #6b7280;
    --gray-300: #d1d5db;
    --gray-200: #e5e7eb;
    --gray-100: #f3f4f6;
    --gray-50:  #f9fafb;
    --white:    #ffffff;

    /* Status */
    --success:  #16a34a;
    --success-bg: #f0fdf4;
    --danger:   #dc2626;
    --danger-bg: #fef2f2;
    --warning:  #d97706;

    /* Layout */
    --container-max: 1100px;
    --radius: 6px;
    --radius-lg: 10px;
}

/* ---------- Reset & base ---------- */

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--gray-700);
    background: var(--gray-50);
}

a { color: var(--brand); }
a:hover { color: var(--brand-light); }

h1, h2, h3, h4 {
    color: var(--gray-900);
    line-height: 1.3;
}

img { max-width: 100%; }

/* ---------- Nav ---------- */

.nav {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 0 24px;
}

.nav-inner {
    max-width: var(--container-max);
    margin: 0 auto;
    display: flex;
    align-items: center;
    height: 56px;
    gap: 24px;
}

.nav-brand {
    text-decoration: none;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.nav-brand-name {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--brand);
}

.nav-brand-tag {
    font-size: 0.8rem;
    color: var(--gray-500);
    font-weight: 400;
}

.nav-links {
    display: flex;
    gap: 20px;
    margin-left: auto;
}

.nav-links a {
    text-decoration: none;
    color: var(--gray-700);
    font-size: 0.925rem;
    font-weight: 500;
}

.nav-links a:hover {
    color: var(--brand);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: 16px;
}

.nav-username {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.nav-dropdown {
    position: relative;
    display: inline-block;
}

.nav-dropdown-toggle {
    background: none;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 5px 12px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.nav-dropdown-toggle:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.nav-caret {
    font-size: 0.7rem;
    line-height: 1;
}

.nav-dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    padding-top: 6px;
    min-width: 140px;
    z-index: 100;
    background: transparent;
}

.nav-dropdown-menu::after {
    content: "";
    position: absolute;
    top: 6px; right: 0; bottom: 0; left: 0;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: -1;
}

.nav-dropdown:hover .nav-dropdown-menu {
    display: block;
}

.nav-dropdown-item {
    display: block;
    padding: 8px 16px;
    font-size: 0.875rem;
    color: var(--gray-700);
    text-decoration: none;
}

.nav-dropdown-item:hover {
    background: var(--gray-50);
    color: var(--brand);
}

/* Nav-links dropdown — opens flush left, not right */
.nav-links .nav-dropdown-menu {
    right: auto;
    left: 0;
}

/* ---------- Container ---------- */

.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 32px 24px;
}

.container-wide {
    max-width: 1600px;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-block;
    padding: 10px 20px;
    font-size: 0.925rem;
    font-weight: 600;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.4;
}

.btn-primary {
    background: var(--brand);
    color: var(--white);
    border-color: var(--brand);
}

.btn-primary:hover {
    background: var(--brand-light);
    border-color: var(--brand-light);
    color: var(--white);
}

.btn-outline {
    background: transparent;
    color: var(--brand);
    border-color: var(--gray-300);
}

.btn-outline:hover {
    border-color: var(--brand);
    background: var(--brand-bg);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.825rem;
}

.btn-lg {
    padding: 14px 32px;
    font-size: 1.05rem;
}

.btn-block {
    display: block;
    width: 100%;
}

/* ---------- Cards ---------- */

.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 28px;
}

.card h3 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.card p {
    margin: 0;
    color: var(--gray-500);
    font-size: 0.925rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}

/* ---------- Hero (landing) ---------- */

.hero {
    text-align: center;
    padding: 48px 0 40px;
    max-width: 720px;
    margin: 0 auto;
}

.hero-free {
    font-size: 3rem;
    font-weight: 800;
    color: var(--brand);
    margin: 0 0 4px;
    letter-spacing: -0.03em;
}

.hero h1 {
    font-size: 2.25rem;
    margin: 0 0 16px;
    letter-spacing: -0.02em;
    color: var(--gray-500);
    font-weight: 400;
}

.hero-sub {
    font-size: 1.1rem;
    color: var(--gray-700);
    margin: 0 0 28px;
    line-height: 1.7;
}

.hero-context {
    max-width: 720px;
    margin: -16px auto 32px;
    text-align: center;
}

.hero-context p {
    font-size: 0.95rem;
    color: var(--gray-500);
    line-height: 1.7;
}

/* ---------- Why section ---------- */

.why-section {
    max-width: 680px;
    margin: 0 auto 32px;
    text-align: center;
    padding: 32px 24px;
}

.why-section h2 {
    margin: 0 0 12px;
    font-size: 1.35rem;
}

.why-section p {
    margin: 0;
    font-size: 1.05rem;
    color: var(--gray-700);
    line-height: 1.8;
}

/* ---------- Features section ---------- */

.features {
    padding: 24px 0 40px;
}

/* ---------- Early access ---------- */

.early-access {
    background: var(--brand-bg);
    border: 1px solid #fecaca;
    border-radius: var(--radius-lg);
    padding: 32px 36px;
    margin: 8px 0 32px;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
}

.early-access h2 {
    margin: 0 0 12px;
    font-size: 1.25rem;
}

.free-headline {
    font-size: 1.75rem !important;
    letter-spacing: -0.02em;
}

.free-catch {
    font-weight: 400;
    color: var(--gray-500);
    font-size: 1.25rem;
}

.early-access p {
    margin: 0 0 12px;
    font-size: 0.925rem;
    color: var(--gray-700);
    line-height: 1.7;
}

.early-access p:last-child {
    margin-bottom: 0;
}

.early-access-note {
    font-size: 0.85rem !important;
    color: var(--gray-500) !important;
    font-style: italic;
}

/* ---------- How it works ---------- */

.how-it-works {
    padding: 40px 0;
}

.how-it-works h2 {
    text-align: center;
    margin: 0 0 28px;
}

.steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 24px;
    text-align: center;
}

.step {
    padding: 20px;
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand);
    color: var(--white);
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 12px;
}

.step h4 {
    margin: 0 0 6px;
}

.step p {
    margin: 0;
    color: var(--gray-500);
    font-size: 0.925rem;
}

/* ---------- CTA bottom ---------- */

.cta-bottom {
    text-align: center;
    padding: 48px 24px;
    margin: 24px 0 0;
    background: var(--brand-bg);
    border-radius: var(--radius-lg);
}

.cta-bottom h2 {
    margin: 0 0 8px;
}

.cta-bottom p {
    color: var(--gray-500);
    margin: 0 0 24px;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
}

/* ---------- Page header ---------- */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    margin: 0;
}

/* ---------- Data table ---------- */

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 0.9rem;
}

.data-table thead {
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.data-table th {
    font-weight: 600;
    color: var(--gray-900);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--gray-100);
}

.data-table tbody tr:last-child {
    border-bottom: none;
}

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 2px 10px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 12px;
    text-transform: capitalize;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge-failed {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-pending {
    background: var(--gray-100);
    color: var(--gray-500);
}

/* ---------- Empty state ---------- */

.empty-state {
    text-align: center;
    padding: 64px 24px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
}

.empty-state h2 {
    margin: 0 0 8px;
    color: var(--gray-700);
}

.empty-state p {
    color: var(--gray-500);
    margin: 0 0 20px;
}

/* ---------- Forms ---------- */

.form-page {
    display: flex;
    justify-content: center;
    padding: 16px 0;
}

.form-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 520px;
}

.form-card h1 {
    margin: 0 0 4px;
    font-size: 1.5rem;
}

.form-subtitle {
    color: var(--gray-500);
    margin: 0 0 24px;
    font-size: 0.925rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--gray-900);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="tel"],
.form-group select {
    width: 100%;
    padding: 9px 12px;
    font-size: 0.925rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--gray-900);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px rgba(150, 28, 31, 0.15);
}

.form-group input[type="file"] {
    font-size: 0.9rem;
    color: var(--gray-700);
}

.form-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--gray-500);
}

.form-check label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-weight: 400;
    font-size: 0.9rem;
    cursor: pointer;
}

.form-check input[type="checkbox"] {
    margin-top: 4px;
}

.form-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--gray-500);
}

.required {
    color: var(--danger);
}

/* ---------- Alerts ---------- */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.alert ul {
    margin: 0;
    padding-left: 18px;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid #bbf7d0;
}

/* ---------- Footer ---------- */

.footer {
    border-top: 1px solid var(--gray-200);
    padding: 24px 24px 20px;
    margin-top: auto;
}

.footer-inner {
    max-width: var(--container-max);
    margin: 0 auto;
    text-align: center;
}

.footer-contact {
    margin: 0 0 4px;
    font-size: 0.85rem;
    color: var(--gray-700);
}

.footer-links {
    margin: 8px 0 0;
    font-size: 0.85rem;
}

.footer-links a {
    color: var(--gray-500);
    text-decoration: none;
}

.footer-links a:hover {
    color: var(--brand);
    text-decoration: underline;
}

.footer-copy {
    margin: 10px 0 0;
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* ---------- Preview ---------- */

.preview-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    border-bottom: 2px solid var(--gray-200);
}

.preview-tab {
    padding: 10px 24px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 0.925rem;
    font-weight: 600;
    color: var(--gray-500);
    cursor: pointer;
}

.preview-tab.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
}

.preview-tab:hover {
    color: var(--brand-light);
}

.preview-panel {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    min-height: 400px;
}

.svg-container {
    padding: 24px;
    text-align: center;
    overflow: auto;
}

.svg-container img {
    max-width: 100%;
    max-height: 600px;
    height: auto;
}

/* ---------- Privacy ---------- */

.privacy-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 0;
}

.privacy-page h1 {
    margin-bottom: 4px;
}

.privacy-updated {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-bottom: 32px;
}

.privacy-page h2 {
    color: var(--brand);
    font-size: 1.25rem;
    margin-top: 32px;
    margin-bottom: 12px;
}

.privacy-page h3 {
    font-size: 1rem;
    margin-top: 20px;
    margin-bottom: 8px;
}

.privacy-page ul {
    margin: 8px 0 16px 24px;
}

.privacy-page .contact-list {
    list-style: none;
    padding-left: 0;
}

.privacy-page .contact-list li {
    margin-bottom: 4px;
}

/* ---------- Balance box ---------- */

.balance-box {
    display: flex;
    gap: 20px;
    justify-content: center;
    padding: 12px 16px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.balance-box strong {
    color: var(--gray-900);
}

/* ---------- Tip ---------- */

.tip {
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--gray-700);
    line-height: 1.6;
}

/* ---------- Disclaimer ---------- */

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--gray-500);
    margin: 48px auto 0;
    max-width: 600px;
    line-height: 1.6;
}

/* ---------- Utilities ---------- */

.text-muted {
    color: var(--gray-500);
    font-size: 0.85rem;
}

/* ---------- Admin filter bar ---------- */

.admin-filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 14px 16px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.admin-filter-input {
    padding: 7px 10px;
    font-size: 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--gray-900);
    min-width: 200px;
    flex: 1;
}

.admin-filter-input:focus {
    outline: none;
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px rgba(150, 28, 31, 0.15);
}

.admin-filter-select {
    padding: 7px 10px;
    font-size: 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--gray-900);
}

/* ---------- Admin table filter row ---------- */

.filter-row {
    background: var(--gray-50);
}

.filter-row td {
    padding: 6px 8px !important;
}

.filter-input {
    width: 100%;
    padding: 4px 6px;
    font-size: 0.8rem;
    border: 1px solid var(--gray-300);
    border-radius: 3px;
    background: var(--white);
    color: var(--gray-900);
    box-sizing: border-box;
}

.filter-input:focus {
    outline: none;
    border-color: var(--brand-light);
    box-shadow: 0 0 0 2px rgba(150, 28, 31, 0.12);
}

select.filter-input {
    padding: 4px 4px;
}

/* ---------- Admin pagination ---------- */

.admin-pagination {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
    justify-content: center;
}

/* ---------- Admin bulk actions ---------- */

.admin-bulk-actions {
    margin-top: 32px;
    padding: 20px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.admin-bulk-actions h3 {
    margin: 0 0 16px;
    font-size: 1rem;
    color: var(--gray-700);
}

.admin-bulk-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.admin-bulk-form label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
}

.admin-bulk-form select {
    flex: 1;
    min-width: 200px;
}

/* ---------- PackOps handoff banner ---------- */

.packops-handoff {
    background: linear-gradient(135deg, var(--gray-900) 0%, #1e293b 100%);
    color: var(--white);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    margin: 32px 0;
    text-align: center;
}

.packops-handoff h3 {
    color: var(--white);
    margin: 0 0 8px;
    font-size: 1.15rem;
}

.packops-handoff p {
    color: #94a3b8;
    margin: 0 0 16px;
    font-size: 0.925rem;
}

.packops-handoff .btn {
    background: var(--brand);
    color: var(--white);
    border-color: var(--brand);
}

.packops-handoff .btn:hover {
    background: var(--brand-light);
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
    .nav-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 12px 0;
        gap: 8px;
    }

    .nav-links {
        order: 3;
        width: 100%;
        margin-left: 0;
        gap: 16px;
    }

    .nav-user {
        margin-left: auto;
    }

    .hero h1 {
        font-size: 1.6rem;
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

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

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .form-card {
        padding: 24px;
    }

    .data-table {
        font-size: 0.825rem;
    }

    .data-table th,
    .data-table td {
        padding: 8px 10px;
    }
}

/* ==========================================================================
   SVG zoom/pan preview (shared partial _svg_preview.html)
   ========================================================================== */

.svg-preview {
    position: relative;
    border: 1px solid var(--gray-200);
    background: white;
    width: 100%;
    aspect-ratio: 4 / 3;
    max-height: 500px;
    overflow: hidden;
    user-select: none;
}

.svg-preview-stage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    box-sizing: border-box;
}

.svg-preview-stage svg {
    cursor: grab;
}

.svg-preview-stage svg:active {
    cursor: grabbing;
}

.svg-preview-toolbar {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    padding: 2px;
}

.svg-preview-toolbar button {
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1;
    padding: 6px 10px;
    min-width: 32px;
    border: 0;
    background: transparent;
    color: var(--gray-700);
    cursor: pointer;
    border-radius: 3px;
}

.svg-preview-toolbar button:hover {
    background: var(--gray-100);
    color: var(--brand);
}

/* ==========================================================================
   Shared JSON viewer (shared partial _json_viewer.html)
   ========================================================================== */

.json-viewer {
    border: 1px solid var(--gray-200);
    background: var(--gray-50);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85rem;
}

.jv-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    background: var(--gray-100);
    border-bottom: 1px solid var(--gray-200);
    flex-wrap: wrap;
    gap: 8px;
}

.jv-tabs, .jv-actions {
    display: flex;
    gap: 4px;
}

.jv-toolbar button {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 4px 10px;
    border: 1px solid var(--gray-300);
    background: white;
    color: var(--gray-700);
    border-radius: 3px;
    cursor: pointer;
}

.jv-toolbar button:hover { color: var(--brand); border-color: var(--brand-light); }
.jv-tabs button.active   { color: var(--brand); border-color: var(--brand); background: white; font-weight: 600; }

.jv-stage {
    padding: 10px 12px;
    max-height: 520px;
    overflow: auto;
}

.jv-tree, .jv-body { padding-left: 14px; }
.jv-tree { padding-left: 0; }

.jv-node.jv-collapsed > .jv-body,
.jv-node.jv-collapsed > .jv-tail { display: none; }

.jv-head { cursor: default; white-space: nowrap; }
.jv-head.jv-collapsible { cursor: pointer; }
.jv-head.jv-empty       { cursor: default; }

.jv-toggle  { display: inline-block; width: 12px; color: var(--gray-500); }
.jv-key     { color: var(--gray-700); }
.jv-colon   { color: var(--gray-500); }
.jv-bracket { color: var(--gray-500); }
.jv-summary { color: var(--gray-500); font-style: italic; margin-left: 6px; }
.jv-string  { color: #0b7a3b; }
.jv-number  { color: #b64e00; }
.jv-boolean { color: #5a3ab4; }
.jv-null    { color: var(--gray-500); font-style: italic; }
.jv-leaf    { padding: 1px 0; }

.jv-flat {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.85rem;
}

.jv-parse-error { color: var(--brand); }

/* ==========================================================================
   Result cards (multi-file upload) + tabs
   ========================================================================== */

.result-card {
    margin-bottom: 32px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.result-card-header {
    padding: 14px 18px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.result-card-header h3 { margin: 0; font-size: 1.05rem; }
.result-card-header .meta { color: var(--gray-500); font-size: 0.9rem; }

.result-card-body { padding: 16px 18px; }

.source-pill {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 10px;
    vertical-align: middle;
    margin-right: 8px;
}
.source-pill.given     { background: var(--gray-200); color: var(--gray-700); }
.source-pill.generated { background: var(--brand-bg);  color: var(--brand);   }

/* Tab panels — scoped per-card via a data-tab-group attribute */
.tab-panel          { display: none; padding-top: 14px; }
.tab-panel.active   { display: block; }

/* Image-preview stage — needs overflow:hidden so transformed <img> clips */
.image-preview-stage {
    overflow: hidden;
    padding: 0;
    cursor: grab;
}
.image-preview-stage:active { cursor: grabbing; }

/* ==========================================================================
   Matcher page (native ↔ reference pairing, Step 3)
   ========================================================================== */

.matcher-page { max-width: 1100px; margin: 0 auto; padding: 20px 0; }
.matcher-page h1 { margin-bottom: 8px; }
.matcher-page .form-subtitle { margin-bottom: 24px; }

.matcher-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    margin-bottom: 24px;
}

.matcher-col h3 {
    margin: 0 0 12px 0;
    font-size: 0.95rem;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.matcher-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    margin-bottom: 10px;
    background: white;
}

.matcher-item.is-paired { background: var(--brand-bg); border-color: var(--brand-light); }
.matcher-item.is-removed { opacity: 0.35; text-decoration: line-through; }

.matcher-thumb {
    width: 96px;
    height: 96px;
    border: 1px solid var(--gray-200);
    background: var(--gray-50);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 4px;
}
.matcher-thumb img {
    max-width: 100%;
    max-height: 100%;
    display: block;
}
.matcher-thumb .thumb-placeholder {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-align: center;
    padding: 4px;
}

.matcher-item .meta   { flex: 1; min-width: 0; }
.matcher-item .name   { font-weight: 600; word-break: break-all; font-size: 0.9rem; }
.matcher-item .sub    { font-size: 0.8rem; color: var(--gray-500); }

.matcher-item select,
.matcher-item .match-note { font-size: 0.85rem; }

.matcher-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.matcher-actions button {
    font-family: inherit;
    font-size: 0.75rem;
    padding: 4px 8px;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 3px;
    cursor: pointer;
    color: var(--gray-700);
}
.matcher-actions button:hover { color: var(--brand); border-color: var(--brand-light); }

.match-note.auto   { color: var(--brand); font-weight: 600; }
.match-note.manual { color: var(--gray-700); }
.match-note.none   { color: var(--gray-500); font-style: italic; }

@media (max-width: 700px) {
    .matcher-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Matcher — single-column native groups (Step 3 revision)
   ========================================================================== */

.matcher-list { display: flex; flex-direction: column; gap: 0; }

.native-group {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    margin-bottom: 14px;
    background: white;
    transition: border-color 0.15s, background 0.15s;
}
.native-group.drop-hot {
    border-color: var(--brand);
    background: var(--brand-bg);
}

.native-row {
    border: 0;
    margin: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.unpaired-group { border-style: dashed; background: var(--gray-50); }
.unpaired-row   { background: transparent; }
.unpaired-row .thumb-placeholder { font-size: 1.2rem; color: var(--gray-300); }

.paired-refs {
    padding: 10px 10px 2px 10px;
    min-height: 56px;
}

.paired-refs:empty::before {
    content: "Drop references here or use the dropdowns.";
    display: block;
    padding: 10px;
    color: var(--gray-500);
    font-style: italic;
    font-size: 0.85rem;
}

.matcher-ref {
    cursor: grab;
    margin-bottom: 8px;
}
.matcher-ref:active,
.matcher-ref.is-dragging { cursor: grabbing; opacity: 0.6; }

/* ==========================================================================
   Upload drop zone (shared across portals)
   ========================================================================== */

.drop-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius-lg);
    background: var(--gray-50);
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
    outline: none;
}
.drop-zone:hover,
.drop-zone:focus-visible { border-color: var(--brand-light); background: white; }
.drop-zone.is-hot {
    border-color: var(--brand);
    background: var(--brand-bg);
    transform: scale(1.005);
}

.drop-zone-icon {
    font-size: 2rem;
    color: var(--brand);
    margin-bottom: 4px;
    line-height: 1;
}
.drop-zone-primary   { font-size: 1rem;   font-weight: 600; color: var(--gray-900); }
.drop-zone-secondary { font-size: 0.9rem; color: var(--gray-500); margin-top: 2px; }
.drop-zone-link      { color: var(--brand); text-decoration: underline; }
.drop-zone-formats   { font-size: 0.8rem; color: var(--gray-500); margin-top: 8px; font-family: ui-monospace, Menlo, monospace; }

.drop-zone-files {
    list-style: none;
    padding: 0;
    margin: 12px 0 0 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.drop-zone-file {
    display: grid;
    grid-template-columns: 100px 1fr auto auto;
    gap: 10px;
    align-items: center;
    padding: 6px 10px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    background: white;
    font-size: 0.9rem;
}
.drop-zone-file .file-kind {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 10px;
    text-align: center;
}
.drop-zone-file.is-native      .file-kind { background: var(--brand-bg); color: var(--brand); }
.drop-zone-file.is-reference   .file-kind { background: var(--gray-200); color: var(--gray-700); }
.drop-zone-file.is-unsupported .file-kind { background: #fff2cd;          color: #8a6d00;       }

.drop-zone-file .file-name { font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop-zone-file .file-size { color: var(--gray-500); font-size: 0.8rem; }
.drop-zone-file .file-remove {
    border: 0; background: transparent; color: var(--gray-400); cursor: pointer;
    font-size: 1.1rem; line-height: 1; padding: 2px 6px; border-radius: 3px;
}
.drop-zone-file .file-remove:hover { background: var(--gray-100); color: var(--gray-700); }

/* Matcher visual-hierarchy polish: prominent natives, indented refs */
.native-row {
    padding: 16px 18px;
    gap: 14px;
}
.native-row .name { font-size: 1.05rem; font-weight: 700; color: var(--gray-900); }
.native-row .sub  { font-size: 0.82rem; }
.native-row .matcher-thumb {
    width: 112px;
    height: 112px;
}
.native-row .matcher-thumb .thumb-placeholder { font-size: 0.9rem; font-weight: 700; color: var(--brand); }

/* Indent every paired reference further beneath its native */
.paired-refs       { padding-left: 56px; }
.paired-refs:empty { padding-left: 56px; }

/* (Guide line removed — indent + badges carry the parent/child hierarchy) */
.native-group { position: relative; }

@media (max-width: 640px) {
    .paired-refs       { padding-left: 24px; }
    .paired-refs:empty { padding-left: 24px; }
}

/* Deeper indent for matcher refs */
.paired-refs       { padding-left: 112px; }
.paired-refs:empty { padding-left: 112px; }

@media (max-width: 640px) {
    .paired-refs       { padding-left: 48px; }
    .paired-refs:empty { padding-left: 48px; }
}

.matcher-thumb { position: relative; }
.matcher-thumb.is-clickable { cursor: zoom-in; }
.matcher-thumb.is-clickable:hover { border-color: var(--brand-light); }

.thumb-ext {
    position: absolute;
    bottom: 4px;
    right: 4px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(20, 20, 20, 0.75);
    color: white;
    pointer-events: none;
    text-transform: uppercase;
}

/* Native thumbs get a brand-red badge so they stand apart from ref badges */
.native-row .thumb-ext {
    background: var(--brand);
}

/* Blow-up modal */
.blowup {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.blowup[hidden] { display: none; }
.blowup-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 10, 0.78);
}
.blowup-panel {
    position: relative;
    background: white;
    border-radius: var(--radius-lg);
    width: min(92vw, 1200px);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}
.blowup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.9rem;
}
.blowup-title { font-family: ui-monospace, Menlo, monospace; color: var(--gray-700); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blowup-close {
    background: transparent;
    border: 0;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--gray-500);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
}
.blowup-close:hover { color: var(--brand); background: var(--gray-100); }
.blowup-body {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    background: var(--gray-50);
}
.blowup-img { max-width: 100%; max-height: 80vh; height: auto; display: block; }
.blowup-pdf { width: 100%; height: 80vh; border: 0; background: white; }
.blowup-fallback { text-align: center; color: var(--gray-500); }

body.blowup-open { overflow: hidden; }

/* Given-preview: faithful <img>/<iframe> render (no inline SVG injection,
   so user-authored SVG text retains its authored styling). */
.given-preview {
    border: 1px solid var(--gray-200);
    background: white;
    padding: 12px;
    cursor: zoom-in;
    text-align: center;
}
.given-preview:hover { border-color: var(--brand-light); }
.given-preview img {
    max-width: 100%;
    max-height: 600px;
    height: auto;
    display: block;
    margin: 0 auto;
}
