/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f4f2ed;
  --bg-glow: rgba(196, 150, 60, .10);
  --surface: #ffffff;
  --surface-2: #f2efe8;
  --surface-3: #e9e5db;
  --border: #e3ded3;
  --border-strong: #cdc6b6;
  --text: #1c1d21;
  --muted: #6a6d75;
  --accent: #9a6a12;
  --accent-hover: #845a0c;
  --on-accent: #ffffff;
  --accent-soft: rgba(154, 106, 18, .12);
  --lent: #1e7f55;
  --lent-soft: rgba(30, 127, 85, .12);
  --borrowed: #2b63c4;
  --borrowed-soft: rgba(43, 99, 196, .12);
  --danger: #c0392b;
  --danger-soft: rgba(192, 57, 43, .1);
  --shadow-sm: 0 1px 2px rgba(30, 25, 10, .06);
  --shadow: 0 1px 2px rgba(30, 25, 10, .05), 0 6px 20px rgba(30, 25, 10, .07);
  --shadow-lg: 0 10px 40px rgba(30, 25, 10, .16);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Cinzel", "Cormorant SC", Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d0f13;
    --bg-glow: rgba(227, 182, 90, .07);
    --surface: #151920;
    --surface-2: #1b2028;
    --surface-3: #232933;
    --border: #252b35;
    --border-strong: #343b47;
    --text: #ece9e3;
    --muted: #949aa5;
    --accent: #e3b65a;
    --accent-hover: #efc675;
    --on-accent: #1d1503;
    --accent-soft: rgba(227, 182, 90, .13);
    --lent: #4cc38a;
    --lent-soft: rgba(76, 195, 138, .13);
    --borrowed: #74a7ff;
    --borrowed-soft: rgba(116, 167, 255, .13);
    --danger: #ff6b5b;
    --danger-soft: rgba(255, 107, 91, .12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lg: 0 16px 50px rgba(0, 0, 0, .55);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.5 var(--font);
  color: var(--text);
  background: radial-gradient(1200px 500px at 50% -200px, var(--bg-glow), transparent 70%), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
p { margin: 0; }
img { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { flex: none; }

.container { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  cursor: pointer; text-decoration: none !important;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-icon { width: 30px; padding: 0; background: transparent; border-color: transparent; color: var(--muted); }
.btn-icon:hover { color: var(--text); background: var(--surface-2); }
.btn-icon svg circle { fill: currentColor; stroke: none; }
.btn-clear:hover { color: var(--danger); background: var(--danger-soft); }
.person-head form { margin: 0; display: contents; }
.btn-lg { height: 48px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: .02em; text-decoration: none !important; }
.brand-mark { width: 26px; height: 26px; }
.brand-mark rect:first-child { fill: var(--accent); }
.brand-mark rect:last-child { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }

/* ---------- avatars ---------- */
.avatar {
  --hue: 40;
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; object-fit: cover;
  font-weight: 700; font-size: 15px;
  color: hsl(var(--hue) 60% 22%); background: hsl(var(--hue) 65% 82%);
}
@media (prefers-color-scheme: dark) {
  .avatar { color: hsl(var(--hue) 70% 85%); background: hsl(var(--hue) 35% 28%); }
}
.avatar-xs { width: 20px; height: 20px; font-size: 11px; }

/* ---------- dropdown menus ---------- */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; border-radius: 50%; display: inline-flex; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30;
  min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  animation: pop .12s ease-out;
}
.menu-up .menu-panel { top: auto; bottom: calc(100% + 6px); }
.menu-head { padding: 8px 10px 10px; display: grid; border-bottom: 1px solid var(--border); margin-bottom: 6px; font-size: 14px; }
.menu-panel form { margin: 0; }
.menu-langs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 0 0 6px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
.menu-lang { text-align: center; padding: 6px 8px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none !important; }
.menu-lang:hover { background: var(--surface-2); color: var(--text); }
.menu-lang.active { background: var(--accent-soft); color: var(--accent); }
.menu-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer; font-size: 14px; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: 68px; left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast {
  padding: 12px 16px; border-radius: 12px; font-weight: 500; font-size: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--accent);
  animation: toast 4.5s ease forwards;
}
.toast.ok { border-left-color: var(--lent); }
.toast.error { border-left-color: var(--danger); animation-duration: 8s; }
@keyframes toast {
  0% { opacity: 0; transform: translateY(-8px); }
  6%, 88% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-8px); visibility: hidden; }
}
.notice { padding: 10px 14px; border-radius: 10px; background: var(--surface-2); }
.notice.error { color: var(--danger); background: var(--danger-soft); }

