* { box-sizing: border-box; margin: 0; padding: 0; }
/* Author display rules otherwise beat the UA style for the hidden attribute. */
[hidden] { display: none !important; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f7fa;
    color: #1a1a2e;
    line-height: 1.5;
}

/* Nav */
nav {
    background: #1a1a2e;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 24px;
    height: 52px;
    /* Stays put on long tables. Below .modal-overlay (1000) so dialogs still cover it. */
    position: sticky;
    top: 0;
    z-index: 500;
}
nav .brand {
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    text-decoration: none;
    margin-right: 16px;
}
nav a {
    color: #a0aec0;
    text-decoration: none;
    font-size: 14px;
    padding: 14px 0;
    border-bottom: 2px solid transparent;
}
nav a:hover, nav a.active {
    color: #fff;
    border-bottom-color: #667eea;
}
/* Marks where the admin-only links begin. */
nav .nav-admin-start {
    margin-left: 8px;
    padding-left: 24px;
    border-left: 1px solid rgba(255,255,255,.18);
}

/* Shared icon-button hit target: solid, visible target at rest on dark chrome */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 6px;
    color: #cbd5e0;
    font-family: inherit;
    font-size: 13px;
    line-height: 1;
    padding: 6px 8px;
    cursor: pointer;
}
.icon-btn:hover, .icon-btn:focus-visible {
    background: rgba(255,255,255,.18);
    color: #fff;
    outline: none;
}

/* Nav user badge + dropdown */
.nav-user { position: relative; }
.nav-user-btn {
    gap: 8px;
    padding: 4px 10px 4px 5px;
    border-radius: 999px;
    color: #fff;
}
.nav-user-avatar {
    flex: 0 0 auto;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: #2d3748;
    object-fit: cover;
}
.nav-user-name {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
}
.nav-user-caret { font-size: 10px; color: #a0aec0; }
.nav-user.open .nav-user-btn {
    background: rgba(255,255,255,.18);
    color: #fff;
}
.nav-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 240px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
    padding: 6px;
    z-index: 900;
}
.nav-user.open .nav-menu { display: block; }
.nav-menu-header {
    padding: 8px 10px 10px;
    margin-bottom: 6px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 12px;
    color: #718096;
    word-break: break-all;
}
.nav-menu-header b { color: #1a1a2e; font-weight: 600; }
.nav-menu-admin {
    display: inline-block;
    background: #fefcbf;
    color: #975a16;
    border-radius: 8px;
    padding: 1px 6px;
    font-size: 11px;
}
.nav-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: #f5f7fa;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #2d3748;
    font-family: inherit;
    font-size: 14px;
    text-align: left;
    padding: 8px 10px;
    cursor: pointer;
}
.nav-menu-item + .nav-menu-item { margin-top: 4px; }
.nav-menu-item:hover, .nav-menu-item:focus-visible {
    background: #e2e8f0;
    outline: none;
}
.nav-menu-icon { flex: 0 0 auto; width: 16px; height: 16px; color: #718096; }

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}
h1 {
    font-size: 22px;
    margin-bottom: 16px;
    color: #1a1a2e;
}
h2 {
    font-size: 17px;
    margin: 24px 0 12px;
    color: #2d3748;
}

