* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0a0b;
  --bg-raised: #111113;
  --surface: #18181b;
  --surface-hover: #1e1e22;
  --border: rgba(255,255,255,0.07);
  --border-bright: rgba(255,255,255,0.12);
  --text-muted: #52525b;
  --text: #a1a1aa;
  --text-bright: #e4e4e7;
  --text-white: #fafafa;
  --accent: #7c5cfc;
  --accent-hover: #9b7eff;
  --accent-glow: rgba(124,92,252,0.15);
  --accent-subtle: rgba(124,92,252,0.08);
  --green: #22c55e;
  --green-dim: rgba(34,197,94,0.12);
  --orange: #f59e0b;
  --orange-dim: rgba(245,158,11,0.12);
  --red: #ef4444;
  --red-dim: rgba(239,68,68,0.1);
  --blue: #3b82f6;
  --radius: 8px;
  --radius-lg: 12px;
  --font-mono: 'JetBrains Mono', 'SF Mono', SFMono-Regular, Consolas, monospace;
  --sidebar-w: 220px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-bright);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.app-layout {
  display: flex;
  height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 20px 20px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-white);
  letter-spacing: -0.4px;
}
.sidebar-logo .logo-icon { color: var(--accent); font-size: 20px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { color: var(--text-bright); background: var(--surface); }
.nav-item.active { color: var(--text-white); background: var(--surface); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-section {
  padding: 20px 20px 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.ok { background: var(--green); box-shadow: 0 0 4px var(--green); }
.status-dot.off { background: var(--red); box-shadow: 0 0 4px var(--red); }

.presence-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.presence-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.presence-title { font-weight: 600; }
.presence-count {
  display: inline-block;
  min-width: 16px;
  text-align: center;
  padding: 1px 5px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-bright);
  font-size: 10px;
}
.presence-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 140px;
  overflow-y: auto;
}
.presence-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text);
  padding: 2px 0;
}
.presence-item.presence-self .presence-name { color: var(--text-bright); font-weight: 600; }
.presence-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 4px var(--green);
  flex-shrink: 0;
}
.presence-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.presence-role {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.8;
}
.presence-role.role-admin { color: var(--accent); }
.presence-role.role-operator { color: var(--blue); }
.presence-sessions {
  font-size: 10px;
  color: var(--text-muted);
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform-origin: top left;
  transition: transform 0.26s cubic-bezier(0.2, 0.7, 0.2, 1);
}
body.control-open .main-content {
  transform: scale(var(--control-scale, 0.78));
}
@media (max-width: 768px) {
  body.control-open .main-content { transform: none; }
}

/* ===== Buttons ===== */
.btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-bright);
  background: var(--surface);
  color: var(--text-bright);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); border-color: rgba(255,255,255,0.18); color: var(--text-white); }
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 12px var(--accent-glow);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 0 20px var(--accent-glow); }
.btn-danger { color: var(--red); border-color: rgba(239,68,68,0.25); background: var(--red-dim); }
.btn-danger:hover { background: rgba(239,68,68,0.18); border-color: rgba(239,68,68,0.4); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: 0.4px; }
.card-body { padding: 16px; }

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-white); font-variant-numeric: tabular-nums; line-height: 1; }
.stat-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-top: 6px; }

/* ===== Forms ===== */
.form-row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-group input, .form-group select, .form-group textarea {
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  color: var(--text-bright);
  font-family: inherit;
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group select { cursor: pointer; }
.form-group select option { background: var(--surface); color: var(--text-bright); }

/* ===== Section label ===== */
.section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--border);
}

/* ===== Timing grid ===== */
.timing-grid {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.timing-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 130px;
}
.timing-field label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}
.timing-field .unit { font-size: 10px; opacity: 0.6; font-weight: 400; }
.range-row { display: flex; align-items: center; gap: 6px; }
.range-row input {
  flex: 1;
  width: 60px;
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  color: var(--text-bright);
  font-family: inherit;
  font-size: 13px;
  text-align: center;
}
.range-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.range-sep { color: var(--text-muted); font-size: 13px; flex-shrink: 0; }

/* ===== Tables ===== */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-bright);
  font-size: 13px;
}
tr:hover td { background: rgba(255,255,255,0.02); }
.mono { font-family: var(--font-mono); font-size: 12px; color: var(--text); }

/* ===== Devices Tab Sections ===== */
.devices-section { margin-bottom: 24px; }
.devices-section:last-child { margin-bottom: 0; }
.devices-section-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.devices-section-label svg { opacity: 0.5; flex-shrink: 0; }
.devices-section-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  padding: 1px 8px;
  border-radius: 10px;
  margin-left: 4px;
  letter-spacing: 0;
  text-transform: none;
}
.stats-grid-compact .stat-card { padding: 12px 16px; }
.stats-grid-compact .stat-value { font-size: 20px; }

