/* ============================================================================
   FFL A&D Bound Book — styles
   ========================================================================== */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-contrast: #ffffff;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --ok: #15803d;
  --ok-bg: #f0fdf4;
  --chip: #e2e8f0;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.1), 0 1px 2px rgba(15, 23, 42, 0.06);
  --radius: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Formerly a monospace stack — now mapped to the sans stack so serials,
     entry numbers and detail values render in the same sans-serif font. */
  --mono: var(--sans);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --surface: #111827;
    --surface-2: #0f172a;
    --border: #1f2937;
    --text: #e5e7eb;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #f87171;
    --danger-bg: #3b0d0d;
    --warn: #fbbf24;
    --warn-bg: #3a2c07;
    --ok: #4ade80;
    --ok-bg: #06280f;
    --chip: #1f2937;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.only-mobile { display: none; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
  background: var(--primary); color: var(--primary-contrast);
  padding: 3px 8px; border-radius: 6px; font-size: 13px; letter-spacing: .5px;
}
.brand-logo { height: 28px; width: auto; display: block; background: #fff; padding: 3px 7px; border-radius: 6px; }
/* Logo already shows the business name — hide the redundant text label. */
#brandText { display: none; }
.brand-text { font-size: 15px; }
.main-nav { display: flex; gap: 4px; margin-left: 8px; }
.main-nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--text-muted);
  font-weight: 600; font-size: 14px;
}
.main-nav a:hover { background: var(--surface-2); text-decoration: none; }
.main-nav a.active { background: var(--primary); color: var(--primary-contrast); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip { font-size: 13px; color: var(--text-muted); }

/* ---------- View ---------- */
.view { max-width: 1180px; margin: 0 auto; padding: 22px 18px 80px; }
.page-title { display: flex; align-items: center; gap: 12px; margin: 4px 0 18px; }
.page-title h1 { font-size: 22px; margin: 0; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 8px 14px; border-radius: 8px;
  font-weight: 600; font-size: 14px; cursor: pointer; font-family: inherit;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.icon-btn { background: none; border: none; font-size: 20px; color: var(--text); cursor: pointer; }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; }
.card h3 { margin: 18px 0 10px; font-size: 15px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field .req { color: var(--danger); }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 14px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--primary); outline-offset: -1px; background: var(--surface);
}
.field textarea { resize: vertical; min-height: 64px; }
.field .hint { font-size: 12px; color: var(--text-muted); }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 18px; }
fieldset legend { font-weight: 700; padding: 0 8px; font-size: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); scrollbar-width: none; -ms-overflow-style: none; }
.table-wrap::-webkit-scrollbar { display: none; height: 0; }
.table-wrap.drag-scroll { cursor: grab; }
.table-wrap.drag-scroll.dragging { cursor: grabbing; user-select: none; }
.table-wrap.drag-scroll.dragging * { user-select: none; }
table.book { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.book th, table.book td { padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.book th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); position: sticky; top: 0; cursor: pointer; user-select: none; }
table.book th .arrow { opacity: .5; font-size: 10px; }
table.book tbody tr:hover { background: var(--surface-2); }
table.book td.serial, table.book td.num { font-family: var(--mono); }
table.book tr.disposed td { color: var(--text-muted); }
.row-link { cursor: pointer; }

/* ---------- Badges / status ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-in { background: var(--ok-bg); color: var(--ok); }
.badge-out { background: var(--chip); color: var(--text-muted); }
.badge-offline { background: var(--warn-bg); color: var(--warn); }
.badge-4473-yes { background: var(--ok-bg); color: var(--ok); }
.badge-4473-no { background: var(--warn-bg); color: var(--warn); }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"], .toolbar select { padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 14px; }
.toolbar .grow { flex: 1 1 220px; }
.count-pill { font-size: 13px; color: var(--text-muted); }

/* ---------- Detail / summary rows ---------- */
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--text-muted); font-weight: 600; }
.kv dd { margin: 0; font-family: var(--mono); }
.section-split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand-mark { font-size: 18px; }
.auth-logo { text-align: center; margin-bottom: 18px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 100; font-size: 14px; max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; z-index: 90; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.3); width: 100%; max-width: 480px; padding: 22px; }
.modal h3 { margin: 0 0 12px; }
.modal .form-actions { justify-content: flex-end; }

