:root {
  --bg: #f4f5f7;
  --card: #fff;
  --line: #d8dde6;
  --text: #1a1d23;
  --muted: #5c6570;
  --accent: #1f4b99;
  --ok: #1b7f4a;
  --bad: #b42318;
  --warn: #9a6700;
  --run: #175cd3;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font: 13px/1.3 ui-sans-serif, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}
header {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f0f2f5;
  border: 1px solid var(--line);
  padding: 3px 8px 3px 4px;
  border-radius: 20px;
}
.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #1f4b99;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}
.user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  text-align: left;
}
.user-name {
  font-weight: 600;
  font-size: 12px;
}
.user-email {
  font-size: 10px;
  color: var(--muted);
}
.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  padding: 3px;
  border-radius: 4px;
  text-decoration: none;
  transition: all 0.15s ease;
}
.btn-logout:hover {
  color: var(--bad);
  background: rgba(180, 35, 24, 0.1);
}
h1 { margin: 0; font-size: 1.1rem; }
h2 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.sub, .hint, .msg { color: var(--muted); }
.sub { margin: 0.1rem 0 0; font-size: 0.8rem; }
.page {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  padding: 0.6rem 1rem 0.8rem;
  overflow: hidden;
  align-items: stretch;
}
.sidebar-col {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar-col .panel {
  height: auto;
  min-height: 0;
  flex-shrink: 0;
}
.sidebar-col .connections {
  flex: 0 0 auto;
}
.sidebar-col .new-run {
  flex: 0 0 auto;
  overflow: visible;
}
.sidebar-col .jobs {
  flex: 1 1 auto;
  min-height: 180px;
  height: auto;
}
.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
}
.panel.report {
  height: 100%;
  min-height: 0;
}
.panel > .row:first-child { flex: 0 0 auto; }
.table-wrap,
.markdown {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}
.report .markdown {
  overflow: auto;
}
.new-run {
  overflow-y: auto;
  padding: 0.5rem 0.7rem;
}
.new-run .form-grid {
  flex: 0 0 auto;
  margin-top: 0.25rem;
  gap: 0.3rem 0.5rem;
}
.new-run .row.start {
  margin-top: 0.35rem;
  gap: 0.5rem;
}
#ds-msg:empty { display: none; margin: 0; }
#ds-msg { margin: 0.2rem 0 0; font-size: 0.78rem; }
.config-preview {
  margin-top: 0.3rem;
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fafbfd;
}
.row h2 { margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin: 0 0 0.35rem; font-size: 0.8rem; }
.lamp {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.06);
}
.lamp.green { background: #1b7f4a; box-shadow: 0 0 6px #1b7f4a88; }
.lamp.yellow { background: #e6b800; box-shadow: 0 0 6px #e6b80088; }
.lamp.red { background: #b42318; box-shadow: 0 0 6px #b4231888; }
.sig-green { color: var(--ok); font-weight: 600; }
.sig-yellow { color: var(--warn); font-weight: 600; }
.sig-red { color: var(--bad); font-weight: 600; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem 0.6rem;
  align-items: end;
  margin-top: 0.4rem;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin: 0;
  font-weight: 600;
  font-size: 0.82rem;
}
.field .hint { font-weight: 400; font-size: 0.78rem; }
.field-actions {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  padding-bottom: 1px;
}
input, select, textarea, button {
  font: inherit;
  color: inherit;
}
.field input, .field select {
  width: 100%;
  min-width: 0;
  padding: 0.22rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font-size: 0.82rem;
}
.check {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  min-height: 1.8rem;
  font-size: 0.82rem;
}
.check input { width: auto; margin: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; }
.row.gap { justify-content: flex-end; }
.row.start { justify-content: flex-start; margin-top: 0.4rem; }
#ds-msg, #queue-meta { min-height: 1.1em; font-size: 0.8rem; }
.grow { flex: 1; margin: 0; }
.markdown { overflow: auto; }
.markdown h1 { font-size: 1.05rem; margin: 0 0 0.4rem; }
.markdown h2 { font-size: 0.95rem; margin: 0.8rem 0 0.3rem; }
.markdown h3 { font-size: 0.88rem; margin: 0.6rem 0 0.25rem; }
.markdown p, .markdown ul { margin: 0.25rem 0 0.45rem; line-height: 1.35; }
.markdown table { margin: 0.25rem 0 0.6rem; }
.markdown .mermaid {
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.5rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  text-align: center;
}
.markdown pre { max-height: none; }
.markdown .status-pass { color: var(--ok); font-weight: 700; }
.markdown .status-fail { color: var(--bad); font-weight: 700; }
.markdown .benchmark-result-card {
  border-radius: 8px;
  padding: 0.9rem 1.2rem;
  margin: 0.8rem 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1.5px solid transparent;
}
.markdown .benchmark-result-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}
.markdown .benchmark-result-score {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
}
.markdown .benchmark-result-pass {
  background: #f0fdf4;
  border-color: #16a34a;
}
.markdown .benchmark-result-pass .benchmark-result-title {
  color: #166534;
}
.markdown .benchmark-result-pass .benchmark-result-score {
  color: #15803d;
}
.markdown .benchmark-result-warn {
  background: #fefce8;
  border-color: #ca8a04;
}
.markdown .benchmark-result-warn .benchmark-result-title {
  color: #854d0e;
}
.markdown .benchmark-result-warn .benchmark-result-score {
  color: #a16207;
}
.markdown .benchmark-result-fail {
  background: #fef2f2;
  border-color: #dc2626;
}
.markdown .benchmark-result-fail .benchmark-result-title {
  color: #991b1b;
}
.markdown .benchmark-result-fail .benchmark-result-score {
  color: #b91c1c;
}
.markdown .report-guide {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
  background: #f8f9fa;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  margin: 0.6rem 0;
}
.markdown .report-guide h3 {
  font-size: 0.84rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  color: var(--text);
}
.markdown .report-guide h4 {
  font-size: 0.8rem;
  font-weight: 600;
  margin: 0.45rem 0 0.2rem;
  color: var(--text);
}
.markdown .report-guide ul {
  margin: 0 0 0.35rem;
  padding-left: 1.1rem;
}
.markdown .report-guide li {
  margin-bottom: 0.15rem;
}
button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 4px;
  padding: 0.25rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
button.ghost { background: #eef1f6; color: var(--text); }
button.copied { background: var(--ok); color: #fff; }
button.danger { background: var(--bad); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  min-width: 26px;
  min-height: 24px;
}
button.icon-btn svg {
  display: block;
}

/* ── Table styles: ultra-compact row heights & spacing ─────────────────────── */
table, .markdown table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin: 0.25rem 0 0.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
th, td, .markdown th, .markdown td {
  text-align: left;
  padding: 0.25rem 0.45rem;
  line-height: 1.25;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #edf0f5;
  vertical-align: middle;
}
th:last-child, td:last-child, .markdown th:last-child, .markdown td:last-child {
  border-right: none;
}
th, .markdown th {
  color: var(--text);
  background: #f4f6fa;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.3rem 0.45rem;
  border-bottom: 2px solid var(--line);
}
tr:last-child td, .markdown tr:last-child td {
  border-bottom: none;
}
tbody tr:hover, .markdown tbody tr:hover {
  background: #fafbfd;
}
.pill {
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-block;
  line-height: 1.2;
}
.pill.ok, .st-succeeded { background: #e6f6ec; color: var(--ok); }
.pill.bad, .st-failed, .st-error { background: #fdecea; color: var(--bad); }
.pill.warn, .st-cancelled { background: #fff4d6; color: var(--warn); }
.pill.run, .st-running { background: #e7f0ff; color: var(--run); }
.pill.st-waiting, .st-waiting { background: #fff7ed; color: #c2410c; }
.pill.unknown, .st-queued { background: #eef1f6; color: var(--muted); }
pre {
  margin: 0 0 0.5rem;
  white-space: pre-wrap;
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  max-height: 22rem;
  overflow: auto;
  font-size: 11px;
  line-height: 1.3;
}
.actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: nowrap;
}
.mono { font-family: ui-monospace, monospace; font-size: 11px; }

.jobs-table { width: 100%; }
.jobs-table th, .jobs-table td { white-space: nowrap; }
.job-user-col {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.76rem;
  color: var(--muted);
}

/* ── Compact Icon Action Buttons ─────────────────────────────────────────── */
.btn-icon-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 24px;
  min-width: 24px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-sizing: border-box;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  background: #f1f5f9;
  color: var(--text);
}
.btn-icon-act svg {
  flex-shrink: 0;
  stroke: currentColor;
}
.btn-act-report {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}
.btn-act-report:hover {
  background: #0284c7;
  color: #ffffff;
  border-color: #0284c7;
}
.btn-act-subjobs {
  background: #f1f5f9;
  color: #475569;
  border-color: #cbd5e1;
}
.btn-act-subjobs:hover {
  background: #e2e8f0;
  color: #1e293b;
  border-color: #94a3b8;
}
.btn-act-subjobs .subjob-count {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.btn-act-subjobs .subjob-arrow {
  font-size: 9px;
  color: var(--muted);
  margin-left: -1px;
}
.btn-act-copy-err {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}
.btn-act-copy-err:hover {
  background: #dc2626;
  color: #ffffff;
  border-color: #dc2626;
}
.btn-act-copy-err.copied {
  background: #dcfce7;
  color: #15803d;
  border-color: #86efac;
}
.btn-act-cancel {
  background: #fef3c7;
  color: #b45309;
  border-color: #fde68a;
}
.btn-act-cancel:hover {
  background: #d97706;
  color: #ffffff;
  border-color: #d97706;
}
.btn-act-delete {
  background: #f8fafc;
  color: #94a3b8;
  border-color: #e2e8f0;
}
.btn-act-delete:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}

/* ── Config preview card ───────────────────────────────────────────────────── */
.cfg-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  padding: 0.3rem 0.6rem;
  background: #eef1f8;
  border-bottom: 1px solid var(--line);
}
.cfg-filename {
  font-weight: 700;
  font-size: 0.84rem;
  color: var(--accent);
  margin-right: 0.2rem;
}
.cfg-badge {
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  font-size: 0.74rem;
  font-weight: 600;
  background: #e7f0ff;
  color: var(--run);
}
.cfg-badge.dim {
  background: #eef1f6;
  color: var(--muted);
}
.badge-counting { background: #e0f2fe; color: #0369a1; }
.badge-employee { background: #f3e8ff; color: #7e22ce; }
.badge-dwell_time { background: #fef3c7; color: #b45309; }
.badge-engagement { background: #dcfce7; color: #15803d; }
.badge-mcmt { background: #ede9fe; color: #4338ca; }
.badge-planogram { background: #ffedd5; color: #c2410c; }
.badge-ch {
  display: inline-block;
  background: #f1f5f9;
  color: #334155;
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
}

.alert-box {
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  border-radius: 4px;
  margin: 0.3rem 0.5rem;
}
.alert-box.warning {
  background: #fefce8;
  border: 1px solid #fde047;
  color: #854d0e;
}
.alert-box code {
  background: rgba(0,0,0,0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-family: monospace;
}

/* ── 1-Line Connection Bar ─────────────────────────────────────────────────── */
.conn-summary-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.35rem 0.6rem;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 0.8rem;
  margin-top: 0.2rem;
}
.conn-stat {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
}
.conn-stat strong, .conn-stat span[id] {
  font-weight: 700;
}
.conn-instance-tag {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.08rem 0.45rem;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  vertical-align: middle;
  line-height: 1.3;
}
.conn-instance-tag.tag-qa {
  background: #1d4ed8;
  color: #fff;
}
.conn-instance-tag.tag-dev {
  background: #c2410c;
  color: #fff;
}
.conn-group-chip.tag-qa { border-color: #93c5fd; }
.conn-group-chip.tag-dev { border-color: #fdba74; }
.conn-group-chip.self.tag-qa { background: #eff6ff; border-color: #1d4ed8; }
.conn-group-chip.self.tag-dev { background: #fff7ed; border-color: #c2410c; }
.conn-group-tag {
  padding: 0.02rem 0.28rem;
  border-radius: 3px;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.conn-group-tag.tag-qa { background: #1d4ed8; color: #fff; }
.conn-group-tag.tag-dev { background: #c2410c; color: #fff; }
.conn-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}
.conn-group-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 0.74rem;
}
.conn-group-chip.self {
  border-color: #94a3b8;
  background: #f1f5f9;
}
.conn-group-chip .hint {
  font-variant-numeric: tabular-nums;
}
.conn-group-row td {
  background: #f1f5f9;
  padding: 0.3rem 0.6rem;
  font-size: 0.76rem;
}
.conn-group-row .lamp {
  margin-right: 0.35rem;
}
.conn-scope-badge {
  margin-left: 0.4rem;
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  background: #1f2937;
  color: #fff;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.conn-details-wrap {
  margin-top: 0.4rem;
  max-height: 180px;
  overflow-y: auto;
}
.conn-detail-text {
  font-size: 0.74rem;
  color: var(--muted);
}
button.small {
  padding: 0.15rem 0.4rem;
  font-size: 0.75rem;
}
.mini-select {
  padding: 0.15rem 0.35rem;
  font-size: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

/* ── Sub-jobs Accordion Table ─────────────────────────────────────────────── */
.job-main-row {
  cursor: default;
}
.job-subrow {
  background: #f8fafc;
}
.job-subrow td {
  padding: 0.4rem 0.6rem;
  border-bottom: 2px solid var(--line);
}
.subjobs-wrap {
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #ffffff;
  overflow: hidden;
}
.subjobs-table {
  width: 100%;
  margin: 0;
  border: none;
  font-size: 0.76rem;
}
.subjobs-table th {
  background: #f1f5f9;
  font-size: 0.7rem;
  padding: 0.2rem 0.4rem;
}
.subjobs-table td {
  padding: 0.2rem 0.4rem;
  border-bottom: 1px solid #f1f5f9;
}
.subjobs-table tr:last-child td {
  border-bottom: none;
}
.dim { color: var(--muted); font-size: 0.72rem; }

.subjob-detail-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}
.subjob-detail-cell span {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
button.mini {
  padding: 0.05rem 0.3rem;
  font-size: 0.68rem;
  line-height: 1.2;
}
.pill.st-error, .st-error {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  font-weight: 700;
}
.copy-err-btn {
  font-weight: 600;
}

.config-preview .table-wrap { overflow-x: auto; }
.cfg-table {
  width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
}
.cfg-idx { color: var(--muted); font-size: 0.75rem; width: 2rem; text-align: center; }
.cfg-url {
  font-size: 10.5px;
  color: var(--muted);
}

@media (max-width: 1100px) {
  body { overflow: auto; }
  .page {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    overflow: visible;
    height: auto;
  }
  .sidebar-col { height: auto; overflow: visible; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel { height: auto; min-height: 14rem; }
  .report { min-height: 28rem; }
  .report .markdown { max-height: 70vh; }
}

