/* ── Variables ── */
:root {
  --bg:        #0a0c10;
  --bg2:       #0f1218;
  --bg3:       #151922;
  --border:    rgba(255,255,255,0.07);
  --border2:   rgba(255,255,255,0.12);
  --text:      #e8eaf0;
  --muted:     #6b7280;
  --accent:    #4f9cf9;
  --accent2:   #7c5af8;
  --green:     #22d3a8;
  --red:       #f43f5e;
  --yellow:    #f59e0b;
  --card-bg:   rgba(255,255,255,0.035);
  --card-bg2:  rgba(255,255,255,0.06);
  --mono:      'Space Mono', monospace;
  --radius:    12px;
  --radius-sm: 7px;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* ── Background noise ── */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.025;
  pointer-events: none;
}

/* ── Grid overlay ── */
body::after {
  content: '';
  position: fixed; inset: 0; z-index: 0;
  background-image: linear-gradient(rgba(79,156,249,0.04) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(79,156,249,0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

/* ── Glow orbs ── */
.orb {
  position: fixed; border-radius: 50%; filter: blur(80px);
  pointer-events: none; z-index: 0;
}
.orb-1 { width: 400px; height: 400px; top: -100px; right: -80px; background: rgba(79,156,249,0.08); }
.orb-2 { width: 300px; height: 300px; bottom: 50px; left: -60px; background: rgba(124,90,248,0.07); }

/* ── Layout ── */
.wrap {
  position: relative; z-index: 1;
  max-width: 860px; margin: 0 auto;
  padding: 0 20px 60px;
}

/* ── Header ── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 28px 0 32px;
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-badge {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 13px; font-weight: 700; color: #fff;
  letter-spacing: -1px;
}
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: -0.5px; }
.logo-sub { font-size: 11px; color: var(--muted); margin-top: 1px; font-family: var(--mono); }

.header-actions { display: flex; align-items: center; gap: 8px; }
.hbtn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border2); background: var(--card-bg);
  color: var(--text); font-size: 12px; font-family: 'Space Grotesk', sans-serif;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.hbtn:hover { background: var(--card-bg2); border-color: rgba(255,255,255,0.2); }
.hbtn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.hbtn .dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
.badge-count {
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 10px; min-width: 18px; text-align: center;
}
.theme-btn {
  padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border2); background: var(--card-bg);
  cursor: pointer; transition: all 0.15s; font-size: 14px;
}
.theme-btn:hover { background: var(--card-bg2); }

/* ── Tabs ── */
.tabs {
  display: flex; gap: 4px;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px; margin: 28px 0 0;
}
.tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: 7px; border: none;
  background: transparent; color: var(--muted); font-size: 13px;
  font-family: 'Space Grotesk', sans-serif; font-weight: 500;
  cursor: pointer; transition: all 0.18s;
}
.tab.active {
  background: var(--bg3); color: var(--text); border: 1px solid var(--border2);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.tab svg { flex-shrink: 0; }

/* ── Panel ── */
.panel { display: none; padding-top: 24px; }
.panel.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Card ── */
.card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.card-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin-bottom: 14px; font-family: var(--mono);
}

/* ── Gear row (upload) ── */
.gear-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.gear-btn {
  flex: 1; min-width: 80px; padding: 10px 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--border2);
  background: var(--bg3); cursor: pointer; transition: all 0.15s;
  text-align: center; color: var(--muted);
}
.gear-btn.active { background: rgba(79,156,249,0.12); border-color: rgba(79,156,249,0.4); color: var(--accent); }
.gear-btn:hover:not(.disabled-gear) { border-color: rgba(255,255,255,0.2); color: var(--text); }
.gear-btn.disabled-gear { opacity: 0.35; cursor: not-allowed; }
.gear-num { display: block; font-size: 22px; font-weight: 700; font-family: var(--mono); }
.gear-label { display: block; font-size: 11px; font-weight: 600; margin-top: 2px; }
.gear-desc { display: block; font-size: 10px; opacity: 0.7; margin-top: 2px; }

/* ── Meta chips ── */
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.meta-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 20px;
  border: 1px solid var(--border2); background: var(--bg3);
  font-size: 11px; color: var(--muted); font-family: var(--mono);
}
.meta-chip span { color: var(--text); font-weight: 600; }
.meta-chip.highlight span { color: var(--accent); }

