/* CoumarinDB styles. Colours are tokens; dark mode follows the system setting. */

:root {
    --bg: #f6f8f5;
    --surface: #ffffff;
    --surface-2: #eef2ec;
    --text: #1a1f1b;
    --muted: #59645c;
    --border: #d9e0d8;
    --accent: #007f17;
    --accent-hover: #00640f;
    --accent-soft: #e3f2e5;
    --on-accent: #ffffff;
    --focus: #1d5fd8;
    --pass-bg: #e3f2e5;
    --pass-text: #0c5a1c;
    --fail-bg: #fbeae5;
    --fail-text: #8a2a10;
    --error-bg: #fbeae5;
    --shadow: 0 1px 2px rgb(16 24 18 / 6%), 0 4px 16px rgb(16 24 18 / 6%);
    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #101311;
        --surface: #171b18;
        --surface-2: #1e2420;
        --text: #e5ebe6;
        --muted: #9ba79f;
        --border: #2d3530;
        --accent: #53c46f;
        --accent-hover: #74d48c;
        --accent-soft: #1b3122;
        --on-accent: #07120a;
        --focus: #7aa7ff;
        --pass-bg: #1b3122;
        --pass-text: #8fe0a4;
        --fail-bg: #3a1f18;
        --fail-text: #f4a58e;
        --error-bg: #3a1f18;
        --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
        color-scheme: dark;
    }
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.55 var(--font);
}

a {
    color: var(--accent);
    text-underline-offset: 2px;
}

a:hover {
    color: var(--accent-hover);
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

h2 {
    font-size: 1.25rem;
    line-height: 1.3;
    margin: 0 0 0.75rem;
}

.wrap {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 16px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    left: 16px;
    top: -48px;
    z-index: 10;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.skip-link:focus {
    top: 8px;
}

.muted,
.hint {
    color: var(--muted);
}

.hint {
    font-size: 0.875rem;
    margin: 0.5rem 0 0;
}

/* ---------- Header ---------- */

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px 32px;
    padding-top: 20px;
    padding-bottom: 20px;
}

.brand {
    margin: 0;
    line-height: 0;
}

.brand img {
    display: block;
    width: auto;
    height: 72px;
    max-width: 100%;
}

.tagline {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.95rem;
    max-width: 52ch;
}

.stats {
    display: flex;
    gap: 28px;
}

.stats[hidden] {
    display: none;
}

.stat strong {
    display: block;
    font-size: 1.6rem;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat span {
    color: var(--muted);
    font-size: 0.875rem;
}

/* ---------- Intro and cards ---------- */

.intro {
    padding-top: 28px;
}

.intro-text {
    max-width: 78ch;
}

.intro-text p {
    margin: 0 0 0.9rem;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 1.05rem;
}

.card p {
    margin: 0 0 0.5rem;
}

.citation {
    font-size: 0.95rem;
}

.downloads {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--accent);
    color: var(--on-accent);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--on-accent);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-small {
    min-height: 34px;
    padding: 5px 12px;
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--accent);
}

.btn-small:hover:not(:disabled) {
    background: var(--accent-soft);
    color: var(--accent-hover);
}

.btn-quiet {
    min-height: 34px;
    padding: 5px 10px;
    font-size: 0.875rem;
    background: transparent;
    border-color: transparent;
    color: var(--accent);
    text-decoration: underline;
}

.btn-quiet:hover {
    background: transparent;
    border-color: transparent;
    color: var(--accent-hover);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--surface-2);
}

/* ---------- Browser ---------- */

.browse {
    padding-top: 36px;
}

.browse:focus {
    outline: none;
}

