/* SEC Library. Mobile first; the Sikh Education Council red is the accent. */
:root {
  --brand: #ef1d26;
  --brand-dark: #c4141c;
  --bg: #f6f5f3;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #e2e0dc;
  --ok-bg: #e7f5ea; --ok: #1d6b33;
  --err-bg: #fdecec; --err: #a11218;
  --warn-bg: #fff6e0; --warn: #7a5300;
  --radius: 12px;
  --tabs-h: 60px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161617; --card: #222224; --text: #f2f2f2; --muted: #a0a0a6; --line: #38383b;
    --ok-bg: #173822; --ok: #9be0ad; --err-bg: #4a1517; --err: #ffb3b5; --warn-bg: #3d2f0c; --warn: #f5d58a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Gurmukhi", "Gurmukhi MN", sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
[lang="pa"], [dir="auto"] { font-family: inherit; }
a { color: var(--brand-dark); }
@media (prefers-color-scheme: dark) { a { color: #ff7a80; } }
h1, h2 { line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .5rem;
  background: var(--brand); color: #fff; padding: .5rem 1rem; padding-top: max(.5rem, env(safe-area-inset-top));
  min-height: 52px;
}
.top h1 { flex: 1; font-size: 1.05rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top a { color: #fff; text-decoration: none; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.brand img { background: #fff; border-radius: 6px; padding: 2px; }
.back { font-size: 2rem; line-height: 1; padding: 0 .5rem 0 0; }
.who {
  margin-left: auto; width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.2);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}

main { max-width: 760px; margin: 0 auto; padding: 1rem; }
.page-title { font-size: 1.4rem; margin: .25rem 0 1rem; }

/* Bottom tabs */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current] { color: var(--brand); font-weight: 600; }

/* Cards, notes, flashes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; }
.card > :last-child { margin-bottom: 0; }
.narrow { max-width: 420px; margin: 2rem auto; }
.note { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: .8rem 1rem; color: var(--muted); }
.flash { border-radius: var(--radius); padding: .7rem 1rem; margin: 0 0 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--err-bg); color: var(--err); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash ul { margin: .3rem 0; padding-left: 1.2rem; }
.flash a { color: inherit; font-weight: 600; }
.muted { color: var(--muted); }
small { font-size: .82rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .5rem 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.link { border: 0; background: none; color: var(--brand-dark); padding: .5rem; min-height: 0; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.buttons { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0; }
.buttons.sticky {
  position: sticky; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); background: var(--bg);
  padding: .6rem 0; margin-bottom: 0; z-index: 5;
}
.buttons.sticky .btn { flex: 1; }

/* Forms */
.field { display: block; margin: 0 0 .8rem; flex: 1; min-width: 0; }
.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
.field small { display: block; color: var(--muted); margin-top: .2rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card); width: 100%;
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
input[type="checkbox"], input[type="radio"] { width: 1.2rem; height: 1.2rem; min-height: 0; accent-color: var(--brand); }
input[type="file"] { border: 0; padding: 0; min-height: 0; }
.short { max-width: 7rem; }
.field:has(.short) { flex: 0 0 auto; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 8rem; }
.row-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin: .5rem 0; }
.row-form .field { margin: 0; flex: 1 1 8rem; }
.row-form .btn { flex: 0 0 auto; }
.stack > * { margin-bottom: .7rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin: 0 0 1rem; background: var(--card); }
legend { font-weight: 700; padding: 0 .3rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .4rem .8rem; }
.checks label, .check, .confirm { display: flex; align-items: center; gap: .5rem; }
.confirm { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: .6rem .8rem; margin: 0 0 1rem; font-weight: 600; }
details summary { cursor: pointer; font-weight: 600; padding: .5rem 0; color: var(--brand-dark); }
details.danger summary { color: var(--err); }

/* Search */
.search { display: flex; gap: .5rem; margin: 0 0 1rem; flex-wrap: wrap; }
.search input[type="search"], .search input[name="code"] { flex: 1 1 12rem; }
.filters .row { width: 100%; }
.filters.inline { display: block; }

/* Home */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
.action {
  display: flex; flex-direction: column; gap: .2rem; padding: 1rem; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); text-decoration: none; color: var(--text);
}
.action:first-child { background: var(--brand); border-color: var(--brand); color: #fff; }
.action:first-child span { color: rgba(255,255,255,.85); }
.action span { font-size: .85rem; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin: 0 0 1rem; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem; text-align: center; }
.stats dt { font-size: .75rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 700; }
.links { padding-left: 1.2rem; }
.links li { margin: .4rem 0; }

/* Lists */
.list { list-style: none; padding: 0; margin: 0 0 1rem; }
.list > li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .5rem; }
.list > li > a { display: flex; align-items: center; gap: .75rem; padding: .7rem .8rem; color: var(--text); text-decoration: none; }
.list .main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.list .main > * { overflow-wrap: anywhere; }
.list .count { font-size: 1.2rem; font-weight: 700; text-align: right; display: flex; flex-direction: column; }
.list .count small { font-size: .7rem; font-weight: 600; color: var(--muted); }
.titles img, .noimg { width: 44px; height: 60px; object-fit: cover; border-radius: 4px; flex: 0 0 auto; background: var(--line); }
.list.plain > li { background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: .5rem 0; margin: 0; }
.list.plain > li:last-child { border-bottom: 0; }
.history li { display: flex; gap: .6rem; }
.history small { display: block; }
.delta { font-weight: 700; min-width: 2.5rem; text-align: right; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--err); }

