/* The look of docs/design: a quiet grey ground, white cards, one teal accent, and a
   colour per kind of category. All sizes follow the 390 px mockups. */
:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #12202b;
  --mute: #5f6e7c;
  --line: #e3e8ed;
  --acc: #0f766e;
  --acc-ink: #0f766e;
  --acc-soft: #e6f4f2;
  --warn: #92440a;
  --warn-soft: #fef3c7;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --seg: #e6ebef;
  --blue-soft: #e6edff; --blue: #2c4fb3;
  --purple-soft: #f3e8ff; --purple: #7a3db8;
  --red-soft: #ffe8e3; --red: #c2410c;
  --grey-soft: #e8ecef; --grey: #37474f;
  --green-soft: #e3f5ee; --green: #0f766e;
  --amber-soft: #fff3d6; --amber: #a16207;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151b; --card: #18222a; --ink: #e8eef2; --mute: #9aacba; --line: #2a3741;
    --acc: #0f766e; --acc-ink: #4fd1c0; --acc-soft: #12332f;
    --warn: #fbbf6a; --warn-soft: #3a2c10; --bad: #ff9d92; --bad-soft: #431c18; --seg: #25313b;
    --blue-soft: #1d2a4d; --blue: #9db4ff; --purple-soft: #33214a; --purple: #cfa6f5;
    --red-soft: #45231a; --red: #ffab8f; --grey-soft: #28343d; --grey: #c3d0d9;
    --green-soft: #12332c; --green: #6fdcbc; --amber-soft: #3b2e0e; --amber: #f2c86b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 30rem;
  margin: 0 auto;
  padding: calc(0.5rem + env(safe-area-inset-top)) calc(1.25rem + env(safe-area-inset-right)) calc(1.5rem + env(safe-area-inset-bottom)) calc(1.25rem + env(safe-area-inset-left));
}
/* room for the bottom navigation (and the scan button on the start page) */
body[data-route="home"] main { padding-bottom: 14rem; }
body[data-route="loans"] main, body[data-route="more"] main { padding-bottom: 7rem; }

h1 { font-size: 1.75rem; line-height: 1.15; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 1.5rem; line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 0.5rem; }
h3, legend { font-size: 0.8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--mute); margin: 0 0 0.5rem; padding: 0; }
p { margin: 0 0 0.75rem; }
a { color: var(--acc-ink); }
ul, ol { padding-left: 1.25rem; }

:focus-visible { outline: 3px solid var(--acc-ink); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons */
button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 2.75rem; padding: 0 1rem;
  border: 1px solid var(--line); border-radius: 0.75rem; background: var(--card);
  font-weight: 600; cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--acc); border-color: var(--acc); color: #fff; }
button.danger { background: #b42318; border-color: #b42318; color: #fff; }
button.wide, .more { width: 100%; }
.button:focus-within { outline: 3px solid var(--acc-ink); outline-offset: 2px; }
button.text-button { background: none; border: 0; padding: 0; color: var(--acc-ink); }
button.danger-text { color: var(--bad); display: flex; margin: 0.5rem auto; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 2.75rem; min-height: 2.75rem; padding: 0; border: 0; border-radius: 0.75rem; background: none; color: inherit; }
.icon-button .ic { width: 1.625rem; height: 1.625rem; }
button.step { width: 2.5rem; min-height: 2.5rem; padding: 0; flex: none; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.75rem 0 0; }

/* Title bars */
#help-link { position: absolute; z-index: 2; top: calc(0.5rem + env(safe-area-inset-top)); right: max(0.5rem, calc(50% - 14.5rem)); color: var(--mute); }
.appbar { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; min-height: 3.5rem; padding-right: 2.25rem; margin-bottom: 0.75rem; }
body[data-route="login"] .appbar { padding-right: 0; }
.appbar p { margin: 0.125rem 0 0; font-size: 0.8125rem; color: var(--mute); }
.topbar { display: flex; align-items: center; min-height: 2.75rem; margin: 0 -0.75rem 0.75rem; }
.topbar-title { flex: 1; margin: 0; padding-right: 0; text-align: center; font-size: 1.125rem; font-weight: 700; }
.topbar::after { content: ""; width: 2.75rem; }
.lang { display: flex; padding: 3px; border-radius: 0.625rem; background: var(--seg); }
.lang button { min-height: 2.125rem; padding: 0 0.625rem; border: 0; border-radius: 0.5rem; background: none; font-size: 0.75rem; color: var(--mute); }
.lang button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.18); }

