/* ---------------------------------------------------------------------------
   CD4 Mimetics — single stylesheet.

   Every page style lives here; templates carry no <style> blocks and no inline
   style attributes. Colours are defined once as custom properties and remapped
   for dark mode, so nothing below hardcodes a colour.
   --------------------------------------------------------------------------- */

:root {
    --navy: #07294d;
    --navy-light: #0e4179;
    --gold: #ffc600;

    --bg: #ffffff;
    --surface: #f5f7fa;
    --surface-alt: #eceff4;
    --border: #d4dae2;
    --text: #16202b;
    --text-muted: #5a6674;
    --accent: var(--navy);
    --accent-text: #ffffff;
    --danger: #b3261e;

    --radius: 6px;
    --gap: 1rem;
    --measure: 68ch;
    --shadow: 0 1px 2px rgb(16 32 48 / 8%), 0 2px 8px rgb(16 32 48 / 6%);

    --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12171d;
        --surface: #1a212a;
        --surface-alt: #222b36;
        --border: #33404e;
        --text: #e6ebf1;
        --text-muted: #9aa7b5;
        --accent: #7fb0e8;
        --accent-text: #0b1219;
        --danger: #f2b8b5;
        --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 2px 8px rgb(0 0 0 / 30%);
    }
}

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.55;
    -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3 {
    line-height: 1.2;
    margin: 0 0 0.5em;
}

h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); }
h2 { font-size: clamp(1.2rem, 1.05rem + 0.7vw, 1.5rem); }

p { margin: 0 0 1rem; max-width: var(--measure); }

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

a:hover { text-decoration-thickness: 2px; }

/* Visible keyboard focus everywhere; the old stylesheet suppressed it. */
:focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
    border-radius: 2px;
}

/* --- skip link ----------------------------------------------------------- */

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--gold);
    color: #000;
    padding: 0.6rem 1rem;
    z-index: 10;
}

.skip-link:focus {
    left: 0;
}

/* --- header / nav -------------------------------------------------------- */

.site-header {
    background: var(--navy);
    color: #fff;
    padding: 1rem var(--gap);
    text-align: center;
    border-bottom: 3px solid var(--gold);
}

.site-header h1 {
    margin: 0;
    color: #fff;
    letter-spacing: 0.01em;
}

.site-header .tagline {
    margin: 0.25rem auto 0;
    color: rgb(255 255 255 / 78%);
    font-size: 0.9rem;
}

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

.topnav ul {
    list-style: none;
    margin: 0 auto;
    padding: 0 0.5rem;
    max-width: 1200px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem;
}

/* Pushes everything after it to the right edge, replacing the old float:right
   pair. Collapses harmlessly when the nav wraps on narrow screens. */
.topnav .spacer { margin-left: auto; }

.topnav a,
.topnav button {
    display: block;
    padding: 0.7rem 0.9rem;
    color: var(--text);
    background: none;
    border: none;
    border-radius: var(--radius);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.topnav a:hover,
.topnav button:hover {
    background: var(--navy);
    color: #fff;
}

.topnav form { margin: 0; }

/* --- layout -------------------------------------------------------------- */

main {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem var(--gap) 2.5rem;
}

.site-footer {
    background: var(--surface-alt);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 1rem var(--gap);
}

.site-footer .inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    justify-content: space-between;
}

.site-footer p { margin: 0; max-width: none; }

/* --- gallery ------------------------------------------------------------- */

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: var(--gap);
    margin: 0;
    padding: 0;
    list-style: none;
}

.gallery a {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
}

.gallery a:hover {
    border-color: var(--navy);
    box-shadow: var(--shadow);
}

.gallery .name {
    padding: 0.6rem 0.75rem;
    font-weight: 600;
    font-size: 0.9rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.gallery img {
    display: block;
    width: 100%;
    height: auto;
    /* structure PNGs are drawn on white; keep them legible in dark mode */
    background: #fff;
}

/* --- compound detail ----------------------------------------------------- */

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25rem;
    align-items: start;
}

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

.card > h2 {
    margin-top: 0;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.structure-image {
    display: block;
    width: 100%;
    max-width: 260px;
    height: auto;
    margin-inline: auto;
    background: #fff;
    border-radius: var(--radius);
}

/* --- data tables --------------------------------------------------------- */

/* Wide tables scroll inside their own box so the page body never does. */
.table-wrap,
.table-container {
    overflow-x: auto;
    max-width: 100%;
}

table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.925rem;
}

caption {
    text-align: left;
    color: var(--text-muted);
    padding-bottom: 0.5rem;
}

th,
td {
    text-align: left;
    padding: 0.5rem 0.7rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

thead th {
    background: var(--surface-alt);
    font-weight: 600;
    white-space: nowrap;
}

tbody tr:hover { background: var(--surface-alt); }

.kv th {
    width: 12rem;
    font-weight: 600;
    background: none;
    color: var(--text-muted);
}

/* --- pagination (django-tables2) ----------------------------------------- */

.table-container ul.pagination,
ul.pagination {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin: 1rem 0 0;
    padding: 0;
}

ul.pagination li a,
ul.pagination li span {
    display: block;
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    background: var(--surface);
}

ul.pagination li.active span,
ul.pagination li.current span {
    background: var(--navy);
    color: #fff;
    border-color: var(--navy);
}

/* --- forms --------------------------------------------------------------- */

form { margin: 0; }

/* Django's as_div renderer emits one <div> per field. */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 0.9rem 1.25rem;
    align-items: start;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    max-width: 42rem;
}

.form-grid > div,
.form-stack > div {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-muted);
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.6rem;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

textarea {
    min-height: 3rem;
    resize: vertical;
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--navy);
}

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

ul.errorlist {
    list-style: none;
    margin: 0 0 0.5rem;
    padding: 0;
    color: var(--danger);
    font-size: 0.875rem;
}

/* --- buttons ------------------------------------------------------------- */

.btn,
button[type="submit"],
input[type="submit"] {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    font: inherit;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: var(--radius);
    text-decoration: none;
    cursor: pointer;
}

.btn:hover,
button[type="submit"]:hover,
input[type="submit"]:hover {
    background: var(--navy-light);
    color: #fff;
}

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

.btn-secondary:hover {
    background: var(--surface-alt);
    color: var(--text);
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    margin-top: 1.1rem;
}

/* --- misc ---------------------------------------------------------------- */

.page-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.page-head h1 { margin: 0; }

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

.empty {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
}

.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.narrow {
    max-width: 26rem;
    margin-inline: auto;
}

.stack > * + * { margin-top: 1rem; }
