/*
 * Stock & Price Tracker
 *
 * Hand-written CSS using BEM naming: .block, .block__element, .block--modifier.
 * One block per component; blocks never style each other's internals.
 */

/* Design tokens */
:root {
    --color-text: #1d2330;
    --color-text-muted: #5b6475;
    --color-background: #f5f6f8;
    --color-surface: #ffffff;
    --color-border: #d9dde4;
    --color-border-subtle: #e8ebf0;
    --color-border-strong: #c3c9d3;
    --color-primary: #6d28d9;
    --color-primary-hover: #5b21b6;
    --color-primary-active: #4c1d95;
    --color-primary-text: #ffffff;
    --color-sidebar: #e8ebf0;
    --color-sidebar-text: #1d2330;
    --color-sidebar-muted: #4a5263;
    --color-sidebar-hover: #dce1e8;
    --color-sidebar-current: #e6dcfa;
    --color-sidebar-current-text: #6d28d9;
    --color-success-text: #1f6b3a;
    --color-success-background: #e3f4e8;
    --color-error-text: #9b1c1c;
    --color-error-background: #fbe7e7;
    --color-danger-border: #e3a5a5;
    --color-danger-active: #7d1515;
    --color-focus: #f2b630;
    --color-row-hover: #f0f3f8;
    --color-in-stock: #1f6b3a;
    --color-in-stock-background: #e3f4e8;
    --color-low-stock: #8a5a00;
    --color-low-stock-background: #fdf1d8;
    --color-attention-background: #fffaeb;
    --color-success-callout-background: #f2fbf5;
    --color-success-callout-border: #a9dbb8;
    --color-attention-border: #f2d27c;
    --color-out-of-stock: #9b1c1c;
    --color-out-of-stock-background: #fbe7e7;
    --color-neutral: #4a5263;
    --color-neutral-background: #eceff3;
    --color-info: #1f5fbf;
    --color-info-background: #e3ecf8;
    --color-paper-shadow: rgb(29 35 48 / 0.18);
    --color-login-glow: rgb(109 40 217 / 0.16);
    --color-login-shadow: rgb(76 29 149 / 0.22);

    --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --font-size-small: 0.875rem;
    --font-size-large: 1.5rem;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    /* Controls (buttons, inputs, links) and the boxes that hold them */
    --radius: 8px;
    --radius-large: 12px;
    --content-width: 72rem;
}

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

body {
    margin: 0;
}

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

/* Links in running text. :where() keeps these weaker than any component's own link styles */
:where(a) {
    color: var(--color-primary);
}

:where(a:hover) {
    color: var(--color-primary-hover);
}

/* Block: page - the document shell */
.page {
    min-height: 100vh;
    font-family: var(--font-body);
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-background);
}

.page__main {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: var(--space-6) var(--space-4) var(--space-8);
}

.page__header {
    margin-bottom: var(--space-6);
}

/* A title on the left and an action button on the right */
.page__header--with-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
}

/* Several buttons on the right of a header with actions */
.page__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.page__title {
    margin: 0;
    font-size: var(--font-size-large);
    font-weight: 600;
}

.page__subtitle {
    margin: var(--space-1) 0 0;
    color: var(--color-text-muted);
}

.page__back {
    display: inline-block;
    margin-bottom: var(--space-2);
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
    text-decoration: none;
}

.page__back:hover {
    color: var(--color-primary);
}

/* Block: brand-mark - the app's logo, a price tag on the accent color */
.brand-mark {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: var(--radius);
    color: var(--color-primary-text);
    background: var(--color-primary);
}

.brand-mark__icon {
    width: 1.125rem;
    height: 1.125rem;
}

.brand-mark--large {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: var(--radius-large);
}

.brand-mark--large .brand-mark__icon {
    width: 2rem;
    height: 2rem;
}

/* Block: sidebar - the main navigation, down the left on wide screens */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    padding: var(--space-4);
    color: var(--color-sidebar-text);
    background: var(--color-sidebar);
}

.sidebar__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 600;
    line-height: 1.25;
    color: inherit;
    text-decoration: none;
}

.sidebar__toggle {
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
    font-size: var(--font-size-small);
    color: var(--color-sidebar-text);
    background: transparent;
    cursor: pointer;
}

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

.sidebar__list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
}

.sidebar__heading {
    margin: var(--space-6) 0 var(--space-2);
    padding: 0 var(--space-3);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-sidebar-muted);
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    color: var(--color-sidebar-muted);
    text-decoration: none;
    transition: background-color 150ms ease, color 150ms ease;
}

@media (prefers-reduced-motion: reduce) {
    .sidebar__link {
        transition: none;
    }
}

/* Decorative: the label beside it is what screen readers announce */
.sidebar__icon {
    flex-shrink: 0;
    width: 1.125rem;
    height: 1.125rem;
}

.sidebar__link:hover {
    color: var(--color-sidebar-text);
    background: var(--color-sidebar-hover);
}

.sidebar__link--current {
    font-weight: 600;
    color: var(--color-sidebar-current-text);
    background: var(--color-sidebar-current);
}

/* Pinned to the bottom of the sidebar */
.sidebar__account {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    margin-top: auto;
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
    font-size: var(--font-size-small);
}

.sidebar__user {
    overflow-wrap: anywhere;
    color: var(--color-sidebar-muted);
}

.sidebar__logout {
    margin: 0;
}

/* Wide screens: a fixed column beside the page that stays put while it scrolls */
@media (min-width: 48rem) {
    .page--with-sidebar {
        display: grid;
        grid-template-columns: 15rem minmax(0, 1fr);
        align-items: start;
    }

    /* A grid item with auto margins shrinks to its content; fill the column instead */
    .page--with-sidebar .page__main {
        width: 100%;
    }

    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        overflow-y: auto;
        border-right: 1px solid var(--color-border);
    }

    .sidebar__toggle {
        display: none;
    }
}

/* Narrow screens: a top bar; the sidebar controller hides the menu until Menu is pressed */
@media (max-width: 47.99rem) {
    .sidebar {
        gap: var(--space-4);
        border-bottom: 1px solid var(--color-border);
    }

    .sidebar--collapsible:not(.sidebar--open) .sidebar__menu {
        display: none;
    }

    /* Pinned to the top while the page scrolls, but only once it collapses:
       without JavaScript the menu is always open and would fill the screen */
    .sidebar--collapsible {
        position: sticky;
        top: 0;
        z-index: 10;
    }

    /* An open menu taller than the screen scrolls by itself, so Log out stays reachable */
    .sidebar--collapsible.sidebar--open {
        max-height: 100dvh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    /* Keeps links to #anchors and focused form errors from landing under the bar */
    :root:has(.sidebar--collapsible) {
        scroll-padding-top: 5rem;
    }
}

/* Block: button */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5625rem var(--space-4);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    font: inherit;
    font-weight: 500;
    line-height: 1.25;
    white-space: nowrap;
    color: var(--color-text);
    text-decoration: none;
    background: var(--color-surface);
    box-shadow: 0 1px 2px rgb(29 35 48 / 0.06);
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.button:hover {
    border-color: var(--color-text-muted);
    background: var(--color-row-hover);
}

.button:active {
    background: var(--color-border-subtle);
}

.button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.button--primary {
    border-color: var(--color-primary);
    color: var(--color-primary-text);
    background: var(--color-primary);
}

.button--primary:hover {
    border-color: var(--color-primary-hover);
    background: var(--color-primary-hover);
}

.button--primary:active {
    border-color: var(--color-primary-active);
    background: var(--color-primary-active);
}

.button--danger {
    border-color: var(--color-danger-border);
    color: var(--color-error-text);
    background: var(--color-error-background);
}

.button--danger:hover {
    border-color: var(--color-error-text);
    color: var(--color-primary-text);
    background: var(--color-error-text);
}

.button--danger:active {
    border-color: var(--color-danger-active);
    background: var(--color-danger-active);
}

/* An icon before the label */
.button--with-icon {
    gap: var(--space-2);
}

.button--small {
    padding: 0.3125rem var(--space-3);
    font-size: var(--font-size-small);
}

/* A quiet button with no fill, for secondary actions */
.button--subtle {
    padding: 0.3125rem var(--space-3);
    border-color: var(--color-border);
    color: var(--color-text);
    background: transparent;
    box-shadow: none;
}

.button--subtle:hover {
    border-color: var(--color-border-strong);
    background: rgb(29 35 48 / 0.05);
}

/* Block: form-field - a label and its input */
.form-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
}

.form-field__label {
    font-size: var(--font-size-small);
    font-weight: 600;
}

.form-field__input {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--color-surface);
}

.form-field__help {
    margin: 0;
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

.form-field__errors {
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--font-size-small);
    color: var(--color-error-text);
}

/* A checkbox inside its label */
.form-field__check {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    font-weight: 600;
}

.form-field--invalid .form-field__input {
    border-color: var(--color-error-text);
}

/* Block: password-field - a password input with a button that shows what was typed */
.password-field {
    position: relative;
    display: flex;
}

.password-field__input {
    flex: 1;
    min-width: 0;
    padding-right: 2.75rem;
}

.password-field__toggle {
    position: absolute;
    top: 1px;
    right: 1px;
    bottom: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    color: var(--color-text-muted);
    background: none;
    cursor: pointer;
    transition: color 0.15s ease;
}

.password-field__toggle:hover {
    color: var(--color-text);
}

.password-field__toggle[hidden] {
    display: none;
}

.password-field__icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* The eye shows the password; once shown, the crossed-out eye hides it again */
.password-field__toggle[aria-pressed="true"] .password-field__icon--show,
.password-field__toggle[aria-pressed="false"] .password-field__icon--hide {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    .password-field__toggle {
        transition: none;
    }
}

/* Block: form - a form on its own page */
.form {
    max-width: 32rem;
    padding: var(--space-6);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    background: var(--color-surface);
}

.form__actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-6);
}

/* A titled set of related fields */
.form__group {
    margin: 0 0 var(--space-6);
    padding: 0;
    border: 0;
}

.form__legend {
    margin-bottom: var(--space-3);
    padding: 0;
    font-weight: 600;
}

