/* ==========================================================================
   Atlas components: page head, tool strip, and the atlas entry
   (spectrum-led compound entry). Shared by any list of compounds/fragments.
   ========================================================================== */

/* --- Page head ----------------------------------------------------------- */
.page-head {
    display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
    padding-bottom: 14px;
}
.page-head h1 { font-size: 26px; font-weight: 700; font-stretch: 92%; letter-spacing: -0.02em; }
.page-meta { color: var(--ink-3); font-size: 14px; }
.page-head .page-actions { margin-left: auto; display: flex; gap: 8px; }

/* --- Tool strip: search + compare tray, sticks under the app bar --------- */
.toolstrip {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    padding: 10px 0;
    background: var(--page);
    border-top: 1px solid var(--rule-strong);
    border-bottom: 1px solid var(--rule);
    margin-bottom: 16px;
}
.search-field {
    position: relative; display: flex; align-items: center;
    flex: 1 1 280px; max-width: 420px;
}
.search-field svg {
    position: absolute; left: 10px; width: 15px; height: 15px;
    color: var(--ink-3); pointer-events: none;
}
.search-field input {
    width: 100%; min-height: 34px; padding: 6px 10px 6px 32px;
    border: 1px solid var(--rule); border-radius: var(--radius);
    background: var(--paper); color: var(--ink); font: inherit; font-size: 14px;
}
.search-field input:hover { border-color: var(--ink-3); }
.search-field input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.search-status { font-size: 13px; color: var(--ink-3); min-width: 72px; }
.search-status .htmx-indicator { display: none; }
.htmx-request .search-status .htmx-indicator, .search-status .htmx-indicator.htmx-request { display: inline; }

