* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: #f7f6f3;
    --panel: #ffffff;
    --panel-border: #e6e4df;
    --text: #1f2937;
    --muted: #6b7280;
    --accent: #2f6fed;
    --accent-weak: rgba(47, 111, 237, 0.18);
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    --h1: 1.75rem;
    --h2: 1.1rem;
    --body: 0.95rem;
    --small: 0.8rem;
    --micro: 0.7rem;
}
body {
    font-family: 'Work Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.55;
}
.container { max-width: 1900px; margin: 0 auto; padding: 22px; }
header {
    background: linear-gradient(135deg, #f4f1ec 0%, #e7edf4 100%);
    color: var(--text);
    padding: 26px 30px;
    border-radius: 14px;
    margin-bottom: 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--panel-border);
}
.header-content { position: relative; padding-left: 12px; }
.header-content:before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--accent);
    border-radius: 6px;
}
.header-content h1 { font-size: var(--h1); font-weight: 700; margin-bottom: 6px; letter-spacing: -0.01em; }
.header-content p { color: var(--muted); font-size: var(--body); }
.version-tag { background: rgba(47,111,237,0.12); color: var(--accent); padding: 6px 14px; border-radius: 16px; font-size: var(--small); font-weight: 600; }
.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
    margin-bottom: 22px;
}
.charts-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 14px;
}
.chart-card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 14px;
    box-shadow: var(--shadow);
}
.chart-title {
    font-size: var(--micro);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 8px;
}
.overlap-summary {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.overlap-title {
    font-size: var(--micro);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 8px;
}
.overlap-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: var(--small);
    color: #374151;
}
.overlap-link {
    border: 1px solid #cdd9fd;
    background: #f2f6ff;
    color: #1d4ed8;
    border-radius: 999px;
    font-size: var(--small);
    font-weight: 600;
    line-height: 1;
    padding: 7px 10px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.overlap-link:hover {
    background: #e4ecff;
    border-color: #b8cbff;
}
.overlap-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.24);
}
.stat-card {
    background: var(--panel);
    padding: 16px 18px;
    border-radius: 12px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--panel-border);
}
.stat-card.highlight { border-color: rgba(47,111,237,0.35); background: #f4f6ff; }
.stat-icon { font-size: 1.2rem; margin-bottom: 6px; }
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--accent); letter-spacing: -0.01em; }
.stat-label { color: var(--muted); font-size: var(--small); margin-top: 2px; }
.controls-panel {
    background: var(--panel);
    padding: 18px 20px;
    border-radius: 12px;
    margin-bottom: 22px;
    box-shadow: var(--shadow);
    border: 1px solid var(--panel-border);
}
.controls-row {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}
.search-wrapper { min-width: 0; }
.filter-group { display: flex; flex-direction: column; gap: 4px; position: relative; min-width: 0; }
.filter-group.filter-disabled .filter-label { color: #a3a3a3; }
.filter-group.filter-disabled select,
.filter-group.filter-disabled .filter-input {
    background: #f1f0eb;
    color: #9ca3af;
    border-color: #e1dfd8;
    cursor: not-allowed;
}
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-12 { grid-column: span 12; }
.actions-group { display: flex; justify-content: flex-end; gap: 10px; align-items: center; }
.filter-label { font-size: var(--micro); color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; }
.search-input, select, .filter-input {
    padding: 9px 12px;
    border: 1px solid #d4d2cc;
    border-radius: 8px;
    font-size: var(--body);
    background: var(--panel);
    color: var(--text);
    width: 100%;
}
.search-input:focus, select:focus, .filter-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.search-input { width: 100%; }
select { min-width: 120px; cursor: pointer; }
.btn {
    padding: 9px 16px;
    border: none;
    border-radius: 8px;
    font-size: var(--body);
    font-weight: 600;
    cursor: pointer;
}
.btn-secondary { background: #f1f0eb; color: #4b5563; border: 1px solid #d9d7d0; }
.btn-secondary:hover { background: #ebe9e4; }
.synergy-report-btn { background: var(--accent); color: white; }
.synergy-report-btn:hover { opacity: 0.9; }
.table-container {
    background: var(--panel);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--panel-border);
}
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
tbody tr[data-row="1"] { height: 48px; }
th[data-col="rsid"], td[data-col="rsid"] { width: 8%; }
th[data-col="chr"], td[data-col="chr"] { width: 5%; }
th[data-col="gene"], td[data-col="gene"] { width: 12%; }
th[data-col="disease"], td[data-col="disease"] { width: 16%; }
th[data-col="orrr"], td[data-col="orrr"] { width: 7%; }
th[data-col="pvalue"], td[data-col="pvalue"] { width: 8%; }
th[data-col="pathway"], td[data-col="pathway"] { width: 16%; }
th[data-col="shared"], td[data-col="shared"] { width: 6%; }
th[data-col="synergy"], td[data-col="synergy"] { width: 5%; }
th[data-col="actions"], td[data-col="actions"] { width: 7%; }
tbody tr:nth-child(even) { background: #fbfaf8; }
th {
    background: #f1f2f5;
    padding: 12px 12px;
    text-align: left;
    font-weight: 700;
    font-size: var(--micro);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--panel-border);
    cursor: pointer;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.02);
}
th:hover { background: #eceff4; }
th .sort-arrow { margin-left: 4px; opacity: 0.4; }
td { padding: 10px 12px; border-bottom: 1px solid #f0f1f6; font-size: var(--body); vertical-align: top; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td[data-col="gene"] {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    word-break: break-word;
}
tr:hover { background: #f3f6ff; }
tr.expanded { background: #f0f4ff; }
.rsid { font-family: 'Monaco', 'Menlo', monospace; color: #5b4ad6; font-weight: 600; cursor: pointer; }
.rsid:hover { text-decoration: underline; }
.gene { font-weight: 600; color: var(--text); }
.badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: var(--micro); font-weight: 700; letter-spacing: 0.2px; }
.badge-t1d { background: #fef3c7; color: #92400e; }
.badge-ra { background: #fee2e2; color: #991b1b; }
.badge-sle { background: #fce7f3; color: #9d174d; }
.badge-ms { background: #e0e7ff; color: #3730a3; }
.badge-ibd { background: #d1fae5; color: #065f46; }
.badge-crohn { background: #d1fae5; color: #065f46; }
.badge-uc { background: #d1fae5; color: #065f46; }
.badge-psoriasis { background: #f3e8ff; color: #6b21a8; }
.badge-celiac { background: #ffedd5; color: #9a3412; }
.badge-graves { background: #d1fae5; color: #047857; }
.badge-hashimoto { background: #dbeafe; color: #1e40af; }
.badge-vitiligo { background: #f3f4f6; color: #374151; }
.badge-as { background: #e0e7ff; color: #3730a3; }
.badge-pbc { background: #fff7ed; color: #9a3412; }
.badge-sjogren { background: #e2e8f0; color: #0f172a; }
.pathway-tag { background: #e5ecff; color: #2b4db8; padding: 3px 8px; border-radius: 999px; font-size: var(--micro); font-weight: 600; }
.synergy-genes { display: flex; flex-wrap: wrap; gap: 4px; }
.synergy-tag { background: #f3f4f6; color: #374151; padding: 2px 6px; border-radius: 4px; font-size: 0.7rem; }
.synergy-pill {
    background: #eef2ff;
    color: #2f6fed;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: var(--micro);
    font-weight: 700;
    position: relative;
}
.synergy-pill[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(100% + 8px);
    background: #111827;
    color: #f9fafb;
    font-size: 0.7rem;
    padding: 6px 8px;
    border-radius: 6px;
    white-space: nowrap;
    z-index: 50;
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}
.synergy-pill[data-tooltip]:hover::before {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(100% + 2px);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #111827;
    z-index: 51;
}
.or-value { font-weight: 700; padding: 2px 6px; border-radius: 6px; font-size: 0.85rem; }
.or-high { background: #fee2e2; color: #dc2626; }
.or-medium { background: #fef3c7; color: #d97706; }
.or-low { background: #d1fae5; color: #059669; }
.or-protective { background: #dbeafe; color: #2563eb; }
.pvalue { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; color: var(--muted); }
.hla-badge { background: #fde7ef; color: #be185d; padding: 2px 6px; border-radius: 6px; font-size: var(--micro); margin-left: 4px; font-weight: 700; }
.details-btn { background: #eef2ff; color: #2f6fed; border: 1px solid #dbe3ff; padding: 5px 10px; border-radius: 6px; font-size: var(--small); cursor: pointer; }
.details-btn:hover { background: #e1e9ff; }
.details-row { display: none; }
.details-row.visible { display: table-row; }
.details-cell { padding: 0 !important; background: #f8f9ff; }
.details-panel { padding: 16px 20px; }
.details-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.details-section { background: white; border-radius: 8px; padding: 14px; border: 1px solid #e8ecf1; }
.details-section h4 { color: #667eea; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; }
.detail-item { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #f3f4f6; font-size: 0.8rem; }
.detail-item:last-child { border-bottom: none; }
.detail-label { font-weight: 600; color: #6b7280; }
.detail-value { color: #1f2937; text-align: right; }
.database-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.db-link { font-size: 0.75rem; color: #4f46e5; background: #eef2ff; padding: 4px 8px; border-radius: 5px; text-decoration: none; }
.db-link:hover { background: #e0e7ff; }
.side-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 90;
}
.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 420px;
    background: var(--panel);
    border-left: 1px solid var(--panel-border);
    box-shadow: -10px 0 30px rgba(15, 23, 42, 0.08);
    z-index: 100;
    display: flex;
    flex-direction: column;
}
.side-panel-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f5f4f1;
}
.side-panel-title { font-weight: 700; color: var(--text); font-size: 0.95rem; }
.side-panel-close {
    background: #f1f0eb;
    border: 1px solid #d9d7d0;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: var(--small);
}
.side-panel-content { padding: 14px 16px; overflow: auto; }
.panel-section { margin-bottom: 14px; }
.panel-section h4 { color: var(--muted); font-size: var(--micro); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 8px; font-weight: 700; }
.panel-item { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid #f3f4f6; font-size: 0.8rem; }
.panel-item:last-child { border-bottom: none; }
.panel-item-long { flex-direction: column; align-items: flex-start; gap: 4px; }
.panel-item-long .panel-value { text-align: left; font-weight: 400; font-size: 0.75rem; color: #374151; word-break: break-word; }
.panel-label { color: var(--muted); font-weight: 700; }
.panel-value { color: var(--text); text-align: right; }
.panel-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.panel-link { font-size: var(--micro); color: var(--accent); background: #eef2ff; padding: 4px 8px; border-radius: 6px; text-decoration: none; font-weight: 600; }
.panel-link:hover { background: #e1e9ff; }
.panel-empty { color: var(--muted); font-size: var(--small); }
.shared-badge {
    background: #e3eaff;
    color: #1d4ed8;
    padding: 3px 6px;
    border-radius: 6px;
    font-size: var(--micro);
    font-weight: 700;
}
.pagination { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid #e8ecf1; background: #f9fafb; }
.pagination button { padding: 5px 10px; border: 1px solid #d1d5db; background: white; border-radius: 4px; cursor: pointer; font-size: 0.8rem; }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
.page-info { font-size: 0.8rem; color: #6b7280; }

.error-panel {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 12px;
    font-size: 0.85rem;
}
.hidden { display: none; }

.input-invalid {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15) !important;
}
.input-help {
    font-size: 0.7rem;
    color: #dc2626;
}

.columns-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 10px;
    z-index: 50;
    min-width: 180px;
}
.columns-menu label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--small);
    color: #374151;
    padding: 4px 2px;
}

.col-hidden { display: none !important; }

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #e5e1d9;
    transition: 0.2s;
    border-radius: 999px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.2s;
    border-radius: 50%;
}
.switch input:checked + .slider { background-color: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(20px); }

@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
    .details-grid { grid-template-columns: 1fr; }
    .controls-row { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
    header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .controls-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .side-panel { width: 100%; }
}