/* An explanation at the top of a group of fields */
.form__description {
    margin: 0 0 var(--space-3);
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

.form__note {
    margin: var(--space-4) 0 0;
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

/* Block: form-errors - errors for the whole form, not one field */
.form-errors {
    margin: 0 0 var(--space-4);
    padding: var(--space-3) var(--space-4);
    list-style: none;
    border-radius: var(--radius-large);
    color: var(--color-error-text);
    background: var(--color-error-background);
}

/* Block: flash - a one-off message after a redirect */
.flash {
    margin: 0 0 var(--space-4);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-large);
}

.flash--success {
    color: var(--color-success-text);
    background: var(--color-success-background);
}

.flash--error {
    color: var(--color-error-text);
    background: var(--color-error-background);
}

/* Block: login - the card on the login page (the page uses page--login) */
.page--login {
    display: grid;
    /* A wash of the accent color from the top, over faint price tags */
    background:
        radial-gradient(ellipse 80% 60% at 50% 0%, var(--color-login-glow), transparent 70%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'%3E%3Cg fill='none' stroke='%236d28d9' stroke-opacity='0.07' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cg transform='translate(14 14)'%3E%3Cpath d='M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z'/%3E%3Ccircle cx='7.5' cy='7.5' r='.5'/%3E%3C/g%3E%3Cg transform='translate(86 82) rotate(90 12 12)'%3E%3Cpath d='M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z'/%3E%3Ccircle cx='7.5' cy='7.5' r='.5'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
        var(--color-background);
}

.page--login .page__main {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
}

.login {
    width: 100%;
    max-width: 25rem;
    margin: 0 auto;
    padding: var(--space-8);
    border-radius: var(--radius-large);
    background: var(--color-surface);
    box-shadow: 0 1px 2px var(--color-paper-shadow), 0 12px 32px -8px var(--color-login-shadow);
}

.login__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: var(--space-6);
    text-align: center;
}

.login__title {
    margin: var(--space-3) 0 var(--space-1);
    font-size: var(--font-size-large);
    font-weight: 600;
    line-height: 1.25;
}

.login__tagline {
    margin: 0;
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

.login__error {
    margin: 0 0 var(--space-4);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    color: var(--color-error-text);
    background: var(--color-error-background);
}

.login__submit {
    width: 100%;
}

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

@media (max-width: 47.99rem) {
    .login {
        padding: var(--space-6);
    }
}

/* Block: stats - a row of headline numbers */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
}

.stats__item {
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    background: var(--color-surface);
}

.stats__value {
    display: block;
    font-size: var(--font-size-large);
    font-weight: 600;
}

.stats__label {
    color: var(--color-text-muted);
    font-size: var(--font-size-small);
}

/* A count that is not zero and needs someone to look at it */
.stats__item--attention {
    border-color: var(--color-attention-border);
    background: var(--color-attention-background);
}

.stats__item--attention .stats__value {
    color: var(--color-low-stock);
}

/*
 * A tile that opens a page, like a linked table row: its one link (stats__link)
 * stretches over the tile, stays in the label's color, and the tile lifts on hover.
 */
.stats__item--linked {
    position: relative;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.stats__item--linked:hover {
    border-color: var(--color-border-strong);
    box-shadow: 0 2px 6px rgb(29 35 48 / 0.08);
}

.stats__item--attention.stats__item--linked:hover {
    border-color: var(--color-attention-border);
}

.stats__link,
.stats__link:hover {
    color: var(--color-text-muted);
    text-decoration: none;
}

.stats__link::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius-large);
}

.stats__link:focus-visible {
    outline: none;
}

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

@media (prefers-reduced-motion: reduce) {
    .stats__item--linked {
        transition: none;
    }
}

/* Smaller tiles, e.g. a store's count per stock status */
.stats--compact {
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.stats--compact .stats__item {
    padding: var(--space-3);
}

/* Block: code - identifiers such as ASINs and SKUs */
.code {
    font-family: var(--font-mono);
    font-size: 0.95em;
}

/* Block: unknown-value - a value we don't know yet (NULL), not zero */
.unknown-value {
    color: var(--color-text-muted);
}

/* Block: filter-bar - the search and filter form above a list */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    background: var(--color-surface);
}

.filter-bar__field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 10rem;
}

.filter-bar__field--grow {
    flex: 1 1 16rem;
}

.filter-bar__label {
    font-size: var(--font-size-small);
    font-weight: 600;
}

.filter-bar__input {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--color-surface);
}

/* A group of checkboxes, e.g. stock statuses */
.filter-bar__options {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    margin: 0;
    padding: 0;
    border: 0;
}

.filter-bar__options .filter-bar__label {
    flex-basis: 100%;
    padding: 0;
}

/* A row of related selects under one heading, e.g. one per retailer */
.filter-bar__group {
    display: grid;
    flex-basis: 100%;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: var(--space-2) var(--space-4);
    margin: 0;
    padding: 0;
    border: 0;
}

.filter-bar__group .filter-bar__label:not(.filter-bar__label--minor) {
    padding: 0;
    margin-bottom: var(--space-1);
}

.filter-bar__group .filter-bar__field {
    min-width: 0;
}

.filter-bar__label--minor {
    font-weight: 400;
    color: var(--color-text-muted);
}

