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

:root {
    --bg: #fafafa;
    --surface: #fff;
    --text: #1a1a1a;
    --text-muted: #666;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --border: #e5e7eb;
    --error-bg: #fef2f2;
    --error-border: #fca5a5;
    --warn-bg: #fffbeb;
    --warn-border: #fcd34d;
    --warn-text: #92400e;
    --radius: 8px;
    --max-width: 1100px;
}

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

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Header */
header {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

nav {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
}

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

.logo:hover {
    text-decoration: none;
    color: var(--accent);
}

/* Main */
main {
    flex: 1;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
    width: 100%;
}

/* Footer */
footer {
    border-top: 1px solid var(--border);
    text-align: center;
    padding: 1rem 1.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Hero / home */
.hero {
    text-align: center;
    padding: 4rem 0 2rem;
}

.hero h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    max-width: 540px;
    margin: 0 auto 2rem;
}

.lookup-form {
    display: flex;
    gap: 0.5rem;
    max-width: 420px;
    margin: 0 auto 1.5rem;
}

.lookup-form input {
    flex: 1;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    outline: none;
}

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

.lookup-form button {
    padding: 0.6rem 1.5rem;
    min-height: 44px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
    font-weight: 500;
}

.lookup-form button:hover {
    background: var(--accent-hover);
}

.examples {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.examples a {
    margin: 0 0.25rem;
}

/* Protein view */
.protein-header {
    margin-bottom: 1.5rem;
}

.protein-header h1 {
    font-size: 1.5rem;
    display: inline;
    margin-right: 0.5rem;
}

.gene-tag {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    vertical-align: middle;
}

.description {
    color: var(--text-muted);
    margin-top: 0.25rem;
}

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

/* Stats */
.data-summary {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1.25rem;
    text-align: center;
    flex: 1;
    min-width: 100px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Warnings */
.warnings {
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    color: var(--warn-text);
    font-size: 0.9rem;
}

.warnings p + p {
    margin-top: 0.25rem;
}

/* B-4 / U-2: UniProt annotations unavailable banner.
   Higher severity than .warnings (red error palette, left bar, icon, bold)
   because it signals a real data-integrity gap — TM helix and signal peptide
   safety checks were silently skipped. Visible above the construct cards. */
.annotations-unavailable-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-left: 4px solid #b91c1c;
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin-bottom: 1.5rem;
    color: #7f1d1d;
    font-size: 0.95rem;
    font-weight: 500;
}

.annotations-unavailable-banner p {
    margin: 0;
}

.annotations-unavailable-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    background: #b91c1c;
    color: #fff;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1;
}

/* U-5: Membrane mode no-excision explanation banner. This is informational,
   not a risk warning — membrane mode is working correctly, the construct
   list is just identical to soluble mode because no construct overlapped
   the TM. Blue palette (matches --accent) deliberately distinguishes it
   from the red annotations-unavailable banner and the yellow .warnings
   block, so a scientist sees at a glance "this is a status note, not a
   safety warning." Sits directly above the construct cards. */
.membrane-no-excision-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin-bottom: 1.5rem;
    color: #1e3a8a;
    font-size: 0.95rem;
}

.membrane-no-excision-banner p {
    margin: 0;
}

.membrane-no-excision-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.85rem;
    font-style: italic;
    line-height: 1;
}

/* B-4 / U-2 follow-up: per-row annotation status badge in the batch table.
   "Unavailable" matches the page banner's red palette so a row with a fetch
   failure is unmistakable when scanning. "OK" is muted green so the success
   path doesn't drown out the surrounding score/flag visuals. */
.annotation-status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.annotation-status-ok {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.annotation-status-unavailable {
    background: var(--error-bg);
    color: #7f1d1d;
    border: 1px solid #b91c1c;
}

/* Visualization grid — two columns */
.viz-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* Panels */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.panel > h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.panel-caption {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Panel title row with action button */
.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.panel-title-row h3 {
    margin-bottom: 0;
}

/* Mol* viewer — compact by default, expandable.
   pdbe-molstar ignores overflow:hidden on its parent, so we constrain
   by setting explicit height on a position:relative sizer div that the
   component fills via absolute positioning. */
#molstar-wrapper {
    width: 100%;
}

#molstar-sizer {
    position: relative;
    width: 100%;
    height: 520px;
    transition: height 0.2s ease;
}

#molstar-sizer pdbe-molstar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#molstar-sizer.viewer-collapsed {
    height: 260px;
}