/* ===== Device Grid ===== */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}
.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.device-card:hover { border-color: var(--border-bright); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.device-card.selected { border-color: var(--accent); background: var(--accent-subtle); }
.device-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.device-num { font-weight: 700; font-size: 16px; color: var(--accent); font-family: var(--font-mono); cursor: pointer; min-width: 28px; border-radius: 4px; padding: 1px 4px; }
.device-num:hover { background: var(--accent-subtle); }
.device-name { font-size: 13px; font-weight: 600; color: var(--text-bright); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; border-radius: 4px; padding: 1px 4px; flex: 1; }
.device-name:hover { background: rgba(255,255,255,0.06); }
.device-info-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.device-serial-label, .device-ip-label { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; min-width: 22px; }
.device-serial-value { font-size: 11px; color: var(--text); font-family: var(--font-mono); font-weight: 500; word-break: break-all; }
.device-ip-value { font-size: 13px; color: var(--accent); font-family: var(--font-mono); font-weight: 600; }
.device-model-row { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.device-adb { font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); opacity: 0.7; }
.inline-edit-input {
  background: var(--bg); border: 1px solid var(--accent); border-radius: 4px;
  color: var(--text); font-size: 13px; padding: 2px 6px; width: 100%;
  font-family: inherit; outline: none;
}
.inline-edit-input:focus { box-shadow: 0 0 0 2px var(--accent-subtle); }
.device-num .inline-edit-input { font-family: var(--font-mono); font-size: 14px; font-weight: 700; text-align: center; }
.device-badges { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge.online { background: var(--green-dim); color: var(--green); }
.badge.offline { background: var(--red-dim); color: var(--red); }
.badge.running { background: rgba(124,92,252,0.12); color: var(--accent); }
.badge.gap { background: var(--orange-dim); color: var(--orange); }
.badge.error { background: var(--red-dim); color: var(--red); }
.badge.stagger_wait { background: rgba(124,92,252,0.12); color: var(--accent); }
.badge.starting { background: var(--orange-dim); color: var(--orange); }
.badge.ready { background: var(--green-dim); color: var(--green); }
.badge.country { background: rgba(59,130,246,0.12); color: #60a5fa; text-transform: none; }
.node-country-btn { cursor: pointer; font-size: 12px; color: var(--accent); border-bottom: 1px dashed var(--accent); padding-bottom: 1px; }
.node-country-btn:hover { color: var(--text-white); border-color: var(--text-white); }
.badge.provisioning { background: var(--orange-dim); color: var(--orange); }
.device-group-tag {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 3px;
  color: #fff;
  font-weight: 600;
}
.device-script-info {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.device-script-name { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-script-runtime { color: var(--text-muted); font-family: var(--font-mono); font-size: 10px; flex-shrink: 0; }

/* ===== Group Cards ===== */
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.15s;
}
.group-card:hover { border-color: var(--border-bright); }
.group-accent { height: 3px; }
.group-content { padding: 16px; }
.group-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.group-header h3 { font-size: 15px; font-weight: 600; color: var(--text-white); }
.group-stats { display: flex; gap: 20px; }
.group-stat-value { font-size: 20px; font-weight: 700; color: var(--text-white); font-variant-numeric: tabular-nums; }
.group-stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-top: 2px; }
.group-defaults { margin-top: 10px; font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

/* ===== Task Count Badge ===== */
.task-count-badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 8px;
}

/* ===== Task Form ===== */
.task-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: slideDown 0.2s ease;
  max-width: 560px;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.task-form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}
.task-form-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-white);
}
.task-form-title svg { color: var(--accent); }
.task-form-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.task-form-close:hover { color: var(--text-bright); background: var(--surface-hover); }
.task-form-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}
.task-form-timing-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.task-form-timing-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.task-form-timing-label svg { color: var(--text-muted); opacity: 0.7; }
.timing-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.timing-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.timing-card-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}
.timing-card-unit {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  opacity: 0.7;
}
.timing-card-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}
.timing-card-inputs input {
  flex: 1;
  width: 50px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: 5px;
  color: var(--text-bright);
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.timing-card-inputs input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.timing-card-sep {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.task-form-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
}
.btn-start {
  display: flex;
  align-items: center;
  gap: 6px;
}
@media (max-width: 600px) {
  .timing-cards { grid-template-columns: 1fr; }
}

/* ===== Task List ===== */
.task-list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.task-card:hover {
  border-color: var(--border-bright);
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
.task-card-indicator {
  width: 4px;
  flex-shrink: 0;
}
.task-card-indicator.running { background: var(--green); box-shadow: inset 0 0 8px rgba(34,197,94,0.3); }
.task-card-indicator.stopped { background: var(--orange); }
.task-card-indicator.paused { background: var(--blue); }
.task-card-indicator.completed { background: var(--text-muted); }
.task-card-content {
  flex: 1;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.task-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.task-card-title-area {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.task-card-id {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.task-card-script {
  font-weight: 600;
  color: var(--accent);
  font-size: 14px;
}
.task-card-query {
  font-size: 12px;
  color: var(--text-bright);
  font-family: var(--font-mono);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-card-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.task-card-status {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.task-card-actions {
  display: flex;
  gap: 4px;
}
.task-card-actions .btn-sm {
  padding: 4px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.task-card-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.task-card-group {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 2px 8px;
  border-radius: 4px;
}
.task-card-timing {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.task-card-sep {
  color: var(--text-muted);
  opacity: 0.3;
  font-size: 11px;
}
.task-card-bottom {
  display: flex;
  align-items: center;
  gap: 16px;
}
.task-card-device-count {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text);
}
.task-card-device-count svg { opacity: 0.5; }
.task-card-time {
  font-size: 11px;
  color: var(--text-muted);
}
.task-card-stopped { opacity: 0.6; }
.task-card-completed { opacity: 0.45; }
.task-card-stopped:hover, .task-card-completed:hover { opacity: 0.85; }

/* ===== Task Detail Panel ===== */
.task-detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: slideDown 0.2s ease;
}
.task-detail-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--bg-raised);
}
.task-detail-title-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.task-detail-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-white);
}
.task-detail-summary {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.summary-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
  text-transform: capitalize;
}
.summary-chip.running { background: var(--green-dim); color: var(--green); }
.summary-chip.gap { background: var(--orange-dim); color: var(--orange); }
.summary-chip.stagger_wait { background: rgba(124,92,252,0.12); color: var(--accent); }
.summary-chip.starting { background: var(--orange-dim); color: var(--orange); }
.summary-chip.idle, .summary-chip.ready { background: var(--surface-hover); color: var(--text); }
.summary-chip.error { background: var(--red-dim); color: var(--red); }
.task-detail-body {
  padding: 16px;
  max-height: 420px;
  overflow-y: auto;
}
.task-device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.device-state-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  transition: border-color 0.15s;
}
.device-state-card:hover { border-color: var(--border-bright); }
.device-state-card.running { border-left: 3px solid var(--green); }
.device-state-card.gap { border-left: 3px solid var(--orange); }
.device-state-card.stagger_wait { border-left: 3px solid var(--accent); }
.device-state-card.starting { border-left: 3px solid var(--orange); }
.device-state-card.error { border-left: 3px solid var(--red); }
.device-state-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.device-state-num {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-white);
  font-family: var(--font-mono);
}
.device-state-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}
.device-state-badge.running { background: var(--green-dim); color: var(--green); }
.device-state-badge.gap { background: var(--orange-dim); color: var(--orange); }
.device-state-badge.stagger_wait { background: rgba(124,92,252,0.12); color: var(--accent); }
.device-state-badge.starting { background: var(--orange-dim); color: var(--orange); }
.device-state-badge.error { background: var(--red-dim); color: var(--red); }
.device-state-badge.idle, .device-state-badge.ready { background: var(--surface-hover); color: var(--text); }
.device-state-serial {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 8px;
}
.device-state-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.device-state-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}
.device-state-row span:first-child { color: var(--text-muted); }
.device-state-row span:last-child { color: var(--text); font-family: var(--font-mono); }

/* ===== Scripts Page ===== */
.scripts-layout {
  display: flex;
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.scripts-sidebar {
  width: 260px;
  flex-shrink: 0;
  overflow-y: auto;
}
.script-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.script-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.script-list-item:hover { border-color: var(--border-bright); background: var(--surface-hover); }
.script-list-item.active { border-color: var(--accent); background: var(--accent-subtle); }
.script-list-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-white);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.script-list-item-meta {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  margin-left: 8px;
}
.scripts-editor-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.script-editor-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.script-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  gap: 12px;
}
.script-editor-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.script-editor-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}
.script-editor-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.script-editor-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.script-editor-content {
  flex: 1;
  width: 100%;
  min-height: 200px;
  padding: 16px;
  background: var(--bg);
  color: var(--text-bright);
  border: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
  outline: none;
}