/* ── Dropzone ── */
.dropzone {
  border: 2px dashed var(--border2); border-radius: var(--radius);
  padding: 36px 20px; text-align: center; cursor: pointer;
  transition: all 0.18s; position: relative; background: var(--bg3);
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: rgba(79,156,249,0.06); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.dz-icon { color: var(--muted); margin-bottom: 10px; }
.dz-label { font-size: 14px; font-weight: 500; }
.dz-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── File list ── */
#file-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.file-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--bg3); border: 1px solid var(--border);
}
.ficon {
  font-size: 10px; font-weight: 700; padding: 4px 6px;
  background: rgba(79,156,249,0.15); color: var(--accent);
  border-radius: 5px; font-family: var(--mono); flex-shrink: 0;
}
.fname { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsize { font-size: 11px; color: var(--muted); font-family: var(--mono); flex-shrink: 0; }
.remove-btn {
  padding: 2px 6px; border: none; background: none;
  color: var(--muted); cursor: pointer; font-size: 12px; border-radius: 4px;
}
.remove-btn:hover { color: var(--red); background: rgba(244,63,94,0.1); }

/* ── Buttons ── */
.btn-row { display: flex; gap: 8px; margin-top: 16px; }
.btn {
  padding: 10px 20px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-family: 'Space Grotesk', sans-serif; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.15s; display: flex; align-items: center; gap: 7px;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; flex: 1; justify-content: center;
  box-shadow: 0 2px 16px rgba(79,156,249,0.25);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(79,156,249,0.35); }
.btn-ghost {
  background: var(--card-bg); border-color: var(--border2); color: var(--muted);
}
.btn-ghost:hover { color: var(--text); background: var(--card-bg2); }
.btn-download {
  background: rgba(34,211,168,0.12); border-color: rgba(34,211,168,0.3);
  color: var(--green); flex: 1; justify-content: center;
}
.btn-download:hover { background: rgba(34,211,168,0.2); }
.btn-preview {
  background: rgba(124,90,248,0.12); border-color: rgba(124,90,248,0.3);
  color: var(--accent2); padding: 10px 22px; min-width: 110px; justify-content: center;
}
.btn-preview:hover { background: rgba(124,90,248,0.2); }
.btn-stream {
  background: var(--card-bg); border-color: var(--border2); color: var(--muted); padding: 10px 12px;
}
.btn-stream:hover { color: var(--text); }
.btn-cancel {
  background: rgba(244,63,94,0.12); border-color: rgba(244,63,94,0.3); color: var(--red);
}

/* ── Progress area ── */
#progress-area { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.prog-item { padding: 14px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.prog-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.prog-name { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.prog-label { font-size: 11px; color: var(--muted); font-family: var(--mono); flex-shrink: 0; margin-left: 8px; }
.prog-label.err { color: var(--red); }
.prog-bar-bg { height: 4px; background: var(--border2); border-radius: 2px; overflow: hidden; }
.prog-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 2px; transition: width 0.3s; }
.prog-bar.err { background: var(--red); }
.prog-nodes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.prog-node-tag {
  font-size: 10px; padding: 2px 7px; border-radius: 10px; font-family: var(--mono);
  border: 1px solid var(--border2); color: var(--muted); background: var(--bg);
}
.prog-node-tag.active { border-color: var(--accent); color: var(--accent); animation: blink 0.8s infinite; }
.prog-node-tag.done { border-color: var(--green); color: var(--green); }
@keyframes blink { 50% { opacity: 0.5; } }

/* ── Result area ── */
#result-area, #dl-result-area { display: none; }
.result-header { font-size: 11px; color: var(--green); font-family: var(--mono); margin-bottom: 10px; }
.result-item { margin-bottom: 8px; }
.ri-name { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.ri-code {
  font-family: var(--mono); font-size: 11px; padding: 10px 12px;
  background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius-sm);
  cursor: pointer; word-break: break-all; transition: all 0.15s; user-select: all;
}
.ri-code:hover { border-color: var(--accent); background: rgba(79,156,249,0.06); }
.ri-code.copied { border-color: var(--green); color: var(--green); }

/* ── Error ── */
.error-msg {
  display: none; padding: 10px 12px; border-radius: var(--radius-sm);
  background: rgba(244,63,94,0.1); border: 1px solid rgba(244,63,94,0.3);
  font-size: 12px; color: var(--red); margin-top: 12px;
}

/* ── Download panel specific ── */
.code-input-wrap {
  display: flex; gap: 8px; align-items: stretch;
}
.code-input-wrap input {
  flex: 1; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); font-family: var(--mono); font-size: 12px;
  outline: none; transition: border-color 0.15s;
}
.code-input-wrap input:focus { border-color: var(--accent); }
.code-input-wrap input::placeholder { color: var(--muted); }

