/*
 * Marketboard base styles, the minimal theme: one typeface, near-black on white with one grey,
 * and thin lines only where the structure needs them. No shadows, no round corners.
 * The CSP blocks inline styles, so all styles are in files. lcars.css loads
 * after this file and changes the look. Without it, this file is the full theme.
 *
 * 1. Tokens        5. Catalog        9. Admin
 * 2. Base          6. Tables         10. Payment simulator
 * 3. Layout        7. Cart, checkout 11. htmx states
 * 4. Controls      8. Orders
 */

/* 1. Tokens */
:root {
  --fg: #111;
  --muted: #777;
  --line: #e6e6e6;
  --tile: #f3f3f1;
  --bg: #fff;
  --danger: #b42318;


  --text-sm: .875rem;
  --text-xs: .75rem;
  --gap: clamp(.75rem, 2vw, 1.5rem);
  --space-section: 2.5rem;
  --page-width: 80rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #eee;
    --muted: #8a8a8a;
    --line: #2a2a2a;
    --tile: #1c1c1c;
    --bg: #0f0f0f;
    --danger: #f97066;
  }
}

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

body {
  margin: 0;
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: .2em; }
h1 { font-size: 1.25rem; font-weight: 500; margin: 0 0 .5rem; }
h2, h3 { font-size: 1rem; font-weight: 500; margin: 0 0 1rem; }
p { margin: 0 0 1rem; }
img { display: block; max-width: 100%; }
/* A <picture> only chooses the file: the image keeps its own layout. */
picture { display: contents; }
fieldset { border: 0; padding: 0; margin: 0 0 var(--space-section); min-width: 0; }
legend { font-weight: 500; margin-bottom: 1rem; padding: 0; }
ul.plain, ol.plain { list-style: none; margin: 0; padding: 0; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: var(--text-sm); margin: .4rem 0 0; }
.narrow { max-width: 24rem; }
.tag { font-size: var(--text-xs); padding: .05rem .4rem; border: 1px solid currentColor; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* 3. Layout */
.site-header, main {
  max-width: var(--page-width);
  margin: 0 auto;
  padding-inline: var(--gap);
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: .5rem 1.25rem;
  padding-block: 1.5rem;
}

.brand { font-weight: 600; letter-spacing: .02em; }
.site-nav { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem 1.25rem; }
.site-nav form { display: inline; }

main { padding-block: 1rem 4rem; }
.page-title { margin-bottom: 2rem; }
.page-title + .muted { margin-top: -1.5rem; margin-bottom: 2rem; }
.section-title { margin: var(--space-section) 0 1rem; }
.empty { padding-block: 4rem; text-align: center; color: var(--muted); }

.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2rem; }
.pager a:only-child:last-child:not(:first-child) { margin-left: auto; }

/* 4. Controls */

/* Text fields. Checkboxes, radio buttons and the search field have their own styles. */
:where(input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="search"]), select, textarea) {
  font: inherit;
  color: inherit;
  background: var(--bg);
  padding: .55rem .6rem;
  border: 1px solid var(--line);
  border-radius: 0;
}
:where(input, select, textarea):focus-visible { outline: none; border-color: var(--fg); }
textarea { width: 100%; resize: vertical; }

button, a.button {
  display: inline-block;
  font: inherit;
  cursor: pointer;
  padding: .7rem 1.6rem;
  color: var(--bg);
  background: var(--fg);
  border: 1px solid var(--fg);
  border-radius: 0;
}
a.button:hover { text-decoration: none; opacity: .85; }
button.secondary { color: var(--fg); background: none; }
button:disabled { color: var(--muted); background: none; border-color: var(--line); cursor: default; }
button.link { padding: 0; color: var(--muted); background: none; border: 0; }
button.link:hover { color: var(--fg); }
.site-nav button.link { color: inherit; font-size: inherit; }

/* Forms with one field under another */
.stacked-form label:not(.check),
.checkout-form label {
  display: block;
  font-size: var(--text-sm);
  color: var(--muted);
  margin: 1rem 0 .3rem;
}
.stacked-form :is(input:not([type="checkbox"], [type="radio"], [type="hidden"]), select, textarea),
.checkout-form :is(input, select) { width: 100%; }
.stacked-form button { margin-top: 1.25rem; }
.narrow .stacked-form button { width: 100%; }