@media (max-width: 47.99rem) {
    .filter-bar__group {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.filter-bar__option {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--font-size-small);
    white-space: nowrap;
}

.filter-bar__reset {
    margin-left: auto;
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

.filter-bar__reset:hover {
    color: var(--color-primary);
}

/* The Filters button: narrow screens only, shown by the filters controller */
.filter-bar__toggle {
    display: none;
}

@media (max-width: 47.99rem) {
    .filter-bar__toggle:not([hidden]) {
        display: flex;
        flex-basis: 100%;
        align-items: center;
        justify-content: center;
        padding: 0.5625rem var(--space-4);
        border: 1px solid var(--color-border-strong);
        border-radius: var(--radius);
        font: inherit;
        font-weight: 500;
        color: var(--color-text);
        background: var(--color-surface);
        cursor: pointer;
    }

    /* Collapsed: only the button shows, without the form's box around it */
    .filter-bar--collapsible:not(.filter-bar--open) {
        padding: 0;
        border: 0;
        background: none;
    }

    .filter-bar--collapsible:not(.filter-bar--open) > :not(.filter-bar__toggle) {
        display: none;
    }

    /* Search boxes take the full width; selects pair up */
    .filter-bar__field {
        flex: 1 1 8rem;
        min-width: 0;
    }

    .filter-bar__field--grow {
        flex-basis: 100%;
    }
}

.filter-bar__count {
    margin-left: var(--space-1);
    font-weight: 600;
    color: var(--color-primary);
}

/* Block: result-summary - "Showing 1-50 of 143" */
.result-summary {
    margin: 0 0 var(--space-3);
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

/* Block: data-table - a scrollable table of records */
.data-table {
    overflow-x: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    background: var(--color-surface);
    box-shadow: 0 1px 2px rgb(29 35 48 / 0.05);
}

.data-table__table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-small);
}

.data-table__heading {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--color-text-muted);
    background: var(--color-background);
}

.data-table__heading--numeric {
    text-align: right;
}

.data-table__sort {
    color: inherit;
    text-decoration: none;
}

.data-table__sort:hover {
    color: var(--color-primary);
}

/* The column the table is sorted by */
.data-table__sort--asc,
.data-table__sort--desc {
    color: var(--color-text);
}

.data-table__sort--asc::after {
    content: " ▲";
    font-size: 0.75em;
}

.data-table__sort--desc::after {
    content: " ▼";
    font-size: 0.75em;
}

.data-table__row {
    transition: background-color 150ms ease, border-color 150ms ease;
}

.data-table__row:hover {
    background: var(--color-row-hover);
}

@media (prefers-reduced-motion: reduce) {
    .data-table__row {
        transition: none;
    }
}

.data-table__row + .data-table__row {
    border-top: 1px solid var(--color-border-subtle);
}

.data-table__row--inactive {
    color: var(--color-text-muted);
}

.data-table__cell {
    /* A table cell's height is a minimum: rows are even whether or not they hold a button, and grow for two-line cells */
    height: 3.25rem;
    padding: var(--space-2) var(--space-4);
    vertical-align: middle;
    /* Also row headers (<th scope="row">), which browsers center */
    text-align: left;
}

.data-table__cell--numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* The number that matters most in a row, e.g. profit on the buy list */
.data-table__cell--strong {
    font-weight: 600;
}

