/* ==========================================================================
   Ais model database - single stylesheet
   1. Tokens
   2. Reset / base
   3. Layout: header, main, footer
   4. Controls: buttons, inputs, tags
   5. Home: search + model tile grid
   6. Model detail / edit pages
   7. Upload page
   8. About page
   9. Responsive
   ========================================================================== */

/* 1. Tokens ------------------------------------------------------------- */

:root {
    /* Palette - the warm off-white frame is the site's existing identity. */
    --color-page: #ffffff;
    --color-frame: rgb(222, 222, 212);
    --color-frame-dark: rgb(212, 212, 194);
    --color-frame-light: rgb(245, 245, 237);

    --color-border: rgb(166, 166, 166);
    --color-border-subtle: rgb(224, 224, 216);
    --color-border-focus: rgb(116, 116, 116);

    --color-text: rgb(66, 66, 66);
    --color-text-strong: rgb(28, 28, 28);
    --color-text-muted: rgb(122, 122, 122);
    --color-text-disabled: rgb(176, 176, 176);

    --color-link: rgb(31, 78, 173);
    --color-ok: rgb(21, 118, 61);
    --color-warn: rgb(176, 42, 30);

    /* Overridden per model via an inline custom property. */
    --model-accent: var(--color-frame-dark);

    /* Type */
    --font-body: 'Poppins', system-ui, -apple-system, sans-serif;
    --text-xs: 0.6875rem;   /* 11px */
    --text-sm: 0.8125rem;   /* 13px */
    --text-base: 0.875rem;  /* 14px */
    --text-md: 1rem;        /* 16px */
    --text-lg: 1.25rem;     /* 20px */
    --text-xl: 1.5rem;      /* 24px */

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;

    --radius-sm: 3px;
    --radius-md: 6px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);

    --container: min(1100px, 92vw);
}

/* 2. Reset / base ------------------------------------------------------- */

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

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-body);
    font-size: var(--text-md);
    line-height: 1.55;
    color: var(--color-text);
    background: var(--color-page);
}

img {
    max-width: 100%;
    height: auto;
}

h1,
h2,
h3 {
    color: var(--color-text-strong);
    line-height: 1.25;
    margin: 0 0 var(--space-3);
}

h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }

a {
    color: inherit;
    text-decoration: none;
}

/* Links inside running prose should look like links. */
.prose a,
.spec-list a {
    color: var(--color-link);
    text-decoration: underline;
}

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

.skip-link {
    position: absolute;
    left: -9999px;
}

.skip-link:focus {
    left: var(--space-4);
    top: var(--space-4);
    z-index: 10;
    padding: var(--space-2) var(--space-3);
    background: var(--color-frame-light);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.container {
    width: var(--container);
    margin-inline: auto;
}

/* 3. Layout ------------------------------------------------------------- */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    flex-wrap: wrap;
    width: var(--container);
    margin: var(--space-5) auto var(--space-6);
}

.site-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--color-text-strong);
}

.site-brand img {
    height: 44px;
    width: auto;
    flex: none;
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
}

.site-nav a {
    font-weight: 600;
    font-size: var(--text-base);
    color: var(--color-text);
    padding-bottom: 2px;
    border-bottom: 2px solid transparent;
}

.site-nav a:hover {
    color: var(--color-text-strong);
}

.site-nav a[aria-current="page"] {
    color: var(--color-text-strong);
    border-bottom-color: var(--color-frame-dark);
}

main {
    flex: 1 0 auto;
    padding-bottom: var(--space-7);
}

.page-title {
    margin-bottom: var(--space-5);
}

.site-footer {
    border-top: 1px solid var(--color-border-subtle);
    padding: var(--space-4) 0 var(--space-6);
    margin-top: auto;
    text-align: center;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.site-footer p {
    width: var(--container);
    margin: 0 auto;
}

.site-footer a {
    text-decoration: underline;
}

/* 4. Controls ----------------------------------------------------------- */

button,
.button {
    font-family: inherit;
    font-size: var(--text-base);
    min-height: 34px;
    padding: 0 var(--space-5);
    color: var(--color-text);
    background: var(--color-frame-light);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--color-frame);
}

button:disabled {
    color: var(--color-text-disabled);
    cursor: not-allowed;
}

button:disabled:hover {
    background: var(--color-frame-light);
}

input[type="text"],
input[type="password"],
input[type="email"] {
    font-family: inherit;
    font-size: var(--text-base);
    min-height: 32px;
    padding: 0 var(--space-3);
    color: var(--color-text);
    background: var(--color-page);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus {
    border-color: var(--color-border-focus);
    outline: none;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--model-accent);
}

/* Tag pills - shared by the upload form, tile metadata and detail page. */

