:root {
    color-scheme: light dark;
    --bg: #f8f7f4;
    --surface: #ffffff;
    --border: #e7e2d8;
    --divider: #cfc8ba;
    --text: #21201c;
    --text-muted: #6f6a5e;
    --accent: #d97706;
    --accent-hover: #b45309;
    --accent-fg: #ffffff;
    --ok-bg: #dcfce7;
    --ok-fg: #15803d;
    --muted-bg: #f1efe8;
    --muted-fg: #57534e;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --danger-fg: #991b1b;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(30, 20, 5, 0.05), 0 8px 20px rgba(30, 20, 5, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17140f;
        --surface: #201b14;
        --border: #34291b;
        --divider: #4a3c28;
        --text: #f4f1ea;
        --text-muted: #b3aa96;
        --accent: #f59e0b;
        --accent-hover: #fbbf24;
        --accent-fg: #1a1305;
        --ok-bg: #14432a;
        --ok-fg: #86efac;
        --muted-bg: #29231a;
        --muted-fg: #b3aa96;
        --danger: #f87171;
        --danger-bg: #3a1a1a;
        --danger-fg: #fca5a5;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 20px rgba(0, 0, 0, 0.35);
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family:
        system-ui,
        -apple-system,
        "Segoe UI",
        sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

.page-header {
    margin-bottom: 1.5rem;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.75rem;
    letter-spacing: -0.01em;
}

.page-header .brand {
    color: var(--accent);
}

.page-header .tagline {
    margin: 0.15rem 0 0;
    color: var(--text-muted);
    font-size: 1rem;
}

h1 {
    font-size: 1.5rem;
    letter-spacing: -0.01em;
    margin: 0 0 1.25rem;
}

.toolbar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1.25rem;
}

.toolbar input[type="search"] {
    flex: 1;
}

input,
textarea,
select {
    font: inherit;
    color: inherit;
}

input[type="text"],
input[type="search"],
input[type="date"],
input[type="file"],
textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="search"]:focus,
input[type="date"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

textarea {
    min-height: 4.5rem;
    resize: vertical;
}

/* Buttons */

.button,
input[type="submit"] {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: var(--accent-fg);
    border: none;
    border-radius: var(--radius-sm);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: var(--shadow);
    transition:
        background-color 0.15s ease,
        transform 0.05s ease;
}

.button:hover,
input[type="submit"]:hover {
    background: var(--accent-hover);
}

.button:active,
input[type="submit"]:active {
    transform: translateY(1px);
}

.button-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}

.button-secondary:hover {
    background: var(--muted-bg);
}

.link-button {
    background: none;
    border: none;
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    padding: 0;
    font: inherit;
}

.link-button:hover {
    color: var(--accent-hover);
}

/* Card surfaces (table, forms) */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card.padded {
    padding: 1.5rem;
}

/* Table */

/* Lets a wide table scroll sideways inside its card on a narrow screen
   instead of overflowing the page. */
.table-scroll {
    overflow-x: auto;
}

table.sightings {
    width: 100%;
    border-collapse: collapse;
}