.compare-tray { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.compare-tray .tray-count { color: var(--ink-2); white-space: nowrap; }
.compare-tray .tray-count strong { color: var(--ink); font-weight: 700; }
.compare-tray .tray-hint { color: var(--ink-3); font-size: 13px; }

/* --- The atlas: ruled grid of entries ----------------------------------- */
.atlas {
    display: grid;
    grid-template-columns: minmax(0, 1fr);             /* 1 column under 760px */
    gap: 1px;
    background: var(--rule);          /* the gap reads as a shared 1px rule */
    border: 1px solid var(--rule);
}
.atlas-empty, .atlas > p {
    grid-column: 1 / -1; background: var(--paper);
    padding: 28px 22px; color: var(--ink-2);
}

.atlas-entry {
    container-type: inline-size;
    display: flex; flex-direction: column;
    background: var(--paper);
    min-width: 0;
    transition: background-color 120ms ease-out;
}
.atlas-entry.htmx-swapping { opacity: 0; transition: opacity 200ms ease-out; }

/* Header strip: number · name · formula */
.atlas-head {
    display: flex; align-items: baseline; gap: 10px;
    padding: 10px 14px 8px;
    border-bottom: 1px solid var(--rule);
}
.atlas-no {
    flex-shrink: 0;
    min-width: 2.2em; padding: 1px 5px;
    border: 1px solid var(--ink); border-radius: var(--radius);
    font-weight: 750; font-size: 13px; text-align: center; line-height: 1.35;
    font-variant-numeric: tabular-nums;
    transition: background-color 120ms ease-out, color 120ms ease-out;
}
.atlas-name { font-size: 16px; font-weight: 680; letter-spacing: -0.01em; min-width: 0; overflow-wrap: anywhere; }
.atlas-name a { text-decoration: none; }
.atlas-name a:hover { text-decoration: underline; }
.atlas-formula { margin-left: auto; font-family: var(--font-data); font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.formula sub { font-size: 0.72em; line-height: 0; }
.formula sup { font-size: 0.9em; line-height: 0; font-weight: 700; }
.formula sub { vertical-align: -0.25em; }
.formula sup { vertical-align: 0.45em; margin-left: 0.05em; }

/* Body: spectrum leads, structure inset explains it */
.atlas-body {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
    align-items: stretch;
    flex: 1;
}
.atlas-spectrum { padding: 10px 6px 4px 12px; min-width: 0; }
.atlas-spectrum-svg { display: block; width: 100%; height: auto; overflow: visible; }
.atlas-spectrum-svg .ax { stroke: var(--ink); stroke-width: 1; }
.atlas-spectrum-svg .tk { stroke: var(--ink); stroke-width: 1; }
.atlas-spectrum-svg .tk-label { fill: var(--ink-3); font-family: var(--font-data); font-size: 9.5px; }
.atlas-spectrum-svg .ax-unit { fill: var(--ink-2); font-family: var(--font-data); font-size: 9.5px; font-style: italic; }
.atlas-spectrum-svg .st { stroke: var(--ink); stroke-width: 1.4; shape-rendering: crispEdges; }
.atlas-spectrum-svg .st.bp { stroke: var(--accent); stroke-width: 2; }
.atlas-spectrum-svg .pk-label { fill: var(--ink-2); font-family: var(--font-data); font-size: 10px; }
.atlas-spectrum-svg .pk-label.bp { fill: var(--accent); font-weight: 700; }
.atlas-spectrum-svg .pc { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 1.5 2.5; }
.atlas-spectrum-svg .hit { stroke: transparent; stroke-width: 8; cursor: crosshair; }
.atlas-spectrum-svg .hit:hover { stroke: var(--accent-soft); }
/* The stick being read: heavier ink. Red stays reserved for the base peak. */
.atlas-spectrum-svg .st.is-active { stroke: var(--ink); stroke-width: 3; }
.atlas-spectrum-svg .st.bp.is-active { stroke: var(--accent); stroke-width: 3; }
.atlas-spectrum { border-radius: var(--radius); }
.atlas-spectrum:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.atlas-nodata { padding: 24px 0; color: var(--ink-3); font-size: 13px; }

.atlas-plate {
    display: flex; align-items: center; justify-content: center;
    border-left: 1px solid var(--rule);
    padding: 8px; min-height: 150px;
    color: var(--ink-3); font-size: 13px;
}
.atlas-plate img { display: block; max-width: 100%; max-height: 150px; }

/* Footer pad: data, live readout, actions */
.atlas-pad {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    padding: 8px 14px 10px;
    border-top: 1px solid var(--rule);
    font-size: 13px;
}
.atlas-data { display: flex; gap: 16px; flex-wrap: wrap; }
.atlas-data div { display: flex; flex-direction: column; }
.atlas-data dt { color: var(--ink-3); font-size: 11.5px; }
.atlas-data dd { font-family: var(--font-data); font-size: 13px; color: var(--ink); }
.atlas-data dd.bp { color: var(--accent); font-weight: 700; }
.atlas-readout {
    font-family: var(--font-data); font-size: 12.5px; color: var(--accent);
    min-width: 11ch;
}
/* In an atlas entry the reading is a fixed-height line under the drawing: it covers no
   label (the base peak's sits top left) and the entry never resizes while reading */
.atlas-entry .atlas-readout {
    display: block; height: 18px; margin-top: 2px; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
/* Resting text says how to read a peak (the hint the aria-label gives screen readers) */
.atlas-entry .atlas-readout:empty::before {
    content: "Point at a peak, or focus and use \2190 \2192"; color: var(--ink-3); font-family: var(--font-ui); font-size: 12px;
}
.atlas-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* Compare selection: a named, marked state (never colour alone) */
.atlas-select {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 28px; padding: 0 10px 0 8px;
    border: 1px solid var(--rule); border-radius: var(--radius);
    cursor: pointer; font-size: 13px; font-weight: 560; color: var(--ink-2);
    user-select: none;
}
.atlas-select:hover { border-color: var(--ink-3); color: var(--ink); }
.atlas-select input { width: 14px; height: 14px; margin: 0; }
.atlas-select .on { display: none; }
.atlas-select:has(input:checked) { border-color: var(--ink); color: var(--ink); }
.atlas-select:has(input:checked) .on { display: inline; }
.atlas-select:has(input:checked) .off { display: none; }
.atlas-select:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.atlas-entry:has(.compare-checkbox:checked) { background: var(--inset); }
.atlas-entry:has(.compare-checkbox:checked) .atlas-no { background: var(--ink); color: var(--on-ink); }
/* The compound number as a quiet label: the library is in name order, so it isn't an index */
.atlas-no-quiet {
    flex-shrink: 0; font-family: var(--font-data); font-size: 12px; color: var(--ink-3);
    font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* Narrow entries: structure above spectrum */
@container (max-width: 420px) {
    .atlas-body { grid-template-columns: 1fr; }
    .atlas-plate { border-left: 0; border-top: 1px solid var(--rule); min-height: 120px; }
    .atlas-plate img { max-height: 120px; }
    .atlas-formula { margin-left: 0; flex-basis: 100%; }
    .atlas-head { flex-wrap: wrap; }
}

@media (min-width: 760px)  { .atlas { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1600px) {
    .atlas { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    body:has(.atlas) .container { max-width: 1720px; }   /* keeps three entries ~550px wide */
}

/* --- Pagination ---------------------------------------------------------- */
.pager {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 0; margin-top: 16px;
    border-top: 1px solid var(--rule-strong);
    font-size: 14px; color: var(--ink-2);
}
.pager .pager-links { display: flex; gap: 8px; }

/* --- Add form ------------------------------------------------------------ */
.add-panel { margin-top: 32px; }
.add-panel .data-input { font-family: var(--font-data); }   /* formulas, SMILES, masses, m/z */
.add-panel .form-grid {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px;
}
.add-panel .form-grid .span-2 { grid-column: 1 / -1; }
.add-panel .req { color: var(--ink); }   /* One Red Rule: required is ink */
@media (max-width: 700px) {
    .add-panel .form-grid { grid-template-columns: 1fr; }
    .search-field { max-width: none; }
    .search-status:empty, .search-status { min-width: 0; }
    .compare-tray { margin-left: 0; width: 100%; }
    .compare-tray .tray-hint { display: none; }
    .compare-tray #compare-btn { margin-left: auto; }
}

/* ==========================================================================
   Fragment library: one ruled cell per fragment, in m/z order
   ========================================================================== */
.search-mz { flex: 0 1 180px; }
.search-field .field-prefix {
    position: absolute; left: 10px;
    font-family: var(--font-data); font-size: 12.5px; font-style: italic; color: var(--ink-3);
    pointer-events: none;
}
.search-mz input { padding-left: 40px; font-family: var(--font-data); }

/* Each fragment is its own framed entry, set apart by a gap. Rows are 1fr, so every
   entry is the size of the largest: equal cells however long a name or SMILES runs. */
.frag-atlas {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    grid-auto-rows: 1fr;
    gap: 20px;
}
.frag-atlas > .atlas-empty { grid-column: 1 / -1; border: 1px solid var(--rule); }
.frag-entry {
    border: 1px solid var(--rule);
    border-top: 2px solid var(--ink);          /* each entry opens on an ink rule, like a heading */
}
.frag-entry .atlas-head .atlas-formula { margin-left: 0; flex-basis: 100%; }   /* always two lines */
.frag-entry .atlas-pad { margin-top: auto; }
.frag-entry .atlas-head { flex-wrap: wrap; row-gap: 2px; }
/* The entry's key: its nominal m/z, boxed like a compound number */
.frag-mz {
    flex-shrink: 0; padding: 1px 6px;
    border: 1px solid var(--ink); border-radius: var(--radius);
    font-family: var(--font-data); font-size: 13px; font-weight: 700; line-height: 1.35;
    font-variant-numeric: tabular-nums;
}
.frag-mz .ui-word { font-weight: 500; font-style: italic; font-size: 11.5px; color: var(--ink-2); }
.frag-plate {
    display: flex; align-items: center; justify-content: center;
    flex: 1; min-height: 124px; padding: 10px 12px;
    color: var(--ink-3); font-size: 13px;
}
.frag-plate img { display: block; max-width: 100%; height: auto; }   /* natural scale */
.dark .frag-plate img { filter: invert(1) hue-rotate(180deg); }
.frag-smiles {
    padding: 0 14px 10px;
    font-family: var(--font-data); font-size: 12px; line-height: 1.4; color: var(--ink-2);
    overflow-wrap: anywhere;
    /* at most two lines (full SMILES in the tooltip and on the detail page) */
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.frag-entry .atlas-data dd.none { color: var(--ink-3); }
@media (max-width: 700px) {
    .toolstrip .search-field { flex-basis: 100%; }
}

/* --- Fragment search: result line, empty state, checks -------------------- */
/* Keyboard focus never lands under the sticky tool strip */
html:has(.toolstrip) { scroll-padding-top: 76px; }
@media (max-width: 700px) { html:has(.toolstrip) { scroll-padding-top: 132px; } }

/* The browser's clear control in search fields, drawn in the palette (not the default blue) */
.search-field input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none; appearance: none;
    width: 12px; height: 12px; cursor: pointer;
    background-color: var(--ink-3);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 2l8 8M10 2l-8 8' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 2l8 8M10 2l-8 8' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.search-field input[type="search"]::-webkit-search-cancel-button:hover { background-color: var(--ink); }

.result-line {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    margin: -4px 0 14px;
}
.result-summary { font-size: 14px; color: var(--ink-2); }
.result-summary strong { color: var(--ink); font-family: var(--font-data); font-weight: 700; }
.result-summary .muted, .result-empty .muted { color: var(--ink-3); }
.result-empty {
    padding: 18px 20px; margin-bottom: 16px;
    border: 1px solid var(--rule); background: var(--paper);
    font-size: 14px; color: var(--ink-2);
    display: flex; flex-direction: column; gap: 6px;
}
.result-empty a { color: var(--ink); font-weight: 600; }
.result-empty a[data-mz-jump] { font-family: var(--font-data); }

/* A record whose nominal m/z and exact mass disagree: marked in ink, never colour alone */
.mass-flag { display: inline-flex; align-self: center; color: var(--ink); cursor: help; }
.mass-flag svg { width: 15px; height: 15px; }
.atlas-data dd.mass-off {
    text-decoration: underline dotted var(--ink-2); text-decoration-thickness: 1px; text-underline-offset: 3px;
    cursor: help;
}
.field-warn {
    margin: 0 0 14px; padding: 8px 12px;
    border: 1px solid var(--ink-3); border-radius: var(--radius);
    font-size: 13px; color: var(--ink);
}

/* ==========================================================================
   Substructure search: pattern field with live drawing, results with the match shaded
   ========================================================================== */
.sub-search { background: var(--paper); border: 1px solid var(--rule); border-top: 2px solid var(--ink); margin-bottom: 18px; }
.sub-form { display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
.sub-fields { padding: 14px 16px 16px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.sub-label { font-size: 14px; font-weight: 650; }
.sub-input-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.pattern-input {
    flex: 1 1 320px; min-width: 0; min-height: 40px; padding: 8px 12px;
    border: 1px solid var(--rule); border-radius: var(--radius); background: var(--page);
    color: var(--ink); font-family: var(--font-data); font-size: 15px;
}
.pattern-input:hover { border-color: var(--ink-3); }
.pattern-input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.sub-kind { margin: 0; padding: 0; }
.sub-kind { display: inline-flex; align-items: stretch; }
.sub-kind label { display: flex; }
.sub-kind span { display: flex; align-items: center; padding-top: 0; padding-bottom: 0; }
.sub-help { font-size: 13px; color: var(--ink-3); line-height: 1.5; }
.sub-help strong { color: var(--ink-2); font-weight: 650; }
.sub-help code, .result-summary code, .result-empty code, .sub-error code {
    font-family: var(--font-data); font-size: 0.92em; color: var(--ink); overflow-wrap: anywhere;
}
.quick-patterns { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.quick-label { font-size: 12.5px; color: var(--ink-3); margin-right: 4px; }
.quick-pattern {
    min-height: 28px; padding: 0 10px; border: 1px solid var(--rule); border-radius: var(--radius);
    background: transparent; color: var(--ink-2); font: inherit; font-size: 13px; cursor: pointer;
}
.quick-pattern:hover { border-color: var(--ink); color: var(--ink); }
.quick-pattern .ui-word { font-size: 11px; color: var(--ink-3); margin-left: 2px; }
.quick-pattern:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sub-preview { border-left: 1px solid var(--rule); display: flex; flex-direction: column; }
.pattern-plate {
    flex: 1; min-height: 150px; padding: 10px;
    display: flex; align-items: center; justify-content: center;
    color: var(--ink-3); font-size: 13px; text-align: center;
}
.pattern-plate img { display: block; max-width: 100%; max-height: 170px; }
.dark .pattern-plate img { filter: invert(1) hue-rotate(180deg); }
.pattern-status { padding: 6px 12px 8px; border-top: 1px solid var(--rule); font-size: 12.5px; font-family: var(--font-data); color: var(--ink-3); }
.pattern-status.is-ok { color: var(--ink-2); }
.pattern-status.is-bad { color: var(--ink); font-weight: 700; }

.sub-error { margin: -4px 0 18px; }
.result-key { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; font-size: 12.5px; color: var(--ink-3); }
.match-swatch { width: 14px; height: 10px; border-radius: var(--radius); background: var(--ink); opacity: 0.16; }   /* = HIGHLIGHT_OPACITY in structure.py */
.sub-more { margin-top: 20px; background: var(--paper); border: 1px solid var(--rule); }
.sub-more h3 { padding: 10px 14px; border-bottom: 1px solid var(--rule); font-size: 14px; }
.sub-more h3 .muted { color: var(--ink-3); font-weight: 500; font-size: 13px; }
.sub-more-list { list-style: none; margin: 0; padding: 4px 0; columns: 3 300px; column-gap: 0; }
.sub-more-list li {
    break-inside: avoid; display: flex; align-items: baseline; gap: 8px;
    padding: 6px 14px; font-size: 14px;
}
.sub-more-list .atlas-no { font-size: 12px; }
.sub-more-list a { font-weight: 600; text-decoration: none; }
.sub-more-list a:hover { text-decoration: underline; }
.sub-more-list .atlas-formula { margin-left: 0; font-size: 12px; }
.sub-more-count { margin-left: auto; font-family: var(--font-data); font-size: 12px; color: var(--ink-3); }

@media (max-width: 760px) {
    .sub-form { grid-template-columns: minmax(0, 1fr); }
    .sub-preview { border-left: 0; border-top: 1px solid var(--rule); }
    .pattern-plate { min-height: 120px; }
}

/* ==========================================================================
   Spectrum analyzer: compound + peaks in, a peak ledger out
   ========================================================================== */
.an-pick { display: flex; flex-direction: column; gap: 6px; max-width: 420px; }
.an-select {
    min-height: 36px; padding: 6px 10px; border: 1px solid var(--rule); border-radius: var(--radius);
    background: var(--page); color: var(--ink); font: inherit; font-size: 14px;
}
.an-select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.an-peaks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.an-peaks > div { display: flex; flex-direction: column; gap: 6px; }
.an-textarea {
    width: 100%; min-height: 70px; padding: 8px 10px; resize: vertical;
    border: 1px solid var(--rule); border-radius: var(--radius); background: var(--page);
    color: var(--ink); font-family: var(--font-data); font-size: 13.5px; line-height: 1.45;
}
.an-textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.pattern-input[aria-invalid="true"], .an-textarea[aria-invalid="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }   /* invalid is ink; the alert carries the error colour */
.ui-opt { font-weight: 500; font-size: 12px; color: var(--ink-3); margin-left: 4px; }
.an-search .sub-fields { gap: 8px; }
.an-search .sub-fields .sub-label:not(:first-child) { margin-top: 4px; }
@media (max-width: 600px) { .an-peaks { grid-template-columns: minmax(0, 1fr); } }
.an-search .pattern-input { flex: none; }   /* a column here, not the substructure row */

/* ==========================================================================
   Auth pages: one ruled panel, with a real library entry beside it
   ========================================================================== */
.auth-page {
    display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 440px);
    justify-content: center; align-items: start; gap: 40px;
    padding: 40px 0 56px;
}
.auth-page-single { grid-template-columns: minmax(0, 420px); }
.auth-panel {
    background: var(--paper); border: 1px solid var(--rule); border-top: 2px solid var(--ink);
    padding: 22px 24px 20px;
}
.auth-panel h1 { font-size: 26px; font-weight: 700; font-stretch: 92%; letter-spacing: -0.02em; margin-bottom: 6px; }
.auth-lead { font-size: 14px; color: var(--ink-2); line-height: 1.5; margin-bottom: 18px; }
.auth-lead strong { color: var(--ink); }
.auth-form .form-group { margin-bottom: 14px; }
.auth-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 5px; }
.auth-label-row label { margin-bottom: 0; }
.auth-label-row a, .auth-foot a { font-size: 13.5px; color: var(--ink); font-weight: 600; }
.auth-submit { width: 100%; justify-content: center; min-height: 40px; margin-top: 4px; }
.auth-panel > .auth-submit { display: flex; margin-top: 14px; }
.auth-panel .alert { margin-bottom: 12px; }
.alert[hidden] { display: none; }
.auth-form input[aria-invalid="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
/* Success on the auth pages is an ink notice, not a green fill */
.auth-panel .alert-note { background: var(--inset); border: 1px solid var(--rule-strong); color: var(--ink); }
.auth-foot { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule); font-size: 13.5px; color: var(--ink-3); }
.auth-consent { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 16px; font-size: 13px; line-height: 1.5; color: var(--ink-2); cursor: pointer; }
.auth-consent input { width: 15px; height: 15px; margin-top: 2px; flex-shrink: 0; }

/* Live password checklist: a dash until a rule is met, then an ink tick (never colour alone) */
.pw-rules { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 3px; font-size: 12.5px; color: var(--ink-3); }
.pw-rules li { display: flex; align-items: center; gap: 6px; }
.pw-rules svg { width: 13px; height: 13px; flex-shrink: 0; }
.pw-rules .pw-on { display: none; }
.pw-rules li.is-met { color: var(--ink); }
.pw-rules li.is-met .pw-on { display: inline; }
.pw-rules li.is-met .pw-off { display: none; }

.auth-specimen { padding-top: 0; }   /* its heading rule shares the panel's top line */
.auth-specimen h2 { font-size: 14px; font-weight: 650; color: var(--ink-2); padding-top: 10px; border-top: 2px solid var(--ink); margin-bottom: 10px; }   /* the same 2px ink line the panel opens on */
.auth-specimen-entry { background: var(--paper); border: 1px solid var(--rule); }
.auth-specimen-head { display: flex; align-items: baseline; gap: 10px; padding: 10px 14px 8px; border-bottom: 1px solid var(--rule); }
.auth-specimen-head .atlas-name { font-size: 15px; font-weight: 680; text-decoration: none; }
.auth-specimen-head .atlas-name:hover { text-decoration: underline; }
.auth-specimen-spectrum { padding: 10px 12px 4px; }
.auth-specimen-meta { padding: 6px 14px 10px; border-top: 1px solid var(--rule); font-family: var(--font-data); font-size: 12px; color: var(--ink-3); }
.auth-specimen-note { margin-top: 12px; font-size: 13.5px; color: var(--ink-2); line-height: 1.5; }
.auth-specimen-note a { color: var(--ink); font-weight: 600; }

@media (max-width: 900px) {
    .auth-page { grid-template-columns: minmax(0, 460px); gap: 28px; padding-top: 20px; }
}

/* Mass error of a measured m/z against the candidate (m/z search with decimals) */
.frag-delta {
    padding: 0 14px 10px; margin-top: -4px;
    font-family: var(--font-data); font-size: 12.5px; font-weight: 600; color: var(--ink);
    font-variant-numeric: tabular-nums;
}
.frag-delta .ui-word { font-weight: 400; color: var(--ink-3); }

/* Tolerance beside a measured m/z search */
.search-ppm { flex: 0 0 118px; }
.search-ppm input { padding-left: 24px; padding-right: 38px; font-family: var(--font-data); }
.search-field .field-suffix {
    position: absolute; right: 10px;
    font-family: var(--font-data); font-size: 12.5px; font-style: italic; color: var(--ink-3); pointer-events: none;
}
/* A candidate outside the tolerance: greyed numbers and a word, never colour */
.frag-delta.is-outside { color: var(--ink-3); font-weight: 400; }

@media (max-width: 700px) {
    /* 16px fields: iOS doesn't zoom on focus */
    .search-field input { font-size: 16px; }
    .toolstrip .search-ppm { flex-basis: 118px; }
    .toolstrip .search-mz { flex: 1 1 0; }
    /* The status band only takes room while searching (the announcer stays readable) */
    .toolstrip .search-status:not(.htmx-request) {
        position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
    }
}

/* Result line: the verdict on line one, Clear pinned right, a quieter note line under both */
.result-line .result-summary { flex: 1 1 auto; min-width: 0; }
.result-line [data-clear-search] { margin-left: auto; }
.result-note { flex-basis: 100%; margin-top: -6px; font-size: 13px; color: var(--ink-3); line-height: 1.45; }

/* A candidate outside the window: a lighter top rule and a greyed head, so matches stand out */
.frag-entry.is-outside { border-top: 1px solid var(--rule-strong); }
.frag-entry.is-outside .frag-mz, .frag-entry.is-outside .atlas-name a, .frag-entry.is-outside .atlas-formula { color: var(--ink-3); }
.frag-entry.is-outside .frag-mz { border-color: var(--rule); }   /* rule, not rule-strong: that token equals ink */
.frag-entry.is-outside .frag-plate img { opacity: 0.45; }   /* a near-miss's structure steps back */
.frag-delta abbr { text-decoration: none; cursor: help; }

/* The tolerance only applies to an m/z with decimals */
.search-ppm.is-idle input { opacity: 0.5; }
.search-ppm.is-idle .field-prefix, .search-ppm.is-idle .field-suffix { opacity: 0.6; }
/* Invalid: a dashed ink border (focus keeps its solid ring), and "!" in place of the field's suffix */
.search-field input[aria-invalid] { border: 1px dashed var(--ink); }
.search-field input[aria-invalid]:focus { border-style: dashed; }
.search-ppm input[aria-invalid] ~ .field-suffix { font-style: normal; font-weight: 700; color: var(--ink); }
.result-note .note-problem { color: var(--ink); font-weight: 600; }
.result-empty a[data-mz-jump] i { font-style: italic; font-weight: 400; color: var(--ink-3); }

/* Comparison tray: the chosen compounds as removable chips */
.tray-chips { display: flex; flex-wrap: wrap; gap: 4px; list-style: none; margin: 0; padding: 0; max-width: 460px; }
/* A chip: the name (click makes it the reference) and a remove button, in one ink frame.
   The reference (first pick, the mirror plot's upper spectrum) is filled and tagged "ref". */
.tray-chip {
    display: inline-flex; align-items: stretch; min-height: 26px;
    border: 1px solid var(--ink); border-radius: var(--radius); background: var(--paper); overflow: hidden;
}
.tray-chip button {
    border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 12.5px; cursor: pointer;
}
.tray-chip-name { padding: 0 6px 0 8px; font-weight: 600; }
.tray-chip-name:hover { text-decoration: underline; }
.tray-chip-remove { padding: 0 7px; color: var(--ink-3); font-size: 14px; border-left: 1px solid var(--rule) !important; }
.tray-chip-remove:hover { color: var(--ink); background: var(--inset); }
.tray-chip button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tray-chip.is-reference { background: var(--ink); }
.tray-chip.is-reference button { color: var(--on-ink); }
.tray-chip.is-reference .tray-chip-remove { border-left-color: color-mix(in srgb, var(--on-ink) 30%, transparent) !important; }
.tray-ref {
    font-family: var(--font-data); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    padding: 0 4px; border: 1px solid currentColor; border-radius: var(--radius); opacity: 0.85;
}
#clear-selection[hidden] { display: none; }

/* Add forms: the field an error is about */
.add-panel [aria-invalid="true"] { border: 1px dashed var(--ink); }
#form-error[hidden] { display: none; }
/* The tray wraps: chips take their own row on narrow screens, so nothing overflows */
.compare-tray { flex-wrap: wrap; row-gap: 6px; }
@media (max-width: 700px) {
    .compare-tray .tray-chips { order: 5; flex-basis: 100%; max-width: none; }
}

/* --- Compound library: reading, selection, tray, Delete ------------------------------- */
/* The shaded column (.hit.is-active) marks the stick being read; no separate hover band in
   library entries, so what is marked is always what the reading line shows */
.atlas-entry .atlas-spectrum-svg .hit:hover { stroke: transparent; }
.atlas-entry .atlas-spectrum[role="slider"]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Touch: there is no pointer to rest on and no arrow keys */
@media (hover: none) {
    .atlas-entry .atlas-readout:empty::before { content: "Tap a peak to read it"; }
}

/* Selected for comparison: a 2px ink rule along the top and the number inverted (with the
   tinted ground), so the state reads at a glance in both themes */
.atlas-entry:has(.compare-checkbox:checked) .atlas-head { box-shadow: inset 0 2px 0 var(--ink); }
.atlas-entry:has(.compare-checkbox:checked) .atlas-no-quiet {
    background: var(--ink); color: var(--on-ink); padding: 0 5px; border-radius: var(--radius);
}

/* Tray: five chips, then "+N more" */
.tray-more {
    min-height: 26px; padding: 0 8px; border: 1px dashed var(--ink-3); border-radius: var(--radius);
    background: transparent; color: var(--ink); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.tray-more:hover { border-style: solid; }
.tray-more:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Delete in the library is ink until hovered or focused: red stays for base peaks */
.atlas-entry .atlas-actions .btn-danger { background: transparent; color: var(--ink-2); border: 1px solid var(--rule); }
.atlas-entry .atlas-actions .btn-danger:hover,
.atlas-entry .atlas-actions .btn-danger:focus-visible { background: var(--accent); color: var(--paper); border-color: var(--accent); }

/* Key line for the marks every library entry uses */
.atlas-key { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: -6px 0 14px; font-size: 12.5px; color: var(--ink-3); }
.key-mark { display: inline-block; width: 14px; height: 0; vertical-align: middle; transform: rotate(-90deg); }
.key-bp { border-top: 2px solid var(--accent); }
.key-pc { border-top: 1px dotted var(--ink-3); }
.key-sep { color: var(--rule-strong); opacity: 0.5; }

/* Phones: the compare hint keeps its own row (it explains the disabled button) */
@media (max-width: 700px) {
    .compare-tray .tray-hint { display: block; order: 6; flex-basis: 100%; }
    .compare-tray .tray-hint:empty { display: none; }
}
@media (max-width: 700px) { .atlas-key { gap: 2px 14px; } .key-sep { display: none; } }

/* ==========================================================================
   Home: what msTide is, with one real entry beside it; then About and how to cite
   ========================================================================== */
.home { padding: 36px 0 64px; }
.home-intro {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 480px);
    gap: 48px; align-items: start;
    padding-bottom: 40px; border-bottom: 1px solid var(--rule);
}
.home-intro h1 {
    font-size: 56px; font-weight: 700; font-stretch: 92%; letter-spacing: -0.035em; line-height: 1;
    margin-bottom: 16px;
}
.home-lede { font-size: 19px; line-height: 1.45; color: var(--ink-2); max-width: 34em; text-wrap: pretty; }
.home-holdings {
    display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 18px;
    font-size: 14px; color: var(--ink-3);
}
.home-holdings a { color: inherit; text-decoration: none; }
.home-holdings a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.home-holdings strong { font-family: var(--font-data); font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); }
.home-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.home-specimen h2 { margin-bottom: 10px; }
.home-specimen-name { padding: 8px 14px 0; font-size: 13px; line-height: 1.4; color: var(--ink-2); }

.home-body {
    display: grid; grid-template-columns: minmax(0, 68ch) minmax(0, 480px);
    justify-content: space-between; gap: 56px; padding-top: 36px;
}
.home-about h2, .home-cite h2 { font-size: 20px; font-weight: 680; letter-spacing: -0.01em; margin-bottom: 14px; }
.home-about p { font-size: 16px; line-height: 1.65; color: var(--ink); text-wrap: pretty; }
.home-about p + p { margin-top: 1em; }

.home-cite {
    align-self: start; position: sticky; top: 76px;
    background: var(--paper); border: 1px solid var(--rule); border-top: 2px solid var(--ink);
    padding: 16px 18px 18px;
}
.home-cite h2 { font-size: 16px; margin-bottom: 6px; }
.home-cite-lead { font-size: 13.5px; color: var(--ink-3); margin-bottom: 10px; }
.home-ref { margin: 0; font-size: 14px; line-height: 1.55; color: var(--ink); }
.home-doi { margin-top: 10px; font-family: var(--font-data); font-size: 12.5px; overflow-wrap: anywhere; }
.home-doi .ui-word { font-family: var(--font-ui); font-size: 11.5px; font-weight: 600; color: var(--ink-3); margin-right: 4px; }
.home-doi a { color: var(--ink); }
.home-cite-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--rule); }

@media (max-width: 1000px) {
    .home-intro, .home-body { grid-template-columns: minmax(0, 1fr); gap: 32px; }
    .home-cite { position: static; }
}
@media (max-width: 600px) {
    .home { padding-top: 24px; }
    .home-intro h1 { font-size: 42px; }
    .home-lede { font-size: 17px; }
    .home-actions .btn { flex: 1 1 100%; justify-content: center; }
}

/* ==========================================================================
   Compound library search: mode, the mode's fields, modification chips, match line
   ========================================================================== */
.library-search .toolstrip { margin-bottom: 0; gap: 10px 14px; }
.search-mode span { min-width: 58px; }
.search-inputs { display: flex; flex: 1 1 420px; min-width: 0; }
.search-inputs .search-field { max-width: 460px; }
.search-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1 1 auto; min-width: 0; }
.search-input {
    min-height: 34px; padding: 6px 10px; min-width: 0;
    border: 1px solid var(--rule); border-radius: var(--radius);
    background: var(--paper); color: var(--ink); font-size: 14px;
    flex: 0 1 220px;
}
.search-input.data-input { font-family: var(--font-data); font-size: 13.5px; }
.search-input::placeholder { color: var(--ink-3); font-family: var(--font-ui); }
.search-input:hover { border-color: var(--ink-3); }
.search-input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.search-wide { flex: 1 1 220px; }
.search-tol { flex: 0 0 76px; }
.search-pm { color: var(--ink-3); font-family: var(--font-data); }
.search-min { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.search-min .search-input { flex: 0 0 64px; width: 64px; }

.mod-filters { border-bottom: 1px solid var(--rule); margin-bottom: 16px; }
.mod-filters > summary {
    display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none;
    padding: 9px 0; font-size: 13.5px; font-weight: 600; color: var(--ink-2);
}
.mod-filters > summary::-webkit-details-marker { display: none; }
.mod-filters > summary::before {
    content: ""; width: 7px; height: 7px; margin: 0 2px 2px 1px;
    border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg);
    transition: transform 120ms ease-out;
}
.mod-filters[open] > summary::before { transform: rotate(45deg); margin-bottom: 4px; }
.mod-filters > summary:hover { color: var(--ink); }
.mod-filters > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mod-active { font-family: var(--font-data); font-size: 12px; font-weight: 700; color: var(--on-ink); background: var(--ink); padding: 1px 6px; border-radius: var(--radius); }
.mod-groups { display: grid; gap: 10px; padding: 2px 0 6px; }
.mod-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; border: 0; padding: 0; margin: 0; }
.mod-group legend { float: left; width: 122px; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 0; }
.mod-help { font-size: 12.5px; color: var(--ink-3); padding: 2px 0 12px; line-height: 1.5; }
.mod-clear { color: var(--ink); font-weight: 600; margin-left: 6px; }

.chip {
    position: relative; display: inline-flex; align-items: center; gap: 6px;
    min-height: 28px; padding: 3px 8px;
    border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper);
    font-size: 13px; color: var(--ink); cursor: pointer; user-select: none;
}
.chip input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.chip:hover { border-color: var(--ink-3); }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip:has(input:checked) { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.chip-count { font-family: var(--font-data); font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.chip:has(input:checked) .chip-count { color: var(--on-ink); opacity: 0.75; }
.chip:has(.chip-count[data-n="0"]):not(:has(input:checked)) { color: var(--ink-3); border-style: dashed; }
a.chip-link { text-decoration: none; cursor: pointer; }
a.chip-link:hover { border-color: var(--ink); text-decoration: none; }

#library-results .result-summary { margin-bottom: 12px; }
.result-summary .result-clear { margin-left: 8px; color: var(--ink); font-weight: 600; font-size: 13px; }
.result-error { color: var(--alert-error-text); }
.atlas-match {
    padding: 6px 14px; border-top: 1px solid var(--rule);
    font-family: var(--font-data); font-size: 12.5px; color: var(--ink-2); background: var(--inset);
}

.detail-mods { border-top: 1px solid var(--rule); padding-top: 10px; }
.detail-mod-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; padding: 0; }
.detail-mod-list .chip { min-height: 26px; font-size: 12.5px; }

@media (max-width: 700px) {
    .search-mode { order: -1; }
    .search-inputs { flex-basis: 100%; }
    .search-row .search-input { flex: 1 1 100%; }
    .search-row .search-tol { flex: 1 1 60px; }
    .mod-group legend { float: none; width: 100%; }
}

/* ==========================================================================
   Admin: visitor analytics (cookieless). Summary pad, daily timeline, ranked
   tables with share bars, searches by tool. Atlas grammar inside the admin card.
   ========================================================================== */
.va { color: var(--ink); }
.va-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding-bottom: 14px; border-bottom: 1px solid var(--rule); }
.va-staff { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--ink-2); cursor: pointer; }
.va-staff input { width: 15px; height: 15px; }
.va-range { font-family: var(--font-data); font-size: 12.5px; color: var(--ink-3); margin-left: auto; }
.va-loading { font-size: 13px; color: var(--ink-3); display: none; }
.htmx-request .va-loading, .va-loading.htmx-request { display: inline; }

.va-pad {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    border-bottom: 1px solid var(--rule); margin: 0;
}
.va-pad > div { padding: 14px 16px 14px 0; }
.va-pad > div + div { padding-left: 16px; border-left: 1px solid var(--rule); }
.va-pad dt { font-size: 12px; color: var(--ink-3); }
.va-pad dd { margin: 0; }
.va-pad dd:not(.va-sub) { font-family: var(--font-data); font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.va-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.va-delta { font-family: var(--font-data); color: var(--ink); font-weight: 600; }
.va-delta.is-down { color: var(--ink-2); }

.va-timeline { margin: 0; padding: 16px 0 10px; border-bottom: 1px solid var(--rule); }
.va-timeline figcaption { font-size: 12px; color: var(--ink-3); padding-top: 4px; }
.va-timeline-svg .va-grid-line { stroke: var(--rule); stroke-width: 1; stroke-dasharray: 2 3; }
.va-timeline-svg .st { stroke: var(--ink); stroke-linecap: butt; }
.va-timeline-svg .st.bp { stroke: var(--accent); }
.va-timeline-svg .va-visitors { fill: var(--paper); stroke: var(--ink); stroke-width: 1.4; }
.va-timeline-svg .va-hit { fill: transparent; }
.va-timeline-svg .va-day:hover .va-hit { fill: var(--accent-soft); }

.va-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 28px; }
.va-section { padding: 16px 0 6px; border-bottom: 1px solid var(--rule); min-width: 0; }
.va-section h3 { font-size: 14px; font-weight: 650; margin-bottom: 8px; }
.va-searches { grid-column: 1 / -1; }
.va-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-bottom: 10px; }
.va-table th { font-size: 11.5px; font-weight: 600; color: var(--ink-3); text-align: left; padding: 0 8px 4px 0; border-bottom: 1px solid var(--rule-strong); }
.va-table td { padding: 5px 8px 5px 0; border-bottom: 1px solid var(--rule); vertical-align: middle; overflow-wrap: anywhere; }
.va-table td a { color: var(--ink); }
.va-table .num { text-align: right; font-family: var(--font-data); font-variant-numeric: tabular-nums; white-space: nowrap; width: 1%; }
.va-table .bar { width: 34%; padding-right: 0; }
.va-bar { display: block; height: 6px; width: var(--w); min-width: 2px; background: var(--ink); }
.va-bar.is-top { background: var(--accent); }
.va-empty { font-size: 13px; color: var(--ink-3); padding: 4px 0 12px; }
.va-empty-all { padding: 28px 0; font-size: 14px; border-bottom: 1px solid var(--rule); }
.va-note { font-size: 12.5px; color: var(--ink-3); margin: 0 0 8px; }
.va-note code { font-family: var(--font-data); color: var(--ink-2); }

.va-search-tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 24px; margin-bottom: 10px; }
.va-tool-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; padding-bottom: 4px; border-bottom: 1px solid var(--rule-strong); }
.va-tool-head .num, .va-terms .num { font-family: var(--font-data); font-variant-numeric: tabular-nums; color: var(--ink-2); }
.va-terms { list-style: none; margin: 0; padding: 0; }
.va-terms li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--rule); font-size: 12.5px; }
.va-terms code { font-family: var(--font-data); overflow-wrap: anywhere; color: var(--ink); }
.va-foot { font-size: 12px; color: var(--ink-3); line-height: 1.5; padding-top: 14px; max-width: 90ch; }
.va-foot a { color: var(--ink-2); }

@media (max-width: 600px) {
    .va-range { margin-left: 0; flex-basis: 100%; }
    .va-pad > div { padding: 12px 0; }
    .va-pad > div + div { padding-left: 0; border-left: 0; border-top: 1px solid var(--rule); }
}
