/* Jemar huisstijl: blauw #013e6a, groen #8dc73f.
   Groen nooit als tekstkleur op wit (te weinig contrast): enkel als accent
   of als achtergrond met blauwe tekst. */
:root {
  --jemar-blue: #013e6a;
  --jemar-blue-dark: #012a49;
  --jemar-green: #8dc73f;

  --bg: #eef2f6;
  --surface: #ffffff;
  --text: #13253a;
  --muted: #5b6b7f;
  --border: #d5dde7;
  --primary: var(--jemar-blue);
  --primary-hover: var(--jemar-blue-dark);
  --primary-text: #ffffff;
  --accent: var(--jemar-green);
  --link: var(--jemar-blue);
  --header-bg: #ffffff;
  --nav-bg: var(--jemar-blue);

  /* Scanuitkomsten: groen = huisstijl, oranje/rood blijven voor duidelijkheid aan de inkom */
  --valid-bg: var(--jemar-green);
  --valid-text: var(--jemar-blue);
  --already-bg: #d97706;
  --unknown-bg: #c0262d;
  --idle-bg: var(--jemar-blue);

  --radius: 12px;
  --shadow: 0 1px 2px rgba(1, 62, 106, .06), 0 2px 8px rgba(1, 62, 106, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1622;
    --surface: #12212f;
    --text: #e6edf4;
    --muted: #9aabbd;
    --border: #22364a;
    --primary: #1a5f94;
    --primary-hover: #2470aa;
    --link: var(--jemar-green);
    --header-bg: #12212f;
    --nav-bg: var(--jemar-blue-dark);
    --idle-bg: #0f3557;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 "Segoe UI", "Myriad Pro", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; color: var(--primary); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) h1,
  :root:not([data-theme="light"]) h2, :root:not([data-theme="light"]) h3 { color: var(--text); } }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
[hidden] { display: none !important; }

/* Header: wit met logo */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--header-bg);
  border-bottom: 4px solid var(--accent);
}
.logo { height: 40px; width: auto; flex: none; }
.brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}
.brand-title { font-weight: 700; font-size: 1.05rem; color: var(--link); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand-title { color: var(--text); } }
.brand-user { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Navigatie: blauwe balk, groen accent op het actieve tabblad */
.tabs {
  display: flex;
  background: var(--nav-bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.tabs a {
  flex: 1;
  text-align: center;
  padding: .8rem .5rem;
  color: rgba(255, 255, 255, .75);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 4px solid transparent;
}
.tabs a:hover { color: #fff; }
.tabs a.active { color: #fff; border-bottom-color: var(--accent); }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.center { text-align: center; padding: 2rem 16px; }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: var(--unknown-bg); }

.login { max-width: 420px; margin: 8vh auto 16px; border-top: 6px solid var(--accent); }
.login-logo { width: 220px; max-width: 70%; height: auto; margin-bottom: 1.25rem; }

/* Knoppen */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: .6rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.btn:hover { border-color: var(--primary); }
.btn:focus-visible, .tabs a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--link); border-color: var(--border); }
.btn-lg { font-size: 1.1rem; padding: .9rem 1.5rem; }
.btn-sm { min-height: 36px; padding: .35rem .8rem; font-size: .9rem; }
.btn-present { background: var(--valid-bg); border-color: var(--valid-bg); color: var(--valid-text); }

input[type=text], input[type=search], select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .55rem .75rem;
  min-height: 44px;
  min-width: 0;
}

.row { display: flex; gap: .5rem; flex-wrap: wrap; }
.row input { flex: 1 1 12rem; }

/* Scanner */
.scanner-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
#reader { width: 100%; min-height: 120px; }

/* Startknop over het (nog zwarte) camerabeeld */
.scan-start {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  width: 100%;
  min-height: 220px;
  border: 0;
  background: var(--jemar-blue);
  color: #fff;
  font: inherit;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
}
.scan-start:hover { background: var(--jemar-blue-dark); }
.scan-start:focus-visible { outline: 3px solid var(--accent); outline-offset: -6px; }
.scan-start-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--jemar-blue);
}
#reader video { display: block; width: 100% !important; }

.scan-result {
  padding: 1.1rem 16px;
  color: #fff;
  background: var(--idle-bg);
  text-align: center;
  transition: background .15s;
}
.scan-result-title { font-size: 1.6rem; font-weight: 800; }
.scan-result-detail { font-size: 1.05rem; opacity: .95; word-break: break-word; white-space: pre-line; }
.scan-result-detail::first-line { font-size: 1.3rem; font-weight: 700; }
.scan-result[data-state=valid] { background: var(--valid-bg); color: var(--valid-text); }
.scan-result[data-state=already] { background: var(--already-bg); }
.scan-result[data-state=unknown],
.scan-result[data-state=error] { background: var(--unknown-bg); }
.scan-result[data-state=busy] { background: var(--idle-bg); opacity: .85; }

.scanner-controls { display: flex; gap: .5rem; margin-bottom: 16px; }
.scanner-controls .btn { flex: 1; }
#btn-camera-toggle { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
#btn-camera-toggle:hover { background: var(--primary-hover); }

.manual { margin-bottom: 16px; }
.manual label { display: block; font-weight: 600; margin-bottom: .35rem; }

