/* © IKlett. Alle rettigheter forbeholdt. Proprietær programvare – kopiering og videredistribusjon er forbudt uten skriftlig avtale. */
/* Felles terminal «Hvem jobber nå?», QR-kort og nedtelling til automatisk utlogging.
   Store treffflater (hansker): navnefliser min. 120 px, PIN-knapper min. 92 px. */
#terminal {
  position: fixed; inset: 0; z-index: 950; background: var(--bg); color: var(--fg);
  display: flex; flex-direction: column; overflow: auto; -webkit-user-select: none; user-select: none;
}
body.terminal-on { overflow: hidden; }
.term-head { display: flex; align-items: center; gap: 14px; padding: calc(14px + env(safe-area-inset-top, 0px)) calc(22px + env(safe-area-inset-right, 0px)) 14px calc(22px + env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--card-border); background: var(--card-bg); }
.term-head img { border-radius: 10px; }
.term-site { font-size: 20px; font-weight: 800; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-lang { min-height: 44px; border-radius: 12px; border: 1px solid var(--card-border); background: var(--bg); color: var(--fg); font: inherit; font-weight: 700; padding: 4px 8px; max-width: 160px; }
.term-foot-r { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.pin-len { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; }
.pin-len .btn { min-height: 64px; font-size: 18px; }
.term-clock { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--primary); }
.term-body { flex: 1; display: grid; grid-template-columns: 1fr 340px; gap: 24px; padding: 22px; align-items: start; }
.term-main h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); letter-spacing: -0.01em; }
.term-sub { margin: 6px 0 18px; color: var(--fg-muted); font-size: 17px; }
.term-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.term-tile {
  min-height: 156px; border-radius: 22px; border: 2px solid var(--card-border); background: var(--card-bg); color: var(--fg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 14px 10px;
  font: inherit; cursor: pointer; transition: transform .08s ease, border-color .12s ease, box-shadow .12s ease;
}
.term-tile:hover { border-color: var(--primary); box-shadow: 0 6px 18px rgba(15, 82, 104, .14); }
.term-tile:active { transform: scale(.97); }
.term-tile:focus-visible, .tp-pad button:focus-visible, .term-cam-start:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.tt-ini {
  width: 66px; height: 66px; border-radius: 50%; background: var(--primary); color: var(--primary-text, #fff);
  display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800;
}
.term-tile.mgr .tt-ini { background: var(--warn-fg, #9a5b00); }
.tt-name { font-size: 22px; font-weight: 800; text-align: center; line-height: 1.15; overflow-wrap: anywhere; }
.tt-role { font-size: 13px; color: var(--fg-muted); font-weight: 700; }
.term-scan { position: sticky; top: 22px; }
.term-cam { position: relative; border-radius: 22px; overflow: hidden; background: var(--card-bg); border: 2px dashed var(--card-border); aspect-ratio: 3 / 4; }
.term-cam video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; transform: scaleX(-1); }
.term-cam.on video { display: block; }
.term-cam.on { border-style: solid; border-color: var(--primary); }
.term-cam-frame { position: absolute; inset: 18%; border: 4px solid rgba(255, 255, 255, .9); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); display: none; }
.term-cam.on .term-cam-frame { display: block; }
.term-cam-start {
  position: absolute; inset: 0; width: 100%; border: 0; background: transparent; color: var(--fg); font: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 20px; text-align: center;
}
.term-cam.on .term-cam-start { display: none; }
.tcs-ic { font-size: 64px; line-height: 1; }
.term-cam-start b { font-size: 22px; }
.term-cam-start small { font-size: 15px; color: var(--fg-muted); }
.term-cam-msg { min-height: 24px; margin-top: 10px; text-align: center; font-weight: 700; color: var(--fg-muted); }
/* Liten huskelapp nederst (første PIN på enheten krever nett): dempet, tar ikke plass fra flisene */
.term-tip { flex-basis: 100%; margin: 0; font-size: 12.5px; line-height: 1.35; color: var(--fg-muted); opacity: .85; }
.term-foot { padding: 10px 22px 18px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.term-office { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-height: 60px; padding: 10px 18px; border-radius: 16px;
  border: 2px solid var(--card-border); background: var(--card-bg); color: var(--fg); font: inherit; font-weight: 800; font-size: 16px; cursor: pointer; text-align: left; }
.term-office small { font-weight: 500; font-size: 13px; color: var(--fg-muted); }
.term-office:hover { border-color: var(--primary); }
.term-exit { border: 2px solid var(--card-border); background: var(--card-bg); color: var(--fg); font: inherit; font-weight: 700; font-size: 15px; min-height: 52px; padding: 8px 16px; cursor: pointer; border-radius: 14px; }
.term-exit:hover { background: rgba(15, 82, 104, .08); color: var(--fg); }

/* PIN for valgt ansatt: gigantiske knapper */
.term-pin { max-width: 460px; width: 100%; margin: 0 auto; padding: 18px 18px 28px; display: flex; flex-direction: column; align-items: center; }
.term-back { align-self: flex-start; min-height: 52px; padding: 8px 16px; border-radius: 14px; border: 2px solid var(--card-border); background: var(--card-bg); color: var(--fg); font: inherit; font-weight: 700; font-size: 17px; cursor: pointer; }
.tp-who { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 10px 0 4px; }
.tp-who h2 { margin: 0; font-size: 28px; }
.tp-dots { display: flex; gap: 18px; margin: 16px 0 6px; }
.tp-dots i { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--primary); display: block; }
.tp-dots i.on { background: var(--primary); }
.tp-msg { min-height: 26px; color: var(--bad-fg); font-weight: 800; font-size: 17px; }
.tp-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; width: 100%; margin-top: 8px; }
.tp-pad button {
  min-height: 92px; border-radius: 22px; border: 2px solid var(--card-border); background: var(--card-bg); color: var(--fg);
  font: inherit; font-size: 38px; font-weight: 800; cursor: pointer; box-shadow: 0 4px 0 var(--card-border); transition: transform .06s ease;
}
.tp-pad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-border); }
.tp-pad .tp-fn { font-size: 28px; color: var(--fg-muted); }
.tp-ok { width: 100%; min-height: 64px; margin-top: 16px; font-size: 20px; }