/* ===== Script History Panel ===== */
.script-history-panel {
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
  max-height: 280px;
  overflow-y: auto;
  flex-shrink: 0;
}
.script-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-raised);
  z-index: 1;
}
.script-history-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text);
}
.script-history-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.script-history-close:hover { color: var(--text-bright); }
.script-history-list {
  display: flex;
  flex-direction: column;
}
.script-history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.script-history-item:last-child { border-bottom: none; }
.script-history-item:hover { background: var(--surface-hover); }
.script-history-item.current { background: var(--accent-subtle); }
.history-version-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
  min-width: 32px;
}
.history-version-badge.current { color: var(--green); }
.history-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.history-date {
  font-size: 11px;
  color: var(--text-muted);
}
.history-task-stats {
  display: flex;
  gap: 10px;
  font-size: 11px;
  font-family: var(--font-mono);
}
.history-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
}
.history-stat-icon { color: var(--text-muted); font-size: 10px; }
.history-stat-value { font-weight: 600; }
.history-stat.runs .history-stat-value { color: var(--blue); }
.history-stat.time .history-stat-value { color: var(--orange); }
.history-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.history-view-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}
.history-view-btn:hover { background: var(--surface-hover); color: var(--text-bright); border-color: var(--border-bright); }
.history-view-btn.active { background: var(--accent-subtle); border-color: var(--accent); color: var(--accent); }
.history-revert-btn {
  background: var(--orange-dim);
  border: 1px solid rgba(245,158,11,0.25);
  color: var(--orange);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.12s;
}
.history-revert-btn:hover { background: rgba(245,158,11,0.18); border-color: rgba(245,158,11,0.4); }

/* ===== Sub-tabs ===== */
.sub-tabs { display: flex; gap: 2px; background: var(--surface); border-radius: 6px; padding: 2px; }
.sub-tab {
  padding: 5px 14px; border-radius: 5px; border: none; background: transparent;
  color: var(--text-muted); font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.sub-tab.active { background: var(--accent-subtle); color: var(--accent); }
.sub-tab:hover:not(.active) { color: var(--text); }
.sub-tab-content { display: none; flex: 1; min-height: 0; overflow: hidden; }
.sub-tab-content.active { display: flex; flex-direction: column; }

/* ===== Checkers ===== */
.checkers-layout { display: flex; flex-direction: column; gap: 12px; flex: 1; overflow-y: auto; padding-bottom: 20px; }
.checkers-header-row { display: flex; justify-content: flex-end; }
.checker-form {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden;
}
.checker-form-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-raised);
  font-size: 13px; font-weight: 600; color: var(--text-white);
}
.checker-form-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.checker-form-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.checker-list { display: flex; flex-direction: column; gap: 6px; }
.checker-card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color 0.15s;
}
.checker-card:hover { border-color: var(--border-bright); }
.checker-card-info { flex: 1; min-width: 0; }
.checker-card-name { font-size: 13px; font-weight: 600; color: var(--text-white); }
.checker-card-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; display: flex; gap: 12px; flex-wrap: wrap; }
.checker-card-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.checker-toggle {
  width: 36px; height: 20px; border-radius: 10px; border: none; cursor: pointer;
  position: relative; transition: background 0.2s;
}
.checker-toggle.on { background: var(--green); }
.checker-toggle.off { background: var(--surface-hover); border: 1px solid var(--border-bright); }
.checker-toggle::after {
  content: ''; position: absolute; top: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: white; transition: left 0.2s;
}
.checker-toggle.on::after { left: 18px; }
.checker-toggle.off::after { left: 2px; }
.checker-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 600;
  font-family: var(--font-mono);
}
.checker-badge.daily { background: rgba(59,130,246,0.12); color: var(--blue); }
.checker-badge.weekly { background: rgba(124,92,252,0.1); color: var(--accent); }
.checker-detail {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden;
}
.checker-detail-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-raised);
}
.checker-detail-header h3 { font-size: 14px; font-weight: 600; }
.checker-runs-list { padding: 8px; display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.checker-run-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: var(--radius); cursor: pointer; transition: background 0.15s;
}
.checker-run-item:hover { background: var(--surface-hover); }
.checker-run-item.active { background: var(--accent-subtle); }
.checker-run-status {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.checker-run-status.running { background: var(--blue); }
.checker-run-status.completed { background: var(--green); }
.checker-run-status.completed_with_errors { background: var(--orange); }
.checker-run-status.failed { background: var(--red); }
.checker-run-info { flex: 1; font-size: 12px; }
.checker-run-info .run-date { color: var(--text-bright); font-weight: 500; }
.checker-run-info .run-meta { color: var(--text-muted); margin-top: 2px; }
.checker-results-panel { border-top: 1px solid var(--border); padding: 12px 16px; }
.checker-results-panel h4 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 10px; }
.checker-results-list { display: flex; flex-direction: column; gap: 6px; }
.checker-result-item {
  padding: 10px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 12px;
}
.checker-result-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.checker-result-serial { font-weight: 600; color: var(--text-bright); font-family: var(--font-mono); font-size: 11px; }
.checker-result-status { font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 3px; }
.checker-result-status.completed { background: var(--green-dim); color: var(--green); }
.checker-result-status.error { background: var(--red-dim); color: var(--red); }
.checker-result-status.running { background: rgba(59,130,246,0.12); color: var(--blue); }
.checker-result-status.pending { background: var(--surface); color: var(--text-muted); }
.checker-result-output {
  margin-top: 6px; padding: 8px 10px; background: var(--surface);
  border-radius: 4px; font-family: var(--font-mono); font-size: 11px;
  color: var(--text); white-space: pre-wrap; word-break: break-all;
  max-height: 200px; overflow-y: auto; line-height: 1.5;
}