/* A secondary line under a cell's main value, e.g. an ASIN or location */
.data-table__meta {
    display: block;
    margin-top: 0.125rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.data-table__cell--code {
    font-family: var(--font-mono);
    white-space: nowrap;
}

.data-table__link {
    color: var(--color-primary);
    text-decoration: none;
}

.data-table__link:hover {
    text-decoration: underline;
}

/*
 * A row that opens one page. Its link (data-table__link--row, one per row) stays a
 * real link, so new-tab clicks and keyboards work, and stretches over the row with
 * a ::after. Names in these rows stay in the text color, without an underline even
 * on hover, so a list isn't a column of accent-colored links; the row's background
 * shows it's clickable.
 */
.data-table__row--linked {
    position: relative;
}

.data-table__link--row,
.data-table__link--row:hover {
    color: inherit;
    font-weight: 500;
    text-decoration: none;
}

.data-table__link--row::after {
    content: "";
    position: absolute;
    inset: 0;
}

/* Focus outlines the whole row */
.data-table__link--row:focus-visible {
    outline: none;
}

.data-table__link--row:focus-visible::after {
    outline: 3px solid var(--color-focus);
    outline-offset: -3px;
}

/* Badges with a tooltip sit above the link, so hovering one still explains it */
.data-table__row--linked [title] {
    position: relative;
    z-index: 1;
}

/* Who verified a listing and when, beside its badge */
.data-table__note {
    display: block;
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

/* A row's buttons, kept on one line */
.data-table__actions {
    display: inline-flex;
    gap: var(--space-2);
    white-space: nowrap;
}

/* An inline form holding a row's button */
.data-table__action {
    display: inline;
    margin: 0;
}

/*
 * Narrow screens: a data-table--cards table shows each row as a card, so no column
 * is hidden off to the side. The data-table__cell--primary cell (usually the
 * product) heads the card and every other cell is labelled with its data-label.
 * Sortable headings become a row of sort links above the cards.
 */
@media (max-width: 47.99rem) {
    .data-table--cards {
        overflow: visible;
        border: 0;
        background: none;
        box-shadow: none;
    }

    .data-table--cards .data-table__table,
    .data-table--cards thead,
    .data-table--cards tbody {
        display: block;
    }

    .data-table--cards thead:not(:has(.data-table__sort)) {
        display: none;
    }

    .data-table--cards thead tr {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2);
        margin-bottom: var(--space-3);
    }

    .data-table--cards thead tr::before {
        content: "Sort by";
        color: var(--color-text-muted);
    }

    .data-table--cards .data-table__heading {
        display: none;
    }

    .data-table--cards .data-table__heading:has(.data-table__sort) {
        display: block;
        padding: 0;
        border: 0;
        font-size: var(--font-size-small);
        font-weight: 500;
        letter-spacing: 0;
        text-transform: none;
        background: none;
    }

    .data-table--cards .data-table__sort {
        display: block;
        padding: var(--space-1) var(--space-3);
        border: 1px solid var(--color-border);
        border-radius: 999px;
        background: var(--color-surface);
    }

    .data-table--cards .data-table__sort--asc,
    .data-table--cards .data-table__sort--desc {
        border-color: var(--color-primary);
        color: var(--color-primary);
    }

    .data-table--cards .data-table__row {
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
        margin-bottom: var(--space-3);
        padding: var(--space-3) var(--space-4);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-large);
        background: var(--color-surface);
        box-shadow: 0 1px 2px rgb(29 35 48 / 0.05);
    }

    .data-table--cards .data-table__row:hover {
        background: var(--color-surface);
    }

    .data-table--cards .data-table__row--linked:hover {
        border-color: var(--color-border-strong);
    }

    .data-table--cards .data-table__link--row::after {
        border-radius: var(--radius-large);
    }

    /* The label floats in the cell's left padding; flow-root keeps a two-line label inside the cell */
    .data-table--cards .data-table__cell {
        display: flow-root;
        height: auto;
        padding: 0 0 0 8rem;
        text-align: left;
        white-space: normal;
    }

    .data-table--cards .data-table__cell[data-label]::before {
        content: attr(data-label);
        float: left;
        width: 7.5rem;
        margin-left: -8rem;
        /* Not a code cell's monospace */
        font-family: var(--font-body);
        color: var(--color-text-muted);
    }

    .data-table--cards .data-table__cell:not([data-label]) {
        padding-left: 0;
    }

    .data-table--cards .data-table__cell--primary {
        order: -1;
        margin-bottom: var(--space-1);
        padding-bottom: var(--space-2);
        border-bottom: 1px solid var(--color-border-subtle);
        font-size: 1rem;
    }
}