/* Cards */
.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 20px;
    margin-bottom: 20px;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th, td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid #e2e8f0;
}
th {
    background: #f7fafc;
    font-weight: 600;
    color: #4a5568;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
tr:hover { background: #f7fafc; }
td a { color: #667eea; text-decoration: none; }
td a:hover { text-decoration: underline; }
tr.hide-search, tr.hide-file { display: none; }

/* Per-mouse report tables run to a dozen-plus columns. The free-text columns give up
   long tokens so the table shrinks to its card instead of overhanging it, while the
   narrow numeric columns stay on one line. */
.mice-table th, .mice-table td { padding: 8px; }
.mice-table .nowrap { white-space: nowrap; }
.mice-table .wrap { overflow-wrap: anywhere; min-width: 90px; }

/* Search box above a table */
.table-search {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.table-search input {
    width: 260px;
    padding: 7px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 13px;
}
.table-search input:focus {
    outline: none;
    border-color: #667eea;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}
.btn-primary {
    background: #667eea;
    color: #fff;
}
.btn-primary:hover { background: #5a67d8; }
.btn-primary:disabled {
    background: #a0aec0;
    cursor: not-allowed;
}
.btn-secondary {
    background: #e2e8f0;
    color: #2d3748;
}
.btn-secondary:hover { background: #cbd5e0; }
.btn-danger {
    background: #e53e3e;
    color: #fff;
}
.btn-danger:hover { background: #c53030; }

/* Forms */
input[type="file"],
select,
input[type="number"],
input[type="date"] {
    padding: 8px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
}
select { min-width: 180px; }
label {
    font-size: 13px;
    font-weight: 600;
    color: #4a5568;
    display: block;
    margin-bottom: 4px;
}
.form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.form-group { display: flex; flex-direction: column; }

/* Upload page */
.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.preview-stat {
    background: #f7fafc;
    border-radius: 6px;
    padding: 12px 16px;
}
.preview-stat .label {
    font-size: 11px;
    text-transform: uppercase;
    color: #718096;
    letter-spacing: 0.5px;
}
.preview-stat .value {
    font-size: 20px;
    font-weight: 700;
    color: #1a1a2e;
    overflow-wrap: anywhere;
}
/* The upload preview lists field values to check before importing, so they read as
   body text rather than the dashboard numbers the study pages show. */
#preview-grid .value {
    font-size: 13px;
    font-weight: 400;
    line-height: 1.7;
}

.notice {
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 12px;
    font-size: 13px;
    border-left: 4px solid;
}
.notice-warn {
    background: #fffaf0;
    border-color: #dd6b20;
    color: #7b341e;
}
.notice ul {
    margin: 8px 0 0;
    padding-left: 20px;
    max-height: 260px;
    overflow-y: auto;
}
.notice li { margin-bottom: 2px; }

.pick {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.pick input { cursor: pointer; }
.recent-uploads ul {
    margin: 0;
    padding-left: 20px;
    font-size: 13px;
}
.recent-uploads li { margin-bottom: 4px; }
.recent-uploads .text-muted { font-size: 12px; }

.pick-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-top: 8px;
    padding: 4px 0;
}
.pick-row {
    display: flex;
    width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
}
.pick-row:hover { background: #f7fafc; }
.pick-row .text-muted { display: block; font-size: 12px; }

/* Pagination */
.pagination {
    display: flex;
    gap: 4px;
    margin-top: 12px;
    align-items: center;
    font-size: 13px;
}
.pagination button {
    padding: 4px 10px;
    border: 1px solid #cbd5e0;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
.pagination button:hover { background: #f7fafc; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .current { font-weight: 600; color: #667eea; }

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 16px;
}
/* Rendered as a <button> on /reports and as an <a> on the study detail pages, so the
   anchor defaults (underline, link colour, inline layout) have to be neutralised. */
.tab-btn {
    padding: 10px 20px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: #718096;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    text-decoration: none;
    white-space: nowrap;
    line-height: normal;
}
.tab-btn:hover { color: #2d3748; }
.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Title + tabs pinned under the nav (52px) so tab switching stays reachable on long
   reports. Negative margins let the background span the container's 24px padding,
   otherwise scrolled content shows through at the edges. */
.sticky-page-header {
    position: sticky;
    top: 52px;
    z-index: 400;
    background: #f5f7fa;
    margin: -24px -24px 0;
    padding: 24px 24px 16px;
}
.sticky-page-header .tabs { margin-bottom: 0; }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.visible { display: flex; }
.modal {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
.modal h3 {
    font-size: 17px;
    margin-bottom: 8px;
}
.modal-narrow { max-width: 320px; }
.modal p, .modal-message {
    font-size: 14px;
    color: #4a5568;
    margin-bottom: 16px;
}
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.modal-input {
    width: 100%;
    padding: 8px 10px;
    margin-top: 6px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
}

/* About panel (modal body content) */
.about {
    padding: 8px 4px 0;
    line-height: 1.5;
    text-align: center;
    color: #1a1a2e;
}
.about-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    margin: 0 auto 22px;
    display: block;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.about-name { font-weight: 800; font-size: 20px; line-height: 1.25; }
.about-tagline { font-size: 13px; color: #555; }
.about-dedication { margin-top: 22px; font-size: 13px; }
/* Force text (not emoji) rendering so the color rule wins. */
.about-dedication .heart {
    color: #d42020;
    font-family: "Segoe UI Symbol", "Apple Symbols", sans-serif;
}
.about-legal {
    margin-top: 30px;
    font-size: 12px;
    color: #666;
}
.about-legal a { color: #1a6fc4; text-decoration: underline; }

/* Status badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.badge-alive { background: #c6f6d5; color: #22543d; }
.badge-dead { background: #fed7d7; color: #9b2c2c; }
.badge-treatment { background: #bee3f8; color: #2a4365; }
.badge-control { background: #fefcbf; color: #744210; }
.badge-import-new { background: #c6f6d5; color: #22543d; }
.badge-import-merge { background: #bee3f8; color: #2a4365; }
.badge-delete-all { background: #fed7d7; color: #9b2c2c; }
.badge-restore { background: #e9d8fd; color: #44337a; }
.badge-auto { background: #e2e8f0; color: #2d3748; }
.badge-manual { background: #bee3f8; color: #2a4365; }
.badge-pre-restore { background: #fefcbf; color: #744210; }

.backup-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    white-space: nowrap;
}
.backup-comment { max-width: 280px; }

/* Data log: expandable rows */
.log-row { cursor: pointer; }
.log-row > td { vertical-align: middle; }
.log-toggle-cell { width: 1%; padding-right: 0; }

/* Solid hit target at rest — see .icon-btn, but on light chrome. */
.log-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #edf2f7;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    color: #4a5568;
    font-size: 10px;
    line-height: 1;
    cursor: pointer;
}
.log-toggle:hover, .log-toggle:focus-visible {
    background: #e2e8f0;
    color: #1a1a2e;
    outline: none;
}
.log-toggle span { display: block; transition: transform 0.15s; }
.log-row.open .log-toggle span { transform: rotate(90deg); }

.log-detail-row { display: none; }
.log-detail-row.open { display: table-row; }
.log-detail-row > td {
    background: #f7fafc;
    padding: 14px 16px 16px 44px;
}
.log-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px 24px;
    margin: 0;
}
.log-details dt {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #718096;
}
.log-details dd {
    font-size: 13px;
    color: #1a1a2e;
    word-break: break-word;
}

/* Collapsible section above a report. */
.report-filter {
    margin-bottom: 8px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 8px 12px;
}
.report-filter > summary {
    cursor: pointer;
    font-weight: 600;
    color: #4a5568;
}

/* Progressive filter set: one row, one column per filter, one value per row inside */
.filter-set {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
    overflow-x: auto;
}
.filter-col {
    flex: 0 0 auto;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px 10px;
}
.filter-col > summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    color: #4a5568;
    display: flex;
    align-items: center;
    gap: 6px;
}
.filter-col > summary::-webkit-details-marker { display: none; }
.filter-col > summary::marker { content: ''; }
.filter-col-label { flex: 1; }
.filter-col-count {
    font-weight: 400;
    font-size: 12px;
    color: #718096;
    white-space: nowrap;
}
.filter-grip {
    cursor: grab;
    color: #718096;
    background: #edf2f7;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    padding: 0 4px;
    line-height: 1.4;
}
.filter-col.dragging { opacity: .5; }
.filter-col.drag-over {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, .25);
}
.filter-col-body {
    margin-top: 6px;
    max-height: 260px;
    overflow-y: auto;
    /* The scrollbar sits inside the intrinsic width, so reserve room for it. */
    padding-right: 4px;
}
.filter-col-body .filter-toggle-all {
    padding: 3px 8px;
    font-size: 12px;
    margin-bottom: 4px;
}
.filter-opt {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    font-size: 13px;
    cursor: pointer;
}

/* Chart */
.chart-container {
    width: 100%;
    height: 350px;
    margin: 12px 0;
    position: relative;
}
.chart-tooltip {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    transition: opacity .08s;
    background: #1a1a2e;
    color: #fff;
    font-size: 12px;
    line-height: 1.5;
    padding: 7px 10px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    white-space: nowrap;
    z-index: 10;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .name {
    font-weight: 700;
    margin-bottom: 2px;
}
.chart-tooltip .swatch {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 2px;
    margin-right: 6px;
}
.chart-tooltip .muted { color: #a0aec0; }
.chart-focus { pointer-events: none; }

/* Loading */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #e2e8f0;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.text-muted { color: #718096; font-size: 13px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: #a0aec0;
}

/* Box file browser (upload page modal) */
.box-crumbs {
    font-size: 13px;
    color: #718096;
    margin-bottom: 10px;
    word-break: break-word;
}
.box-crumbs a { color: #4a5568; text-decoration: none; }
.box-crumbs a:hover { text-decoration: underline; }
.box-list {
    max-height: 340px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}
.box-row { border-bottom: 1px solid #edf2f7; }
.box-row:last-child { border-bottom: none; }
.box-row a {
    display: block;
    padding: 9px 12px;
    color: #2d3748;
    text-decoration: none;
}
.box-row a:hover { background: #f7fafc; }
.box-row-muted { padding: 9px 12px; color: #a0aec0; }
.box-auth-mode {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}
.box-auth-mode label {
    margin: 0;
    font-weight: 600;
}
.box-auth-mode select { min-width: 0; }

/* Upload: the three ways of finding workbooks, and the table they all feed. */
.source-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.source-header h2 { margin: 0; }
.source-header .box-auth-mode { margin-top: 0; }

.source-columns {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    margin-top: 16px;
    border-top: 1px solid #e2e8f0;
}
.source-col {
    padding: 16px 18px;
    border-right: 1px solid #e2e8f0;
}
.source-col:last-child { border-right: none; }
.source-col h3 {
    font-size: 14px;
    font-weight: 700;
    color: #2d3748;
    margin: 0 0 4px;
}
.source-hint {
    font-size: 12px;
    color: #718096;
    margin: 0 0 12px;
    min-height: 32px;
}
.source-col input[type="file"] { max-width: 100%; font-size: 13px; }
/* Dimmed rather than hidden, so it stays obvious that Box is a way in. */
.source-col-off { opacity: .5; }

.source-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-top: 1px solid #e2e8f0;
    padding-top: 12px;
    font-size: 13px;
}

@media (max-width: 760px) {
    .source-columns { grid-template-columns: 1fr; }
    .source-col {
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }
    .source-col:last-child { border-bottom: none; }
    .source-hint { min-height: 0; }
}

.table-scroll { overflow-x: auto; }

.file-table { width: 100%; }
.file-table .col-pick { width: 34px; text-align: center; }
.file-table td { vertical-align: middle; }
.file-table select {
    width: 100%;
    min-width: 120px;
    padding: 4px 6px;
    font-size: 13px;
}
.file-row-error td { color: #7b341e; background: #fffaf0; }

.change-tag {
    display: inline-block;
    border-radius: 10px;
    padding: 2px 9px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.change-new { background: #c6f6d5; color: #22543d; }
.change-update { background: #feebc8; color: #7b341e; }
.change-unchanged { background: #edf2f7; color: #4a5568; }

.file-table-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}

.notice-info {
    background: #ebf8ff;
    border-color: #3182ce;
    color: #2a4365;
}

/* Load results reuse the file table, so the dialog needs room for four columns. */
.modal-wide { max-width: 760px; }
.result-ok { background: #c6f6d5; color: #22543d; }
.result-fail { background: #fed7d7; color: #742a2a; }

/* Box file rows behave like a file list: click to choose, Ctrl/Shift to extend. */
.box-file {
    padding: 9px 12px;
    color: #2d3748;
    cursor: pointer;
    user-select: none;
}
.box-file:hover { background: #f7fafc; }
.box-file.selected { background: #ebf4ff; color: #2b4c7e; font-weight: 600; }
.box-hint { font-size: 12px; margin: 8px 0 0; }

/* A filter whose values are all identical: shown, but greyed and not expandable. */
.filter-col-locked {
    background: #edf2f7;
    border-style: dashed;
    opacity: .75;
}
.filter-col-locked > summary { cursor: default; }
.filter-col-locked .filter-col-count { font-style: italic; }