table.sightings th,
table.sightings td {
    text-align: left;
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table.sightings thead th {
    background: var(--muted-bg);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

table.sightings tbody tr {
    transition: background-color 0.1s ease;
}

table.sightings tbody tr:hover {
    background: var(--muted-bg);
}

table.sightings tbody tr:last-child td {
    border-bottom: none;
}

.thumb {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.thumb-empty {
    display: inline-block;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    background: var(--muted-bg);
    border: 1px dashed var(--border);
}

/* Shop cell: name + address, struck through when out of business */

.shop-name {
    display: block;
}

.shop-address {
    display: block;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.shop-out-of-business {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* A row whose product wasn't seen at that (open) shop last time reads
   grayed out. */

table.sightings tbody tr.not-seen {
    color: var(--text-muted);
}

/* A shop that's gone supersedes the stock report: the product line in that
   row is struck through, not grayed. On a closed shop's own page every line
   is (table gets .shop-closed); on the list, only rows for a closed shop
   (their shop link carries .shop-out-of-business). */

table.sightings tbody tr:has(.shop-out-of-business) .product-link,
table.sightings.shop-closed tbody .product-link {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* Pill flagging an exceptional state (not seen, shop out of business). */

.out-of-status-flag {
    display: inline-block;
    margin-left: 0.5em;
    padding: 0.1rem 0.55rem;
    border: 1px solid color-mix(in srgb, var(--muted-fg) 45%, transparent);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    background: var(--muted-bg);
    color: var(--muted-fg);
    cursor: help;
}

.product-link {
    color: inherit;
    text-decoration: none;
    font-weight: 600;
}

.product-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

.shop-link {
    color: inherit;
    text-decoration: none;
}

.shop-link.shop-out-of-business {
    color: var(--text-muted);
    text-decoration: line-through;
}

.shop-link:hover .shop-name {
    color: var(--accent);
    text-decoration: underline;
}

/* Single-product page */

.back-link {
    margin: 0 0 1rem;
}

.back-link a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

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

.product-overview {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.product-head {
    flex: 1 1 12rem;
}

.product-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 0.75rem;
    font-size: 1.75rem;
}

.edit-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.edit-icon svg {
    display: block;
}

.edit-icon:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.product-photo {
    width: 160px;
    height: 160px;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.product-photo-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0.5rem;
    background: var(--muted-bg);
    border: 1px dashed var(--border);
    color: var(--text-muted);
    font-size: 0.82rem;
    box-shadow: none;
}

.photo-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-view img {
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
}

.shop-page-address {
    margin: 0 0 1rem;
    color: var(--text-muted);
}

.product-head .shop-count {
    margin: 0;
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
    color: var(--accent);
}

.product-head .shop-count-label {
    margin: 0.25rem 0 0;
    color: var(--text-muted);
}

/* Tighter between the two cross-links than between the tally above and the
   first one. */
.product-cross-link {
    margin: 0.2rem 0 0;
    color: var(--text-muted);
}

.shop-count-label + .product-cross-link {
    margin-top: 0.9rem;
}

.shop-status {
    display: inline-block;
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid transparent;
}

.shop-status-in-stock {
    background: var(--ok-bg);
    color: var(--ok-fg);
}

.shop-status-not-seen,
.shop-status-out-of-business {
    background: var(--muted-bg);
    color: var(--muted-fg);
    border-color: color-mix(in srgb, var(--muted-fg) 45%, transparent);
}

/* Row actions */

.actions a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.82rem;
}

.actions a:hover {
    text-decoration: underline;
}

/* Forms */

form label {
    display: block;
    margin: 1.1rem 0 0.3rem;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-muted);
}

form label:first-child {
    margin-top: 0;
}

form input[type="submit"] {
    margin-top: 1.5rem;
}

.card.padded > p:last-child {
    margin-top: 1.25rem;
}

.card.padded > p:last-child a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.card.padded > p:last-child a:hover {
    color: var(--accent);
}

/* Shop/product pickers */

#shop-picker,
#product-picker,
#address-picker {
    position: relative;
    background: var(--muted-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1.1rem 0;
}

/* Whichever picker's dropdown is open draws above the others stacked
   around it - keyed off the menu actually showing, not a fixed per-picker
   ranking, so a new picker kind needs no z-index of its own. */
#shop-picker:has(.picker-menu:not(:empty)),
#product-picker:has(.picker-menu:not(:empty)),
#brand-picker:has(.picker-menu:not(:empty)),
#address-picker:has(.picker-menu:not(:empty)) {
    z-index: 1;
}

#shop-picker label,
#product-picker label,
#brand-picker label,
#address-picker label {
    margin-top: 0;
}

.picker-combo {
    position: relative;
}

/* While results show, the input and the list read as one dropdown: the input
   drops its bottom edge and both carry the shadow. */
.picker-combo:has(.picker-menu:not(:empty)) {
    box-shadow: var(--shadow);
}

/* The input keeps its bottom border as the line between it and the list. */
.picker-combo:has(.picker-menu:not(:empty)) .picker-input {
    border-color: var(--border);
    border-bottom-color: var(--divider);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: none;
}

.picker-menu:not(:empty) {
    position: absolute;
    left: 0;
    right: 0;
    margin-top: -1px;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top-color: var(--divider);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: var(--shadow);
}

/* Only the results scroll; the add row / hint below them stay pinned. */
.picker-scroll {
    max-height: 15rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Fade the last visible result while there's more to scroll to. */
.picker-scroll.is-clipped {
    mask-image: linear-gradient(to bottom, #000 calc(100% - 2rem), transparent);
}

.picker-result,
.picker-add {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.8rem;
    background: none;
    border: none;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.picker-result:hover,
.picker-result.highlighted,
.picker-add:hover,
.picker-add.highlighted {
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.picker-add,
.picker-more {
    border-top: 1px solid var(--divider);
}

.picker-add:first-child {
    border-top: none;
}

.picker-add {
    color: var(--accent);
}

.picker-more {
    margin: 0;
    padding: 0.5rem 0.8rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.merge-prompt {
    background: var(--muted-bg);
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}

.merge-prompt p {
    margin: 0 0 0.75rem;
}

.merge-prompt input[type="submit"] {
    margin-top: 0;
}

/* Errors */

ul.errors {
    background: var(--danger-bg);
    color: var(--danger-fg);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    margin: 0 0 1.25rem;
    border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}

ul.errors li {
    margin: 0.15rem 0;
}

/* Log in / log out header strip */

.auth-nav {
    max-width: 900px;
    margin: 0 auto;
    padding: 0.6rem 1.25rem 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.auth-nav a {
    color: var(--accent);
    text-decoration: none;
}

.auth-nav a:hover {
    text-decoration: underline;
}

/* Site footer */

.site-footer {
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 2.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 1.25rem;
    font-size: 0.85rem;
}

.site-footer a {
    color: var(--text-muted);
    text-decoration: none;
}

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

/* Legal pages */

.legal {
    max-width: 42rem;
}

.legal h2 {
    font-size: 1.1rem;
    margin: 1.75rem 0 0.5rem;
}

.legal li {
    margin: 0.3rem 0;
}

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

/* Phone-width tweaks: tighter gutters, stacked full-width action buttons
   for easier tapping, smaller headings. */

@media (max-width: 640px) {
    .container {
        padding: 1.25rem 1rem 3rem;
    }

    .page-header h1 {
        font-size: 1.5rem;
    }

    .action-buttons .button {
        flex: 1 1 100%;
        text-align: center;
    }

    table.sightings th,
    table.sightings td {
        padding: 0.6rem;
    }

    .product-title {
        font-size: 1.4rem;
    }

    .product-head .shop-count {
        font-size: 2rem;
    }
}