.threads-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.threads-label { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.thread-btns { display: flex; gap: 4px; }
.thread-btn {
  padding: 5px 12px; border-radius: 20px; border: 1px solid var(--border2);
  background: var(--bg3); color: var(--muted); font-size: 12px;
  font-family: var(--mono); cursor: pointer; transition: all 0.15s;
}
.thread-btn.active { background: rgba(79,156,249,0.12); border-color: rgba(79,156,249,0.4); color: var(--accent); }
.threads-badge {
  font-size: 11px; color: var(--muted); font-family: var(--mono);
  padding: 4px 10px; border-radius: 10px; background: var(--bg3); border: 1px solid var(--border);
}

/* ── Status bar ── */
.status-bar { display: none; padding: 12px 14px; border-radius: var(--radius-sm); margin-top: 14px; font-size: 13px; }
.status-bar.info    { background: rgba(79,156,249,0.08); border: 1px solid rgba(79,156,249,0.2); color: var(--accent); }
.status-bar.success { background: rgba(34,211,168,0.08); border: 1px solid rgba(34,211,168,0.2); color: var(--green); }
.status-bar.warn    { background: rgba(245,158,11,0.08); border: 1px solid rgba(245,158,11,0.2); color: var(--yellow); }
.status-bar.error   { background: rgba(244,63,94,0.08); border: 1px solid rgba(244,63,94,0.2); color: var(--red); }
.status-json {
  margin-top: 8px; font-size: 11px; font-family: var(--mono); opacity: 0.7;
  white-space: pre-wrap; word-break: break-all;
}
.progress-wrap { margin-top: 10px; }
.progress-track { height: 4px; background: rgba(255,255,255,0.08); border-radius: 2px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.3s; border-radius: 2px; }
.progress-label { font-size: 11px; color: var(--muted); margin-top: 5px; font-family: var(--mono); }
.speed-badge { font-size: 11px; font-family: var(--mono); padding: 2px 8px; background: rgba(255,255,255,0.07); border-radius: 10px; }
.eta-label { font-size: 11px; color: var(--muted); font-family: var(--mono); margin-top: 3px; }

/* ── File info panel ── */
.info-panel { display: none; }
.info-grid {
  display: grid; grid-template-columns: 120px 1fr;
  gap: 6px 14px; font-size: 12px;
}
.info-label { color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 4px; }
.info-value { font-family: var(--mono); font-size: 11px; word-break: break-all; }
.info-value.highlight { color: var(--accent); font-weight: 700; }
.file-icon-badge { font-size: 28px; float: right; }

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }

.copy-link-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 20px; border: 1px solid var(--border2);
  background: var(--bg3); color: var(--muted); font-size: 11px;
  cursor: pointer; transition: all 0.15s;
}
.copy-link-btn:hover { color: var(--accent); border-color: rgba(79,156,249,0.4); }
.copy-link-btn.copied { color: var(--green); border-color: rgba(34,211,168,0.4); }

/* ── Chunk map ── */
.chunk-map-wrap { margin-bottom: 16px; }
.chunk-map-label { font-size: 11px; color: var(--muted); margin-bottom: 6px; font-family: var(--mono); }
.chunk-map { display: flex; flex-wrap: wrap; gap: 3px; }
.chunk-cell {
  width: 10px; height: 10px; border-radius: 2px;
  background: var(--border2); transition: background 0.3s;
}
.chunk-cell.filled { background: var(--accent); opacity: 0.6; }
.chunk-cell.last { background: var(--green); opacity: 1; }

/* ── Action zone ── */
.action-zone { display: none; flex-wrap: wrap; gap: 8px; }
.action-zone.visible { display: flex; }

/* ── History panel ── */
.history-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.history-header-left { display: flex; align-items: center; gap: 8px; }
.hist-count { font-size: 11px; padding: 1px 7px; background: var(--bg3); border-radius: 10px; border: 1px solid var(--border); font-family: var(--mono); color: var(--muted); }
.collapse-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.clear-hist { padding: 4px 10px; border-radius: 20px; border: 1px solid var(--border2); background: none; color: var(--muted); font-size: 11px; cursor: pointer; transition: all 0.15s; }
.clear-hist:hover { color: var(--red); border-color: rgba(244,63,94,0.4); }

.history-body { overflow: hidden; transition: max-height 0.3s; }
.history-body.collapsed { max-height: 0 !important; }

.hist-filter input {
  width: 100%; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg3);
  color: var(--text); font-size: 12px; margin-bottom: 8px; outline: none;
  font-family: 'Space Grotesk', sans-serif;
}
.hist-filter input:focus { border-color: var(--accent); }