.status {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.status.error {
    background: var(--error-bg);
    color: var(--fail-text);
}

.status[hidden] {
    display: none;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    align-items: flex-end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.field label,
.range-label,
.rules legend {
    font-size: 0.875rem;
    font-weight: 600;
}

.field-search {
    flex: 1 1 360px;
}

.field select {
    max-width: 100%;
}

input[type="search"],
input[type="number"],
select {
    min-height: 42px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

input[type="search"] {
    width: 100%;
}

input::placeholder {
    color: var(--muted);
    opacity: 0.85;
}

.more-filters {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.more-filters summary {
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
}

.more-filters summary span {
    color: var(--accent);
}

.more-filters-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px 32px;
    padding: 4px 14px 16px;
}

.range-filters {
    display: grid;
    gap: 10px;
}

.range-row {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(0, 110px) minmax(0, 110px);
    gap: 8px;
    align-items: center;
}

.range-row input {
    width: 100%;
    min-width: 0;
}

.rules {
    margin: 0;
    padding: 0;
    border: 0;
    display: grid;
    gap: 8px;
}

.rules legend {
    margin-bottom: 6px;
    padding: 0;
}

.rules label {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    font-size: 0.925rem;
}

.rules input {
    margin-top: 4px;
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.results-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    margin: 16px 0 10px;
}

.result-count {
    margin: 0;
    font-weight: 600;
}

.results-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.export-label {
    color: var(--muted);
    font-size: 0.875rem;
}

.results-actions .btn-quiet[hidden] {
    display: none;
}

/* ---------- Table ---------- */

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.compounds {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.compounds th,
.compounds td {
    padding: 8px 7px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.compounds thead th {
    background: var(--surface-2);
    font-size: 0.8rem;
    font-weight: 700;
}

.compounds thead th.num {
    white-space: nowrap;
}

.compounds th.num,
.compounds td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.compounds abbr {
    text-decoration: none;
}

.compounds tbody tr {
    cursor: pointer;
}

.compounds tbody tr:hover {
    background: var(--accent-soft);
}

.compounds tbody tr:last-child td {
    border-bottom: 0;
}

.sort {
    display: inline-flex;
    align-items: center;
    text-align: left;
    gap: 4px;
    padding: 4px 2px;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.sort-arrow::after {
    content: "\2195";
    color: var(--muted);
    font-size: 0.9em;
}

th[aria-sort="ascending"] .sort-arrow::after {
    content: "\2191";
    color: var(--accent);
}

th[aria-sort="descending"] .sort-arrow::after {
    content: "\2193";
    color: var(--accent);
}

.c-structure {
    width: 106px;
    padding-top: 4px;
    padding-bottom: 4px;
}

.thumb {
    width: 96px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.7rem;
    text-align: center;
}

.thumb svg,
.detail-structure svg {
    width: 100%;
    height: 100%;
}

.no-structures .c-structure,
.no-structures th[data-key="structure"],
.no-structures .detail-structure {
    display: none;
}

.c-id {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.c-name {
    min-width: 130px;
}

.name-link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-weight: 600;
    text-align: left;
    text-decoration: underline;
    text-decoration-color: transparent;
    text-underline-offset: 2px;
    cursor: pointer;
}

.name-link:hover {
    text-decoration-color: currentColor;
}

.c-source {
    min-width: 130px;
}

/* Keep "5,7-Dioxygenated" together instead of breaking after the hyphen. */
.nowrap {
    white-space: nowrap;
}

.empty {
    margin: 0;
    padding: 28px 16px;
    text-align: center;
    color: var(--muted);
}

.empty[hidden] {
    display: none;
}

.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px 12px;
    margin-top: 12px;
}

.page-size {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: auto;
    font-size: 0.875rem;
    color: var(--muted);
}

.page-size select {
    min-height: 34px;
    padding: 4px 8px;
}

.page-info {
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

/* ---------- Details dialog ---------- */

.detail {
    width: min(920px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}

.detail::backdrop {
    background: rgb(10 14 11 / 55%);
}

.detail-close {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    justify-content: flex-end;
    height: 0;
    margin: 0;
}

.detail-close .icon-btn {
    margin: 12px 12px 0 0;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
    gap: 8px 28px;
    padding: 24px;
}

.detail-structure {
    aspect-ratio: 4 / 3;
    align-self: start;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--muted);
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.detail-info h2 {
    margin: 2px 48px 4px 0;
    font-size: 1.45rem;
}

.detail-class {
    margin: 0 0 10px;
    color: var(--muted);
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.badge {
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

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

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

.props {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 6px 16px;
    margin: 0 0 16px;
    font-size: 0.925rem;
}

.props dt {
    color: var(--muted);
}

.props dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.props .mono {
    font-family: var(--mono);
    font-size: 0.85rem;
}

.detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ---------- References and footer ---------- */

.references {
    padding-top: 40px;
}

.references ol {
    max-width: 90ch;
    margin: 0;
    padding-left: 1.4rem;
    color: var(--muted);
    font-size: 0.925rem;
}

.references li {
    margin-bottom: 0.5rem;
}

.site-footer {
    margin-top: 40px;
    padding: 20px 0 28px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 0.9rem;
}

.site-footer p {
    margin: 0;
}

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
    .brand img {
        height: 52px;
    }

    .stats {
        gap: 20px;
    }

    .stat strong {
        font-size: 1.3rem;
    }

    .field,
    .field select {
        width: 100%;
    }

    .range-row {
        grid-template-columns: 1fr 1fr;
    }

    .range-label {
        grid-column: 1 / -1;
    }

    .detail-grid {
        grid-template-columns: minmax(0, 1fr);
        padding: 16px;
    }

    .props {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
    }

    .props dd {
        margin-bottom: 8px;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .btn,
    .icon-btn,
    .compounds tbody tr {
        transition: background-color 120ms ease, color 120ms ease;
    }
}