/* ---------- Boot ---------- */
.boot { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 200; }
.boot.hidden { display: none; }
.boot-inner { text-align: center; color: var(--text-muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Notices ---------- */
.notice { border-radius: var(--radius); padding: 12px 15px; font-size: 14px; margin-bottom: 16px; border: 1px solid transparent; }
.notice-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.notice-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.notice-info { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }

/* ---------- Accordion (Admin) ---------- */
details.acc { margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
details.acc > summary { cursor: pointer; padding: 15px 18px; font-weight: 700; font-size: 16px; list-style: none; display: flex; align-items: center; }
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::before { content: "\25B8"; display: inline-block; margin-right: 10px; color: var(--text-muted); transition: transform .15s; }
details.acc[open] > summary::before { transform: rotate(90deg); }
details.acc > summary:hover { background: var(--surface-2); }
details.acc > .acc-body { padding: 4px 18px 20px; border-top: 1px solid var(--border); }

/* ---------- Chips (reference lists) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip-item { display: inline-flex; align-items: center; gap: 6px; background: var(--chip); border-radius: 999px; padding: 3px 6px 3px 11px; font-size: 13px; }
.chip-item button { border: none; background: var(--border); color: var(--text); border-radius: 50%; width: 18px; height: 18px; cursor: pointer; line-height: 1; font-size: 12px; padding: 0; }
.chip-item button:hover { background: var(--danger); color: #fff; }

/* ---------- Reference-list rows ---------- */
.cat-list { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.cat-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: none; }
.cat-text { flex: 1; font-size: 14px; word-break: break-word; }

/* ---------- Audit list ---------- */
.audit { font-size: 13px; }
.audit-item { border-bottom: 1px solid var(--border); padding: 10px 0; }
.audit-item:last-child { border-bottom: none; }
.audit-when { color: var(--text-muted); font-size: 12px; }
.audit-who { font-weight: 600; }
.audit-change { font-family: var(--mono); font-size: 12.5px; color: var(--text-muted); }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .only-mobile { display: inline-flex; }
  .main-nav { display: none; position: absolute; top: 54px; left: 0; right: 0; flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px; }
  .main-nav.open { display: flex; }
  .form-grid, .section-split { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
  .brand-text { display: inline-block; max-width: 44vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
}

/* ---------- Print (ATF bound-book report) ---------- */
@media print {
  .app-header, .toolbar, .page-actions, .btn, #toast, #modalRoot, .no-print { display: none !important; }
  body { background: #fff; color: #000; font-size: 11px; }
  .view { max-width: none; padding: 0; }
  .table-wrap { border: none; box-shadow: none; overflow: visible; }
  table.book { font-size: 10px; }
  table.book th { position: static; background: #fff; color: #000; border-bottom: 2px solid #000; }
  table.book th, table.book td { white-space: normal; border-color: #999; }
  .print-header { display: block !important; margin-bottom: 10px; }
  .card { border: 1px solid #000; box-shadow: none; }
  @page { margin: 0.5in; }
}
.print-header { display: none; }

/* ---- Resources tab (quick-link tiles) ---- */
.res-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.res-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  color: var(--text);
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.res-tile:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 10px rgba(0,0,0,.08);
  transform: translateY(-1px);
}
.res-tile-title { font-weight: 600; color: var(--primary); }
.res-ext { font-weight: 400; opacity: .7; }
.res-tile-desc { font-size: 13px; color: var(--text-muted); }