.history-list { display: flex; flex-direction: column; gap: 4px; }
.history-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: var(--radius-sm); background: var(--bg3); border: 1px solid var(--border);
  cursor: pointer; transition: all 0.15s;
}
.history-item:hover { border-color: var(--border2); background: var(--card-bg2); }
.hist-icon { font-size: 16px; flex-shrink: 0; }
.hist-info { flex: 1; min-width: 0; }
.hist-name { font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-meta { font-size: 10px; color: var(--muted); margin-top: 1px; font-family: var(--mono); }
.hist-code { font-size: 10px; color: var(--muted); font-family: var(--mono); flex-shrink: 0; }
.hist-actions { display: flex; gap: 4px; flex-shrink: 0; }
.hist-act-btn {
  padding: 3px 6px; border: none; background: none; color: var(--muted);
  cursor: pointer; border-radius: 4px; font-size: 11px; transition: all 0.12s;
}
.hist-act-btn:hover { background: var(--bg); }
.hist-act-btn.copy:hover { color: var(--accent); }
.hist-act-btn.del:hover { color: var(--red); }
.history-empty { text-align: center; padding: 24px; color: var(--muted); font-size: 13px; }

.hist-pagination { display: none; align-items: center; justify-content: center; gap: 10px; margin-top: 10px; }
.hist-page-btn {
  padding: 4px 12px; border: 1px solid var(--border2); border-radius: 20px;
  background: var(--bg3); color: var(--muted); font-size: 11px; cursor: pointer;
}
.hist-page-btn:hover:not(:disabled) { color: var(--text); }
.hist-page-btn:disabled { opacity: 0.4; cursor: default; }
.hist-page-info { font-size: 11px; color: var(--muted); font-family: var(--mono); }

/* ── Node stats bar ── */
.node-stats-bar { display: none; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.node-stat-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--muted); font-family: var(--mono);
}
.node-stat-chip b { color: var(--accent); }

/* ── Script config ── */
.script-wrap textarea {
  width: 100%; padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); font-family: var(--mono); font-size: 11px;
  resize: vertical; outline: none; min-height: 120px;
  transition: border-color 0.15s;
}
.script-wrap textarea:focus { border-color: var(--accent); }
.script-analyze {
  display: none; margin-top: 10px; padding: 10px 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 11px;
}
.analyze-row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.analyze-key { color: var(--muted); }
.analyze-val { }
.analyze-val.ok { color: var(--green); }
.analyze-val.err { color: var(--red); }
.analyze-endpoint { margin-top: 6px; padding: 4px 8px; background: rgba(79,156,249,0.08); border-radius: 4px; display: flex; gap: 6px; align-items: center; }
.analyze-method { color: var(--accent); font-weight: 700; font-size: 10px; }

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 14px;
  width: 100%; max-width: 600px; max-height: 90vh; overflow: hidden;
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  transform: translateY(10px); transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: none; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.modal-title-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.modal-close {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border2);
  background: var(--bg3); color: var(--muted); cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--card-bg2); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-body video, .modal-body audio { width: 100%; border-radius: 8px; }
.modal-body img { max-width: 100%; border-radius: 8px; display: block; margin: 0 auto; }
.modal-body textarea { width: 100%; height: 300px; resize: vertical; font-family: var(--mono); font-size: 11px; padding: 12px; background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius-sm); color: var(--text); outline: none; }
.modal-loading { color: var(--muted); font-size: 13px; }

/* ── Node modal ── */
.node-modal { max-width: 680px; }
.node-add-form { margin-bottom: 20px; }
.field-label { font-size: 11px; color: var(--muted); font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.node-form-grid { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 10px; margin-bottom: 10px; }
.node-input {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); font-size: 12px; font-family: 'Space Grotesk', sans-serif; outline: none;
  transition: border-color 0.15s;
}
.node-input:focus { border-color: var(--accent); }
.node-input::placeholder { color: var(--muted); }
.btn-add-node {
  padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid rgba(79,156,249,0.4);
  background: rgba(79,156,249,0.1); color: var(--accent); font-size: 12px;
  cursor: pointer; transition: all 0.15s; font-family: 'Space Grotesk', sans-serif;
}
.btn-add-node:hover { background: rgba(79,156,249,0.2); }
.node-add-error { display: none; font-size: 11px; color: var(--red); margin-top: 6px; }

