:root {
  --bg: #07080c;
  --bg-grad: radial-gradient(1200px 600px at 70% -10%, #0c0e16 0%, #07080c 55%);
  --panel: #0e1016;
  --panel2: #131620;
  --panel3: #181c26;
  --line: #1a1e27;
  --line2: #232837;
  --text: #dfe3ec;
  --muted: #8a93a6;
  --accent: #5f63ea;
  --accent-2: #7f87f7;
  --indigo-deep: #4f46e5;
  --violet: #a78bfa;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #fb7185;
  --info: #7dd3fc;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow-pop: 0 24px 60px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Inter", Roboto, sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #12141b, #0e1016);
  position: sticky; top: 0; z-index: 40;
}
header h1 {
  font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px;
  display: flex; align-items: center; gap: 9px;
}
header h1::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--accent));
  box-shadow: 0 0 0 3px rgba(127, 135, 247, .16), 0 0 14px rgba(127, 135, 247, .55);
}
.header-right { display: flex; align-items: center; gap: 14px; }
.header-right select { padding: 6px 10px; }
.health { font-size: 13px; color: var(--muted); }
.health.ok { color: #4ade80; }
.health.err { color: #fb7185; }

.seg-toggle { cursor: pointer; user-select: none; line-height: 0; }
.seg-toggle input { display: none; }
.seg-track {
  position: relative; display: flex; width: 96px; height: 30px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--line2); border-radius: 9px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .45);
}
.seg-thumb {
  position: absolute; top: 2px; left: 2px;
  width: calc(50% - 2px); height: calc(100% - 4px);
  background: linear-gradient(180deg, #7f87f7, #4f46e5);
  border-radius: 7px;
  box-shadow: 0 2px 10px rgba(95, 99, 234, .5), inset 0 1px 0 rgba(255, 255, 255, .22);
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}
.seg-option {
  position: relative; z-index: 1; flex: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #778;
  transition: color .2s ease;
}
.seg-toggle input:not(:checked) ~ .seg-track .seg-thumb { transform: translateX(0); }
.seg-toggle input:not(:checked) ~ .seg-track .seg-option.en { color: #fff; }
.seg-toggle input:checked ~ .seg-track .seg-thumb { transform: translateX(100%); }
.seg-toggle input:checked ~ .seg-track .seg-option.zh { color: #fff; }

#user-menu { position: relative; }
.icon-btn {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .05); border: 1px solid var(--line2); color: inherit;
  border-radius: 8px; cursor: pointer; font-size: 16px; line-height: 1;
  transition: background .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, .1); border-color: var(--accent); }
.dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 170px;
  background: var(--card, #1a1e26); border: 1px solid var(--line2, #2a2f3a);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  padding: 6px; z-index: 60;
}
.dropdown-item {
  display: block; width: 100%; text-align: left; padding: 9px 10px;
  background: none; border: none; border-radius: 6px; color: inherit;
  font-size: 13px; cursor: pointer; transition: background .15s ease;
}
.dropdown-item:hover { background: rgba(255, 255, 255, .08); }

#layout { display: flex; align-items: stretch; min-height: calc(100vh - 57px); }
#sidebar {
  width: 200px; flex: none; background: rgba(10, 12, 17, .6);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(8px);
  padding: 12px 10px; overflow: hidden; transition: width .18s ease, padding .18s ease;
}
.sidebar-head { display: flex; justify-content: flex-end; margin-bottom: 4px; }
#sidebar-toggle {
  background: none; border: 1px solid var(--line2); color: var(--muted); border-radius: 6px;
  width: 28px; height: 28px; cursor: pointer; font-size: 14px; line-height: 1;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