/* Block: external-link - a link that opens in a new tab (ui.external_link()) */
.external-link__icon {
    display: inline-block;
    width: 0.875em;
    height: 0.875em;
    margin-left: 0.25em;
    vertical-align: -0.0625em;
}

/* Read by screen readers only */
.external-link__hint {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Block: retailer-list - the retailers a product is listed at, as badges */
.retailer-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Block: badge - a short status label */
.badge {
    display: inline-block;
    padding: 0 var(--space-2);
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
    color: var(--color-neutral);
    background: var(--color-neutral-background);
}

.badge--in-stock {
    color: var(--color-in-stock);
    background: var(--color-in-stock-background);
}

.badge--low-stock {
    color: var(--color-low-stock);
    background: var(--color-low-stock-background);
}

.badge--out-of-stock {
    color: var(--color-out-of-stock);
    background: var(--color-out-of-stock-background);
}

/* Data old enough that it may no longer be true */
.badge--stale {
    margin-right: var(--space-1);
    color: var(--color-low-stock);
    background: var(--color-low-stock-background);
}

/* The store charges its retailer's lower online price */
.badge--price-match {
    margin-right: var(--space-1);
    color: var(--color-info);
    background: var(--color-info-background);
}

/* A setting that is missing, e.g. no sales tax rate for a store */
.badge--warning {
    margin-right: var(--space-1);
    color: var(--color-low-stock);
    background: var(--color-low-stock-background);
}

/* A retailer listing a person has matched to the Amazon product */
.badge--verified {
    color: var(--color-in-stock);
    background: var(--color-in-stock-background);
}

/* On the Buy list; Price gaps also shows stores that aren't */
.badge--worth-buying {
    color: var(--color-success-text);
    background: var(--color-success-background);
}

.badge--below {
    color: var(--color-neutral);
    background: var(--color-neutral-background);
}

/* A retailer listing nobody has checked yet */
.badge--unverified {
    color: var(--color-low-stock);
    background: var(--color-low-stock-background);
}

.badge--retired {
    margin-left: var(--space-1);
    font-weight: 400;
}

/* Block: pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    margin-top: var(--space-4);
    font-size: var(--font-size-small);
}

.pagination__link {
    padding: var(--space-1) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-primary);
    text-decoration: none;
    background: var(--color-surface);
}

.pagination__link:hover {
    border-color: var(--color-primary);
}

.pagination__link--disabled,
.pagination__link--disabled:hover {
    border-color: var(--color-border);
    color: var(--color-text-muted);
}

.pagination__status {
    color: var(--color-text-muted);
}

/* Block: panel - a titled section of a detail page */
.panel {
    margin-bottom: var(--space-6);
}

.panel__title {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2) var(--space-3);
    margin: 0 0 var(--space-3);
    font-size: 1.125rem;
    font-weight: 600;
}

.panel__count {
    font-size: var(--font-size-small);
    font-weight: 400;
    color: var(--color-text-muted);
}

/* A link beside a panel's title, e.g. to the full list */
.panel__link {
    margin-left: auto;
    font-size: var(--font-size-small);
    font-weight: 400;
    color: var(--color-primary);
    text-decoration: none;
}

.panel__link:hover {
    text-decoration: underline;
}

/* A heading for one part of a panel */
.panel__subtitle {
    margin: var(--space-4) 0 var(--space-2);
    font-size: var(--font-size-small);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* A short explanation under a panel's title */
.panel__note {
    margin: 0 0 var(--space-3);
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

.panel__empty {
    margin: 0;
    padding: var(--space-4);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-large);
    color: var(--color-text-muted);
}

/* Block: detail-list - label/value pairs */
.detail-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: var(--space-3) var(--space-6);
    margin: 0;
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    background: var(--color-surface);
}