.tag-container {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: var(--space-3) 0 0;
    padding: 0;
    list-style: none;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    font-size: var(--text-sm);
    background: var(--color-frame-light);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
}

.tag-close {
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: var(--text-base);
}

.tag-close:hover {
    color: var(--color-warn);
}

/* Download control, shared by tiles and the detail page. */

.download-group {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.download-count {
    font-size: var(--text-sm);
    font-style: italic;
    color: var(--color-text-muted);
}

.download-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    color: var(--color-text);
    cursor: pointer;
}

.download-button:hover {
    background: var(--color-frame-light);
    color: var(--color-text-strong);
}

/* 5. Home: search + tile grid ------------------------------------------ */

.search-form {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: center;
    margin-bottom: var(--space-6);
}

.search-form input[type="text"] {
    flex: 1 1 240px;
    min-width: 0;
    max-width: 420px;
    border-radius: var(--radius-pill);
}

.search-form button {
    flex: none;
}

.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
}

.model-tile {
    display: flex;
    flex-direction: column;
    padding: var(--space-3);
    background: linear-gradient(to bottom, var(--model-accent-wash, transparent), var(--color-page));
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.model-tile:hover {
    border-color: var(--color-border-focus);
    box-shadow: var(--shadow-md);
}

.model-tile-link {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.model-tile-title {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--color-text-strong);
    overflow-wrap: anywhere;
}

.model-tile-meta {
    font-size: var(--text-xs);
    font-style: italic;
    color: var(--color-text-muted);
}

.model-tile-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--color-frame-light);
}

.model-tile .download-group {
    justify-content: space-between;
    margin-top: auto;
    padding-top: var(--space-2);
}

.empty-state {
    padding: var(--space-7) 0;
    text-align: center;
    color: var(--color-text-muted);
}

/* Screening page (/submissions) ---------------------------------------- */

.screening-intro {
    margin: 0 0 var(--space-5);
    color: var(--color-text-muted);
    font-size: var(--text-base);
}

.screening-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: auto;
    padding-top: var(--space-3);
}

.screening-actions button,
.screening-actions .screening-edit {
    flex: 1;
    min-height: 30px;
    padding: 0 var(--space-2);
    font-family: inherit;
    font-size: var(--text-sm);
    text-align: center;
    color: var(--color-text);
    background: var(--color-frame-light);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.screening-actions .screening-edit {
    line-height: 30px;
}

.screening-accept {
    color: var(--color-ok) !important;
    border-color: var(--color-ok) !important;
}

.screening-reject {
    color: var(--color-warn) !important;
    border-color: var(--color-warn) !important;
}

.screening-actions [aria-disabled="true"] {
    opacity: 0.5;
    pointer-events: none;
}

.screening-status {
    margin: var(--space-2) 0 0;
    font-size: var(--text-xs);
    text-align: center;
}

.screening-status:empty {
    display: none;
}

.screening-status.is-busy {
    color: var(--color-text-muted);
}

.screening-status.is-error {
    color: var(--color-warn);
}

/* 6. Model detail / edit ----------------------------------------------- */

.model-header {
    margin-bottom: var(--space-5);
}

.model-header h1 {
    margin-bottom: var(--space-2);
    overflow-wrap: anywhere;
}

.model-columns {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr);
    gap: var(--space-5);
    align-items: start;
}

.model-preview {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.model-preview img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-frame-light);
}

.threshold-slider {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
}

.threshold-slider p {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.model-details {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.spec-list {
    margin: 0;
}

.spec-list h2 {
    font-size: var(--text-md);
    margin-bottom: var(--space-1);
}

.spec-list h2:not(:first-child) {
    margin-top: var(--space-4);
}

.spec-list ul {
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--text-base);
}

.spec-list li + li {
    margin-top: 2px;
}

.status-badge {
    display: inline-block;
    font-size: var(--text-sm);
    font-weight: 600;
}

.status-badge.is-approved { color: var(--color-ok); }
.status-badge.is-pending { color: var(--color-warn); }

.model-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border-subtle);
}

.browse-buttons {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-6);
}

.browse-buttons a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-base);
    padding: var(--space-1) var(--space-3);
    background: var(--color-frame-light);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
}

.browse-buttons a:hover {
    border-color: var(--color-border-focus);
}

/* Edit form */

.edit-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.edit-form .field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.edit-form .field label {
    font-size: var(--text-base);
}

.edit-form .field > .field-row-label {
    margin-top: var(--space-2);
}

.edit-form .field-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.edit-form .field-inline input[type="text"] {
    flex: 1 1 12rem;
    min-width: 0;
    max-width: 20rem;
}

/* The pixel size is only ever a few characters wide. */
.edit-form .field-inline input#pixelSize {
    flex: none;
    width: 5rem;
}