/* ===== Checker Reports ===== */
.reports-layout { display: flex; flex-direction: column; gap: 16px; }
.reports-toolbar {
  display: flex; align-items: center; gap: 10px; padding: 0;
}
.report-count { font-size: 12px; color: var(--text-muted); margin-left: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.report-table th {
  text-align: left; padding: 8px 10px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted);
  background: var(--bg-raised); border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.report-table td {
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  color: var(--text-bright); white-space: nowrap;
}
.report-table tr:hover td { background: var(--surface-hover); }
.report-serial { font-family: var(--font-mono); font-size: 11px; }
.report-model { color: var(--text-muted); font-weight: 400; font-size: 10px; }
.report-email { font-family: var(--font-mono); font-size: 11px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.report-badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
}
.report-badge.ok { background: var(--green-dim); color: var(--green); }
.report-badge.err { background: var(--red-dim); color: var(--red); }
.report-badge.premium { background: rgba(124,92,252,0.1); color: var(--accent); }
.report-badge.no { background: var(--surface); color: var(--text-muted); }

/* Sortable column headers on the Database page. Click to toggle asc/desc. */
.report-table thead th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 18px;
}
.report-table thead th.sortable:hover { color: var(--accent); }
.report-table thead th.sortable::after {
  content: "\2195";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  opacity: 0.35;
}
.report-table thead th.sortable.sort-asc::after  { content: "\2191"; opacity: 1; color: var(--accent); }
.report-table thead th.sortable.sort-desc::after { content: "\2193"; opacity: 1; color: var(--accent); }

/* ===== Stream Grid ===== */
.stream-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  contain: layout style;
}
.phone-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  will-change: transform;
  contain: layout style paint;
  transform: translateZ(0);
}
.phone-card:hover { border-color: var(--border-bright); }
.phone-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent), 0 0 22px var(--accent-glow), 0 0 44px var(--accent-glow);
  outline: none;
  z-index: 2;
}
.phone-card.active.script-running,
.phone-card.active.script-waiting {
  outline: none;
}
.phone-card.active::before {
  content: '\25CF  LIVE';
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 6;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
  background: var(--accent);
  border-radius: 5px;
  box-shadow: 0 0 12px var(--accent), 0 2px 8px rgba(0,0,0,0.5);
  pointer-events: none;
  animation: livePulse 1s ease-in-out infinite;
  text-shadow: 0 0 4px rgba(255,255,255,0.4);
}
@keyframes livePulse {
  0%, 100% {
    box-shadow: 0 0 10px var(--accent), 0 2px 8px rgba(0,0,0,0.5);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 22px var(--accent), 0 0 36px var(--accent-glow), 0 2px 8px rgba(0,0,0,0.5);
    transform: scale(1.08);
  }
}
.phone-card.active .phone-script-badge {
  top: 32px;
}
.phone-card.touched:not(.active) .phone-label-num::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  vertical-align: middle;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.75;
  box-shadow: 0 0 4px var(--accent-glow);
}
.phone-card canvas {
  width: 100%;
  display: block;
  min-height: 160px;
  background: var(--bg);
}
.phone-card canvas:not([data-has-frame]) {
  background: linear-gradient(110deg, var(--bg) 30%, var(--surface) 50%, var(--bg) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  animation-play-state: paused;
}
.phone-card[data-visible] canvas:not([data-has-frame]) {
  animation-play-state: running;
}
/* Stale frame indicator — no new frames for >10s */
.phone-card[data-stale] { border-color: var(--orange); }
.phone-card[data-stale]::after {
  content: '!';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 16px;
  height: 16px;
  background: var(--orange);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  z-index: 2;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.phone-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}
.phone-label-num {
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
  cursor: pointer;
  padding: 1px 3px;
  border-radius: 3px;
}
.phone-label-num:hover { background: rgba(124,92,252,0.25); }
.phone-label-name {
  cursor: pointer;
  padding: 1px 3px;
  border-radius: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.phone-label-name:hover { background: rgba(255,255,255,0.12); }
.stream-inline-edit {
  background: rgba(0,0,0,0.8);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: #fff;
  font-size: 11px;
  padding: 1px 4px;
  font-family: inherit;
  outline: none;
}
.stream-inline-edit:focus { box-shadow: 0 0 0 2px var(--accent-subtle); }
.phone-card .phone-status {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 4px var(--green);
}
.phone-card.no-stream .phone-status { background: var(--text-muted); box-shadow: none; }
.phone-restart-btn {
  position: absolute;
  top: 4px;
  right: 18px;
  width: 20px;
  height: 20px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  background: rgba(0,0,0,0.55);
  color: #f5b7b1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  z-index: 4;
}
.phone-card:hover .phone-restart-btn { opacity: 1; }
.phone-restart-btn:hover { background: #e74c3c; color: #fff; }
.phone-card.script-running .phone-status { background: var(--green); box-shadow: 0 0 6px var(--green); }
.phone-card.script-running { outline: 2px solid var(--green); outline-offset: -2px; }
.phone-card.script-waiting .phone-status { background: #f0a030; box-shadow: 0 0 6px #f0a030; }
.phone-card.script-waiting { outline: 2px solid #f0a030; outline-offset: -2px; }
.phone-script-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 20px;
  background: rgba(0, 200, 80, 0.85);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  pointer-events: none;
}
.phone-script-badge.waiting {
  background: rgba(200, 150, 30, 0.85);
  text-transform: capitalize;
}
.phone-card.script-paused .phone-status { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.phone-card.script-paused { outline: 2px solid var(--accent); outline-offset: -2px; }
.phone-script-badge.paused {
  background: rgba(124, 92, 252, 0.85);
  text-transform: capitalize;
}

/* ===== Stream eye-filter toggles =====
   Show/hide optional overlays on each phone card (timer, pause, last restart).
   State is persisted to localStorage, so reloads keep the operator's view. */
.eye-filters {
  display: inline-flex;
  gap: 6px;
  margin-left: auto;
  align-items: center;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}
.eye-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.eye-toggle input { display: none; }
.eye-toggle:has(input:checked) {
  background: var(--accent-subtle, rgba(124, 92, 252, 0.18));
  border-color: var(--accent);
  color: var(--text);
}
.eye-toggle svg { opacity: 0.85; }

/* ===== Per-card overlays =====
   Positioned absolutely over the canvas. They share the same hover/toggle
   behaviour as the restart button so they don't clutter idle cards. */
.phone-timer {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 5;
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  border-radius: 3px;
  pointer-events: none;
  line-height: 1.4;
  letter-spacing: 0.3px;
}
.phone-timer.running { color: #8ef0a4; }
.phone-timer.gap { color: #f0c040; }
.phone-timer.stagger_wait { color: #f0a030; }
.phone-timer.paused { color: #c0a0ff; }
.phone-card.active .phone-timer {
  /* Push below the "LIVE" badge when the card is the focused one. */
  top: 32px;
}
.phone-card.has-script-badge .phone-timer {
  /* Show badge + timer stacked: badge on top, timer below it. */
  top: 26px;
}
.phone-card.active.has-script-badge .phone-timer { top: 52px; }

.phone-pause-btn {
  position: absolute;
  top: 4px;
  right: 42px;
  width: 20px;
  height: 20px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: #c0a0ff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  z-index: 4;
}
.phone-card:hover .phone-pause-btn,
.phone-card.script-paused .phone-pause-btn { opacity: 1; }
.phone-pause-btn:hover { background: var(--accent); color: #fff; }
.phone-pause-btn.resume { color: #8ef0a4; }
.phone-pause-btn.resume:hover { background: var(--green, #2da060); color: #fff; }

.phone-last-restart {
  position: absolute;
  left: 6px;
  bottom: 22px;
  z-index: 4;
  padding: 1px 5px;
  background: rgba(0, 0, 0, 0.65);
  color: #f5d5a0;
  font-size: 9px;
  font-weight: 500;
  border-radius: 3px;
  pointer-events: none;
  letter-spacing: 0.2px;
}

/* Hide overlays when the matching eye-filter is off. The class lives on the
   grid container so a single toggle updates every card without a re-render. */
#stream-grid.hide-timer .phone-timer,
#stream-grid.hide-pause .phone-pause-btn,
#stream-grid.hide-restart .phone-last-restart { display: none; }

/* ===== Control Slider (right side) ===== */
#control-modal {
  position: fixed;
  inset: auto;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  width: auto;
  height: 100vh;
  display: block;
  z-index: 300;
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.2, 0.7, 0.2, 1);
}
#control-modal:not(.hidden) { transform: translateX(0); }
#control-modal.hidden {
  display: block;
  transform: translateX(100%);
  pointer-events: none;
}
.control-panel {
  pointer-events: auto;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0;
  height: 100vh;
  max-height: 100vh;
  width: auto;
  background: rgba(12,12,14,0.96);
  backdrop-filter: blur(14px);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0,0,0,0.5);
}
.control-phone-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-width: 320px;
  max-width: 500px;
  height: 100%;
}

/* Header */
.control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 16px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 0;
}
.control-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-white);
}
.control-device-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-subtle);
  border-radius: 8px;
  color: var(--accent);
}
.control-device-ip {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.control-close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s;
}
.control-close-btn:hover { background: var(--red-dim); color: var(--red); }

/* Phone frame */
.control-phone {
  background: #000;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.control-stream {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.control-stream canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  background: #000;
  object-fit: contain;
}

/* Stream loading overlay */
#control-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#control-status.visible { opacity: 1; }

.control-loader-ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid rgba(124, 92, 252, 0.15);
  border-top-color: var(--accent);
  animation: control-spin 0.9s cubic-bezier(0.4, 0.15, 0.6, 0.85) infinite;
}

.control-loader-icon {
  font-size: 36px;
  line-height: 1;
  filter: grayscale(0.3);
  animation: control-pulse 2s ease-in-out infinite;
}

.control-loader-text {
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
  text-align: center;
  max-width: 240px;
  animation: control-fade-text 1.8s ease-in-out infinite;
}

@keyframes control-spin {
  to { transform: rotate(360deg); }
}

@keyframes control-pulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

@keyframes control-fade-text {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Android nav bar */
.control-navbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
  width: 100%;
  padding: 8px 0;
  background: #101012;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0;
}
.control-nav-btn {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.5);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.12s;
}
.control-nav-btn:hover { color: rgba(255,255,255,0.85); background: rgba(255,255,255,0.06); }
.control-nav-btn:active { transform: scale(0.88); color: var(--accent); }
.control-nav-btn.nav-home { color: rgba(255,255,255,0.7); }

/* More options popup */
.extras-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.extras-popup-overlay.hidden { display: none; }
.extras-popup {
  background: var(--bg-raised);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 20px;
  min-width: 220px;
  max-width: 320px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  animation: fadeScale 0.15s ease;
}
.extras-popup-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-white);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
  text-align: center;
}
.extras-popup-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: auto;
  min-height: 56px;
  padding: 12px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s ease;
}
.control-btn:hover {
  background: var(--surface);
  color: var(--text-bright);
  border-color: var(--border);
}
.control-btn:active {
  transform: scale(0.92);
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: rgba(124,92,252,0.25);
}
.control-btn svg {
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.15s, transform 0.15s;
}
.control-btn:hover svg { opacity: 1; transform: scale(1.1); }
.control-btn:active svg { opacity: 1; color: var(--accent); }