label.check { display: flex; gap: .5rem; align-items: baseline; margin: 1rem 0 0; }
label.check input { flex: none; }

/* Messages */
.notice { padding: .8rem 1rem; margin-bottom: 1.5rem; border: 1px solid var(--fg); }
.notice.error { border-color: var(--danger); color: var(--danger); }
/* An open chargeback: a block that staff cannot miss. */
.notice.dispute { border-width: 2px; }
.notice.dispute h2 { margin: 0 0 .5rem; font-size: 1.25rem; }
.notice.dispute p { margin: .25rem 0; }
.field-error { color: var(--danger); font-size: var(--text-sm); margin: .3rem 0 0; }

/* Search: one thin line, no box */
.search { margin-bottom: 2rem; }
.search input {
  width: 100%;
  max-width: 20rem;
  padding: .4rem 0;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}
.search input:focus-visible { outline: none; border-bottom-color: var(--fg); }

/* 5. Catalog */
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
}
@media (max-width: 34rem) { .grid { grid-template-columns: repeat(2, 1fr); } }

.tile { display: block; }
.tile:hover { text-decoration: none; }
.tile-media { aspect-ratio: 1; background: var(--tile); overflow: hidden; }
.tile-media img { width: 100%; height: 100%; object-fit: cover; transition: transform .4s ease; }
.tile:hover img { transform: scale(1.03); }
.tile-meta {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  padding-top: .6rem;
  font-size: .9rem;
}

.price-sale { color: var(--fg); }
.price-sale, s.muted { white-space: nowrap; }
s.muted { margin-left: .25rem; }

/* Category links above the grid: one row, the current one underlined. */
.category-nav { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; max-width: var(--page-width); margin: 0 auto; padding: .5rem var(--gap) 0; }
.category-nav [aria-current="page"] { text-decoration: underline; text-underline-offset: .3em; }

/* Product page: the image beside the details, one above the other on narrow screens */
.product {
  display: grid;
  gap: calc(var(--gap) * 2);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  align-items: start;
}
.product-info { max-width: 28rem; }
.product-info h1 { margin-bottom: 1rem; }
.product-info .price { font-size: 1.05rem; }
.thumbs {
  list-style: none;
  margin: var(--gap) 0 0;
  padding: 0;
  display: grid;
  gap: .5rem;
  grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
}
.thumbs img { aspect-ratio: 1; width: 100%; object-fit: cover; background: var(--tile); }

.add-to-cart { margin-bottom: var(--space-section); }
.added { padding-block: .7rem; margin-bottom: var(--space-section); }
.description { margin-bottom: 2rem; white-space: pre-line; }

/* The variant choice: one row for each variant. The checked row has a dark border. */
.variants { margin-bottom: 1.25rem; }
.variants legend { font-weight: 400; font-size: var(--text-sm); color: var(--muted); margin-bottom: .5rem; }
.variant {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  padding: .75rem .9rem;
  border: 1px solid var(--line);
  cursor: pointer;
}
.variant + .variant { border-top: 0; }
.variant:has(input:checked) { outline: 1px solid var(--fg); outline-offset: -1px; }
.variant.sold-out { cursor: default; color: var(--muted); }
.variant > span:last-child { margin-left: auto; text-align: right; }

.attributes { margin: 0; border-top: 1px solid var(--line); }
.attributes div {
  display: grid;
  grid-template-columns: minmax(6rem, 1fr) 2fr;
  gap: 1rem;
  padding: .6rem 0;
  border-bottom: 1px solid var(--line);
}
.attributes dt { color: var(--muted); }
.attributes dd { margin: 0; }

/* 6. Tables. The class name is historical: all data tables use it. */
.cart { width: 100%; border-collapse: collapse; }
.cart th { font-weight: 400; color: var(--muted); text-align: left; }
.cart th, .cart td { padding: 1rem .75rem 1rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.cart :is(th, td):last-child { padding-right: 0; }
.cart td > .muted { display: block; font-size: var(--text-sm); }
.cart tfoot :is(th, td) { border-bottom: 0; color: var(--fg); padding-block: .6rem; }
.cart tfoot .grand-total :is(th, td) { font-weight: 500; padding-top: 1rem; border-top: 1px solid var(--line); }
.cart .num { text-align: right; white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* Small number fields inside tables */
.qty { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; }
.qty form { display: flex; gap: .5rem; align-items: center; }
.qty input[type="number"], .qty-input { width: 4.5rem; padding: .2rem .35rem; }

/* 7. Cart and checkout */
form.inline { display: inline; margin-left: .5rem; }
.cart-actions { margin-top: 2rem; text-align: right; }

.voucher { max-width: 24rem; margin-top: 2rem; }
.voucher label { display: block; font-size: var(--text-sm); color: var(--muted); margin-bottom: .3rem; }
.voucher-row { display: flex; gap: .5rem; }
.voucher-row input { flex: 1; min-width: 0; text-transform: uppercase; }

.checkout { display: grid; gap: calc(var(--gap) * 2); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 52rem) { .checkout { grid-template-columns: minmax(0, 3fr) minmax(16rem, 2fr); } }
.checkout-form { max-width: 34rem; }
.pay-buttons { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1rem; }
.pay-buttons button { flex: 1 1 12rem; }

.summary { align-self: start; padding: 1.5rem; background: var(--tile); }
.summary ul { list-style: none; margin: 0 0 1rem; padding: 0; }
.summary li, .summary-row { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; margin: 0; }
.summary-row.total { border-top: 1px solid var(--line); padding-top: .8rem; margin-top: .4rem; font-weight: 500; }

/* 8. Orders */
.order-status { padding-bottom: 1.5rem; margin-bottom: .5rem; border-bottom: 1px solid var(--line); }
.order-status .status-label { font-weight: 500; margin-bottom: .25rem; }
.order-status p { margin: 0 0 .25rem; }

/* The progress tracker: a line with a square for each step. The finished steps are dark. */
.tracker {
  list-style: none;
  display: flex;
  max-width: 36rem;
  margin: 0 0 1.5rem;
  padding: 0;
}
.tracker li {
  position: relative;
  flex: 1;
  padding-top: 1.4rem;
  font-size: var(--text-sm);
  color: var(--muted);
}
.tracker li::before {
  content: "";
  position: absolute;
  top: .4rem;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--line);
}
.tracker li::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: .9rem;
  height: .9rem;
  background: var(--bg);
  border: 2px solid var(--line);
}
.tracker li:last-child::before { right: auto; width: 0; }
.tracker li.done { color: var(--fg); }
.tracker li.done::after { background: var(--fg); border-color: var(--fg); }
.tracker li.done:has(+ .done)::before { background: var(--fg); }

/* The timeline on the tracking page, and the entry lists on the admin pages */
.timeline, .entries { list-style: none; margin: 0 0 1.5rem; padding: 0; }
.timeline li, .entries li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.timeline li { display: grid; grid-template-columns: 7.5rem 1fr; gap: 1rem; }
.timeline time, .entries time { color: var(--muted); }
.entries li { font-size: .9rem; }
.entries time { margin-right: .5rem; }
.timeline-title, .timeline-detail { margin: 0; }
.timeline-detail { color: var(--muted); white-space: pre-line; }
@media (max-width: 34rem) { .timeline li { grid-template-columns: 1fr; gap: 0; } }

.order-meta {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  margin-top: var(--space-section);
}
.order-meta h2 { font-size: var(--text-sm); font-weight: 400; color: var(--muted); margin: 0 0 .5rem; }

/* 9. Admin */
.admin { --page-width: 90rem; }
.admin-grid { display: grid; gap: calc(var(--gap) * 2); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 60rem) { .admin-grid { grid-template-columns: minmax(0, 2fr) minmax(18rem, 1fr); } }
.admin-grid h3 { font-size: .95rem; margin: 1.5rem 0 .25rem; }
.admin-grid > :is(section, aside) > .section-title:first-child { margin-top: 0; }