#sidebar-toggle:hover { color: #fff; border-color: var(--accent); background: rgba(95, 99, 234, .14); }
.nav-group-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #565e70;
  margin: 16px 4px 7px; white-space: nowrap; font-weight: 700;
}
#sidebar .tab {
  position: relative; display: block; width: 100%; text-align: left; margin-bottom: 3px;
  padding: 8px 12px; background: transparent; border: 1px solid transparent;
  color: #9aa5b8; border-radius: 8px; cursor: pointer; font-size: 13px; white-space: nowrap;
  transition: background .14s ease, color .14s ease;
}
#sidebar .tab:hover { background: rgba(255, 255, 255, .04); color: #dfe3ec; }
#sidebar .tab.active {
  background: linear-gradient(180deg, rgba(127, 135, 247, .22), rgba(95, 99, 234, .12));
  color: #fff; font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(127, 135, 247, .32);
}
#sidebar .tab.active::before {
  content: ""; position: absolute; left: -10px; top: 6px; bottom: 6px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--violet);
  box-shadow: 0 0 10px rgba(167, 139, 250, .75);
}
#sidebar.min { width: 44px; padding: 12px 6px; }
#sidebar.min .nav-group-title, #sidebar.min .tab { display: none; }
.tab {
  background: #1a1e26; color: #dfe; border: 1px solid var(--line2); padding: 8px 16px;
  border-radius: 6px; cursor: pointer;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab:hover { filter: brightness(1.1); }

main { flex: 1; min-width: 0; padding: 18px 22px; }
.view { display: none; }
.view.active { display: block; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.bar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.bar span { color: var(--muted); font-size: 13px; }
.bar .filter-toggle { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; }
.bar button, .device-actions button, .modal-actions button, .pipeline-kill {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff; border: none; padding: 8px 14px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; font-weight: 550;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .12);
  transition: filter .14s ease, box-shadow .14s ease, transform .05s ease;
}
.bar button:hover, .device-actions button:hover, .modal-actions button:hover {
  filter: brightness(1.12);
  box-shadow: 0 4px 16px rgba(95, 99, 234, .45), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.bar button:active, .device-actions button:active, .modal-actions button:active { transform: translateY(1px); }
button.danger { background: linear-gradient(180deg, #f87171, #dc2626); }
button.danger:hover { box-shadow: 0 4px 16px rgba(220, 38, 38, .45); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.btn, button.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff; border: none; padding: 9px 16px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; font-weight: 550;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .12);
  transition: filter .14s ease, box-shadow .14s ease;
}
button.btn:hover, button.primary:hover { filter: brightness(1.12); box-shadow: 0 4px 16px rgba(95, 99, 234, .45); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; box-shadow: 0 0 0 3px rgba(95, 99, 234, .4);
}

table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: rgba(11, 13, 18, .75); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; font-size: 13px;
}
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #1b1f28; font-size: 13px; }
tr:last-child td { border-bottom: none; }
th {
  background: rgba(19, 22, 29, .9); color: #8d96a8; font-weight: 600;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
}
tr:hover td { background: rgba(255, 255, 255, .022); }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
}
.badge.running { background: #0e2a23; color: #34d399; }
.badge.stopped { background: #22262e; color: #c9cdd6; }
.badge.completed { background: #0e2a23; color: #34d399; }
.badge.failed, .badge.error { background: #331923; color: #fb7185; }
.badge.pending, .badge.running { }
.badge.cancelled { background: #2e2510; color: #fbbf24; }
.badge.active-task { background: #382110; color: #fdba74; }
.badge.enabled { background: #0e2a23; color: #34d399; }
.badge.disabled { background: #22262e; color: #c9cdd6; }
.badge.schedule { background: #191c3a; color: #a5b4ff; }
.badge.skipped { background: #22262e; color: #c9cdd6; }
.badge.manual { background: #22262e; color: #c9cdd6; }
.badge.log-lvl { width: 64px; text-align: center; }
.badge.log-lvl.info { background: #0f2a34; color: #7dd3fc; }
.badge.log-lvl.debug { background: #22262e; color: #c9cdd6; }
.badge.log-lvl.warn { background: #2e2510; color: #fbbf24; }
.badge.log-lvl.error { background: #331923; color: #fb7185; }
.badge.ok { background: #0e2a23; color: #34d399; }
.badge.offline { background: #22262e; color: #c9cdd6; }
.badge.active-host { background: #0e2a23; color: #34d399; }
tr.row-active td { background: rgba(52, 211, 153, .09); }

#view-logs .bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#log-device { min-width: 220px; }
#log-hint {
  background: #0d0f15; border: 1px solid var(--line2); border-radius: var(--radius-sm);
  color: #c9d3ff; font-family: "Consolas", "Menlo", monospace; font-size: 12px;
  padding: 10px 12px; margin: 10px 0; white-space: pre-wrap; max-height: 40vh; overflow: auto;
}
.log-body {
  background: #090b0f; border: 1px solid var(--line2); border-radius: var(--radius-sm);
  height: 62vh; overflow-y: auto; padding: 6px 10px;
  font-family: "Consolas", "Menlo", monospace; font-size: 12px; color: #dfe3ec;
}
.log-line { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; border-bottom: 1px solid #13161d; }
.log-time { color: #818ba0; flex: none; }
.log-dev { color: #fbbf24; flex: none; }
.log-empty { color: var(--muted); padding: 10px; }
.log-msg { word-break: break-all; }

.device-actions { margin-top: 12px; display: flex; gap: 10px; align-items: center; }
.device-actions select { background: #1a1e26; color: #dfe3ec; border: 1px solid var(--line2); padding: 8px; border-radius: var(--radius-sm); }
a.link { color: #9aa7ff; cursor: pointer; text-decoration: none; transition: color .12s ease; }
a.link:hover { text-decoration: underline; color: #b4bfff; }

.modal {
  position: fixed; inset: 0; background: rgba(3, 5, 9, .7);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  animation: modalBg .16s ease;
}
.modal.hidden { display: none; }
.hidden { display: none !important; }
@keyframes modalBg { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: linear-gradient(180deg, #14161f, #10121a);
  border: 1px solid #222636; border-radius: 14px;
  width: 640px; max-width: 94vw; padding: 20px;
  box-shadow: var(--shadow-pop);
  animation: modalCard .2s cubic-bezier(.2, .8, .25, 1);
}
@keyframes modalCard { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
.modal-card.wide { width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; }
.modal-head button { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; transition: color .12s ease; }
.modal-head button:hover { color: #fff; }
label { display: block; margin: 10px 0 4px; font-size: 12px; color: var(--muted); }
input, textarea, select {
  background: #0d0f15; color: var(--text);
  border: 1px solid var(--line2); border-radius: var(--radius-sm);
  font-family: inherit;
  transition: border-color .14s ease, box-shadow .14s ease;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input, textarea { padding: 9px 11px; }
textarea { min-height: 320px; font-family: "Consolas", "Menlo", monospace; font-size: 12px; white-space: pre; }
select { padding: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }

#run-detail { font-size: 13px; }
#run-detail table { margin-top: 10px; }

#view-shot-wrap { text-align: center; }
#view-shot { max-width: 100%; max-height: 72vh; border-radius: var(--radius-sm); border: 1px solid var(--line2); margin: 6px 0; }

.view-status { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.view-status.ok { color: #34d399; }
.view-status.err { color: #fb7185; }
.view-status.warn { color: #fbbf24; }
.view-stream {
  width: 100%; height: 64vh; background: #090b0f;
  border: 1px solid var(--line2); border-radius: var(--radius-sm); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.view-stream .vmos-canvas-container { max-width: 100%; max-height: 100%; }
.live-btns { justify-content: flex-start; flex-wrap: wrap; }
.live-send { gap: 8px; }
.live-send input { width: 260px; }
button.live-btn {
  background: #1a1e26; color: #dfe3ec; border: 1px solid var(--line2);
  padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
  transition: background .12s ease, border-color .12s ease;
}
button.live-btn:hover { background: #232733; border-color: var(--accent); }

.checkgrid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; max-height: 220px;
  overflow-y: auto; padding: 10px; background: rgba(10, 12, 17, .6);
  border: 1px solid var(--line2); border-radius: var(--radius-sm);
}
.checkgrid label.check {
  display: flex; align-items: center; gap: 6px; font-size: 13px; color: #dfe;
  margin: 0; white-space: nowrap; min-width: 0; padding: 3px 4px; border-radius: 5px;
  transition: background .1s ease;
}
.checkgrid label.check:hover { background: rgba(255, 255, 255, .035); }
.checkgrid label.check input[type="checkbox"] { width: 14px; height: 14px; flex: none; accent-color: var(--accent); }
.checkgrid label.check .name { overflow: hidden; text-overflow: ellipsis; }
.row { display: flex; gap: 18px; align-items: center; margin: 10px 0 4px; }
label.radio { display: inline-flex; gap: 6px; font-size: 13px; color: #dfe; margin: 0; }
.muted { color: var(--muted); font-size: 12px; }

.limits-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 12px; padding: 10px 12px;
  background: rgba(10, 12, 17, .6); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.limits-bar label { margin: 0; display: inline-block; }
.limits-bar input[type="number"], .limits-bar input[type="text"] { width: 130px; }
.limits-bar select { padding: 7px; }
.num-input { width: 90px !important; }
.mv-input {
  padding: 6px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--line2); background: #0f1218; color: #dfe;
  font-family: inherit; transition: border-color .14s ease, box-shadow .14s ease;
}
.mv-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95, 99, 234, .25); outline: none; }
.mv-num { width: 74px; }
.mv-select { max-width: 160px; }
.msg {
  margin: 10px 0; padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 13px; background: rgba(10, 12, 17, .6); border: 1px solid var(--line2); white-space: pre-wrap;
}
.msg.ok { border-color: #0e2a23; color: #34d399; }
.msg.err { border-color: #331923; color: #fb7185; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line2); }
.persona-pic { width: 56px; height: 56px; border-radius: 50%; }
.badge.interest { background: #191c3a; color: #a5b4ff; }
.post-title { font-weight: 600; }
.badge.feedback-0 { background: #22262e; color: #c9cdd6; }
.badge.feedback-1, .badge.added, .badge.delivered { background: #0e2a23; color: #34d399; }
.badge.feedback-2, .badge.not_found { background: #2e2510; color: #fbbf24; }
.badge.feedback-3, .badge.error { background: #331923; color: #fb7185; }
.badge.feedback-4, .badge.exists { background: #191c3a; color: #a5b4ff; }
.badge.available, .badge.queued { background: #191c3a; color: #a5b4ff; }
.badge.dispensed { background: #2e2510; color: #fbbf24; }
.badge.wechat, .badge.facebook, .badge.instagram, .badge.x { background: #22262e; color: #dfe; }

/* Settings tab */
.badge.warn { background: #2e2510; color: #fbbf24; }
.settings-grid { display: flex; flex-direction: column; gap: 0; margin-top: 12px; max-width: 760px; }
.setting-row { display: flex; align-items: center; gap: 14px; padding: 10px 12px; border-bottom: 1px solid #1b1f28; }
.setting-row:hover { background: rgba(255, 255, 255, 0.02); }
.setting-label { flex: 1 1 auto; min-width: 220px; font-size: 13px; color: #dfe; }
.setting-input input[type="text"], .setting-input input[type="number"], .setting-input select {
  padding: 7px 9px; border-radius: var(--radius-sm); border: 1px solid var(--line2); background: #0f1218; color: #dfe; font-size: 13px;
}
.setting-input input[type="text"], .setting-input input[type="number"] { width: 220px; }
.setting-input input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); }
#view-settings .hint { margin-top: 14px; color: #8a93a6; font-size: 12px; max-width: 760px; }

/* Pipeline canvas */
.pipeline-workspace { display: flex; gap: 0; height: calc(100vh - 160px); min-height: 400px; }
.pipeline-scripts { width: 180px; min-width: 180px; background: rgba(10, 12, 17, .6); border-right: 1px solid #1b1f28; overflow-y: auto; padding: 10px; }
.pipeline-scripts-hint { color: #666; font-size: 12px; padding: 8px 0; }
.pipeline-script-item {
  padding: 8px 10px; margin-bottom: 4px; background: #151821; border: 1px solid var(--line2);
  border-radius: var(--radius-sm); font-size: 12px; color: #dfe; cursor: grab;
  user-select: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: border-color .12s ease, background .12s ease, transform .12s ease;
}
.pipeline-script-item:hover { border-color: var(--accent); background: #191d2b; transform: translateY(-1px); }
.pipeline-script-item:active { cursor: grabbing; }
.pipeline-canvas { flex: 1; position: relative; overflow: auto; background: #0b0d12; background-image: radial-gradient(circle, #191d25 1px, transparent 1px); background-size: 20px 20px; }
.pipeline-edges-svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.pipeline-edges-svg line { pointer-events: stroke; cursor: pointer; }
.pipeline-edges-svg line:hover { stroke-width: 4; }
.pipeline-nodes { position: relative; z-index: 2; }
.pipeline-node {
  position: absolute; width: 140px; min-height: 48px; background: #151821;
  border: 2px solid var(--line2); border-radius: 10px; padding: 8px 10px; cursor: move; user-select: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.pipeline-node:hover { border-color: #555; box-shadow: 0 6px 18px rgba(0, 0, 0, .6); }
.pipeline-node.node-running { border-color: var(--accent); box-shadow: 0 0 16px rgba(95, 99, 234, .35); }
.pipeline-node.node-completed { border-color: #14532d; }
.pipeline-node.node-failed { border-color: #7f1d1d; }
.pipeline-node-title { font-size: 11px; color: #dfe; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pipeline-node-actions { display: flex; gap: 8px; margin-top: 4px; }
.pipeline-node-connect, .pipeline-node-delete, .pipeline-node-edit { font-size: 13px; color: #666; cursor: pointer; }
.pipeline-node-connect:hover, .pipeline-node-edit:hover { color: var(--accent); }
.pipeline-node-delete:hover { color: #fb7185; }
.pipeline-node.wait-node { border-color: #92600a; }
.pipeline-block-item { border-color: #92600a; color: #fdba74; }
.wait-countdown { color: #fdba74; font-variant-numeric: tabular-nums; }
.pipeline-run-device { background: #11141c; font-weight: 600; color: #dfe; }
.schedlog { padding: 8px 10px; border-bottom: 1px solid #1b1f28; font-size: 12px; color: #dfe; }
.schedlog.skip { background: #2e2510; }
.schedlog.error { background: #331923; }
.badge.info { background: #0f2a34; color: #7dd3fc; }
.badge.super { background: #301a2e; color: #e879f9; }
.perm-cell { display: inline-block; margin: 2px; padding: 2px 8px; border-radius: 999px; background: rgba(19, 22, 29, .9); border: 1px solid #1b1f28; font-size: 12px; color: #8d96a8; }
.perm-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid #1b1f28; }
.perm-row:last-child { border-bottom: none; }
.perm-label { flex: 1; font-weight: 600; }
.pipeline-title { font-weight: 600; font-size: 14px; color: #dfe; margin: 0 12px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1f232c; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #272c38; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }