/* ==========================================================================
   THE RED FLAG LIBRARY — Admin / Inventory
   Builds on css/styles.css (design tokens, .btn, .toast).
   ========================================================================== */

body.admin { background: var(--bg-2); color: var(--ink-2); }

/* ---- passcode gate ------------------------------------------------------ */
.gate { position: fixed; inset: 0; z-index: 200; background: var(--dark); display: grid; place-items: center; padding: 1.5rem; }
.gate[hidden] { display: none; }
.gate__card { width: min(380px, 100%); background: var(--bg); border-radius: 16px; padding: 2rem 1.8rem; text-align: center; box-shadow: 0 40px 80px -40px rgba(0,0,0,0.8); }
.gate__logo { width: 62px; height: 62px; border-radius: 50%; margin: 0 auto 1rem; }
.gate__card h1 { font-family: var(--display); font-size: 1.6rem; font-weight: 800; letter-spacing: -0.03em; }
.gate__card > p { font-size: 0.9rem; color: var(--muted); margin: 0.35rem 0 1.2rem; }
.gate__card input { width: 100%; padding: 0.75em 0.9em; border: 1px solid var(--line-2); border-radius: var(--r-sm); margin-bottom: 0.9rem; }
.gate__card input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-tint); }
.gate__err { color: var(--red); font-size: 0.82rem; min-height: 1.1em; margin-bottom: 0.5rem; }
.gate__note { font-size: 0.72rem; color: var(--muted); margin-top: 1.1rem; line-height: 1.5; }

/* ---- header ------------------------------------------------------------- */
.adm-top {
  position: sticky; top: 0; z-index: 40; background: var(--dark); color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem clamp(1rem, 4vw, 2rem);
}
.adm-brand { display: inline-flex; align-items: center; gap: 0.65rem; color: #fff; }
.adm-brand img { width: 34px; height: 34px; border-radius: 50%; }
.adm-brand span { display: flex; flex-direction: column; line-height: 1.15; }
.adm-brand b { font-family: var(--display); font-size: 0.95rem; font-weight: 800; letter-spacing: -0.02em; }
.adm-brand small { font-size: 0.72rem; color: var(--on-dark-muted); letter-spacing: 0.1em; text-transform: uppercase; }
.adm-top__actions { display: flex; gap: 0.5rem; align-items: center; }
.sync { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em; padding: 0.3em 0.7em; border-radius: 999px; white-space: nowrap; }
.sync--ok   { background: rgba(46,158,91,0.16); color: #57d98a; }
.sync--busy { background: rgba(255,255,255,0.12); color: #cfd3d8; }
.sync--warn { background: rgba(255,77,99,0.18); color: #ff8b9c; }
@media (max-width: 560px) { .sync { display: none; } }
.adm-top__actions .btn--ghost { background: transparent; border-color: rgba(255,255,255,0.25); color: #fff; }
.adm-top__actions .btn--ghost:hover { border-color: #fff; background: rgba(255,255,255,0.08); }

.adm-wrap { max-width: 1060px; margin: 0 auto; padding: clamp(1.1rem, 3vw, 2rem) clamp(1rem, 4vw, 2rem) 3rem; display: grid; gap: clamp(1rem, 2.5vw, 1.5rem); }

/* ---- stats -------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.8rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 1.05rem 1.1rem; }
.stat__num { display: block; font-family: var(--display); font-weight: 800; font-size: 1.7rem; color: var(--ink); letter-spacing: -0.03em; line-height: 1.1; }
.stat__lbl { display: block; font-size: 0.76rem; color: var(--muted); margin-top: 0.25rem; }
.stat--warn .stat__num { color: var(--red); }

/* ---- panels ------------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: clamp(1.1rem, 3vw, 1.6rem); }
.panel__head h2 { font-family: var(--display); font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
.panel__head p { font-size: 0.88rem; color: var(--muted); margin-top: 0.25rem; }
.panel__head--row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.panel__head { margin-bottom: 1.1rem; }

/* ---- add row ------------------------------------------------------------ */
.add-row { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: center; }
.manual { display: flex; gap: 0.5rem; flex: 1; min-width: 260px; }
.manual input { flex: 1; padding: 0.7em 0.85em; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--bg); }
.manual input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-tint); }

/* ---- scanner ------------------------------------------------------------ */
.scanner { margin-top: 1.1rem; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: #000; }
.scanner[hidden] { display: none; }
.scanner__stage { position: relative; aspect-ratio: 4/3; max-height: 60vh; background: #000; }
.scanner__stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner__frame {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(78%, 340px); aspect-ratio: 2/1; border: 2px solid rgba(255,255,255,0.9);
  border-radius: 10px; box-shadow: 0 0 0 100vmax rgba(0,0,0,0.45);
}
.scanner__bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.7rem 0.9rem; background: var(--dark); color: #fff; flex-wrap: wrap; }
.scanner__bar p { font-size: 0.85rem; color: var(--on-dark-muted); }
.scanner__bar .btn--ghost { background: transparent; border-color: rgba(255,255,255,0.25); color: #fff; }
.scan-fallback { margin-top: 0.9rem; font-size: 0.85rem; color: var(--ink-2); background: #fff8e6; border: 1px solid #f0dfae; border-radius: var(--r-sm); padding: 0.8rem 0.95rem; }
.scan-fallback[hidden] { display: none; }

/* ---- book form ---------------------------------------------------------- */
.bookform { display: grid; grid-template-columns: 128px 1fr; gap: 1.2rem; }
.bookform__cover { position: relative; aspect-ratio: 2/3; border-radius: var(--r-sm); overflow: hidden; background: var(--bg-2); border: 1px solid var(--line); display: grid; place-items: center; }
.bookform__cover img { width: 100%; height: 100%; object-fit: cover; }
.bookform__cover img[src=""], .bookform__cover img:not([src]) { display: none; }
.bookform__cover span { position: absolute; font-size: 0.75rem; color: var(--muted); }
.f-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }
.f label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--ink); margin-bottom: 0.28rem; }
.f input, .f select { width: 100%; padding: 0.62em 0.75em; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--bg); color: var(--ink); }
.f input:focus, .f select:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-tint); }
.bookform__actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.4rem; }
@media (max-width: 560px) { .bookform { grid-template-columns: 1fr; } .bookform__cover { width: 128px; } }