/* ---------- summary / tabs ---------- */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.stat {
  position: relative; display: grid; gap: 2px; text-align: left;
  padding: 18px 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  cursor: pointer; overflow: hidden;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.stat:hover { border-color: var(--border-strong); }
.stat::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--tone); transform: scaleX(0); transition: transform .2s; }
.stat[aria-selected="true"] { border-color: color-mix(in srgb, var(--tone) 45%, var(--border)); box-shadow: var(--shadow); }
.stat[aria-selected="true"]::after { transform: none; }
.stat-lent { --tone: var(--lent); --tone-soft: var(--lent-soft); }
.stat-borrowed { --tone: var(--borrowed); --tone-soft: var(--borrowed-soft); }
.stat-label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-label svg { width: 22px; height: 22px; padding: 4px; border-radius: 7px; background: var(--tone-soft); stroke: var(--tone); fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.stat-value { font-size: 40px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 14px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.search { position: relative; flex: 1; display: flex; align-items: center; }
.search svg { position: absolute; left: 12px; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }

input[type=search], input[type=number], input:not([type]), .input-prefix {
  height: 42px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, .input-prefix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-prefix input:focus { box-shadow: none; }
.input-sm { height: 34px !important; font-size: 14px; }
.search input { width: 100%; padding-left: 38px; }
.search input.input-sm { padding-left: 12px; }
.toggle { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 500; font-size: 14px; white-space: nowrap; text-decoration: none !important; }
.toggle:hover { color: var(--text); }
.toggle-track { width: 36px; height: 21px; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--border-strong); position: relative; transition: background .15s; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm); transition: transform .15s; }
.toggle.on { color: var(--text); }
.toggle.on .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle.on .toggle-thumb { transform: translateX(15px); }

/* ---------- panels & person groups ---------- */
.panel-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.panel { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.panel > .empty, .panel > .no-matches { flex: 1 1 100%; }
/* Absorbs leftover space on the last row so a lone group doesn't stretch full width. */
.panel::after { content: ""; flex: 999 1 0; }
.person-group { flex: 1 1 auto; min-width: min(100%, 360px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.person-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.person-info { display: grid; line-height: 1.3; min-width: 0; }
.person-link { display: flex; align-items: center; gap: 12px; min-width: 0; margin-right: auto; color: inherit; text-decoration: none !important; border-radius: 10px; }
.person-link:hover strong { text-decoration: underline; text-underline-offset: 3px; }

/* person page */
.avatar-lg { width: 64px; height: 64px; font-size: 26px; }
.person-hero { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; margin: 8px 0 20px; }
.person-hero-info { display: grid; gap: 2px; margin-right: auto; min-width: 0; }
.person-hero-info h1 { font-family: var(--font-display); font-size: 28px; overflow-wrap: anywhere; }
.person-hero-info a { font-size: 14px; }
.person-hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.person-hero-actions .btn svg { stroke-width: 2.2; }
.summary-static .stat { text-decoration: none !important; color: inherit; }
.summary-static .stat::after { transform: none; opacity: .6; }
.toolbar-end { justify-content: flex-end; }
.person-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-sm); scroll-margin-top: 80px; }
.person-section-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.person-section-head h2 { display: inline-flex; align-items: center; gap: 10px; font-size: 17px; margin-right: auto; overflow-wrap: anywhere; }
.person-section-head h2 svg { width: 26px; height: 26px; padding: 5px; border-radius: 8px; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.person-section-lent h2 svg { background: var(--lent-soft); stroke: var(--lent); }
.person-section-borrowed h2 svg { background: var(--borrowed-soft); stroke: var(--borrowed); }
.person-section-actions { display: inline-flex; align-items: center; gap: 4px; }
.person-section-empty { padding: 8px 2px 4px; }
.person-info strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-info .muted { font-size: 13px; }
.pill { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill-lent { background: var(--lent-soft); color: var(--lent); }
.pill-borrowed { background: var(--borrowed-soft); color: var(--borrowed); }

/* ---------- card tiles ---------- */
.card-grid { display: flex; flex-wrap: wrap; gap: 18px 16px; }
.tile { display: flex; flex-direction: column; min-width: 0; width: 160px; }
.art {
  position: relative; aspect-ratio: 488 / 680; border-radius: 4.75% / 3.4%;
  background: var(--surface-3); overflow: hidden; box-shadow: var(--shadow);
  transition: transform .2s ease, box-shadow .2s ease;
}
.art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile:hover .art { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.art-fallback { display: grid; place-items: center; height: 100%; padding: 12px; text-align: center; font-weight: 600; color: var(--muted); }

/* Foil & etched sheen */
.finish-foil::after, .finish-etched::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background-size: 300% 300%; background-position: 100% 0;
  mix-blend-mode: color-dodge; opacity: .5;
  transition: background-position .9s ease, opacity .3s;
}
.finish-foil::after {
  background-image: linear-gradient(115deg,
    transparent 25%, rgba(255, 70, 180, .5) 35%, rgba(70, 200, 255, .5) 45%,
    rgba(255, 245, 90, .5) 55%, rgba(80, 255, 160, .45) 65%, transparent 75%);
}
.finish-etched::after {
  background-image: linear-gradient(115deg,
    transparent 25%, rgba(255, 255, 255, .45) 40%, rgba(200, 210, 230, .25) 50%,
    rgba(255, 255, 255, .45) 60%, transparent 75%);
  opacity: .55;
}
.tile:hover .finish-foil::after, .tile:hover .finish-etched::after { background-position: 0 100%; opacity: .65; }
.pick-art.finish-foil::after, .pick-art.finish-etched::after { opacity: .45; animation: sheen 5s ease-in-out infinite alternate; }
@keyframes sheen { from { background-position: 100% 0; } to { background-position: 0 100%; } }

.qty, .finish-tag, .returned-tag {
  position: absolute; z-index: 1;
  font-size: 12px; font-weight: 700; line-height: 1;
  padding: 5px 8px; border-radius: 99px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.qty { top: 8px; right: 8px; background: rgba(10, 10, 12, .78); color: #fff; font-size: 13px; }
.finish-tag { top: 8px; left: 8px; color: #1d1503; background: linear-gradient(100deg, #ffd6f5, #c9f0ff 50%, #fff3b8); }
.finish-etched .finish-tag { background: linear-gradient(100deg, #f4f6fa, #cfd6e2 50%, #f4f6fa); }
.returned-tag { left: 8px; right: 8px; bottom: 8px; text-align: center; background: rgba(20, 110, 70, .88); color: #fff; padding: 7px 8px; }
.tile.returned .art img { filter: grayscale(.85); opacity: .55; }

.tile-body { padding: 10px 2px 8px; display: grid; gap: 2px; }
.tile-name { font-size: 14px; font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile-set { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.set-icon { width: 15px; height: 15px; object-fit: contain; }
@media (prefers-color-scheme: dark) { .set-icon { filter: invert(.85); } }
.tile-when { font-size: 12.5px; color: var(--muted); }
.tile-actions { display: flex; align-items: center; gap: 4px; margin-top: auto; }
.tile-actions form { margin: 0; }
/* Long (translated) labels clip instead of pushing the menu button out of the tile. */
.tile-actions > form, .tile-actions > .return-menu { min-width: 0; }
.tile-actions > form > .btn, .tile-actions > .return-menu > summary { max-width: 100%; overflow: hidden; }
.btn-return { color: var(--lent); }
.btn-return svg { stroke-width: 2.5; }
.tile.returned .tile-actions > form .btn { color: var(--muted); }
.return-menu > summary { border-radius: 8px; }
.return-panel { left: 0; right: auto; display: grid; gap: 10px; padding: 12px; min-width: 210px; }
.return-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.stepper-sm { height: 32px; border-radius: 8px; }
.stepper-sm button { width: 30px; font-size: 16px; }
.stepper-sm input { width: 36px; font-size: 14px; }

/* return several */
.return-dialog {
  width: min(560px, calc(100vw - 32px)); max-height: min(720px, calc(100dvh - 48px));
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.return-dialog[open] { display: flex; animation: pop .15s ease-out; }
.return-dialog::backdrop { background: rgba(8, 9, 12, .55); backdrop-filter: blur(3px); }
.return-dialog form { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; }
.dialog-head h2 { font-size: 18px; }
.dialog-head .btn-icon svg { stroke-width: 2; }
.dialog-body { overflow: auto; padding: 4px 20px 12px; display: grid; gap: 16px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.select-all { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; cursor: pointer; justify-self: start; }
.return-batch { display: grid; gap: 2px; }
.return-batch h3 { font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.return-batch h3 .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.return-line { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; }
.return-line:hover { background: var(--surface-2); }
.return-line:has(input[name=loan_id]:checked) { background: var(--lent-soft); }
.return-pick { flex: 1; min-width: 0; display: grid; grid-template-columns: auto 34px minmax(0, 1fr); align-items: center; gap: 10px; cursor: pointer; }
.return-line .of { font-size: 13px; white-space: nowrap; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--lent); margin: 0; }

/* ---------- empty / no matches ---------- */
.empty { text-align: center; padding: 56px 16px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); display: grid; justify-items: center; gap: 8px; }
.empty h3 { font-size: 18px; margin-top: 8px; }
.empty .btn { margin-top: 12px; }
.empty-art { position: relative; width: 90px; height: 80px; }
.empty-art span { position: absolute; left: 30px; top: 6px; width: 46px; height: 64px; border-radius: 6px; border: 2px solid var(--border-strong); background: var(--surface-2); }
.empty-art span:nth-child(1) { transform: rotate(-14deg) translateX(-18px); }
.empty-art span:nth-child(2) { transform: rotate(0deg); }
.empty-art span:nth-child(3) { transform: rotate(14deg) translateX(18px); border-color: var(--accent); background: var(--accent-soft); }
.no-matches { text-align: center; padding: 32px 0; }

/* ---------- new loan ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 500; font-size: 14px; margin-bottom: 8px; }
.back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.back:hover { color: var(--text); text-decoration: none; }
.page-title { font-family: var(--font-display); font-size: 30px; margin-bottom: 22px; letter-spacing: .01em; }

.loan-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.loan-steps { display: grid; gap: 16px; }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: grid; gap: 16px; box-shadow: var(--shadow-sm); }
.step-title { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; }
.step-num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700; }

.field { display: grid; gap: 6px; position: relative; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-label .muted { font-weight: 400; }
.field.invalid input, .field.invalid .input-prefix { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; }
.input-prefix { display: flex; align-items: center; gap: 2px; padding: 0 0 0 12px; }
.input-prefix > span { color: var(--muted); font-weight: 600; }
.input-prefix input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; padding: 0 12px 0 0; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.segmented label { position: relative; }
.segmented input, .pill-option input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: flex; align-items: center; justify-content: center; gap: 8px; height: 40px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.segmented span svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented input[value=lent]:checked + span svg { stroke: var(--lent); }
.segmented input[value=borrowed]:checked + span svg { stroke: var(--borrowed); }
.segmented input:focus-visible + span, .pill-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px 0 5px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; font-weight: 500; cursor: pointer; }
.chip:hover { border-color: var(--border-strong); }
.chip.active { border-color: var(--accent); background: var(--accent-soft); }

.combo .search input { height: 46px; font-size: 16px; }
.suggestions {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 10; margin: 6px 0 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  max-height: 320px; overflow: auto;
}
.suggestions li { padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.suggestions li:hover, .suggestions li[aria-selected="true"] { background: var(--surface-2); }
.hint { color: var(--muted); font-size: 14px; }

.printings-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 34px; }
.printings-head input { width: 180px; }
.printings {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px;
  max-height: 460px; overflow: auto; padding: 4px; margin: 0 -4px;
}
.printing { position: relative; display: grid; gap: 4px; align-content: start; cursor: pointer; min-width: 0; }
.printing input { position: absolute; opacity: 0; }
.printing-art { display: block; aspect-ratio: 146 / 204; border-radius: 6px; overflow: hidden; background: var(--surface-3); outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .12s, transform .12s; }
.printing-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.printing:hover .printing-art { transform: translateY(-2px); }
.printing input:checked ~ .printing-art { outline-color: var(--accent); }
.printing input:focus-visible ~ .printing-art { outline-color: var(--accent); outline-style: dashed; }
.printing-set { font-size: 12px; font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.printing-meta { font-size: 11.5px; color: var(--muted); }
.printing input:checked ~ .printing-set { color: var(--accent); }

.details-row { display: flex; flex-wrap: wrap; gap: 20px 32px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill-option span { display: inline-flex; align-items: center; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border-strong); font-weight: 600; font-size: 14px; cursor: pointer; background: var(--surface); transition: all .15s; }
.pill-option span:hover { background: var(--surface-2); }
.pill-option input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.pill-option input[value=foil]:checked + span, .pill-option input[value=etched]:checked + span {
  color: #1d1503; border-color: transparent; background: linear-gradient(100deg, #ffd6f5, #c9f0ff 50%, #fff3b8);
}
.pill-option input[value=etched]:checked + span { background: linear-gradient(100deg, #f4f6fa, #cfd6e2 50%, #f4f6fa); }
.stepper { display: inline-flex; align-items: center; height: 38px; border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.stepper button { width: 38px; height: 100%; border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.stepper button:hover { background: var(--surface-2); color: var(--text); }
.stepper input { width: 48px; height: 100%; border: 0; border-radius: 0; text-align: center; padding: 0; font-weight: 600; background: none; -moz-appearance: textfield; }
.stepper input:focus { box-shadow: none; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* card being picked */
.pick { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 20px; align-items: start; padding: 14px; border-radius: 12px; background: var(--surface-2); }
.pick-art { width: 100%; }
.pick-art img { position: absolute; inset: 0; }
.pick-controls { display: grid; gap: 16px; align-content: start; }
.pick-name { font-weight: 600; }
.pick-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; }
.btn-add { height: 38px; border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-add:hover { background: var(--accent); color: var(--on-accent); }

/* this loan */
.cart {
  position: sticky; top: 80px; display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.cart-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cart-head h2 { font-size: 16px; font-weight: 600; }
.cart-who { font-size: 14px; margin-top: -6px; }
.cart-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: min(52vh, 480px); overflow: auto; }
.cart-item { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; }
.cart-item:hover { background: var(--surface-2); }
.cart-item.just-added { animation: added 1.2s ease-out; }
@keyframes added { from { background: var(--accent-soft); } }
.cart-thumb { width: 34px; border-radius: 3px; box-shadow: var(--shadow-sm); }
.cart-thumb img { position: absolute; inset: 0; }
.cart-info { display: grid; min-width: 0; line-height: 1.3; }
.cart-info strong { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-info .muted { font-size: 12px; }
.cart-qty-controls { display: inline-flex; align-items: center; gap: 2px; }
.cart-qty { min-width: 20px; text-align: center; font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.cart-btn { width: 24px; height: 24px; display: inline-grid; place-items: center; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; }
.cart-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.cart-btn:disabled { opacity: .35; cursor: default; }
.cart-remove svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.cart-remove:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }
.cart-empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 18px 8px; font-size: 14px; }
.cart-empty .empty-art { transform: scale(.8); }

/* ---------- login ---------- */
.login-main { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.login-card {
  position: relative; width: min(440px, 100%);
  padding: 120px 32px 32px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow-lg);
  display: grid; justify-items: center; gap: 14px;
}
.login-langs { order: 10; margin-top: 6px; display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-2); }
.login-langs a { padding: 4px 10px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); text-decoration: none !important; }
.login-langs a:hover { color: var(--text); }
.login-langs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.login-card h1 { font-family: var(--font-display); font-size: 26px; letter-spacing: .01em; }
.login-card > p { max-width: 34ch; }
.brand-lg { font-size: 15px; color: var(--accent); text-transform: uppercase; letter-spacing: .14em; }
.brand-lg .brand-mark { width: 20px; height: 20px; }
.fan { position: absolute; top: -44px; left: 50%; width: 0; height: 0; }
.fan-card {
  position: absolute; left: -45px; top: 0; width: 90px; height: 126px; border-radius: 8px;
  border: 3px solid #14110c; box-shadow: var(--shadow-lg); transform-origin: 50% 160%;
}
.fan-card::before { content: ""; position: absolute; inset: 6px 6px 50%; border-radius: 3px; background: rgba(255, 255, 255, .18); }
.fan-card::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: 12px; height: 26px; border-radius: 3px; background: rgba(0, 0, 0, .18); }
.fan-card.c1 { background: linear-gradient(160deg, #6fa8ff, #2c4fa3); transform: rotate(-18deg); }
.fan-card.c2 { background: linear-gradient(160deg, #ffd27a, #b8801f); transform: rotate(0deg) translateY(-8px); z-index: 1; }
.fan-card.c3 { background: linear-gradient(160deg, #ff8a6b, #a8321c); transform: rotate(18deg); }
.fan-card.c2::before { background: linear-gradient(115deg, rgba(255, 120, 200, .45), rgba(120, 220, 255, .45), rgba(255, 250, 150, .45)); }
.tg-widget { min-height: 44px; margin-top: 8px; }
.alt-login { font-size: 13px; }
.dev-login { display: grid; gap: 6px; width: 100%; margin-top: 12px; padding-top: 18px; border-top: 1px dashed var(--border-strong); text-align: left; }
.dev-login-row { display: flex; gap: 8px; }
.dev-login-row .input-prefix { flex: 1; }
.dev-login .btn { height: 42px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .loan-layout { grid-template-columns: 1fr; padding-bottom: 72px; }
  .cart { position: static; }
  /* Keep the submit button reachable while scrolling through editions. */
  .cart #submit { position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: auto; z-index: 15; box-shadow: var(--shadow-lg); }
}
@media (max-width: 600px) {
  .container { padding-top: 16px; }
  .topbar-actions .btn-primary span, .hide-sm { display: none; }
  .topbar-actions .btn-primary { width: 38px; padding: 0; }
  .summary { gap: 10px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 30px; }
  .stat-sub { font-size: 13px; }
  .toolbar { flex-direction: column; align-items: stretch; gap: 12px; }
  .person-group { padding: 12px; border-radius: 12px; }
  .card-grid { gap: 14px 10px; }
  .tile { width: calc(50% - 5px); }
  .step { padding: 16px; }
  .page-title { font-size: 24px; }
  .pick { grid-template-columns: 96px minmax(0, 1fr); gap: 14px; }
  .return-line { flex-wrap: wrap; row-gap: 6px; }
  .return-pick { flex-basis: 100%; }
  .return-line .stepper { margin-left: 72px; }
  .dialog-head, .dialog-body, .dialog-foot { padding-left: 16px; padding-right: 16px; }
  .printings { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .printings-head { flex-wrap: wrap; }
  .printings-head input { width: 100%; }
  .login-card { padding: 110px 20px 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
