/* School Library — clean, readable, phone-first. System fonts only so it works with no internet. */
:root {
  --bg: #f5f2ea; --card: #fffdf8; --card2: #f0ece1; --ink: #1f262d; --muted: #5d6671; --line: #ddd6c6;
  --accent: #1d6b57; --accent-ink: #fff; --accent-soft: #dff0e9;
  --ok: #1d6b57; --ok-bg: #dff0e9; --warn: #8a5a00; --warn-bg: #fdf0cf; --bad: #a53a28; --bad-bg: #f9e0db; --info: #1f5c99; --info-bg: #dfeaf7;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 4px 14px rgba(30, 30, 20, .06);
  --radius: 12px; --side: 232px; --top: 56px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181c; --card: #1c2228; --card2: #232a31; --ink: #e8ebee; --muted: #9aa5b0; --line: #333c45;
    --accent: #55b99b; --accent-ink: #0c1713; --accent-soft: #1f3a32;
    --ok: #6fd0b0; --ok-bg: #1d3a31; --warn: #f0c46a; --warn-bg: #3b2f14; --bad: #ff9985; --bad-bg: #44211b; --info: #8cbcf0; --info-bg: #1c3149;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; }
a { color: var(--accent); }
p { margin: 0 0 .8em; }
small, .muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 6px; }
.ico { display: inline-flex; vertical-align: middle; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--side) 1fr; grid-template-rows: var(--top) 1fr; min-height: 100vh; min-height: 100dvh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; min-width: 0; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; overflow: hidden; display: grid; place-items: center; flex: none; }
.brand .logo img, .login .logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.side { background: var(--card); border-right: 1px solid var(--line); padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: var(--top); height: calc(100vh - var(--top)); height: calc(100dvh - var(--top)); overflow-y: auto; }
.side a, .tabbar a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 500; }
.side a:hover { background: var(--card2); }
.side a[aria-current="page"], .tabbar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.side .sep { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 12px 4px; }
main { padding: 22px clamp(14px, 3vw, 32px) 80px; max-width: 1180px; width: 100%; margin: 0 auto; min-width: 0; }
.tabbar { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .who-name { display: none; }
  .top { gap: 8px; padding: 0 10px; }
  .pill { white-space: nowrap; }
  .side { display: none; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--card); border-top: 1px solid var(--line); overflow-x: auto; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); gap: 2px; scrollbar-width: none; }
  .tabbar a { flex-direction: column; gap: 2px; font-size: .72rem; padding: 6px 10px; min-width: 64px; text-align: center; flex: 1 0 auto; }
  main { padding-bottom: 96px; }
  h1 { font-size: 1.4rem; }
}
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin: 2px 0 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack > * + * { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* ---------- cards, buttons, inputs ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card.flat { box-shadow: none; }
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 9px 15px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; min-height: 42px; text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--card2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .88rem; border-radius: 8px; }
.icon-btn { padding: 8px; min-height: 40px; min-width: 40px; justify-content: center; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-height: 42px; width: 100%; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
textarea { resize: vertical; }
label { font-weight: 600; font-size: .92rem; display: block; margin-bottom: 4px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 14px; }
.field.full { grid-column: 1 / -1; }
.field .hint { display: block; color: var(--muted); margin-top: 3px; }
.field .err { display: block; color: var(--bad); font-weight: 600; min-height: 0; }
.req { color: var(--bad); }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin: 6px 0; }
.searchbox { position: relative; flex: 1 1 260px; }
.searchbox input { padding-left: 40px; font-size: 1.05rem; min-height: 48px; }
.searchbox .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 14px; }
.filters select { width: auto; min-width: 140px; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 650; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); } .b-warn { background: var(--warn-bg); color: var(--warn); } .b-bad { background: var(--bad-bg); color: var(--bad); }
.b-info { background: var(--info-bg); color: var(--info); } .b-neutral { background: var(--card2); color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.tbl { width: 100%; border-collapse: collapse; font-size: .94rem; }
.tbl th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 12px; background: var(--card2); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.tbl tr:hover td { background: color-mix(in srgb, var(--card2) 55%, transparent); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- catalog ---------- */
.books { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.book { display: flex; gap: 12px; padding: 12px; text-decoration: none; color: inherit; align-items: stretch; }
.book:hover { border-color: var(--accent); }
.spine { width: 52px; flex: none; border-radius: 6px 8px 8px 6px; display: grid; place-items: center; color: #fff; font-family: var(--serif); font-weight: 700; font-size: 1.4rem; box-shadow: inset -4px 0 0 rgba(0, 0, 0, .18), inset 3px 0 0 rgba(255, 255, 255, .12); min-height: 78px; }
.book h3 { margin: 0 0 2px; font-size: 1rem; }
.book .meta { color: var(--muted); font-size: .88rem; margin-bottom: 6px; }
.detail { display: grid; grid-template-columns: 120px 1fr; gap: 18px; }
.detail .spine { width: 120px; min-height: 170px; font-size: 3rem; }
@media (max-width: 560px) { .detail { grid-template-columns: 1fr; } .detail .spine { width: 90px; min-height: 120px; font-size: 2.2rem; } }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 10px 0; }
dl.facts dt { color: var(--muted); } dl.facts dd { margin: 0; }

/* ---------- stats / dashboard ---------- */
.stat { padding: 14px 16px; }
.stat .n { font-family: var(--serif); font-size: 2rem; font-weight: 700; line-height: 1; }
.stat .l { color: var(--muted); font-size: .86rem; margin-top: 4px; }
.stat.bad .n { color: var(--bad); } .stat.warn .n { color: var(--warn); } .stat.ok .n { color: var(--ok); }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: minmax(80px, 150px) 1fr 38px; gap: 8px; align-items: center; font-size: .9rem; }
.bar .track { background: var(--card2); border-radius: 99px; height: 10px; overflow: hidden; }
.bar .fill { background: var(--accent); height: 100%; border-radius: 99px; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 70px; }
.spark i { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }

/* ---------- circulation desk ---------- */
.desk { display: grid; gap: 14px; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 900px) { .desk { grid-template-columns: 1fr; } }
.scanbar { display: flex; gap: 8px; }
.scanbar input { font-size: 1.25rem; min-height: 56px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.modes { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.modes button { font: inherit; font-weight: 600; background: var(--card); color: var(--ink); border: 0; padding: 8px 14px; cursor: pointer; min-height: 40px; }
.modes button + button { border-left: 1px solid var(--line); }
.modes button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.feed { display: grid; gap: 8px; margin-top: 12px; }
.feed .item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); animation: pop .18s ease-out; }
.feed .item.ok { border-left: 5px solid var(--ok); } .feed .item.bad { border-left: 5px solid var(--bad); } .feed .item.warn { border-left: 5px solid var(--warn); }
.feed .item .body { flex: 1; min-width: 0; }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } }
.patron-card { display: flex; gap: 12px; align-items: center; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; font-family: var(--serif); font-size: 1.1rem; }
.loan { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.loan:first-child { border-top: 0; }
.loan .t { min-width: 0; } .loan .t strong { display: block; overflow-wrap: anywhere; }
video.scan { width: 100%; max-height: 300px; border-radius: 10px; background: #000; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); border: 2px dashed var(--line); border-radius: var(--radius); }
.empty strong { color: var(--ink); display: block; margin-bottom: 4px; font-family: var(--serif); font-size: 1.1rem; }
.notice { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; border: 1px solid; }
.notice.warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.notice.bad { background: var(--bad-bg); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.notice.info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 35%, transparent); }
.notice.ok { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.pill { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: .84rem; font-weight: 650; padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
.pill.s-ok { color: var(--ok); } .pill.s-off { background: var(--warn-bg); color: var(--warn); border-color: transparent; } .pill.s-err { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.s-sync .dot { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.banner { background: var(--warn-bg); color: var(--warn); padding: 8px 16px; font-weight: 600; text-align: center; font-size: .92rem; }
.banner.info { background: var(--info-bg); color: var(--info); }
.banner button { margin-left: 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.menu { position: absolute; right: 12px; top: calc(var(--top) - 4px); background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 210px; z-index: 40; }
.menu .who { padding: 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu button, .menu a { display: flex; gap: 10px; width: 100%; text-align: left; font: inherit; background: none; border: 0; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--ink); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--card2); }

dialog.dlg { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--card); color: var(--ink); width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog.dlg.wide { width: min(860px, calc(100vw - 24px)); }
dialog.dlg::backdrop { background: rgba(10, 14, 18, .55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px 20px; position: sticky; top: 0; background: var(--card); z-index: 1; }
.dlg-head h2 { margin: 0; }
.dlg-body { padding: 8px 20px 16px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--card); }

.toasts { position: fixed; right: 14px; bottom: 84px; display: grid; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 28px)); }
@media (min-width: 861px) { .toasts { bottom: 18px; } }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 550; transition: opacity .3s, transform .3s; }
.toast.t-ok { background: var(--ok); color: #fff; } .toast.t-bad { background: var(--bad); color: #fff; } .toast.t-warn { background: var(--warn); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent), var(--bg); }
.login .card { width: min(420px, 100%); padding: 28px 24px; }
.login .logo { width: 54px; height: 54px; border-radius: 14px; overflow: hidden; display: grid; place-items: center; margin-bottom: 14px; }
.login h1 { margin-bottom: 4px; }
.login .field + .field { margin-top: 12px; }
.login .btn { width: 100%; justify-content: center; margin-top: 18px; min-height: 48px; }

/* ---------- labels / printing ---------- */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.label { border: 1px dashed var(--line); border-radius: 6px; padding: 8px; background: #fff; color: #000; text-align: center; break-inside: avoid; }
.label svg { max-width: 100%; height: auto; }
.label .lt { font-size: 11px; line-height: 1.2; margin-bottom: 4px; max-height: 2.4em; overflow: hidden; font-weight: 600; }
.label .ls { font-size: 11px; margin-top: 2px; }
@media print {
  .top, .side, .tabbar, .page-head .row, .noprint, .banner, .toasts { display: none !important; }
  .app { display: block; } body { background: #fff; } main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; } .label { border-color: #bbb; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* print-only sheets */
#print-area { display: none; }
@media print {
  body.print-sheet #root, body.print-sheet dialog, body.print-sheet .toasts { display: none !important; }
  body.print-sheet #print-area { display: block; color: #000; background: #fff; }
  body.print-sheet .labels { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .slip { border: 1px dashed #777; padding: 10px 12px; margin: 0 0 8px; break-inside: avoid; font-size: 14px; }
  .slip .pw { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; font-weight: 700; letter-spacing: .04em; }
}
