:root {
  --bg: #e9edf2;
  --surface: #ffffff;
  --ink: #16202b;
  --muted: #5d6b7a;
  --line: #d3dae2;
  --accent: #0e6b6b;
  --accent-ink: #ffffff;
  --on: #1a8f4e;
  --on-bg: #e3f5ea;
  --off: #7b8794;
  --off-bg: #eef1f4;
  --warn: #b35c00;
  --warn-bg: #fff2e0;
  --danger: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 32, 43, .08), 0 8px 24px rgba(22, 32, 43, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Hebrew", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.45; }
body { min-height: 100dvh; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
button { font: inherit; color: inherit; }
input, select { font: inherit; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; min-height: 38px;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(14, 107, 107, .35); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #0b5757; }
.btn.danger { color: var(--danger); border-color: #e3b8b5; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 14px; }
.btn.active { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text], input[type=password], input[type=number], input[type=time], select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
label.field { display: block; margin: 12px 0 0; font-size: 14px; color: var(--muted); }
label.field > input, label.field > select { margin-top: 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.err { color: var(--danger); min-height: 1.4em; margin: 10px 0 0; font-size: 14px; }
.ok { color: var(--on); }
.muted { color: var(--muted); font-size: 14px; }

/* ---------- gate ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: min(380px, 100%); background: var(--surface); border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.gate-card h1 { font-size: 24px; margin-bottom: 6px; }
.gate-card p { margin: 0 0 16px; color: var(--muted); }
.gate-card input { margin-bottom: 10px; }
.gate-card .btn { width: 100%; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px clamp(14px, 3vw, 32px); background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 20px; }
.brand .sub { color: var(--muted); font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); }
.dot.on { background: var(--on); }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- devices grid ---------- */
.devices {
  display: grid; gap: 20px; padding: clamp(14px, 3vw, 32px);
  grid-template-columns: repeat(auto-fill, minmax(560px, 1fr));
}
@media (max-width: 640px) { .devices { grid-template-columns: 1fr; } }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

.device {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: 230px 1fr; gap: 20px; padding: 18px; align-items: start;
}
@media (max-width: 640px) { .device { grid-template-columns: 1fr; } .screen-wrap { justify-self: center; } }

.screen-wrap { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.screen {
  position: relative; width: 210px; aspect-ratio: 9 / 19.5; border-radius: 22px; overflow: hidden;
  background: #0f1419; border: 6px solid #0f1419; cursor: default; user-select: none;
}
.screen img { display: block; width: 100%; height: 100%; object-fit: cover; }
.screen.control { cursor: crosshair; outline: 3px solid var(--warn); touch-action: none; }
.screen:focus-visible { outline: 3px solid var(--accent); }
.screen-hint { position: absolute; bottom: 8px; left: 8px; right: 8px; text-align: center; font-size: 11px; color: #fff; background: rgba(0,0,0,.55); border-radius: 6px; padding: 3px; pointer-events: none; }
.pending { font-size: 12px; color: var(--warn); }
.screen.recording { outline: 3px solid var(--danger); }
.screen-off {
  position: absolute; inset: 0; display: grid; place-items: center; color: #9aa6b2; font-size: 14px;
  background: #0f1419; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.screen.offline .screen-off { opacity: 1; }
.screen-tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.tap-mark {
  position: absolute; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--warn);
  transform: translate(-50%, -50%); pointer-events: none; animation: tap .5s ease-out forwards;
}
@keyframes tap { from { opacity: 1; scale: .6; } to { opacity: 0; scale: 1.6; } }

.info { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.dev-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.dev-name { font-size: 20px; }
.dev-name { cursor: text; border-bottom: 1px dashed transparent; }
.dev-name:hover { border-bottom-color: var(--line); }
.dev-sub { color: var(--muted); font-size: 14px; margin-top: -6px; }
.dev-sub b { color: var(--ink); font-weight: 500; }
.conn { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--off-bg); color: var(--off); }
.conn.on { background: var(--on-bg); color: var(--on); }
.btn.wa { border-color: #bfe3cc; }
.device.offline .screen img { filter: grayscale(1) brightness(.5); }
.busy { font-size: 13px; color: var(--warn); background: var(--warn-bg); padding: 2px 10px; border-radius: 999px; }

/* lines */
.lines { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.lines li { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 10px 14px; }
.lines li + li { border-top: 1px solid var(--line); }
.lines li.is-on { background: var(--on-bg); }
.line-name { font-weight: 600; }
.line-num { color: var(--muted); font-size: 14px; direction: ltr; unicode-bidi: isolate; }
.pill { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--off-bg); color: var(--off); white-space: nowrap; }
.pill.on { background: #fff; color: var(--on); border: 1px solid #b7e2c7; }
.pill.data { background: #fff; color: var(--accent); border: 1px solid #b9dada; }
.lines-note { margin: 0; color: var(--muted); font-size: 13px; }
.lines-empty { padding: 14px; color: var(--muted); font-size: 14px; }

/* switch */
.switch { position: relative; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: #c5cdd6; transition: background .15s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + span { background: var(--on); }
.switch input:checked + span::after { transform: translateX(-20px); }
.switch input:disabled + span { opacity: .5; }
.switch input:focus-visible + span { outline: 3px solid rgba(14,107,107,.35); }

/* rotation */
.rotation { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.rot-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rot-state { font-weight: 600; flex: 1; }
.rot-next { color: var(--muted); font-size: 14px; margin-top: 4px; }
.rot-next .bad { color: var(--danger); }
.dev-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.job-line { font-size: 13px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; white-space: pre-wrap; }
.job-line.fail { color: var(--danger); }

/* ---------- drawer ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(22,32,43,.35); z-index: 20; }
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: min(480px, 100%); background: var(--surface);
  z-index: 21; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 18px; }
.drawer-body { padding: 20px; overflow: auto; flex: 1; }
.drawer-body h3 { font-size: 15px; margin: 18px 0 8px; }
.drawer-body h3:first-child { margin-top: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li .grow { flex: 1; min-width: 0; }
.list li small { display: block; color: var(--muted); }
.order-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.order-item .grow { flex: 1; }
.steps { font-size: 13px; color: var(--muted); white-space: pre-wrap; background: var(--off-bg); padding: 10px; border-radius: 8px; max-height: 220px; overflow: auto; direction: ltr; text-align: left; }
.shots { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.shots img { width: 90px; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.over { border-color: var(--accent); color: var(--accent); }
.lpa { font-family: ui-monospace, Menlo, monospace; font-size: 13px; direction: ltr; text-align: left; background: var(--off-bg); padding: 10px; border-radius: 8px; word-break: break-all; }
.days { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.days label { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 14px; cursor: pointer; }
.days input { margin: 0 4px 0 0; }
.job { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.job .st { font-weight: 600; }
.job .st.done { color: var(--on); } .job .st.failed { color: var(--danger); } .job .st.running { color: var(--warn); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%); z-index: 30;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow);
}
.toast.bad { background: var(--danger); }

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