/* Bottom navigation */
.tabs { position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; padding: 0.5rem 0 calc(0.75rem + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 0.125rem; min-width: 6rem; font-size: 0.75rem; font-weight: 500; color: var(--mute); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--acc-ink); font-weight: 600; }

/* Search and filter */
.search { display: flex; align-items: center; gap: 0.625rem; height: 3rem; padding: 0 0.875rem; margin-bottom: 0.75rem; background: var(--card); border: 1px solid var(--line); border-radius: 0.875rem; color: var(--mute); }
.search:focus-within { outline: 3px solid var(--acc-ink); outline-offset: 2px; }
.search input[type="search"] { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: 0; background: none; color: var(--ink); }
.chips { display: flex; gap: 0.5rem; margin: 0 -1.25rem 0.75rem; padding: 3px 1.25rem; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; min-height: 2.25rem; padding: 0 0.875rem; border-radius: 999px; font-weight: 500; font-size: 0.875rem; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--acc); border-color: var(--acc); color: #fff; }

/* Cards and lists */
.card { display: block; min-width: 0; margin: 0 0 0.75rem; padding: 0.875rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 1rem; }
fieldset.card legend { float: left; width: 100%; }
fieldset.card legend + * { clear: both; }
.item-list, .cards, .rows, .menu, .barcodes, .suggestion-list { list-style: none; margin: 0; padding: 0; }
.item-list { display: flex; flex-direction: column; gap: 0.625rem; margin-bottom: 0.75rem; }
.item-card { display: flex; align-items: center; gap: 0.75rem; margin: 0; padding: 0.75rem; color: inherit; text-decoration: none; }
.item-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.item-card .item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-name { font-weight: 600; }
.item-meta { font-size: 0.8125rem; color: var(--mute); }
.thumb { display: flex; align-items: center; justify-content: center; flex: none; width: 3.375rem; height: 3.375rem; border-radius: 0.75rem; }
.thumb .ic { width: 1.75rem; height: 1.75rem; }
.tone-blue { background: var(--blue-soft); color: var(--blue); }
.tone-purple { background: var(--purple-soft); color: var(--purple); }
.tone-red { background: var(--red-soft); color: var(--red); }
.tone-grey { background: var(--grey-soft); color: var(--grey); }
.tone-green { background: var(--green-soft); color: var(--green); }
.tone-amber { background: var(--amber-soft); color: var(--amber); }
.badge { flex: none; align-self: center; min-width: 1.75rem; padding: 0.25rem 0.5625rem; border-radius: 999px; background: var(--acc-soft); color: var(--acc-ink); font-size: 0.75rem; font-weight: 600; text-align: center; white-space: nowrap; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* Floating buttons of the start page */
.fabs { position: fixed; z-index: 4; right: max(1.25rem, calc(50% - 13.75rem)); bottom: calc(5.75rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
button.fab { width: 4rem; height: 4rem; padding: 0; border: 0; border-radius: 1.375rem; background: var(--acc); color: #fff; box-shadow: 0 10px 24px rgb(15 118 110 / 0.38); }
button.fab .ic { width: 1.875rem; height: 1.875rem; }
button.fab.secondary { width: 3rem; height: 3rem; border-radius: 1rem; border: 1px solid var(--line); background: var(--card); color: var(--acc-ink); box-shadow: 0 6px 16px rgb(18 32 43 / 0.16); }
button.fab.secondary .ic { width: 1.5rem; height: 1.5rem; }

/* Messages */
.notice, .note { padding: 0.75rem 0.875rem; margin-bottom: 0.75rem; border-radius: 0.875rem; background: var(--acc-soft); }
.note { display: flex; gap: 0.625rem; font-size: 0.875rem; }
.note p { margin: 0; }
.note strong { display: block; }
.note .ic { color: var(--acc-ink); }
.error, .field-error { color: var(--bad); }
.field-error { font-size: 0.8125rem; }
.empty { color: var(--mute); }
.suggestion-list li { display: flex; flex-direction: column; gap: 0.125rem; padding: 0.625rem 0; border-top: 1px solid var(--line); }
.suggestion-list button { align-self: flex-start; margin-top: 0.375rem; }
.attribution { font-size: 0.75rem; }
.title-form { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; }

/* Forms */
input[type="search"], input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; min-width: 0; min-height: 3rem; padding: 0 0.875rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 0.75rem;
}
textarea { padding: 0.75rem 0.875rem; resize: vertical; }
select { appearance: none; padding-right: 2.5rem; background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%), linear-gradient(135deg, var(--mute) 50%, transparent 50%); background-position: right 1.25rem center, right 0.875rem center; background-size: 6px 6px; background-repeat: no-repeat; }
fieldset { min-width: 0; margin: 0 0 0.75rem; padding: 0; border: 0; }
.field { display: flex; flex-direction: column; gap: 0.375rem; min-width: 0; margin-bottom: 0.875rem; }
.field .label { font-size: 0.8125rem; font-weight: 600; color: var(--mute); }
.field.checkbox { flex-direction: row; align-items: center; gap: 0.625rem; align-self: end; min-height: 3rem; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); column-gap: 0.75rem; align-items: end; }
.item-meta { overflow: hidden; text-overflow: ellipsis; }
.item-card .item-meta { white-space: nowrap; }
.with-icon { position: relative; display: block; }
.with-icon .ic { position: absolute; top: 50%; left: 0.875rem; width: 1.125rem; height: 1.125rem; transform: translateY(-50%); color: var(--mute); pointer-events: none; }
.with-icon select { padding-left: 2.5rem; }
.stepper { display: flex; align-items: center; gap: 0.375rem; }
.stepper input[type="number"] { flex: 1; text-align: center; font-weight: 600; appearance: textfield; padding: 0 0.25rem; }
.stepper input::-webkit-inner-spin-button { display: none; }
.photo-drop { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 9.375rem; padding: 0.75rem; margin-bottom: 0.875rem; background: var(--card); border: 2px dashed color-mix(in srgb, var(--mute) 45%, transparent); border-radius: 1rem; text-align: center; }
.photo-drop .actions { flex-direction: column; margin: 0; }
.photo-drop #photo-take { flex-direction: column; border: 0; min-height: 4.5rem; color: var(--mute); }
.photo-drop #photo-take .ic { width: 2.125rem; height: 2.125rem; color: var(--acc-ink); }
.photo-drop #photo-choose { border: 0; min-height: 2.25rem; color: var(--acc-ink); font-size: 0.875rem; }

/* The main actions stay at the bottom edge */
.bottom-actions { position: sticky; z-index: 3; bottom: 0; display: flex; gap: 0.625rem; margin: 1rem -1.25rem 0; padding: 0.75rem 1.25rem calc(0.75rem + env(safe-area-inset-bottom)); background: var(--bg); }
.bottom-actions button { flex: 1; min-width: 0; padding: 0 0.5rem; min-height: 3.375rem; border-radius: 1rem; font-size: 1rem; }

/* Switches */
.switch-row input[type="checkbox"], input[type="checkbox"].provider-toggle {
  appearance: none; position: relative; flex: none; width: 3.125rem; height: 1.875rem; margin: 0;
  border-radius: 999px; background: color-mix(in srgb, var(--mute) 40%, var(--card)); cursor: pointer;
}
.switch-row input[type="checkbox"]::after, input[type="checkbox"].provider-toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch-row input[type="checkbox"]:checked, input[type="checkbox"].provider-toggle:checked { background: var(--acc); }
.switch-row input[type="checkbox"]:checked::after, input[type="checkbox"].provider-toggle:checked::after { transform: translateX(1.25rem); }
input:disabled { opacity: 0.45; }
input[type="checkbox"] { width: 1.25rem; height: 1.25rem; accent-color: var(--acc); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Item page */
.hero { display: flex; align-items: center; justify-content: center; height: 10.625rem; margin-bottom: 0.875rem; border-radius: 1.25rem; overflow: hidden; }
.hero .ic { width: 4.375rem; height: 4.375rem; }
.hero img { width: 100%; height: 100%; object-fit: cover; }
.item h2 { margin-bottom: 0.375rem; overflow-wrap: anywhere; }
.item-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.875rem; color: var(--mute); }
.attributes { display: grid; grid-template-columns: auto minmax(0, 1fr); margin: 0; }
.attributes dt, .attributes dd { margin: 0; padding: 0.4375rem 0; border-bottom: 1px solid var(--line); }
.attributes dt { padding-right: 1rem; color: var(--mute); }
.attributes dd { text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.attributes .empty { font-weight: 400; }
.quantity { display: flex; flex-wrap: wrap; align-items: center; gap: 0.625rem; padding-top: 0.625rem; }
.quantity-label { flex: 1; color: var(--mute); }
#qty-text { font-weight: 600; font-size: 0.875rem; text-align: center; }
.notes { margin: 0; white-space: pre-wrap; }

/* Photos */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.75rem; }
.photo { margin: 0; }
.photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 0.75rem; }
.photo.primary img { outline: 3px solid var(--acc); outline-offset: -3px; }
.photo figcaption { margin-top: 0.25rem; font-size: 0.8125rem; color: var(--mute); }
.photo .actions { margin-top: 0.375rem; }
.photo-missing { display: grid; place-items: center; aspect-ratio: 4 / 3; border: 1px dashed var(--mute); border-radius: 0.75rem; color: var(--mute); }