.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: .75rem;
  padding: .45rem 0 .45rem .6rem;
  border-bottom: 1px solid var(--border);
  border-left: 4px solid transparent;
  font-size: .92rem;
}
.history li:last-child { border-bottom: 0; }
.h-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.h-label { font-weight: 700; }
.h-detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-valid { border-left-color: var(--valid-bg) !important; }
.h-already, .h-duplicate { border-left-color: var(--already-bg) !important; }
.h-unknown, .h-error, .h-notRegistered { border-left-color: var(--unknown-bg) !important; }

/* Overzicht */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  text-align: center;
}
.stat:nth-child(2) { border-top-color: var(--accent); }
.stat-value { display: block; font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--link); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .stat-value { color: var(--text); } }
.stat-label { color: var(--muted); font-size: .85rem; }

.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }

/* Telling */
.count-panel { border-top: 4px solid var(--accent); }
.count-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .5rem; }
.count-head h2 { margin: 0; }
.count-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.count-table th, .count-table td { padding: .55rem .5rem; border-bottom: 1px solid var(--border); }
.count-table thead th { font-size: .85rem; color: var(--muted); font-weight: 600; text-align: right; }
.count-table tbody th { text-align: left; font-weight: 600; }
.count-table td { text-align: right; font-size: 1.1rem; }
.count-table tr.count-main td { font-size: 1.5rem; font-weight: 800; color: var(--link); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .count-table tr.count-main td { color: var(--text); } }
.count-table tbody tr:last-child th, .count-table tbody tr:last-child td { border-bottom: 0; }
@media (max-width: 600px) {
  .count-table thead { display: none; }
  .count-table tr { display: grid; grid-template-columns: repeat(3, 1fr); gap: .25rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
  .count-table tbody tr:last-child { border-bottom: 0; }
  .count-table tbody th { grid-column: 1 / -1; border: 0; padding: 0; }
  .count-table td { border: 0; padding: 0; text-align: left; display: flex; flex-direction: column; }
  .count-table td::before { content: attr(data-label); font-size: .75rem; font-weight: 400; color: var(--muted); }
}
.toolbar input { flex: 1 1 12rem; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .85rem; color: #fff; background: var(--primary); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table tr.is-present td:first-child { box-shadow: inset 4px 0 0 var(--accent); }

@media (max-width: 600px) {
  .table thead { display: none; }
  .table tr { display: block; padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
  .table tr.is-present { box-shadow: inset 4px 0 0 var(--accent); }
  .table tr.is-present td:first-child { box-shadow: none; }
  .table td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem 0; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; flex: none; }
  .table td[colspan]::before { content: none; }
}

/* Live */
.live-status {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 12px;
  padding: .35rem .8rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: .85rem;
  color: var(--muted);
}
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: live-pulse 2s ease-in-out infinite; }
.live-error .live-dot { background: var(--unknown-bg); animation: none; }
.live-error { color: var(--unknown-bg); border-color: var(--unknown-bg); }
@keyframes live-pulse { 50% { opacity: .3; } }

.progress { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .6s ease; }
#live-progress-text { margin: .4rem 0 16px; }

.notice {
  background: #fff7e6;
  color: #7a4b00;
  border: 1px solid #f3d29a;
  border-radius: 8px;
  padding: .6rem .8rem;
  font-size: .9rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .notice { background: #2b2210; color: #f5d08a; border-color: #5a4518; }
}

.live-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 700px) { .live-grid { grid-template-columns: 1fr; } }

.live-feed { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; }
.live-feed li {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: .75rem;
  padding: .55rem .5rem;
  border-bottom: 1px solid var(--border);
  border-left: 4px solid var(--accent);
}
.live-feed li.muted { border-left-color: transparent; display: block; }
.live-feed li:last-child { border-bottom: 0; }
.live-time, .live-who { display: flex; flex-direction: column; min-width: 0; }
.live-time strong { font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.live-time span, .live-who span { font-size: .8rem; color: var(--muted); }
.live-who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-new { animation: live-flash 3s ease-out; }
@keyframes live-flash { from { background: color-mix(in srgb, var(--accent) 45%, transparent); } to { background: transparent; } }

.live-scanners { list-style: none; margin: 0; padding: 0; }
.live-scanners li { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.live-scanners li:last-child { border-bottom: 0; }
.live-scanners strong { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Instellingen */
.setting-row {
  display: grid;
  grid-template-columns: minmax(8rem, 12rem) 1fr auto;
  gap: .5rem;
  align-items: center;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border);
}
.setting-row label { font-weight: 600; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .setting-row { grid-template-columns: 1fr auto; }
  .setting-row label { grid-column: 1 / -1; }
}
.settings-add { margin-top: 1rem; }
.check { display: flex; gap: .5rem; align-items: center; padding: .35rem 0; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.diag { display: grid; grid-template-columns: auto 1fr; gap: .25rem 1rem; margin: 0 0 1rem; font-size: .9rem; }
.diag dt { color: var(--muted); }
.diag dd { margin: 0; overflow-wrap: anywhere; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--jemar-blue);
  color: #fff;
  padding: .7rem 1rem;
  border-radius: 8px;
  border-left: 4px solid var(--accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  z-index: 20;
}
.toast-error { background: var(--unknown-bg); border-left-color: #fff; }

@media (max-width: 420px) {
  .logo { height: 32px; }
  .brand { padding-left: 10px; }
  .topbar .btn-ghost { padding: .4rem .7rem; }
}