.detail-list__term {
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

.detail-list__value {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

/* Where a value comes from, e.g. "TN rate" */
.detail-list__note {
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

/* Block: price-chart - the price history line chart on a product page */
.price-chart {
    margin: 0 0 var(--space-4);
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    background: var(--color-surface);
}

/* Chart.js fills its container; the container sets the height */
.price-chart__canvas {
    position: relative;
    height: 20rem;
}

.price-chart__caption {
    margin-top: var(--space-3);
    font-size: var(--font-size-small);
    color: var(--color-text-muted);
}

/* Block: callout - a highlighted note at the top of a page */
.callout {
    margin: 0 0 var(--space-6);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-large);
    background: var(--color-surface);
}

.callout--success {
    border-color: var(--color-success-callout-border);
    background: var(--color-success-callout-background);
}

/* One of several statements in a callout, e.g. a price gap per retailer */
.callout__line {
    margin: 0 0 var(--space-1);
}

.callout__link {
    font-size: var(--font-size-small);
}

/* The verdict itself, e.g. "Worth buying now:" */
.callout__lead {
    color: var(--color-in-stock);
}

/*
 * Block: breakdown - the arithmetic behind a figure, one amount per line and the
 * result last, printed like a till receipt. The paper's torn top and bottom are a
 * mask, which also clips box-shadow, so the shadow is a drop-shadow on the block
 * around it.
 */
.breakdown {
    max-width: 36rem;
    filter: drop-shadow(0 1px 2px var(--color-paper-shadow));
}

.breakdown__paper {
    --tooth: 1rem;

    padding: calc(var(--tooth) / 2 + var(--space-3)) var(--space-2);
    background: var(--color-surface);
    /* A row of 90° teeth along each edge, one per --tooth of width */
    mask:
        conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) top / var(--tooth) 51% repeat-x,
        conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / var(--tooth) 51% repeat-x;
}

.breakdown__table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-small);
}

/* Visible to screen readers; the panel title already names the section */
.breakdown__caption {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.breakdown__label,
.breakdown__amount,
.breakdown__note {
    padding: var(--space-2) var(--space-3);
}

/* On one line; the notes wrap instead */
.breakdown__label {
    text-align: left;
    font-weight: 400;
    white-space: nowrap;
}

.breakdown__amount {
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.breakdown__note {
    color: var(--color-text-muted);
}

/* The till's total: a dashed rule above, a double rule under the amount */
.breakdown__row--total {
    border-top: 1px dashed var(--color-border-strong);
    font-weight: 600;
}

.breakdown__row--total .breakdown__label {
    font-weight: 600;
}

.breakdown__row--total .breakdown__amount {
    text-decoration: underline double;
    text-underline-offset: 0.2em;
}

/* Narrow screens: each note goes under its amount instead of a squeezed third column */
@media (max-width: 47.99rem) {
    .breakdown__table,
    .breakdown__table tbody {
        display: block;
    }

    .breakdown__row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .breakdown__label {
        white-space: normal;
    }

    .breakdown__note {
        grid-column: 1 / -1;
        padding-top: 0;
    }

    .breakdown__note:empty {
        display: none;
    }
}

/* Block: new-token - a just-created API token, shown once */
.new-token {
    margin: 0 0 var(--space-6);
    padding: var(--space-4);
    border: 1px solid var(--color-in-stock);
    border-radius: var(--radius-large);
    background: var(--color-in-stock-background);
}

.new-token__title {
    margin: 0 0 var(--space-2);
    font-size: 1.125rem;
    color: var(--color-in-stock);
}

.new-token__note {
    margin: 0 0 var(--space-3);
}

.new-token__row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.new-token__value {
    flex: 1 1 20rem;
    min-width: 0;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: var(--font-size-small);
    background: var(--color-surface);
}