.check-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: var(--text-base);
}

.check-list label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* 7. Upload page ------------------------------------------------------- */

.upload-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.upload-top {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: var(--space-5);
    align-items: start;
}

.dropzone {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    padding: var(--space-3);
    text-align: center;
    font-size: var(--text-base);
    color: var(--color-text-muted);
    background: var(--color-frame-light);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    user-select: none;
}

.dropzone:hover,
.dropzone.is-dragover {
    border-color: var(--color-border-focus);
    color: var(--color-text);
}

.dropzone label {
    cursor: pointer;
}

.dropzone .file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.thumbnail-preview {
    position: absolute;
    inset: 0;
}

.thumbnail-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.thumbnail-remove {
    position: absolute;
    top: var(--space-1);
    right: var(--space-1);
    min-height: 0;
    padding: 2px 6px;
    font-size: var(--text-sm);
    background: rgba(255, 255, 255, 0.85);
    border-radius: var(--radius-sm);
}

.upload-summary {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.upload-summary .field {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-base);
}

.upload-summary .field input[type="text"] {
    flex: 1 1 12rem;
    min-width: 0;
    max-width: 24rem;
    font-size: var(--text-md);
}

.upload-summary .read-only-spec {
    font-size: var(--text-base);
    color: var(--color-text-muted);
}

fieldset.form-section {
    margin: 0;
    padding: var(--space-5);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
}

fieldset.form-section legend {
    padding: 0 var(--space-2);
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--color-text-strong);
}

fieldset.form-section legend .optional {
    font-weight: 400;
    color: var(--color-text-muted);
}

.field-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    font-size: var(--text-base);
}

.field-row + .field-row {
    margin-top: var(--space-4);
}

/* Group label, used both as a column label in .field-row and as a
   sub-heading in the edit form's .field blocks. */
.field-row-label {
    font-weight: 600;
    color: var(--color-text-strong);
}

.field-row > .field-row-label {
    flex: 0 0 11rem;
}

.field-row label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.field-row input[type="text"] {
    min-width: 0;
    max-width: 100%;
}

.field-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.upload-submit {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    padding-bottom: var(--space-6);
}

.upload-submit button {
    padding: 0 var(--space-6);
}

/* Overlay shown while an upload is in flight: the Ais icon, spinning. */
.upload-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: rgba(255, 255, 255, 0.8);
}

/* Needed because display:flex above would otherwise defeat [hidden]. */
.upload-overlay[hidden] {
    display: none;
}

.upload-overlay-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-7);
    text-align: center;
    background: var(--color-frame-light);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.upload-overlay-card p {
    margin: 0;
    font-size: var(--text-md);
    color: var(--color-text);
}

.upload-spinner-icon {
    width: 140px;
    height: 140px;
    animation: spin 3s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .upload-spinner-icon {
        animation-duration: 9s;
    }
}

.form-status {
    margin: 0;
    max-width: 60ch;
    text-align: center;
    font-size: var(--text-base);
}

.form-status:empty {
    display: none;
}

.form-status.is-busy {
    color: var(--color-text-muted);
}

.form-status.is-success,
.form-status.is-error {
    padding: var(--space-3) var(--space-4);
    border: 1px solid;
    border-radius: var(--radius-md);
}

.form-status.is-success {
    color: var(--color-ok);
    border-color: var(--color-ok);
    background: rgba(21, 118, 61, 0.06);
}

.form-status.is-error {
    color: var(--color-warn);
    border-color: var(--color-warn);
    background: rgba(176, 42, 30, 0.06);
}

/* 8. About page -------------------------------------------------------- */

.prose {
    max-width: 68ch;
    font-size: var(--text-md);
}

.prose p + p {
    margin-top: var(--space-4);
}

/* The about page is a short read with no illustration, so it is centred as
   a single narrow column rather than set left against a wide empty page. */
.about-title {
    text-align: center;
    margin-bottom: var(--space-6);
}

.about-prose {
    max-width: 62ch;
    margin-inline: auto;
    text-align: center;
    text-wrap: pretty;
}

.about-prose p + p {
    margin-top: var(--space-5);
}

/* 9. Responsive -------------------------------------------------------- */

@media (max-width: 900px) {
    .model-columns {
        grid-template-columns: minmax(0, 1fr);
    }

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

    .dropzone {
        max-width: 300px;
    }
}

@media (max-width: 600px) {
    :root {
        --container: 94vw;
    }

    .site-header {
        margin-bottom: var(--space-5);
    }

    .site-brand {
        font-size: var(--text-md);
    }

    .site-brand img {
        height: 34px;
    }

    .site-nav {
        gap: var(--space-4);
    }

    .model-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .field-row > .field-row-label {
        flex-basis: 100%;
    }
}