/* Title page */
.title-head { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.title-head .covers { display: flex; gap: .5rem; }
.title-head .covers img { width: 110px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.title-head > div:last-child { flex: 1 1 14rem; }
.book-title { font-size: 1.35rem; margin: 0 0 .3rem; }
.roman { font-size: 1.05rem; color: var(--muted); margin: 0 0 .5rem; }
.tags { display: flex; flex-wrap: wrap; gap: .35rem; margin: .4rem 0; }
.tag { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: .15rem .6rem; font-size: .8rem; }
.tag.loc { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.tag.none { color: var(--muted); }
table.stock { width: 100%; border-collapse: collapse; margin-bottom: .5rem; }
table.stock th, table.stock td { text-align: left; padding: .4rem .3rem; border-bottom: 1px solid var(--line); }
table.stock td:not(:first-child), table.stock th:not(:first-child) { text-align: right; width: 5rem; }
.details { display: grid; grid-template-columns: 1fr; gap: .4rem; margin: 0; }
.details div { display: grid; grid-template-columns: 8rem 1fr; gap: .5rem; }
.details dt { color: var(--muted); font-size: .9rem; }
.details dd { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }

/* Photo capture */
.photos.highlight { border-color: var(--brand); border-width: 2px; }
.photo-pair { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .6rem; }
.photo { display: flex; flex-direction: column; gap: .4rem; align-items: stretch; }
.photo img { aspect-ratio: 2/3; object-fit: cover; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); }
.photo label.btn { font-size: .9rem; }
.photo.busy { opacity: .6; }

/* Scanner */
.scanner { margin-bottom: .8rem; }
.scanner video, .checkout video { width: 100%; max-height: 50vh; object-fit: cover; border-radius: var(--radius); background: #000; margin-bottom: .5rem; }
.scanner-msg { min-height: 1.4em; }
.session-log li { padding: .6rem .8rem; display: flex; gap: .6rem; align-items: center; }
.session-log li .main { flex: 1; }
.session-log li.created { border-left: 4px solid var(--ok); }
.session-log li.draft { border-left: 4px solid #d99a00; }
.session-log li.invalid, .session-log li.failed { border-left: 4px solid var(--err); }
.session-log li.undone { opacity: .5; text-decoration: line-through; }

/* Loans */
.loan { padding: .7rem .8rem; display: flex; flex-direction: column; gap: .15rem; }
.loan-head { display: flex; justify-content: space-between; gap: .5rem; }
.days { font-weight: 700; color: var(--muted); }
.days.old { color: var(--err); }
.lines .line { padding: .7rem .8rem; }
.lines .row { margin-top: .4rem; }
.lines .field { margin: 0; }
.picker li { display: flex; align-items: center; gap: .5rem; padding: .5rem .7rem; }
.picker li .main { flex: 1; }

@media (min-width: 700px) {
  .actions { grid-template-columns: repeat(4, 1fr); }
  .details { grid-template-columns: 1fr 1fr; }
}