.node-io-bar { display: flex; gap: 6px; margin: 10px 0; flex-wrap: wrap; }
.node-io-btn {
  display: flex; align-items: center; gap: 5px; padding: 5px 10px;
  border-radius: 20px; border: 1px solid var(--border2); background: var(--bg3);
  color: var(--muted); font-size: 11px; cursor: pointer; transition: all 0.15s;
}
.node-io-btn:hover { color: var(--text); border-color: var(--border2); }

.node-remote-row {
  display: none; gap: 8px; align-items: center;
  padding: 10px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 10px;
}
.node-remote-row.open { display: flex; }
.node-remote-row input { flex: 1; padding: 7px 10px; border-radius: 5px; border: 1px solid var(--border2); background: var(--bg); color: var(--text); font-size: 12px; outline: none; }
.node-fetch-btn { padding: 6px 14px; border-radius: 5px; border: 1px solid rgba(79,156,249,0.4); background: rgba(79,156,249,0.1); color: var(--accent); font-size: 12px; cursor: pointer; }
.node-cancel { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; }

.node-progress-wrap { display: none; padding: 10px 0; }
.node-progress-track { height: 3px; background: var(--border2); border-radius: 2px; margin-bottom: 5px; overflow: hidden; }
.node-progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; }
.node-progress-label { font-size: 11px; color: var(--muted); font-family: var(--mono); }

.node-section-label { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--muted); margin: 10px 0 8px; font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.5px; }
.test-all-btn {
  display: flex; align-items: center; gap: 4px; padding: 4px 10px;
  border-radius: 20px; border: 1px solid var(--border2); background: var(--bg3);
  color: var(--muted); font-size: 11px; cursor: pointer; transition: all 0.15s;
}
.test-all-btn:hover { color: var(--text); }

.node-list { display: flex; flex-direction: column; gap: 6px; }
.node-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg3); cursor: pointer; transition: all 0.15s;
}
.node-item.selected { border-color: rgba(79,156,249,0.4); background: rgba(79,156,249,0.06); }
.node-item:hover { border-color: var(--border2); }
.node-radio { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all 0.15s; }
.node-item.selected .node-radio { border-color: var(--accent); }
.node-radio-inner { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); opacity: 0; transition: opacity 0.15s; }
.node-item.selected .node-radio-inner { opacity: 1; }
.node-info { flex: 1; min-width: 0; }
.node-url-text { font-size: 12px; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-name-text { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.node-tag { font-size: 10px; padding: 1px 6px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.node-tag.active { border-color: rgba(34,211,168,0.4); color: var(--green); }
.node-tag.default { border-color: rgba(79,156,249,0.4); color: var(--accent); }

.node-ping-badge {
  font-size: 10px; font-family: var(--mono); padding: 2px 8px;
  border-radius: 10px; border: 1px solid transparent; flex-shrink: 0;
}
.node-ping-badge.fast { background: rgba(34,211,168,0.1); border-color: rgba(34,211,168,0.3); color: var(--green); }
.node-ping-badge.mid  { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.3); color: var(--yellow); }
.node-ping-badge.slow { background: rgba(244,63,94,0.1); border-color: rgba(244,63,94,0.3); color: var(--red); }
.node-ping-badge.timeout { background: rgba(244,63,94,0.1); border-color: rgba(244,63,94,0.3); color: var(--red); }
.node-ping-badge.idle, .node-ping-badge.testing { background: var(--bg); border-color: var(--border); color: var(--muted); }

.node-actions { display: flex; gap: 4px; flex-shrink: 0; }
.node-action-btn {
  padding: 4px 8px; border: none; background: none; color: var(--muted);
  cursor: pointer; border-radius: 4px; font-size: 11px; transition: all 0.12s;
}
.node-action-btn:hover { background: var(--bg); }
.node-action-btn.test:hover { color: var(--accent); }
.node-action-btn.del:hover { color: var(--red); }
.node-empty { text-align: center; padding: 20px; color: var(--muted); font-size: 13px; }

/* ── Upload history modal ── */
.upload-hist-item { margin-bottom: 8px; padding: 10px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.uh-top { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 12px; }
.uh-name { font-weight: 500; }
.uh-time { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.uh-code { font-family: var(--mono); font-size: 11px; padding: 7px 10px; background: var(--bg); border: 1px solid var(--border2); border-radius: 5px; cursor: pointer; word-break: break-all; }
.uh-code:hover { border-color: var(--accent); }
.uh-code.copied { border-color: var(--green); color: var(--green); }
.upload-hist-empty { text-align: center; padding: 24px; color: var(--muted); font-size: 13px; }
.hist-footer { display: none; align-items: center; justify-content: space-between; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.btn-clear-history { padding: 5px 12px; border-radius: 20px; border: 1px solid rgba(244,63,94,0.3); background: none; color: var(--red); font-size: 11px; cursor: pointer; }
.hist-paging { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); font-family: var(--mono); }
.pg-btn { padding: 3px 10px; border: 1px solid var(--border2); border-radius: 20px; background: var(--bg3); color: var(--muted); font-size: 12px; cursor: pointer; }
.pg-btn:hover:not(:disabled) { color: var(--text); }
.pg-btn:disabled { opacity: 0.4; cursor: default; }


/* ── Toast ── */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  padding: 9px 16px; border-radius: var(--radius-sm); background: var(--bg2);
  border: 1px solid var(--border2); font-size: 12px; box-shadow: var(--shadow);
  animation: toastIn 0.2s ease; max-width: 280px;
}
.toast.success { border-color: rgba(34,211,168,0.4); color: var(--green); }
.toast.error   { border-color: rgba(244,63,94,0.4); color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ── Light mode ── */
body.light {
  --bg:       #f3f4f8; --bg2: #ffffff; --bg3: #eaecf2;
  --border:   rgba(0,0,0,0.08); --border2: rgba(0,0,0,0.14);
  --text:     #1a1d26; --muted: #6b7280;
  --card-bg:  rgba(0,0,0,0.03); --card-bg2: rgba(0,0,0,0.06);
}
body.light::before { opacity: 0.015; }
body.light::after { background-image: linear-gradient(rgba(79,156,249,0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(79,156,249,0.06) 1px, transparent 1px); }

/* ── Responsive ── */
@media (max-width: 600px) {
  .node-form-grid { grid-template-columns: 1fr; }
  .gear-row { gap: 6px; }
  .header { flex-wrap: wrap; gap: 12px; }
  .info-grid { grid-template-columns: 100px 1fr; }
}

/* ══════════════════════════════════════════════
   MODERN SCROLLBAR
   ══════════════════════════════════════════════ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 99px;
  transition: background 0.2s;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.22);
}
::-webkit-scrollbar-corner { background: transparent; }

body.light ::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); }
body.light ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.22); }

/* Firefox */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.1) transparent; }
body.light * { scrollbar-color: rgba(0,0,0,0.12) transparent; }

/* ══════════════════════════════════════════════
   ENHANCED MODAL SYSTEM
   ══════════════════════════════════════════════ */
.modal-overlay {
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
}
.modal {
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.1);
  background: linear-gradient(145deg, rgba(20,24,34,0.98), rgba(14,18,26,0.98));
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.04),
    0 24px 80px rgba(0,0,0,0.7),
    0 8px 24px rgba(0,0,0,0.4);
  animation: modalSlideIn 0.22s cubic-bezier(0.34,1.46,0.64,1) both;
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
.modal-overlay.open .modal { transform: none; } /* override old transition */
.modal-head {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  background: rgba(255,255,255,0.02);
  border-radius: 18px 18px 0 0;
}
.modal-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
}
.modal-title-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  flex-shrink: 0;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: var(--muted); cursor: pointer;
  font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover {
  color: var(--text);
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.18);
}
.modal-body {
  padding: 24px;
  overflow-y: auto;
}

/* Preview modal adaptive */
#preview-modal .modal-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}
#preview-modal .modal-body video,
#preview-modal .modal-body audio {
  width: 100%;
  border-radius: 10px;
  outline: none;
}
#preview-modal .modal-body img {
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

/* Light mode modals */
body.light .modal {
  background: linear-gradient(145deg, rgba(255,255,255,0.98), rgba(242,244,250,0.99));
  border-color: rgba(0,0,0,0.1);
  box-shadow: 0 24px 80px rgba(0,0,0,0.2), 0 8px 24px rgba(0,0,0,0.12);
}
body.light .modal-head { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.07); }
body.light .modal-close { background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.1); }
body.light .modal-close:hover { background: rgba(0,0,0,0.08); }

/* ── Toast enhanced ── */
.toast {
  border-radius: 12px;
  backdrop-filter: blur(16px);
  background: rgba(20,24,34,0.92);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  font-weight: 500;
  padding: 10px 18px;
}
.toast.success { background: rgba(34,211,168,0.12); border-color: rgba(34,211,168,0.3); }
.toast.error   { background: rgba(244,63,94,0.12); border-color: rgba(244,63,94,0.3); }

/* ══════════════════════════════════════════════
   SCRIPT MANAGER STYLES
   ══════════════════════════════════════════════ */
.script-modal { max-width: 700px; }
.script-mgr-add {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 4px;
}
.script-mgr-field { margin-bottom: 12px; }
.script-mgr-field label { display: block; margin-bottom: 6px; }
.script-mgr-textarea {
  width: 100%; padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); font-family: var(--mono); font-size: 11px;
  resize: vertical; outline: none; min-height: 110px;
  transition: border-color 0.15s; line-height: 1.6;
}
.script-mgr-textarea:focus { border-color: var(--accent2); }
.script-mgr-actions { display: flex; justify-content: flex-end; margin-top: 4px; }

.script-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg3);
  cursor: pointer; transition: all 0.15s; margin-bottom: 6px;
}
.script-item.selected { border-color: rgba(124,90,248,0.45); background: rgba(124,90,248,0.07); }
.script-item:hover { border-color: var(--border2); }
.script-item .node-radio-inner { background: var(--accent2); }
.script-item.selected .node-radio { border-color: var(--accent2); }

.script-active-label {
  font-size: 11px; font-family: var(--mono);
  color: var(--accent2); background: rgba(124,90,248,0.1);
  border: 1px solid rgba(124,90,248,0.3);
  padding: 2px 10px; border-radius: 20px;
}

/* Script badge purple */
.script-badge { background: var(--accent2) !important; }

/* ── Script config button glow ── */
#script-config-btn:hover {
  border-color: rgba(124,90,248,0.4);
  box-shadow: 0 0 12px rgba(124,90,248,0.15);
}

/* ── Node modal polish ── */
.node-modal { max-width: 700px; }

/* ── Upload history modal polish ── */
.upload-hist-item {
  border-radius: var(--radius-sm);
  transition: border-color 0.15s;
}
.upload-hist-item:hover { border-color: var(--border2); }


/* ══════════════════════════════════════════════
   SCRIPT GENERATOR
   ══════════════════════════════════════════════ */
.script-gen-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 20px;
  border: 1px solid rgba(124,90,248,0.4); background: rgba(124,90,248,0.08);
  color: var(--accent2); font-size: 11px; cursor: pointer; transition: all 0.15s;
  font-family: 'Space Grotesk', sans-serif;
}
.script-gen-toggle:hover { background: rgba(124,90,248,0.16); }
.script-gen-toggle .arrow { transition: transform 0.2s; display: inline-block; }
.script-gen-toggle.open .arrow { transform: rotate(90deg); }

.script-generator {
  display: none;
  background: rgba(124,90,248,0.04);
  border: 1px solid rgba(124,90,248,0.15);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.script-generator.open { display: block; }

.gen-section { margin-bottom: 14px; }
.gen-section-title {
  font-size: 11px; font-family: var(--mono); color: var(--accent2);
  text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.gen-kv-list { display: flex; flex-direction: column; gap: 5px; margin-bottom: 6px; }
.gen-kv-row { display: flex; gap: 6px; align-items: center; }
.gen-kv-row input {
  flex: 1; padding: 7px 10px; border-radius: 5px;
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); font-size: 11px; font-family: var(--mono); outline: none;
  transition: border-color 0.15s;
}
.gen-kv-row input:focus { border-color: var(--accent2); }
.gen-kv-row input::placeholder { color: var(--muted); }
.gen-kv-row input.kv-file-name { flex: 0.7; }
.gen-kv-row input.kv-mime { flex: 0.6; }
.gen-kv-del {
  width: 22px; height: 22px; border: none; background: none;
  color: var(--muted); cursor: pointer; border-radius: 4px;
  font-size: 12px; display: flex; align-items: center; justify-content: center;
  transition: all 0.12s; flex-shrink: 0;
}
.gen-kv-del:hover { background: rgba(244,63,94,0.1); color: var(--red); }
.gen-add-row-btn {
  padding: 4px 10px; border-radius: 20px; border: 1px dashed rgba(124,90,248,0.35);
  background: none; color: var(--accent2); font-size: 11px; cursor: pointer;
  transition: all 0.15s; font-family: 'Space Grotesk', sans-serif;
}
.gen-add-row-btn:hover { border-color: var(--accent2); background: rgba(124,90,248,0.08); }

.gen-method-row { display: flex; gap: 6px; margin-bottom: 6px; }
.gen-method-btn {
  padding: 5px 12px; border-radius: 5px; border: 1px solid var(--border2);
  background: var(--bg3); color: var(--muted); font-size: 11px;
  font-family: var(--mono); cursor: pointer; transition: all 0.12s;
}
.gen-method-btn.active { border-color: rgba(79,156,249,0.5); background: rgba(79,156,249,0.1); color: var(--accent); }

.gen-url-input {
  width: 100%; padding: 7px 10px; border-radius: 5px;
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); font-size: 11px; font-family: var(--mono); outline: none;
  transition: border-color 0.15s;
}
.gen-url-input:focus { border-color: var(--accent); }
.gen-url-input::placeholder { color: var(--muted); }