/* Nedtelling etter «Lagre» */
.term-countdown {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 960;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 24px);
  background: var(--card-bg); color: var(--fg); border: 2px solid var(--primary); border-radius: 18px; padding: 12px 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .28); font-weight: 800; font-size: 16px;
}
.term-countdown .btn { min-height: 52px; padding: 6px 16px; }
@media (min-width: 1024px) { .term-countdown { bottom: 24px; } }

.term-toast { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 11000; background: var(--card-bg); color: var(--fg); border: 2px solid var(--ok-fg, #1f8a4c); border-radius: 14px; padding: 12px 18px; font-weight: 800; box-shadow: 0 10px 26px rgba(0, 0, 0, .25); }
.term-toast.bad { border-color: var(--bad-fg); }
.term-dialog-bg { position: fixed; inset: 0; z-index: 10000; background: rgba(0, 0, 0, .65); display: flex; align-items: center; justify-content: center; padding: 16px; }
.term-dialog { background: var(--card-bg); border: 3px solid var(--primary); border-radius: 20px; max-width: 420px; width: 100%; padding: 24px; text-align: center; }
.term-dialog h3 { margin: 0 0 12px; font-size: 20px; }
.term-dialog p { color: var(--fg-muted); }
.big-pin { display: flex; justify-content: center; gap: 12px; margin: 10px 0; }
.big-pin span { width: 64px; height: 84px; border-radius: 16px; background: var(--bg); border: 2px solid var(--card-border); display: flex; align-items: center; justify-content: center; font-size: 46px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* QR-kort (skjerm og utskrift). Kortstørrelse som et vanlig ID-kort: 85,6 × 54 mm */
.badge-card { width: 320px; max-width: 100%; background: #fff; color: #15252b; border: 2px solid #0f5268; border-radius: 14px; padding: 12px 14px; text-align: center; }
.bc-top { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 14px; color: #0f5268; }
.bc-top img { border-radius: 6px; }
.bc-qr { display: flex; justify-content: center; margin: 8px 0 4px; }
.bc-qr svg { width: 150px; height: 150px; }
.bc-name { font-size: 22px; font-weight: 800; }
.bc-hint { font-size: 12px; color: #4b5b61; }
@media print {
  /* Etikettutskriften deler siden i kolonner – kortarket skal ha hele bredden */
  @page { size: A4 portrait; margin: 10mm; }
  body.printing-badges #print-area { display: block !important; padding: 0 !important; }
  body.printing-badges #print-area .badge-sheet { display: grid; grid-template-columns: repeat(2, 85.6mm); gap: 5mm 6mm; justify-content: center; }
  body.printing-badges .badge-card { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.printing-badges .badge-card { width: 85.6mm; height: 54mm; box-sizing: border-box; padding: 3mm 4mm; border: 0.5mm solid #0f5268; border-radius: 3mm;
    display: grid; grid-template-columns: 30mm 1fr; grid-template-rows: auto 1fr auto; column-gap: 3mm; text-align: left; break-inside: avoid; page-break-inside: avoid; }
  body.printing-badges .bc-top { grid-column: 1 / 3; justify-content: flex-start; font-size: 9pt; }
  body.printing-badges .bc-qr { grid-row: 2 / 4; margin: 1mm 0 0; }
  body.printing-badges .bc-qr svg { width: 30mm; height: 30mm; }
  body.printing-badges .bc-name { align-self: end; font-size: 15pt; }
  body.printing-badges .bc-hint { font-size: 7.5pt; }
}

@media (max-width: 860px) {
  .term-body { grid-template-columns: 1fr; }
  .term-scan { position: static; }
  .term-cam { aspect-ratio: auto; height: 200px; }
  .term-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
@media (max-width: 420px) {
  .term-body { padding: 14px; }
  /* Smal skjerm: virksomhetsnavnet skal fortsatt leses (ikke kuttes til én bokstav) */
  .term-head { gap: 8px; padding: 10px 12px; }
  .term-site { font-size: 15px; }
  .term-lang { max-width: 118px; font-size: 14px; padding: 4px 4px; }
  .term-clock { font-size: 20px; }
  .tp-pad button { min-height: 80px; font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) { .term-tile, .tp-pad button { transition: none; } }