/* Viewer fallback mode — drop the fixed 520px sizer height so the
   .chart-fallback message sits at its natural size instead of floating in
   a tall empty box. See U-7 in QA thread-5. */
#molstar-sizer.viewer-fallback-mode {
    position: static;
    height: auto;
}

/* pLDDT chart */
.plot-panel #plddt-chart {
    width: 100%;
    height: 480px;
}

/* Chart fallback (shown when Plotly fails to load — see B-3 / U-6) */
.chart-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 120px;
    padding: 1.25rem 1rem;
    border: 1px dashed var(--border, #d1d5db);
    border-radius: 6px;
    background: #fafafa;
    color: var(--text-muted, #6b7280);
    font-size: 0.9rem;
    font-style: italic;
    text-align: center;
    line-height: 1.4;
}

/* Construct suggestions */
.constructs-section {
    margin-bottom: 2rem;
}

.constructs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.constructs-header h2 {
    font-size: 1.25rem;
}

.construct-cards {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.construct-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}

.construct-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.construct-label {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #fff;
}

.label-core_domain { background: #2563eb; }
.label-core_extended { background: #7c3aed; }
.label-domain_split { background: #059669; }
.label-combined { background: #d97706; }
.label-tm_excised { background: #dc2626; }
.label-ectodomain { background: #2563eb; }
.label-intracellular { background: #7c3aed; }

.construct-label[data-tip] {
    cursor: help;
    position: relative;
}

.construct-label[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 6px;
    background: #1e293b;
    color: #f1f5f9;
    font-size: 0.78rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    line-height: 1.4;
    padding: 0.5rem 0.65rem;
    border-radius: 6px;
    width: 240px;
    white-space: normal;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 10;
}

.construct-label[data-tip]:hover::after {
    opacity: 1;
}

.construct-range {
    font-weight: 600;
    font-size: 0.95rem;
}

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

.construct-stats {
    margin-bottom: 0.5rem;
}

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

.construct-explanation {
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.5;
    margin-bottom: 0.75rem;
}

.construct-actions {
    display: flex;
    gap: 0.5rem;
}

.no-constructs {
    color: var(--text-muted);
    font-style: italic;
}

/* PAE heatmap section */
.pae-section {
    margin-bottom: 2rem;
}

.pae-section .panel-title-row h2 {
    margin-bottom: 0;
    font-size: 1.25rem;
}

.pae-explainer {
    margin-bottom: 0.75rem;
    max-width: 72ch;
}

#pae-chart {
    width: 100%;
    /* Height is set by Plotly; give it a sensible minimum */
    min-height: 400px;
}

#pae-wrapper.pae-collapsed {
    display: none;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
}

.btn:hover {
    background: var(--bg);
    text-decoration: none;
}

.btn-secondary {
    background: var(--surface);
    color: var(--accent);
    border-color: var(--accent);
}

.btn-secondary:hover {
    background: rgba(37, 99, 235, 0.05);
}

.btn-small {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}

/* Error */
.error-card {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
}

.error-card h2 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.error-card p {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* Batch section — home page */
.batch-section {
    text-align: center;
    padding: 2rem 0;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

.batch-section h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.batch-form {
    max-width: 600px;
    margin: 1.5rem auto 0;
    text-align: left;
}

.batch-input-group {
    margin-bottom: 1rem;
}

.batch-input-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.batch-input-group textarea {
    width: 100%;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: monospace;
    font-size: 0.9rem;
    resize: vertical;
    outline: none;
}

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

.batch-input-group input[type="file"] {
    font-size: 0.9rem;
}

.batch-divider {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 1rem 0;
    position: relative;
}

.batch-divider span {
    background: var(--bg);
    padding: 0 0.75rem;
    position: relative;
    z-index: 1;
}

.batch-divider::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border);
}

.batch-submit {
    display: block;
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    margin-top: 1rem;
}

.batch-limit {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

.text-muted {
    color: var(--text-muted);
    font-weight: 400;
}

/* Batch results page */
.batch-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.batch-header h1 {
    font-size: 1.5rem;
}

.batch-actions {
    display: flex;
    gap: 0.5rem;
}

.batch-summary {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.batch-errors {
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    color: var(--warn-text);
    font-size: 0.9rem;
}

.batch-errors summary {
    cursor: pointer;
    font-weight: 500;
}

.batch-errors ul {
    margin-top: 0.5rem;
    padding-left: 1.25rem;
}

.batch-errors li {
    margin-bottom: 0.25rem;
}

/* Batch legend */
.legend {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
}

.legend > summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-muted);
    user-select: none;
}

.legend > summary:hover {
    color: var(--accent);
}

.legend-body {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1.5rem;
    padding: 0 1rem 1rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}

.legend-section h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.legend-section p,
.legend-section ul {
    font-size: 0.85rem;
    color: var(--text);
    line-height: 1.5;
}

.legend-section ul {
    padding-left: 1.1rem;
}

.legend-section li {
    margin-bottom: 0.2rem;
}

.legend-badges {
    margin: 0.5rem 0;
    font-size: 0.85rem;
}

.legend-caveat {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

.legend-tags {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    margin-bottom: 0.4rem;
    line-height: 1.4;
}

@media (max-width: 768px) {
    .legend-body {
        grid-template-columns: 1fr;
    }
}

/* Batch results table */
.batch-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 0.9rem;
}

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

.batch-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    white-space: nowrap;
}

.batch-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.batch-table th.sortable:hover {
    color: var(--accent);
}

/* FIX-4 (a11y): the sortable <th> contains a real <button> for keyboard
   activation + AT semantics. The button itself should look like a header
   cell — no native border, padding, or background. Inherit color/font so
   the existing `th.sortable:hover` color change still applies via
   `color: inherit`. Focus is preserved (no `outline: none`) for keyboard
   users. */
.batch-table th.sortable .sort-button {
    appearance: none;
    background: none;
    border: 0;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    cursor: pointer;
    text-align: inherit;
}

.batch-table th.sortable .sort-button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.batch-table th.sorted-asc::after {
    content: " \25B2";
    font-size: 0.65rem;
}

.batch-table th.sorted-desc::after {
    content: " \25BC";
    font-size: 0.65rem;
}

.batch-table tbody tr:hover {
    background: rgba(37, 99, 235, 0.03);
}

.batch-table tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.015);
}

.batch-table tbody tr:nth-child(even):hover {
    background: rgba(37, 99, 235, 0.03);
}

/* Score badges */
.score-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 3rem;
    text-align: center;
}

.score-high {
    background: #d1fae5;
    color: #065f46;
}

.score-mid {
    background: #fef3c7;
    color: #92400e;
}

.score-low {
    background: #fee2e2;
    color: #991b1b;
}

/* Reason tags */
.reason-tag {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    margin: 0.1rem;
    white-space: nowrap;
}

.tag-high_confidence { background: #dbeafe; color: #1e40af; }
.tag-single_domain { background: #d1fae5; color: #065f46; }
.tag-multi_domain { background: #e0e7ff; color: #3730a3; }
.tag-mostly_disordered { background: #fee2e2; color: #991b1b; }
.tag-compact { background: #ede9fe; color: #5b21b6; }
.tag-weak_domain_packing { background: #fef3c7; color: #92400e; }
.tag-has_tm { background: #fee2e2; color: #991b1b; }
.tag-has_cc { background: #f3e8ff; color: #6b21a8; }

/* Annotation flags (TM, SP) in batch table */
.flag-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    margin-right: 3px;
}

.flag-tm {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.flag-sp {
    background: #ffedd5;
    color: #9a3412;
    border: 1px solid #fdba74;
}

.flag-cc {
    background: #f3e8ff;
    color: #6b21a8;
    border: 1px solid #d8b4fe;
}

.construct-length-small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 768px) {
    .viz-grid {
        grid-template-columns: 1fr;
    }

    .data-summary {
        flex-wrap: wrap;
    }

    .stat {
        min-width: 80px;
    }

    .constructs-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .batch-header {
        flex-direction: column;
    }

    .batch-table {
        font-size: 0.8rem;
        display: block;
        overflow-x: auto;
    }
}

/* === FR-5.1: Membrane mode toggle === */

.expression-context-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
}
.toggle-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.segmented-control {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.segmented-control input[type="radio"] {
    display: none;
}
.segmented-control label,
.seg-btn {
    padding: 0.35rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-right: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.segmented-control label:last-of-type,
.seg-btn:last-child {
    border-right: none;
}
.segmented-control input[type="radio"]:checked + label,
.seg-btn.seg-active {
    background: var(--accent);
    color: #fff;
}
.flag-badge.flag-tm-membrane {
    background: #dbeafe;
    color: #1e40af;
    border-color: #93c5fd;
}
.reason-tag.tag-has_tm_membrane {
    background: #dbeafe;
    color: #1e40af;
}
.mode-badge {
    font-size: 0.7em;
    font-weight: 400;
}
.mode-membrane {
    color: #1e40af;
}
.construct-label.label-membrane_construct {
    background: #dbeafe;
    color: #1e40af;
}