/* Touch feedback */
.touch-dot {
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(124, 92, 252, 0.45);
  border: 2px solid rgba(124, 92, 252, 0.7);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: touchPulse 0.35s ease-out forwards;
}
@keyframes touchPulse {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--bg-raised);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  min-width: 400px;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 48px rgba(0,0,0,0.4);
  animation: fadeScale 0.15s ease;
}
@keyframes fadeScale {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { color: var(--text-white); font-size: 15px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text-bright); }
.modal-body { padding: 20px; }
.modal-body .form-group { margin-bottom: 14px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ===== Page header ===== */
.page-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.page-header h2 { font-size: 17px; font-weight: 700; color: var(--text-white); letter-spacing: -0.3px; }

/* ===== Toolbar ===== */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar select, .toolbar input {
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-bright);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.toolbar select:hover, .toolbar input:hover { border-color: var(--border-bright); }
.toolbar select:focus, .toolbar input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.filter-bar-icon {
  color: var(--text-muted);
  flex-shrink: 0;
  opacity: 0.4;
}
.filter-bar select,
.filter-bar input {
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-bright);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.filter-bar select:hover,
.filter-bar input:hover { border-color: var(--border-bright); }
.filter-bar select:focus,
.filter-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.filter-bar select.active-filter {
  border-color: var(--accent);
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 500;
}
.filter-bar input.active-filter {
  border-color: var(--accent);
  background: var(--accent-subtle);
}
.filter-search { width: 150px; }
.filter-clear-btn {
  font-size: 11px;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.15s;
  margin-left: auto;
}
.filter-clear-btn:hover {
  color: var(--red);
  border-color: rgba(239,68,68,0.3);
  background: var(--red-dim);
}

/* ===== Empty ===== */
.empty { color: var(--text-muted); text-align: center; padding: 32px 16px; font-size: 13px; line-height: 1.6; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

/* ===== Device Analytics Stats ===== */
.stat-card .stat-sub {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  font-family: var(--font-mono);
}
.stat-card.stat-clickable { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.stat-card.stat-clickable:hover { border-color: var(--border-bright); background: var(--surface-hover); }
.stat-card.stat-clickable.active { border-color: var(--accent); background: var(--accent-subtle); }

/* ===== Activity Log ===== */
.activity-log {
  max-height: 400px;
  overflow-y: auto;
  font-size: 12px;
}
.activity-entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.activity-entry:last-child { border-bottom: none; }
.activity-entry:hover { background: rgba(255,255,255,0.02); }
.activity-time {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  min-width: 52px;
  flex-shrink: 0;
}
.activity-device {
  font-weight: 600;
  color: var(--text);
  min-width: 70px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.activity-event-badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  flex-shrink: 0;
}
.activity-event-badge.error { background: var(--red-dim); color: var(--red); }
.activity-event-badge.script_running { background: var(--green-dim); color: var(--green); }
.activity-event-badge.gap_started { background: var(--orange-dim); color: var(--orange); }
.activity-event-badge.completed { background: rgba(59,130,246,0.12); color: #60a5fa; }
.activity-event-badge.script_starting { background: rgba(124,92,252,0.12); color: var(--accent); }
.activity-detail {
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-script {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
}
.activity-cycle {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

/* Device card micro-stats */
.device-micro-stats {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 10px;
  font-family: var(--font-mono);
}
.device-micro-stat {
  display: flex;
  align-items: center;
  gap: 3px;
}
.device-micro-stat .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}
.device-micro-stat .dot.green { background: var(--green); }
.device-micro-stat .dot.red { background: var(--red); }
.device-micro-stat .dot.blue { background: #60a5fa; }
.device-micro-stat-val { color: var(--text-muted); }

/* ===== Hidden ===== */
.hidden { display: none !important; }
/* The HTML `hidden` attribute — needs !important to override component styles
   like `.nav-item { display: flex }` that would otherwise win on specificity. */
[hidden] { display: none !important; }

/* ===== Tab content ===== */
.tab { display: none; flex-direction: column; gap: 16px; }
.tab.active { display: flex; }

/* ===== Mobile Menu ===== */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1100;
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  color: var(--text-bright);
  padding: 8px;
  cursor: pointer;
  line-height: 0;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
}

@media (max-width: 768px) {
  .mobile-menu-btn {
    display: block;
    top: calc(12px + env(safe-area-inset-top));
    left: calc(12px + env(safe-area-inset-left));
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main-content {
    padding: 16px 12px;
    padding-top: calc(56px + env(safe-area-inset-top));
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .page-header { flex-wrap: wrap; gap: 8px; }
  .toolbar { flex-wrap: wrap; gap: 6px; }
  .filter-bar { padding: 8px 10px; gap: 6px; }
  .filter-search { width: 100% !important; }
  .page-header h2 { font-size: 18px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .device-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .form-row { flex-direction: column; }
  .timing-cards { grid-template-columns: 1fr; }
  .scripts-layout { flex-direction: column; }
  .scripts-sidebar { width: 100%; max-height: 200px; overflow-y: auto; }
  .task-card-content { padding: 10px 12px; }
  .stream-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }

  /* Control slider — fullscreen on mobile */
  #control-modal {
    left: 0;
    right: 0;
    width: 100%;
    background: #000;
    backdrop-filter: none;
  }
  .control-panel {
    flex-direction: column;
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    border-left: none;
    box-shadow: none;
    background: #000;
  }
  .control-phone-col {
    min-width: 0;
    max-width: 100%;
    width: 100%;
  }
  .control-header {
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
    border: none;
    border-radius: 0;
    background: #101012;
    flex-shrink: 0;
  }
  .control-header-left { gap: 8px; font-size: 12px; }
  .control-device-icon { width: 28px; height: 28px; border-radius: 6px; }
  .control-device-icon svg { width: 16px; height: 16px; }
  .control-close-btn { width: 28px; height: 28px; border-radius: 6px; }
  .control-phone {
    border: none;
    border-radius: 0;
  }
  .control-navbar {
    border: none;
    border-radius: 0;
    gap: 40px;
    padding: 6px 0;
    flex-shrink: 0;
  }
  .control-nav-btn { width: 38px; height: 38px; }
  .control-device-ip { font-size: 10px; }
}

/* ===== Errors Tab ===== */
#error-ranking-table {
  width: 100%;
  border-collapse: collapse;
}
#error-ranking-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
#error-ranking-table td {
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
#error-ranking-table tbody tr:hover {
  background: var(--surface-hover);
}
.error-rank-num {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 12px;
}
.error-rank-num.top-3 {
  color: var(--red);
}
.error-count-cell {
  font-weight: 700;
  font-size: 14px;
}
.error-count-high { color: var(--red); }
.error-count-med { color: var(--orange); }
.error-count-low { color: var(--text); }
.error-count-zero { color: var(--text-muted); font-weight: 400; }
.error-bar {
  display: inline-block;
  height: 6px;
  border-radius: 3px;
  background: var(--red);
  margin-right: 6px;
  vertical-align: middle;
  opacity: 0.7;
}
.error-type-label {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.error-type-label.early_finish { background: rgba(245,158,11,0.15); color: #f59e0b; }
.error-type-label.script_error { background: rgba(239,68,68,0.15); color: #ef4444; }
.error-type-label.bad_exit { background: rgba(168,85,247,0.15); color: #a855f7; }
.error-type-label.start_timeout { background: rgba(59,130,246,0.15); color: #3b82f6; }
.error-type-label.device_offline { background: rgba(107,114,128,0.15); color: #6b7280; }
.error-type-label.stuck { background: rgba(236,72,153,0.15); color: #ec4899; }
.error-type-label.transition_error { background: rgba(107,114,128,0.15); color: #6b7280; }

.error-log-entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.error-log-entry:hover {
  background: var(--surface-hover);
}
.error-log-time {
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 60px;
  font-size: 11px;
}
.error-log-device {
  color: var(--text-bright);
  font-weight: 500;
  min-width: 80px;
  white-space: nowrap;
}
.error-log-detail {
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.error-log-script {
  color: var(--accent);
  font-size: 11px;
  white-space: nowrap;
}
.error-log-cycle {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}

/* Error detail panel */
.error-detail-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 520px;
  max-width: 90vw;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.4);
}
.error-detail-panel.hidden { display: none; }
.error-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.error-detail-header h3 {
  font-size: 14px;
  color: var(--text-white);
}
.error-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.error-detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.error-detail-row span:first-child {
  color: var(--text-muted);
}
.error-detail-row span:last-child {
  color: var(--text-bright);
  text-align: right;
}
.error-detail-output {
  margin-top: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}
.error-detail-output-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 16px;
  margin-bottom: 6px;
}

.error-log-failure-line {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--orange);
  padding: 2px 0 0 70px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cause-badge {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* ===== Trainers ===== */
.trainer-card.trainer-disabled { opacity: 0.5; }
.trainer-slots-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; cursor: pointer; min-height: 22px; align-items: center; }
.trainer-slot-pill {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600;
  background: var(--surface-hover); color: var(--text-muted);
}
.trainer-slot-pill.trainer-slot-running { background: rgba(16,185,129,0.15); color: #10b981; }
.trainer-slot-pill.trainer-slot-completed { background: rgba(59,130,246,0.15); color: #3b82f6; }
.trainer-slot-pill.trainer-slot-skipped { background: rgba(245,158,11,0.15); color: #f59e0b; }
.trainer-slot-pill.trainer-slot-error { background: rgba(239,68,68,0.15); color: #ef4444; }
.trainer-slot-pill.trainer-slot-pending { background: var(--surface-hover); color: var(--text-muted); }
.trainer-slot-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.trainer-slot-row {
  display: flex; gap: 12px; align-items: center; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font-size: 12px;
}
.trainer-slot-row:hover { border-color: var(--border-bright); }
.trainer-slot-row.trainer-slot-running { border-left: 3px solid #10b981; }
.trainer-slot-row.trainer-slot-completed { border-left: 3px solid #3b82f6; }
.trainer-slot-row.trainer-slot-error { border-left: 3px solid #ef4444; }
.trainer-slot-row.trainer-slot-skipped { border-left: 3px solid #f59e0b; }
.trainer-slot-time { font-weight: 600; color: var(--text-white); min-width: 180px; }

/* ============================================================================
   Login page
   ============================================================================ */
.login-body {
  height: 100vh; overflow: hidden;
  background: radial-gradient(ellipse at top, rgba(124,92,252,0.08), transparent 60%), var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px 32px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.4), 0 1px 0 rgba(255,255,255,0.04) inset;
}
.login-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 28px;
  color: var(--text-white);
  font-weight: 700; font-size: 18px;
  letter-spacing: -0.01em;
}
.login-logo-icon { color: var(--accent); font-size: 22px; }
.login-title {
  font-size: 22px; font-weight: 600; color: var(--text-white);
  margin-bottom: 24px; letter-spacing: -0.02em;
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; }
.login-form label span { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.login-form input {
  width: 100%; padding: 11px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-white); font-size: 14px; font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.login-form input:focus { outline: none; border-color: var(--accent); background: var(--surface-hover); }
.login-error {
  padding: 10px 14px;
  background: var(--red-dim); border: 1px solid rgba(239,68,68,0.25); border-radius: 6px;
  color: #fca5a5; font-size: 12px;
}
.login-submit {
  margin-top: 6px; padding: 12px 16px;
  background: var(--accent); border: none; border-radius: 6px;
  color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.login-submit:hover { background: var(--accent-hover); }
.login-submit:active { transform: translateY(1px); }
.login-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* ============================================================================
   Sidebar user block + role chips
   ============================================================================ */
.sidebar-user {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
}
.sidebar-user-name { color: var(--text-white); font-weight: 600; font-size: 12px; }
.sidebar-user-role {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  font-weight: 700; color: var(--text-muted);
}
.sidebar-user-role.role-admin { color: var(--accent); }
.sidebar-user-role.role-operator { color: var(--blue); }
.logout-btn { margin-top: 6px; font-size: 11px; padding: 4px 8px; }

.role-chip {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.role-chip.role-admin { background: var(--accent-subtle); color: var(--accent); }
.role-chip.role-operator { background: rgba(59,130,246,0.12); color: var(--blue); }

/* ============================================================================
   Users tab + user modal
   ============================================================================ */
.capabilities-row { display: flex; flex-direction: column; gap: 6px; }
.cap-check {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; cursor: pointer;
}
.cap-check:hover { background: var(--surface-hover); }
.cap-check input { margin: 0; }
.cap-check .hint { font-size: 10px; color: var(--text-muted); margin-left: auto; }

.user-group-list {
  display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 160px; overflow-y: auto;
}
.user-group-list .cap-check { flex: 1 1 calc(50% - 6px); min-width: 200px; }

.user-overrides-list { display: flex; flex-direction: column; gap: 4px; max-height: 140px; overflow-y: auto; }
.override-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
  font-size: 11px;
}
.override-row code { font-family: var(--font-mono); font-size: 11px; color: var(--text-bright); }

/* ============================================================================
   Audit tab
   ============================================================================ */
.audit-result {
  display: inline-block; padding: 2px 6px; border-radius: 4px;
  font-size: 10px; font-weight: 600; text-transform: uppercase;
}
.audit-result.audit-ok { background: var(--green-dim); color: var(--green); }
.audit-result.audit-denied { background: var(--red-dim); color: var(--red); }
.audit-result.audit-error { background: var(--orange-dim); color: var(--orange); }

#audit-table tbody tr { cursor: help; }
#audit-table tbody tr:hover { background: var(--surface-hover); }

/* ====================================================================
   Node Config — per-device VPN split (admin)
   ==================================================================== */
.nc-muted { color: var(--text-muted); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* toolbar select variant used in page header */
.toolbar-select {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-bright);
  padding: 5px 10px; border-radius: 6px; font-size: 12px; font-family: inherit; outline: none;
  min-width: 180px;
}
.toolbar-select:hover { border-color: var(--border-bright); }
.toolbar-select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }

/* Tunnels grid: responsive cards */
.nc-tunnels-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.nc-tunnel {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--nc-color, var(--accent));
  border-radius: 8px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
  transition: border-color 0.12s, transform 0.12s;
}
.nc-tunnel:hover { border-color: var(--border-bright); border-left-color: var(--nc-color, var(--accent)); }
.nc-tunnel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.nc-tunnel-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; font-weight: 600; color: var(--text-white);
}
.nc-tunnel-status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.nc-tunnel-status-dot.up { background: var(--green); box-shadow: 0 0 6px var(--green); }
.nc-tunnel-status-dot.down { background: var(--red); box-shadow: 0 0 6px var(--red); }
.nc-tunnel-status-dot.degraded { background: var(--orange); box-shadow: 0 0 6px var(--orange); }
.nc-tunnel-status-dot.unknown { background: var(--text-muted); }
.nc-tunnel-meta { font-size: 12px; color: var(--text); display: flex; gap: 6px; flex-wrap: wrap; }
.nc-tunnel-meta .provider { color: var(--text-bright); font-weight: 500; }
.nc-tunnel-sub {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nc-tunnel-count {
  align-self: flex-start; margin-top: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: color-mix(in srgb, var(--nc-color, var(--accent)) 15%, transparent);
  color: var(--nc-color, var(--accent));
}
.nc-tunnel-actions { display: flex; gap: 4px; margin-top: 4px; }
.nc-tunnel-empty {
  grid-column: 1 / -1;
  padding: 28px; text-align: center; color: var(--text-muted);
  border: 1px dashed var(--border); border-radius: 8px;
}
.nc-tunnel-empty a { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Bulk bar appears when rows selected */
.nc-bulk-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--accent-subtle); font-size: 12px; color: var(--text-bright);
}
.nc-bulk-bar b { color: var(--accent); font-weight: 600; }
.nc-bulk-bar select {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-bright);
  padding: 4px 10px; border-radius: 5px; font-size: 12px; font-family: inherit;
}

/* Table styling (matches other tables in the SPA) */
.nc-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.nc-table thead th {
  background: var(--bg-raised); color: var(--text-muted);
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
  font-size: 10px; padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.nc-table thead tr.nc-col-colors th { padding: 0; height: 3px; background: var(--bg-raised); border-bottom: 0; }
.nc-table thead tr.nc-col-colors th.nc-vpn-col { border-bottom: 3px solid var(--nc-color); }
.nc-table thead th.nc-sortable { cursor: pointer; user-select: none; }
.nc-table thead th.nc-sortable:hover { color: var(--text-bright); }
.nc-table thead th.nc-vpn-col {
  text-align: center; cursor: pointer; min-width: 76px;
}
.nc-table thead th.nc-vpn-col:hover { background: var(--surface-hover); }
.nc-table thead th.nc-vpn-col .nc-head-sub {
  display: block; font-size: 9px; font-weight: 400; color: var(--text-muted);
  margin-top: 2px; text-transform: none; letter-spacing: 0;
}

.nc-table tbody td {
  padding: 7px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; color: var(--text-bright);
}
.nc-table tbody tr:hover td { background: var(--surface-hover); }
.nc-table tbody tr.nc-row-selected td { background: var(--accent-subtle); }

.nc-num { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-muted); font-size: 11px; }
.nc-sn  { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); font-size: 11px; }
.nc-ip  { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-bright); font-size: 11px; }
.nc-label-input {
  background: transparent; border: 1px solid transparent; color: var(--text-bright);
  font-size: 12px; padding: 3px 6px; border-radius: 4px; width: 140px; font-family: inherit;
}
.nc-label-input:hover { border-color: var(--border); }
.nc-label-input:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.nc-row-check { cursor: pointer; }

/* VPN dot cells */
.nc-cell-vpn {
  text-align: center; cursor: pointer; padding: 0 !important; width: 76px;
}
.nc-cell-vpn .nc-dot-wrap {
  display: flex; align-items: center; justify-content: center; height: 34px;
}
.nc-cell-vpn .nc-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--text-muted); background: transparent;
  transition: all 0.12s;
}
.nc-cell-vpn:hover .nc-dot { border-color: var(--nc-color); }
.nc-cell-vpn.nc-cell-selected .nc-dot {
  background: var(--nc-color); border-color: var(--nc-color);
  box-shadow: 0 0 8px color-mix(in srgb, var(--nc-color) 60%, transparent);
}
.nc-cell-vpn.nc-cell-selected { background: color-mix(in srgb, var(--nc-color) 10%, transparent); }

/* Dropdown mode (when >12 tunnels) */
.nc-vpn-select {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-bright);
  padding: 4px 8px; border-radius: 4px; font-size: 11px; font-family: inherit; min-width: 160px;
}
.nc-vpn-select:focus { border-color: var(--accent); outline: none; }

/* Apply-state badges reuse existing .badge + extras */
.badge.applied { background: var(--green-dim); color: var(--green); }
.badge.pending { background: var(--orange-dim); color: var(--orange); }
.badge.applying { background: rgba(124,92,252,0.12); color: var(--accent); }
.badge.failed { background: var(--red-dim); color: var(--red); }
.badge.unassigned { background: rgba(255,255,255,0.05); color: var(--text-muted); }

/* Toast */
.nc-toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--surface); border: 1px solid var(--accent);
  color: var(--text-bright); padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  opacity: 0; transform: translateY(10px); transition: all 0.2s;
  pointer-events: none; z-index: 1000; max-width: 420px;
}
.nc-toast.show { opacity: 1; transform: translateY(0); }
.nc-toast.error { border-color: var(--red); }

/* ===== Live script-log panel (per-device, opt-in) ===== */
.control-logs-panel {
  display: flex;
  flex-direction: column;
  width: 460px;
  max-width: 50vw;
  height: 100%;
  background: rgba(8,9,11,0.98);
  border-left: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #d8dde3;
}
.control-logs-panel.hidden { display: none; }
.control-logs-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-raised); flex-shrink: 0;
}
.control-logs-title { display: flex; align-items: center; gap: 8px; font-family: inherit; font-size: 13px; font-weight: 600; color: var(--text); }
.control-logs-dot { width: 8px; height: 8px; border-radius: 50%; background: #4a5260; transition: background 0.2s; }
.control-logs-dot.live { background: #36d399; box-shadow: 0 0 8px rgba(54,211,153,0.6); animation: logs-pulse 1.6s infinite; }
.control-logs-dot.error { background: #ef4444; }
@keyframes logs-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.control-logs-status { font-family: ui-monospace, monospace; font-size: 11px; color: var(--text-muted); font-weight: 400; }
.control-logs-actions { display: flex; align-items: center; gap: 8px; }
.control-logs-toggle { display: flex; align-items: center; gap: 4px; font-family: inherit; font-size: 11px; color: var(--text-muted); cursor: pointer; user-select: none; }
.control-logs-toggle input { margin: 0; cursor: pointer; }
.control-logs-btn {
  background: rgba(255,255,255,0.04); border: 1px solid var(--border); color: var(--text-muted);
  padding: 4px 10px; font-size: 11px; font-family: inherit; border-radius: 4px; cursor: pointer;
}
.control-logs-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.control-logs-body {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 0;
  font-size: 11.5px; line-height: 1.45; word-break: break-word; white-space: pre-wrap;
  scrollbar-width: thin; scrollbar-color: #2a2f3a transparent;
}
.control-logs-body::-webkit-scrollbar { width: 8px; }
.control-logs-body::-webkit-scrollbar-thumb { background: #2a2f3a; border-radius: 4px; }
.control-logs-line {
  padding: 1px 12px 1px 8px; border-left: 2px solid transparent;
  display: grid; grid-template-columns: 60px 1fr; gap: 8px; align-items: baseline;
}
.control-logs-line.out { color: #c8d0db; border-left-color: rgba(108,117,255,0.5); }
.control-logs-line.err { color: #ffb4b4; background: rgba(239,68,68,0.06); border-left-color: #ef4444; }
.control-logs-line .ts { color: #5a6573; font-size: 10px; user-select: none; }
.control-logs-line .msg { white-space: pre-wrap; word-break: break-word; }
.control-logs-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; border-top: 1px solid var(--border); background: var(--bg-raised);
  font-size: 11px; color: var(--text-muted); flex-shrink: 0;
}
@media (max-width: 768px) {
  .control-logs-panel { width: 100%; max-width: 100%; }
}