.gen-result-row { display: flex; gap: 6px; align-items: center; }
.gen-result-input {
  flex: 1; padding: 7px 10px; border-radius: 5px;
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); font-size: 11px; font-family: var(--mono); outline: none;
  transition: border-color 0.15s;
}
.gen-result-input:focus { border-color: var(--green); }
.gen-result-input::placeholder { color: var(--muted); }

.gen-cookie-input {
  width: 100%; padding: 7px 10px; border-radius: 5px;
  border: 1px solid var(--border2); background: var(--bg3);
  color: var(--text); font-size: 11px; font-family: var(--mono); outline: none;
  transition: border-color 0.15s; margin-bottom: 6px;
}
.gen-cookie-input:focus { border-color: var(--accent2); }
.gen-cookie-input::placeholder { color: var(--muted); }

.gen-referer-row { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.gen-referer-row label { font-size: 11px; color: var(--muted); white-space: nowrap; font-family: var(--mono); }

.gen-build-btn {
  width: 100%; padding: 9px; border-radius: var(--radius-sm);
  border: 1px solid rgba(34,211,168,0.35); background: rgba(34,211,168,0.08);
  color: var(--green); font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 0.15s; font-family: 'Space Grotesk', sans-serif;
  margin-top: 10px;
}
.gen-build-btn:hover { background: rgba(34,211,168,0.15); border-color: rgba(34,211,168,0.5); }

.gen-fd-type-toggle {
  display: flex; align-items: center; gap: 6px; margin-left: auto;
}
.gen-fd-type-btn {
  padding: 3px 8px; border-radius: 4px; border: 1px solid var(--border2);
  background: none; color: var(--muted); font-size: 10px;
  font-family: var(--mono); cursor: pointer; transition: all 0.12s;
}
.gen-fd-type-btn.active { border-color: rgba(124,90,248,0.5); background: rgba(124,90,248,0.1); color: var(--accent2); }

/* ── Node Edit inline row ── */
.node-edit-row {
  display: none; background: var(--bg); border: 1px solid rgba(79,156,249,0.3);
  border-radius: var(--radius-sm); padding: 12px; margin-top: 6px;
  animation: fadeIn 0.15s ease;
}
.node-edit-row.open { display: block; }
.node-edit-grid { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 8px; margin-bottom: 8px; }
.node-edit-actions { display: flex; justify-content: flex-end; gap: 6px; }
.btn-save-node {
  padding: 6px 14px; border-radius: 5px; border: 1px solid rgba(79,156,249,0.4);
  background: rgba(79,156,249,0.1); color: var(--accent); font-size: 11px; cursor: pointer; transition: all 0.15s;
}
.btn-save-node:hover { background: rgba(79,156,249,0.2); }
.btn-cancel-node {
  padding: 6px 14px; border-radius: 5px; border: 1px solid var(--border2);
  background: none; color: var(--muted); font-size: 11px; cursor: pointer; transition: all 0.15s;
}
.btn-cancel-node:hover { color: var(--text); }
.node-action-btn.edit:hover { color: var(--accent); }

/* ── Script IO bar ── */
.script-io-bar { display: flex; gap: 6px; margin: 8px 0 4px; flex-wrap: wrap; }
.script-io-btn {
  display: flex; align-items: center; gap: 5px; padding: 5px 10px;
  border-radius: 20px; border: 1px solid var(--border2); background: var(--bg3);
  color: var(--muted); font-size: 11px; cursor: pointer; transition: all 0.15s;
  font-family: 'Space Grotesk', sans-serif;
}
.script-io-btn:hover { color: var(--text); border-color: var(--border2); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } }

/* ── Script Manager Topbar ── */
.script-mgr-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

/* Generator modal - always show content */
#script-generator-modal .script-generator {
  display: block !important;
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
}

/* ── Active script name in header button ── */
.script-active-name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--accent2);
  background: rgba(124,90,248,0.12);
  border: 1px solid rgba(124,90,248,0.25);
  border-radius: 10px;
  padding: 1px 7px;
  font-family: var(--mono);
  flex-shrink: 0;
}

/* Preview modal adaptive sizing transition */
#preview-modal .modal {
  transition: width 0.18s ease, max-height 0.18s ease;
}
