:root {
  --bg: #faf6f1;
  --surface: #ffffff;
  --ink: #2a2320;
  --muted: #776a62;
  --line: #e7ddd3;
  --brand: #7a1f1f;
  --brand-ink: #ffffff;
  --accent: #e0a526;
  --ok: #2f7a43;
  --ok-bg: #e5f3e8;
  --warn: #9a5b00;
  --warn-bg: #fdf1dc;
  --bad: #b3261e;
  --bad-bg: #fbe5e3;
  --info-bg: #eef1f6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1715;
    --surface: #26201d;
    --ink: #f1e9e2;
    --muted: #b3a59b;
    --line: #3d3430;
    --brand: #c0504a;
    --ok: #7cc58f;
    --ok-bg: #1f3325;
    --warn: #f0b85a;
    --warn-bg: #3a2c14;
    --bad: #f08a80;
    --bad-bg: #3d1f1c;
    --info-bg: #2a2d33;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- top bar */
.topbar {
  background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
.nav a {
  color: var(--brand-ink); text-decoration: none; opacity: .85;
  padding: 6px 10px; border-radius: 8px; white-space: nowrap;
}
.nav a.active { background: rgba(255, 255, 255, .18); opacity: 1; }
.topbar .who { font-size: 13px; opacity: .9; white-space: nowrap; }
.topbar button { background: transparent; color: var(--brand-ink); border-color: rgba(255, 255, 255, .5); }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---------- cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stat { font-size: 28px; font-weight: 700; }
.banner { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.info { background: var(--info-bg); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }

.people { list-style: none; margin: 8px 0 0; padding: 0; }
.people li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }

/* ---------- chips */
.chip {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--info-bg); color: var(--ink); white-space: nowrap;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- forms */
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; text-decoration: none; display: inline-block;
}
button:hover { filter: brightness(.97); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.link { border: none; background: none; color: var(--brand); padding: 4px 6px; }
button:disabled { opacity: .5; cursor: default; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input[type=checkbox] { width: auto; }
textarea { min-height: 60px; }
.field { margin-bottom: 12px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; font-size: 15px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
tr.void td { text-decoration: line-through; color: var(--muted); }
tfoot td { font-weight: 700; }

/* ---------- modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px; padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { margin: 0; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.photos { display: flex; gap: 10px; flex-wrap: wrap; }
.photo { width: 120px; text-align: center; font-size: 12px; }
.photo img { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; background: var(--line); display: block; }
.photo .none { width: 120px; height: 120px; border-radius: 8px; background: var(--info-bg); display: flex; align-items: center; justify-content: center; color: var(--muted); }

.code-big { font: 700 40px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 6px; text-align: center; padding: 16px; background: var(--bg); border-radius: var(--radius); }

.history { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.history li { padding: 6px 0; border-top: 1px solid var(--line); }

/* ---------- login */
.login { max-width: 380px; margin: 10vh auto; }
.login .logo { text-align: center; font-size: 22px; font-weight: 800; color: var(--brand); margin-bottom: 16px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0;
  transition: opacity .2s; pointer-events: none; max-width: 90vw;
}
#toast.show { opacity: 1; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .hide-sm { display: none; }
  th, td { padding: 8px 6px; }
}
.block { display: block; text-decoration: none; }
.mt { margin-top: 10px; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
