:root {
  --bg: #0f1115;
  --panel: #191d25;
  --panel-2: #222834;
  --line: #313947;
  --text: #f2f5fa;
  --muted: #9aa6b8;
  --ok: #16a34a;
  --ok-soft: #06301a;
  --bad: #dc2626;
  --bad-soft: #3a0d0d;
  --warn: #d97706;
  --warn-soft: #3a2506;
  --accent: #3b82f6;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Rubik, Arial, system-ui, sans-serif;
  font-size: 17px;
  overscroll-behavior: none;
}

body { direction: rtl; }

button { font-family: inherit; font-size: inherit; cursor: pointer; border: 0; }

/* ---------- מסך נעילה ---------- */
.gate {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px; background: var(--bg);
}
.gate h1 { margin: 0; font-size: 26px; }
.gate p { margin: 0; color: var(--muted); text-align: center; max-width: 30ch; line-height: 1.5; }
.gate input, .field input, .field select {
  width: min(340px, 100%); padding: 15px 16px; font-size: 19px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
}
.gate button {
  width: min(340px, 100%); padding: 16px; font-size: 19px; font-weight: 600;
  border-radius: var(--radius); background: var(--accent); color: #fff;
}
.field { display: flex; flex-direction: column; gap: 7px; width: min(340px, 100%); }
.field label { color: var(--muted); font-size: 14px; }
.gate .err { color: #fca5a5; min-height: 22px; font-size: 15px; }

/* ---------- מסך המוכר ---------- */
.scanner { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .who { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .who b { color: var(--text); font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.pill {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.online { color: #86efac; border-color: #14532d; background: var(--ok-soft); }
.pill.offline { color: #fca5a5; border-color: #7f1d1d; background: var(--bad-soft); }
.icon-btn { background: var(--panel-2); color: var(--muted); border-radius: 10px; padding: 8px 11px; font-size: 15px; }

.stage { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
.stage video { width: 100%; height: 100%; object-fit: cover; }
.stage .hint {
  position: absolute; inset-inline: 0; top: 14px; text-align: center;
  color: #fff; font-size: 14px; text-shadow: 0 1px 4px #000; pointer-events: none;
}
.stage .frame {
  position: absolute; inset: 12% 8%; border: 2px dashed rgba(255, 255, 255, .5);
  border-radius: 18px; pointer-events: none;
}
.camera-error {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center;
  color: var(--muted); line-height: 1.6;
}

.controls { padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); background: var(--panel); display: grid; gap: 10px; }
.btn-capture {
  padding: 20px; font-size: 21px; font-weight: 700; border-radius: var(--radius);
  background: var(--ok); color: #fff;
}
.btn-capture:disabled { opacity: .5; }
.btn-secondary {
  padding: 13px; font-size: 15px; border-radius: var(--radius);
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.controls .note { font-size: 12.5px; color: var(--muted); text-align: center; line-height: 1.5; }

/* ---------- שכבת ההכרעה ---------- */
.verdict {
  position: fixed; inset: 0; z-index: 50; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 28px; text-align: center;
}
.verdict.show { display: flex; }
.verdict.ok { background: var(--ok); }
.verdict.bad { background: var(--bad); }
.verdict.warn { background: var(--warn); }
.verdict.busy { background: #1e293b; }
.verdict .mark { font-size: 78px; line-height: 1; }
.verdict .headline { font-size: 34px; font-weight: 800; }
.verdict .detail { font-size: 18px; line-height: 1.55; max-width: 26ch; opacity: .95; }
.verdict .code {
  font-family: ui-monospace, Consolas, monospace; font-size: 27px; letter-spacing: 2px;
  background: rgba(0, 0, 0, .28); padding: 9px 16px; border-radius: 10px; direction: ltr;
}
.verdict button {
  margin-top: 8px; padding: 15px 34px; font-size: 18px; font-weight: 600;
  border-radius: var(--radius); background: rgba(0, 0, 0, .3); color: #fff;
}
.spinner {
  width: 54px; height: 54px; border: 5px solid rgba(255, 255, 255, .25);
  border-top-color: #fff; border-radius: 50%; animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- מסך המנהל ---------- */
.manager { max-width: 1000px; margin: 0 auto; padding: 18px 16px 60px; }
.manager h1 { font-size: 23px; margin: 0 0 4px; }
.manager .sub { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; margin-bottom: 16px; }
.toolbar input[type="date"], .toolbar button {
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 15px;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile .n { font-size: 30px; font-weight: 700; line-height: 1.1; }
.tile .k { color: var(--muted); font-size: 13px; margin-top: 5px; }
.tile.bad .n { color: #f87171; }
.tile.warn .n { color: #fbbf24; }
.tile.ok .n { color: #4ade80; }

.diagnosis { border-radius: var(--radius); padding: 15px 17px; margin-bottom: 20px; line-height: 1.6; font-size: 15px; border: 1px solid; }
.diagnosis b { display: block; margin-bottom: 5px; font-size: 16px; }
.diagnosis.good { background: var(--ok-soft); border-color: #14532d; color: #bbf7d0; }
.diagnosis.alarm { background: var(--bad-soft); border-color: #7f1d1d; color: #fecaca; }
.diagnosis.neutral { background: var(--panel); border-color: var(--line); color: var(--muted); }

.rows { display: flex; flex-direction: column; gap: 9px; }
.row {
  display: grid; grid-template-columns: 62px 1fr auto; gap: 13px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 13px;
}
.row.duplicate { border-color: #7f1d1d; background: #24101099; }
.row.unreadable, .row.error { border-color: #78350f; background: #2418069c; }
.row img { width: 62px; height: 62px; object-fit: cover; border-radius: 9px; background: #000; cursor: zoom-in; }
.row .code { font-family: ui-monospace, Consolas, monospace; font-size: 18px; direction: ltr; text-align: right; }
.row .meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; line-height: 1.5; }
.row .tag { font-size: 12px; padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: #86efac; }
.tag.duplicate { background: var(--bad-soft); color: #fca5a5; }
.tag.unreadable, .tag.error { background: var(--warn-soft); color: #fcd34d; }
.row .fix { display: flex; gap: 6px; margin-top: 7px; }
.row .fix input {
  width: 130px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); direction: ltr; font-family: ui-monospace, Consolas, monospace;
}
.row .fix button { padding: 7px 13px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

.lightbox {
  position: fixed; inset: 0; z-index: 70; background: #000000e6;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

.no-photo {
  width: 62px; height: 62px; border-radius: 9px;
  background: var(--panel-2); border: 1px dashed var(--line);
  display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 10px; color: var(--muted); line-height: 1.3; padding: 4px;
}

/* ---------- מקלדת החירום ---------- */
/* מופיעה רק כשה-OCR לא קרא את הקוד. שלוש ספרות מהירות במקום המתנה למנהל. */
.keypad { width: min(310px, 100%); }
.keypad-display {
  font-family: ui-monospace, Consolas, monospace; font-size: 40px; letter-spacing: 8px;
  text-align: center; padding: 10px 0 14px; direction: ltr; min-height: 56px;
}
.keypad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad-grid button {
  padding: 17px 0; font-size: 24px; font-weight: 600; border-radius: 12px;
  background: rgba(0, 0, 0, .28); color: #fff;
}
.keypad-grid button.wide { font-size: 15px; }
.keypad-grid button.go { font-size: 17px; background: rgba(255, 255, 255, .92); color: #111; font-weight: 700; }
.keypad-grid button:disabled { opacity: .4; }

/* ---------- פס ההתקנה וההוראות ---------- */
/* חי מחוץ למסך הנעילה ולמסך הסריקה, כדי להיות נגיש בשני המצבים. */
.install-bar {
  position: fixed; z-index: 65; left: 12px; right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 8px; box-shadow: 0 6px 24px #0008;
}
.install-bar > button:first-child {
  flex: 1; padding: 13px; font-size: 16px; font-weight: 600;
  border-radius: 10px; background: var(--accent); color: #fff;
}
.install-bar > button:first-child:disabled { opacity: .6; }
#installDismiss {
  padding: 13px 14px; font-size: 15px; border-radius: 10px;
  background: transparent; color: var(--muted);
}

.sheet {
  position: fixed; inset: 0; z-index: 70; background: #000000cc;
  display: flex; align-items: flex-end; justify-content: center; padding: 16px;
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: min(420px, 100%); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
}
.sheet-card h2 { margin: 0 0 14px; font-size: 20px; }
.sheet-card ol { margin: 0 0 14px; padding-inline-start: 22px; line-height: 2; font-size: 16px; }
.sheet-note { margin: 0 0 16px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.sheet-card button {
  width: 100%; padding: 14px; font-size: 17px; font-weight: 600;
  border-radius: var(--radius); background: var(--accent); color: #fff;
}
