:root {
  --indigo: #6366f1;
  --indigo-600: #4f46e5;
  --indigo-50: #eef2ff;
  --bg: #f9fafb;
  --card: #ffffff;
  --sidebar: #1f2937;
  --sidebar-hover: #374151;
  --sidebar-active: #111827;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --blue: #1d4ed8;
  --blue-bg: #dbeafe;
  --violet: #7c3aed;
  --violet-bg: #ede9fe;
  --cyan: #0891b2;
  --cyan-bg: #cffafe;
  --pink: #db2777;
  --pink-bg: #fce7f3;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--indigo-600); }

/* ---------- app shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: 0 0 220px; background: var(--sidebar); color: #e5e7eb;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-mark {
  background: var(--indigo); color: #fff; font-weight: 700; font-size: 12px;
  padding: 4px 8px; border-radius: 7px; letter-spacing: .5px;
}
.brand-text { font-weight: 600; letter-spacing: .2px; color: #f9fafb; }
#nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; flex: 1; }
#nav button {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: transparent; color: #cbd5e1; border: none; border-left: 3px solid transparent;
  padding: 9px 12px; border-radius: 7px; cursor: pointer; font-size: 13.5px; width: 100%;
}
#nav button .ico { width: 16px; text-align: center; opacity: .8; font-size: 12px; }
#nav button:hover { background: var(--sidebar-hover); color: #fff; }
#nav button.active { background: var(--sidebar-active); color: #fff; border-left-color: var(--indigo); }
.sidebar-foot { padding: 14px 18px; font-size: 11px; border-top: 1px solid #374151; color: #94a3b8; }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; flex: 0 0 56px; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 5;
}
.page-title { font-weight: 600; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip { font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--border); padding: 4px 10px; border-radius: 999px; }
main { padding: 24px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* ---------- typography ---------- */
h2 { margin: 0 0 16px; font-size: 18px; font-weight: 600; }
h3 { margin: 0 0 12px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
.muted { color: var(--muted); }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.card.flat { background: var(--bg); }

/* ---------- forms ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; background: var(--card); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 9px 11px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(99,102,241,.18); }
textarea { resize: vertical; min-height: 70px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 160px; }
code { background: var(--indigo-50); color: var(--indigo-600); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

/* ---------- buttons ---------- */
button.btn {
  background: var(--indigo); color: #fff; border: none; border-radius: 8px;
  padding: 9px 16px; cursor: pointer; font-size: 13px; font-weight: 500; margin-top: 12px;
}
button.btn:hover { background: var(--indigo-600); }
button.btn.sec { background: var(--card); border: 1px solid var(--border-strong); color: var(--text); }
button.btn.sec:hover { background: var(--bg); }
button.btn.danger { background: var(--card); color: var(--bad); border: 1px solid var(--border-strong); padding: 5px 10px; margin: 0; }
button.btn.danger:hover { background: var(--bad-bg); }
button.btn.mini { padding: 6px 11px; margin: 0; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; background: var(--bg); }
tbody tr:hover { background: var(--indigo-50); }
tbody tr:last-child td { border-bottom: none; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.queued { background: var(--blue-bg); color: var(--blue); }
.badge.running { background: var(--warn-bg); color: var(--warn); }
.badge.searching { background: var(--cyan-bg); color: var(--cyan); }
.badge.otp { background: var(--violet-bg); color: var(--violet); }
.badge.done, .badge.booked { background: var(--ok-bg); color: var(--ok); }
.badge.failed { background: var(--bad-bg); color: var(--bad); }
.badge.pending, .badge.stopped { background: #e5e7eb; color: var(--muted); }
.tag { display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.tag.goto { background: var(--blue-bg); color: var(--blue); }
.tag.click { background: var(--ok-bg); color: var(--ok); }
.tag.fill { background: var(--violet-bg); color: var(--violet); }
.tag.select { background: var(--warn-bg); color: var(--warn); }
.tag.waitFor { background: var(--cyan-bg); color: var(--cyan); }
.tag.sleep { background: var(--pink-bg); color: var(--pink); }
.tag.screenshot { background: #e5e7eb; color: var(--muted); }
.tag.pollUntil { background: var(--cyan-bg); color: var(--cyan); }

/* ---------- grouped applications + pool banner + sessions ---------- */
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--bg); }
.pool-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.session-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; }
.session-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.session-head { display: flex; align-items: center; gap: 10px; }
.session-head a { text-decoration: none; }
.sess-vnc { height: 300px; margin-top: 4px; }
.sess-connect { width: 100%; height: 300px; border: 1.5px dashed var(--border-strong); background: var(--bg); color: var(--muted); border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 500; }
.sess-connect:hover { border-color: var(--indigo); color: var(--indigo-600); background: var(--indigo-50); }

/* ---------- info grid (job detail) ---------- */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.info-grid .k { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--faint); margin-bottom: 3px; }
.info-grid .v { font-weight: 500; font-size: 13px; }

/* ---------- VNC live view ---------- */
.vnc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.vnc-frame { width: 100%; height: 540px; border: 1px solid var(--border); border-radius: 10px; background: #000; }
.vnc-frame.full { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 50; border-radius: 0; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ok); }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- screenshot timeline ---------- */
.shots { display: flex; flex-wrap: wrap; gap: 10px; }
.shot { position: relative; cursor: zoom-in; }
.shot img { width: 150px; height: 95px; object-fit: cover; border: 1px solid var(--border); border-radius: 8px; display: block; }
.shot .idx { position: absolute; top: 4px; left: 4px; background: rgba(17,24,39,.8); color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 999px; }
.shot .nm { font-size: 10px; color: var(--faint); margin-top: 3px; text-align: center; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- step editor cards ---------- */
.step-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.step-card .step-head { display: flex; align-items: center; gap: 10px; }
.step-num { width: 24px; height: 24px; flex: 0 0 24px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border-strong); color: var(--muted); font-size: 12px; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.step-card .grow { flex: 1; }
.step-actions { display: flex; gap: 4px; }
.icon-btn { background: var(--card); border: 1px solid var(--border-strong); color: var(--muted); width: 28px; height: 28px; border-radius: 7px; cursor: pointer; font-size: 13px; line-height: 1; }
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.field-bind { display: flex; gap: 8px; align-items: flex-end; min-width: 240px; } /* keep the input usable next to the +field picker */
.field-bind > div { flex: 1 1 auto; min-width: 0; }       /* the input wrapper grows */
.field-bind .se_bind { flex: 0 0 120px; width: 120px; }   /* compact +field picker (don't let it eat the input) */
.add-step { width: 100%; border: 1.5px dashed var(--border-strong); background: var(--bg); color: var(--muted); padding: 11px; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 500; margin-top: 4px; }
.add-step:hover { border-color: var(--indigo); color: var(--indigo-600); background: var(--indigo-50); }

/* ---------- log ---------- */
pre.log {
  background: #0b1020; border: 1px solid #1e293b; border-radius: 10px; padding: 14px;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; color: #cbd5e1;
  max-height: 380px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.empty { color: var(--faint); padding: 20px 4px; text-align: center; }

/* ---------- misc ---------- */
.toprow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.err { color: var(--bad); font-size: 13px; margin-top: 10px; min-height: 18px; }
.ok-msg { color: var(--ok); font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); margin: -4px 0 12px; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 100; cursor: zoom-out; padding: 30px; }
.lightbox[hidden] { display: none; }   /* the hidden attr must win over display:flex */
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { width: 340px; box-shadow: 0 8px 30px rgba(17,24,39,.08); }
.login-card .brand-mark { display: inline-block; margin-bottom: 10px; }

/* ---------- responsive ---------- */
@media (max-width: 880px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-basis: auto; height: auto; position: static; }
  .brand { padding: 12px 16px 8px; }
  #nav { flex-direction: row; flex-wrap: wrap; padding: 6px 10px; }
  #nav button { width: auto; border-left: none; border-bottom: 3px solid transparent; }
  #nav button.active { border-left: none; border-bottom-color: var(--indigo); }
  .sidebar-foot { display: none; }
  .topbar { position: static; }
  main { padding: 16px; }
  .row > div { min-width: 100%; }                 /* stack form fields */
  .field-bind { flex-wrap: wrap; }
  .field-bind .se_bind { flex: 1 1 100%; width: 100%; }
  .session-grid { grid-template-columns: 1fr; }   /* one session per row on narrow screens */
  .group-head { flex-wrap: wrap; }
}
@media (max-width: 560px) {
  .info-grid { grid-template-columns: 1fr 1fr; }
  .vnc-frame { height: 360px; }
  .shot img { width: 120px; height: 78px; }
}

/* ---------- locked engine-phase cards ---------- */
.step-card.locked { opacity: .72; background: #f5f5f7; border-style: dashed; }
.step-card.locked .step-num { background: #9aa0aa; }