.stats {
  list-style: none;
  padding: 0;
  margin: 0 0 2rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
}
.stats li { background: var(--tile); }
.stats li > a, .stats li:not(:has(a)) { display: block; padding: 1rem 1.25rem; }
.stats strong { display: block; font-size: 1.5rem; font-weight: 500; }
.stats .warning { border-left: 3px solid var(--danger); }

.tabs { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin-bottom: 1.5rem; }
.tabs a[aria-current="page"] { font-weight: 600; text-decoration: underline; text-underline-offset: .3em; }

/* 10. Payment simulator (development only) */
.simulator main { max-width: 26rem; padding-block: 4rem; }
.simulator-badge {
  display: inline-block;
  font-size: .8rem;
  padding: .2rem .5rem;
  border: 1px dashed var(--fg);
  margin-bottom: 2rem;
}
.simulator-lines { list-style: none; padding: 0; margin: 2rem 0 0; }
.simulator-lines li { display: flex; justify-content: space-between; padding: .4rem 0; }
.simulator form { display: flex; flex-direction: column; align-items: flex-start; gap: 1rem; margin-top: 2rem; }

/* 11. htmx states. The CSP blocks inline styles, so htmx does not add its own indicator styles. */
.htmx-request button { opacity: .5; }
.htmx-swapping { opacity: 0; transition: opacity .15s ease-out; }

/* Admin editors */
.title-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 1rem; }
.title-row .page-title { margin-bottom: 1.5rem; }
.editor { max-width: 48rem; }
/* The front page banner. /banner.css sets its colours (src/banner.rs). These are the colours until it loads. */
.site-banner { background: var(--tile); color: var(--fg); padding: .8rem 1rem; margin-bottom: var(--space-section); text-align: center; font-weight: 500; }
.site-banner p { margin: 0; }
.stacked-form input.color-input { width: 4rem; height: 2.5rem; padding: 0; border: 1px solid var(--line); background: none; cursor: pointer; }

.pick-list {
  max-height: 14rem;
  overflow-y: auto;
  padding: .5rem .75rem;
  border: 1px solid var(--line);
}
.pick-list .check { display: block; margin: .25rem 0; }
.sub-fields { padding-left: 1rem; border-left: 2px solid var(--line); }
.action-row { display: grid; gap: calc(var(--gap) * 2); grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); align-items: start; }
.inline-action { margin-top: .5rem; }
.field-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
.variant-card { padding: 1.25rem; border: 1px solid var(--line); margin-bottom: 1rem; max-width: 48rem; }
.variant-card h3 { margin-bottom: .25rem; }
.delete-form { border-top: 1px solid var(--line); margin-top: 1.5rem; padding-top: .5rem; }
.editor fieldset { margin-top: 1.5rem; }
.action-row .delete-form { margin-top: 0; padding-top: 0; border-top: 0; }
button.danger { color: var(--danger); border-color: var(--danger); }
.image-list { list-style: none; padding: 0; margin: 0 0 1.5rem; display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); }
.image-list img { aspect-ratio: 1; width: 100%; object-fit: cover; background: var(--tile); }
.image-list form + form { margin-top: .75rem; }

.stats li > span { display: block; padding: 1rem 1.25rem; }
.stats .stat-label { display: block; color: var(--muted); font-size: var(--text-sm); }

/* Charts (server-drawn SVG). Each chart renders twice. CSS shows the copy that matches the colour scheme. */
.chart { margin-bottom: 1rem; overflow-x: auto; }
/* Each chart shows at its own size, never larger. On a narrow screen it keeps
   a readable size and scrolls to the side. */
.chart svg { display: block; max-width: 100%; min-width: 40rem; height: auto; }
.chart-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .chart-light { display: none; }
  .chart-dark { display: block; }
}
/* The hover labels of the metrics chart (templates/admin/chart_points.svg).
   Each shows the amount of a point: light text in a dark box, and the reverse in dark mode. */
.chart .pt-tip { opacity: 0; pointer-events: none; }
.chart .pt:hover .pt-tip { opacity: 1; }
.chart .pt-dot { fill: var(--bg); }
.chart .pt-box { fill: var(--fg); }
.chart .pt-text { fill: var(--bg); font-family: ui-sans-serif, system-ui, sans-serif; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
details summary { cursor: pointer; color: var(--muted); margin-bottom: .75rem; }
