/* Lloyds Metals brand: black #231F20, red #E82329 */
:root {
  --chrome: #231F20;   /* top bar, matches the logo background in both themes */
  --accent: #E82329;   /* brand red: active tab, header stripe, counters */
  --brand: #231F20;    /* primary buttons, focus rings */
  --brand-ink: #ffffff;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #17202b;
  --muted: #5f6b7a;
  --line: #dde3ea;
  --ok: #1f8a4c;
  --ok-bg: #e3f4ea;
  --warn: #9a6400;
  --warn-bg: #fff3d6;
  --danger: #c0352b;
  --danger-bg: #fde7e5;
  --info: #0b5cad;
  --info-bg: #e3effc;
  --grey-bg: #eceff3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #ececec;
    --brand-ink: #1a1718;
    --accent: #ff4a4f;
    --bg: #121011;
    --surface: #1c1a1b;
    --ink: #ecebeb;
    --muted: #a7a2a3;
    --line: #353132;
    --ok: #4cc27f; --ok-bg: #143323;
    --warn: #f0b44c; --warn-bg: #3a2d10;
    --danger: #f07167; --danger-bg: #3d1b18;
    --info: #79b4f0; --info-bg: #142a42;
    --grey-bg: #242e3a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.1rem; margin-bottom: 12px; }
small { font-size: .82em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; margin: 12px 0; }
.container { max-width: 880px; margin: 0 auto; padding: 16px; }

/* ---------- top bar & tabs */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--chrome); color: #fff;
  border-bottom: 3px solid var(--accent);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-logo { height: 30px; width: auto; flex: none; display: block; }
.brand-text { padding-left: 14px; border-left: 1px solid rgba(255,255,255,.25); min-width: 0; }
.brand strong { display: block; font-size: .95rem; white-space: nowrap; }
.brand small { opacity: .75; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.who { font-size: .85rem; opacity: .85; margin-right: 4px; }
.btn.icon { padding: 6px 9px; }
@media (max-width: 760px) { .who { display: none; } }
@media (max-width: 560px) {
  .brand-text { display: none; }
  .brand-logo { height: 22px; }
}

.tabs {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 0 12px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 12px 14px; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.tabs a.active { color: var(--ink); border-color: var(--accent); }
.count:not(:empty) {
  display: inline-block; margin-left: 6px; min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: .75rem; line-height: 20px; text-align: center;
}

/* ---------- banners & toast */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; font-size: .9rem; border-bottom: 1px solid var(--line);
}
.banner.info { background: var(--info-bg); color: var(--info); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 150%);
  max-width: min(92vw, 520px); padding: 12px 18px; border-radius: 10px;
  background: #1d2733; color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.25);
  transition: transform .25s ease; z-index: 50; font-weight: 500;
}
.toast.show { transform: translate(-50%, 0); }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }
.toast.warn { background: #a86d00; }

/* ---------- buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.4); color: inherit; }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: .85rem; }
.btn.lg { min-height: 52px; font-size: 1.05rem; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; margin-top: 12px; }

label { display: block; font-size: .88rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 16px; /* prevents iOS zoom */
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.invalid { border-color: var(--danger) !important; background: var(--danger-bg); }
label.check { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 500; }
label.check input { width: 22px; height: 22px; margin: 0; flex: none; }

/* ---------- cards & forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.form { display: grid; gap: 14px; }
.grid2 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.photo-row { display: flex; gap: 14px; align-items: stretch; }
.photo-row .grow { display: grid; gap: 14px; }
.photo-box {
  flex: none; width: 112px; min-height: 132px; border: 2px dashed var(--line); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; text-align: center; cursor: pointer;
  background: var(--bg) center / cover no-repeat; color: var(--muted); font-size: .85rem;
}
.photo-box.has-photo { border-style: solid; }
.photo-box.has-photo .photo-ph { background: rgba(0,0,0,.55); color: #fff; padding: 2px 8px; border-radius: 6px; align-self: flex-end; margin-bottom: 6px; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(100%, 380px); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 22px; text-align: center; box-shadow: var(--shadow); }
.login-card form { display: grid; gap: 14px; margin-top: 20px; text-align: left; }
.login-card { overflow: hidden; }
.login-brand { background: var(--chrome); border-bottom: 3px solid var(--accent); margin: -28px -22px 22px; padding: 22px 24px; }
.login-brand img { display: block; width: 100%; height: auto; }
.hint { font-size: .85rem; color: var(--muted); background: var(--info-bg); padding: 10px; border-radius: 10px; margin-top: 16px; }

/* ---------- stats & lists */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .8rem; color: var(--muted); }
.search { margin: 0 0 12px; }
.list { display: grid; gap: 10px; margin-top: 12px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-icon { font-size: 2.4rem; }

.visit-head { display: flex; gap: 12px; }
.visit-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }
.visit-title h3 { font-size: 1.05rem; }
.meta { font-size: .9rem; overflow-wrap: anywhere; }
.avatar { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; flex: none; background: var(--grey-bg); }
.avatar.big { width: 88px; height: 88px; }
.avatar.ph { display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.extra { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.note { margin-top: 10px; padding: 8px 10px; background: var(--info-bg); color: var(--info); border-radius: 8px; font-size: .9rem; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.host-card .actions { display: grid; justify-content: stretch; }
.host-card .actions .row { flex-wrap: nowrap; }
.pass { margin-right: auto; font-size: .9rem; }
.pass b { font-family: ui-monospace, Menlo, monospace; font-size: 1.15rem; letter-spacing: 2px; background: var(--grey-bg); padding: 2px 8px; border-radius: 6px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.s-pending { background: var(--warn-bg); color: var(--warn); }
.s-approved { background: var(--ok-bg); color: var(--ok); }
.s-rejected { background: var(--danger-bg); color: var(--danger); }
.s-checked_in { background: var(--info-bg); color: var(--info); }
.s-checked_out { background: var(--grey-bg); color: var(--muted); }

/* ---------- admin */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters label { min-width: 140px; }
.filters .grow { min-width: 200px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--bg); color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
.user { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.user.inactive { opacity: .55; }
.pin-form input { width: 110px; margin: 0; padding: 7px 10px; }

/* elements with the hidden attribute must stay hidden even when a rule sets display */
[hidden] { display: none !important; }

/* photo box is a button */
button.photo-box { font: inherit; padding: 0; color: var(--muted); }
button.photo-box:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* live camera dialog */
.cam-modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  padding: 16px; background: rgba(0, 0, 0, .8);
}
.cam-sheet { width: min(100%, 520px); background: var(--surface); border-radius: 16px; padding: 12px; text-align: center; }
.cam-frame { position: relative; aspect-ratio: 3 / 4; max-height: 65vh; margin: 0 auto; background: #000; border-radius: 12px; overflow: hidden; }
@media (min-width: 700px) { .cam-frame { aspect-ratio: 4 / 3; } }
.cam-frame video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-frame video.mirror { transform: scaleX(-1); }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 16px; color: #fff; font-size: .95rem; }
.cam-actions { display: flex; gap: 8px; margin-top: 12px; }

/* solid action buttons keep strong contrast with white text in both themes */
.btn.ok { background: #1f8a4c; border-color: #1f8a4c; color: #fff; }
.btn.danger { background: #c62a2f; border-color: #c62a2f; color: #fff; }