/* Loans: cards on their own page, rows inside the card of an item */
.loan-list { list-style: none; margin: 0; padding: 0; }
.loan { display: flex; flex-direction: column; gap: 0.625rem; padding: 0.625rem 0; border-bottom: 1px solid var(--line); }
.loan-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.loan-head .badge { align-self: flex-start; }
.loan-main { display: flex; flex-direction: column; min-width: 0; }
.loan-list:not(.cards) .loan:last-child { border-bottom: 0; }
.loan-main a { color: inherit; text-decoration: none; }
.cards .loan { margin-bottom: 0.625rem; padding: 0.875rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 1rem; }
button.return { width: 100%; min-height: 2.5rem; }
.lend-form { margin-top: 0.875rem; }
.lend-form h4 { margin: 0 0 0.75rem; font-size: 0.9375rem; }

.locations-page .cards .card .actions { margin-top: 0.5rem; }
.locations-page .danger-text { margin: 0; }
.locations-page [role="alertdialog"] p { margin: 0.5rem 0 0; }

/* Admin tab and category editor */
.card.menu { margin-bottom: 0.75rem; padding: 0.25rem 1rem; }
.menu li + li { border-top: 1px solid var(--line); }
.menu .row { display: flex; align-items: center; justify-content: flex-start; gap: 0.75rem; width: 100%; min-height: 3.25rem; padding: 0; border: 0; border-radius: 0; background: none; color: inherit; text-decoration: none; font-weight: 500; text-align: left; }
.menu .row span:not(.ic) { flex: 1; }
.menu .row .ic:first-child { color: var(--acc-ink); }
.menu .row .ic:last-child { color: var(--mute); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.source { display: flex; align-items: center; gap: 0.5rem; padding: 0.625rem 0; border-top: 1px solid var(--line); }
.moves { display: inline-flex; }
.moves .icon-button { width: 2.25rem; color: var(--mute); }
.moves .ic { width: 1.125rem; height: 1.125rem; }
.schema-field { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 0.5rem; align-items: center; padding: 0.75rem 0; border-top: 1px solid var(--line); }
.schema-field .field-key { grid-column: 1 / 3; }
.schema-field .field-remove { grid-column: 3; justify-self: end; }
.schema-field .required { display: flex; align-items: center; gap: 0.375rem; font-size: 0.875rem; }
.schema-field .field-error { grid-column: 1 / -1; }
.login-hint { color: var(--mute); }

/* Scanner: full screen and dark in both themes, like a camera app */
.overlay { position: fixed; z-index: 10; inset: 0; display: flex; flex-direction: column; overflow: auto; padding: calc(0.5rem + env(safe-area-inset-top)) 1.25rem calc(1rem + env(safe-area-inset-bottom)); background: radial-gradient(120% 80% at 30% 20%, #33414d 0%, #141c24 60%, #0b1117 100%); color: #fff; }
.overlay-head { display: flex; align-items: center; width: 100%; max-width: 27.5rem; margin: 0 auto; }
.overlay-head::after { content: ""; width: 2.75rem; }
.overlay-head .icon-button { margin-left: -0.75rem; }
.overlay-head strong { flex: 1; text-align: center; font-size: 1.125rem; }
.viewfinder { position: relative; display: grid; grid-template-rows: minmax(0, 1fr) auto; flex: 1; width: 100%; max-width: 27.5rem; min-height: 15rem; margin: 0.75rem auto; }
.viewfinder video { width: 100%; height: 100%; min-height: 0; object-fit: cover; border-radius: 1.25rem; background: #000; }
.frame { position: absolute; top: calc(50% - 7.25rem); left: 50%; width: min(17.5rem, 80%); height: 12.5rem; transform: translateX(-50%); pointer-events: none; }
.frame i { position: absolute; width: 2.375rem; height: 2.375rem; border: 0 solid #fff; }
.frame i:nth-child(1) { top: 0; left: 0; border-width: 4px 0 0 4px; border-top-left-radius: 0.5rem; }
.frame i:nth-child(2) { top: 0; right: 0; border-width: 4px 4px 0 0; border-top-right-radius: 0.5rem; }
.frame i:nth-child(3) { bottom: 0; left: 0; border-width: 0 0 4px 4px; border-bottom-left-radius: 0.5rem; }
.frame i:nth-child(4) { bottom: 0; right: 0; border-width: 0 4px 4px 0; border-bottom-right-radius: 0.5rem; }
.frame b { position: absolute; top: calc(50% - 1px); left: 0.75rem; right: 0.75rem; height: 3px; border-radius: 3px; background: #34d3bf; box-shadow: 0 0 14px #34d3bf; }
.hint { margin: 0.75rem 0 0; text-align: center; color: #d7e0e7; }
.scan-error { flex: 1; display: grid; place-content: center; max-width: 22rem; margin: 1rem auto; text-align: center; color: #ffb4aa; }
.overlay-actions { display: flex; flex-direction: column; gap: 0.625rem; width: 100%; max-width: 27.5rem; margin: 0 auto; }
#manual-form, button.glass { display: flex; align-items: center; gap: 0.625rem; min-height: 3.25rem; border-radius: 1rem; border: 1px solid rgb(255 255 255 / 0.22); background: rgb(255 255 255 / 0.14); color: #fff; }
#manual-form { padding: 0 0.375rem 0 1rem; }
#manual-form input { flex: 1; min-width: 0; min-height: 2.75rem; padding: 0; border: 0; background: none; color: #fff; font-weight: 600; }
#manual-form input::placeholder { color: #fff; opacity: 0.85; }
#manual-form button { min-height: 2.5rem; border: 0; background: rgb(255 255 255 / 0.16); color: #fff; }
button.glass { justify-content: center; }
.overlay :focus-visible { outline-color: #34d3bf; }
.overlay-help { margin: 0; text-align: center; }
.overlay-help a { color: #d7e0e7; }

/* Manual */
.manual { max-width: 42rem; }
.manual > .actions { margin: 0 0 1rem; padding-right: 3rem; }
.manual-index { padding-left: 1.5rem; }
.manual-index li { margin: 0.75rem 0; }
.manual-table { overflow-x: auto; }
.manual table { border-collapse: collapse; }
.manual th, .manual td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.manual-image { display: block; width: auto; max-width: min(100%, 22rem); height: auto; margin: 0 auto; border: 1px solid var(--line); border-radius: 0.875rem; }
.manual-nav { display: flex; justify-content: space-between; gap: 1rem; margin: 1.5rem 0; }
.manual-menu { margin-bottom: 1rem; }
.manual-menu > button { width: 100%; justify-content: flex-start; }
.manual-menu > button .ic:last-child { margin-left: auto; transition: transform 0.15s; }
.manual-menu > button[aria-expanded="true"] .ic:last-child { transform: rotate(180deg); }
.manual-menu > button[aria-expanded="false"] + div { display: none; }
#help-chapters { margin-top: 0.5rem; padding: 0.25rem; background: var(--card); border: 1px solid var(--line); border-radius: 0.875rem; }
#help-chapters ol { margin: 0; padding: 0; list-style: none; }
#help-chapters a { display: flex; align-items: center; min-height: 2.75rem; padding: 0.5rem 0.75rem; line-height: 1.3; border-radius: 0.625rem; color: var(--ink); text-decoration: none; }
#help-chapters a[aria-current="page"] { background: var(--acc-soft); color: var(--acc-ink); font-weight: 600; }
#help-chapters .manual-menu-index { color: var(--mute); border-bottom: 1px solid var(--line); border-radius: 0.625rem 0.625rem 0 0; }

/* Tablets: all category chips visible */
@media (min-width: 37.5rem) {
  .chips { flex-wrap: wrap; margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; overflow: visible; }
}

/* Wide screens: the menu on the left replaces the bottom navigation, the content uses the width */
#side-nav { display: none; }
@media (min-width: 56.25rem) {
  body.has-side #side-nav { display: block; }
  body.has-side main { max-width: none; margin: 0 0 0 15rem; padding: 1.5rem 2rem 2rem; }
  body.has-side main > * { max-width: 40rem; }
  body.has-side[data-route="home"] main > *, body.has-side[data-route="loans"] main > *,
  body.has-side[data-route="categories"] main > * { max-width: 110rem; } /* lists use the whole width */
  body.has-side[data-route="item"] main > * { max-width: 75rem; }
  body.has-side #topline, body.has-side #bottom-nav, body.has-side .appbar .lang { display: none; }
  .appbar { padding-right: 0; }

  .side { position: fixed; z-index: 6; top: 0; bottom: 0; left: 0; display: flex; flex-direction: column; gap: 0.25rem; width: 15rem; overflow-y: auto; padding: 1.25rem 0.75rem; background: var(--card); border-right: 1px solid var(--line); }
  .side .brand { margin: 0; padding: 0 0.75rem 1rem; font-size: 1.375rem; font-weight: 700; letter-spacing: -0.02em; }
  .side a, .side button:not(.lang button) { display: flex; flex: none; align-items: center; justify-content: flex-start; gap: 0.75rem; width: 100%; min-height: 2.75rem; padding: 0 0.75rem; border: 0; border-radius: 0.75rem; background: none; color: var(--ink); font-weight: 500; text-align: left; text-decoration: none; }
  .side a:hover, .side button:not(.lang button):hover { background: var(--bg); }
  .side .ic { color: var(--mute); }
  .side a[aria-current="page"] { background: var(--acc-soft); color: var(--acc-ink); font-weight: 600; }
  .side a[aria-current="page"] .ic { color: var(--acc-ink); }
  .side-heading { margin: 1rem 0.75rem 0.25rem; font-size: 0.75rem; font-weight: 600; color: var(--mute); }
  .side .error { margin: 0 0.75rem; font-size: 0.8125rem; }
  .side-foot { display: flex; flex-direction: column; gap: 0.25rem; margin-top: auto; padding-top: 1rem; }
  .side-bottom { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem 0; font-size: 0.8125rem; color: var(--mute); }

  /* Start page: title and actions in one row, then search, filters and the cards in columns */
  body[data-route="home"] .home { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 1rem; align-items: center; }
  .home > .appbar { grid-column: 1; grid-row: 1; }
  .home > .fabs { grid-column: 2; grid-row: 1; position: static; flex-direction: row; margin-bottom: 0.75rem; }
  .home > .search { grid-column: 1 / -1; width: 100%; max-width: 32rem; }
  .home > #filters, .home > #results { grid-column: 1 / -1; min-width: 0; }
  .home button.fab { width: auto; height: auto; min-height: 2.75rem; padding: 0 1.125rem; border-radius: 0.75rem; box-shadow: none; }
  .home button.fab.secondary { width: auto; height: auto; box-shadow: none; color: var(--ink); }
  .home button.fab .ic { width: 1.25rem; height: 1.25rem; }
  .home button.fab .visually-hidden { position: static; width: auto; height: auto; overflow: visible; clip: auto; }

  .item-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr)); gap: 0.75rem; }
  .loans-page .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr)); gap: 0.75rem; align-items: start; }
  .loans-page .cards .loan { margin: 0; }
  .more { width: auto; }

  /* Item page: picture and name left, the cards right */
  .item { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); column-gap: 1.5rem; align-items: start; }
  .item > .topbar, .item > .bottom-actions { grid-column: 1 / -1; }
  .item .hero { height: auto; aspect-ratio: 4 / 3; }

  .topbar { margin-left: -0.75rem; }
  .topbar-title { text-align: left; padding-left: 0.5rem; }
  .topbar::after { display: none; }
  .bottom-actions { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
  .bottom-actions button { flex: 0 1 16rem; }
  .manual > .actions { padding-right: 0; }
  /* Help: the chapter list stays beside the text */
  body.has-side[data-route="help"] main > .manual-page { display: grid; grid-template-columns: 15rem minmax(0, 40rem); column-gap: 2rem; max-width: none; align-items: start; }
  .manual-page > .actions, .manual-menu > button { display: none; }
  .manual-page > .manual-menu { position: sticky; top: 1.5rem; max-height: calc(100vh - 3rem); overflow-y: auto; }
  .manual-menu > button[aria-expanded="false"] + div { display: block; }
  #help-chapters { margin-top: 0; }
  .manual-text > h2 { margin-top: 0.25rem; }
}
