/* برنامه‌ی نگهبان — طراحی شبانه برای محوطه‌ی صنعتی
   تنها عنصر پررنگ: دکمه‌ی اسکن با قاب راه‌راه ایمنی */
:root {
  --bg: #0F1B2D;
  --panel: #16263D;
  --panel-2: #1D3150;
  --line: #2A3D57;
  --text: #E6EDF5;
  --muted: #8FA3BA;
  --hazard: #F5B301;
  --ok: #3FB67A;
  --alarm: #FF5A4E;
  --radius: 14px;
  color-scheme: dark;
  font-family: Vazirmatn, Tahoma, sans-serif;
  font-size: 17px;
  line-height: 1.6;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); min-height: 100dvh; }
#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 96px; }
h1, h2, h3 { margin: 0; line-height: 1.35; }
h1 { font-size: 1.35rem; font-weight: 800; }
h2 { font-size: 1.05rem; font-weight: 700; color: var(--muted); margin: 28px 0 10px; }
h3 { font-size: 1.1rem; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--hazard); outline-offset: 2px; }

/* سربرگ */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 0.85rem; white-space: nowrap; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.chip.warn .dot { background: var(--hazard); }
.chip.bad .dot { background: var(--alarm); }

/* بلوک‌ها */
.block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.block + .block { margin-top: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack > * + * { margin-top: 10px; }

/* دکمه‌ها — بزرگ برای دستکش */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 56px; padding: 12px 18px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 700; cursor: pointer; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-ok { background: var(--ok); color: #06210F; border-color: var(--ok); }
.btn-danger { background: transparent; color: var(--alarm); border-color: var(--alarm); }
.btn-small { min-height: 40px; width: auto; padding: 6px 14px; font-size: 0.9rem; }
.btn-link { background: none; border: none; color: var(--muted); min-height: 44px; width: auto; text-decoration: underline; }

/* دکمه‌ی اسکن: قاب راه‌راه ایمنی */
.scan {
  position: relative; display: grid; place-items: center; width: 100%; aspect-ratio: 1.6; border: none; border-radius: 20px; cursor: pointer;
  padding: 12px; background: repeating-linear-gradient(-45deg, var(--hazard) 0 18px, #111 18px 36px);
}
.scan span { display: grid; place-items: center; gap: 4px; width: 100%; height: 100%; border-radius: 12px; background: var(--bg); color: var(--hazard); }
.scan strong { font-size: 1.6rem; font-weight: 800; }
.scan small { color: var(--muted); font-size: 0.9rem; }
.scan:active span { background: var(--panel); }

/* پیشرفت مسیر */
.stations { list-style: none; margin: 0; padding: 0; counter-reset: st; }
.stations li { display: grid; grid-template-columns: 36px 1fr; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.stations li:last-child { border-bottom: none; }
.stations .n { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); font-weight: 700; color: var(--muted); }
.stations li.done .n { background: var(--ok); border-color: var(--ok); color: #06210F; }
.stations li.next .n { border-color: var(--hazard); color: var(--hazard); }
.stations li.done .name { color: var(--muted); }

/* فرم */
label.field { display: block; }
label.field > span { display: block; margin-bottom: 6px; font-weight: 700; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; min-height: 54px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 1.1rem; }
input[type=number] { direction: ltr; text-align: center; font-size: 1.4rem; font-weight: 700; }
input.alarm { border-color: var(--alarm); color: var(--alarm); }
.hint { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.hint.alarm { color: var(--alarm); font-weight: 700; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg button { min-height: 56px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg button[aria-pressed=true].is-alarm { background: var(--alarm); border-color: var(--alarm); color: #fff; }
.photo-preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; margin-top: 8px; }

/* فهرست گشت‌ها */
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.plist li:last-child { border-bottom: none; }
.time { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.badge { font-size: 0.8rem; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.closure { border-color: var(--hazard); color: var(--hazard); }
.badge.live { border-color: var(--ok); color: var(--ok); }

.banner { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; font-weight: 700; }
.banner.alarm { background: var(--alarm); color: #fff; }
.banner.warn { border: 2px solid var(--hazard); color: var(--hazard); }

/* اسکنر */
.scanner { position: fixed; inset: 0; background: #000; z-index: 20; display: grid; grid-template-rows: 1fr auto; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; inset: 22% 14%; border: 4px solid var(--hazard); border-radius: 20px; pointer-events: none; }
.scanner .bar { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); background: var(--bg); }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); width: min(92vw, 480px); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

#toasts { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); inset-inline: 16px; display: grid; gap: 8px; z-index: 30; }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 700; max-width: 528px; margin: 0 auto; width: 100%; }
.toast-error { background: var(--alarm); color: #fff; }

.login { min-height: 80dvh; display: grid; align-content: center; gap: 16px; }
.login h1 { font-size: 1.8rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.fatal { position: fixed; inset: auto 12px calc(12px + env(safe-area-inset-bottom)); z-index: 40; background: var(--panel); border: 2px solid var(--alarm);
  border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; max-height: 80dvh; overflow: auto; }
.fatal pre { margin: 0; padding: 10px; background: var(--bg); border-radius: 8px; font-size: 0.75rem; white-space: pre-wrap; word-break: break-word; text-align: left; }