/* ---- filters ------------------------------------------------------------ */
.filters-row { display: grid; grid-template-columns: 1fr auto auto; gap: 0.6rem; margin-bottom: 1rem; }
.filters-row input, .filters-row select { padding: 0.62em 0.8em; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--bg); color: var(--ink); }
.filters-row input:focus, .filters-row select:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-tint); }
@media (max-width: 640px) { .filters-row { grid-template-columns: 1fr; } }
.tools { display: flex; gap: 0.45rem; flex-wrap: wrap; }

/* ---- inventory list ----------------------------------------------------- */
.inv { display: grid; gap: 0.6rem; }
.inv-row {
  display: grid; grid-template-columns: 46px 1fr auto auto; gap: 0.9rem; align-items: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.7rem 0.85rem;
}
.inv-row.is-low { border-color: #f3c9cf; background: #fffafb; }
.inv-cover { aspect-ratio: 2/3; border-radius: 4px; overflow: hidden; background: var(--bg-2); }
.inv-cover img { width: 100%; height: 100%; object-fit: cover; }
.inv-main { min-width: 0; }
.inv-title { font-weight: 600; color: var(--ink); font-size: 0.94rem; line-height: 1.3; }
.inv-meta { font-size: 0.76rem; color: var(--muted); margin-top: 0.15rem; }
.inv-meta b { color: var(--ink-2); font-weight: 500; }
.inv-badge { display: inline-block; font-size: 0.66rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--red); background: var(--red-tint); border-radius: 4px; padding: 0.12em 0.4em; margin-left: 0.35rem; }
.inv-qty { display: inline-flex; align-items: center; gap: 0.55rem; border: 1px solid var(--line-2); border-radius: 999px; padding: 0.15rem 0.55rem; background: var(--surface); }
.inv-qty button { width: 22px; height: 22px; font-size: 1rem; line-height: 1; color: var(--ink); }
.inv-qty span { min-width: 1.6ch; text-align: center; font-size: 0.9rem; font-weight: 600; color: var(--ink); }
.inv-acts { display: flex; gap: 0.35rem; }
.icon-btn { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; color: var(--muted); transition: background 0.2s, color 0.2s; }
.icon-btn:hover { background: var(--bg-2); color: var(--ink); }
.icon-btn.is-danger:hover { background: var(--red-tint); color: var(--red); }
@media (max-width: 620px) {
  .inv-row { grid-template-columns: 40px 1fr; row-gap: 0.6rem; }
  .inv-qty, .inv-acts { grid-column: 2; justify-self: start; }
  .inv-acts { justify-self: end; margin-top: -2.2rem; }
}
.inv-empty { text-align: center; color: var(--muted); font-size: 0.9rem; padding: 1.6rem 0; }
.inv-empty[hidden] { display: none; }

.adm-foot { font-size: 0.8rem; color: var(--muted); text-align: center; line-height: 1.6; }
.adm-foot b { color: var(--ink-2); }
