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

:root {
  --bg0: #07090f;
  --bg1: #0d1117;
  --bg2: #111827;
  --bg3: #1a2035;
  --border: #1f2937;
  --border2: #2d3748;
  --text1: #f8fafc;
  --text2: #cbd5e1;
  --text3: #94a3b8;
  --text4: #4b5563;
  --accent: #6366f1;
  --accent-dim: #6366f122;
  --green: #059669;
  --green-dim: #d1fae5;
  --amber: #d97706;
  --red: #dc2626;

  --c-digit: #818cf8;    --bg-digit: #1e1b4b;
  --c-acd: #60a5fa;      --bg-acd: #0c1a3b;
  --c-play: #2dd4bf;     --bg-play: #134e4a;
  --c-script: #a78bfa;   --bg-script: #1a1a2e;
  --c-hangup: #f87171;   --bg-hangup: #3b0a0a;
  --c-holiday: #fb923c;  --bg-holiday: #451a03;
  --c-office: #fb923c;   --bg-office: #451a03;
  --c-stop: #9ca3af;     --bg-stop: #1f2937;
  --c-crm: #4ade80;      --bg-crm: #1a2e1a;
  --c-dial: #38bdf8;     --bg-dial: #0c2233;
  --c-monitor: #c084fc;  --bg-monitor: #1a1a2e;
  --c-history: #d1d5db;  --bg-history: #1a1a1a;
}

html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg0);
  color: var(--text2);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Layout ─────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Header ─────────────────────────────────────────────── */
#header {
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex; align-items: center; gap: 16px;
  flex-shrink: 0; position: relative; z-index: 20;
}
#header .title-block .sub { font-size: 10px; color: var(--text4); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 2px; }
#header .title-block .main { font-size: 20px; font-weight: 700; color: var(--text1); letter-spacing: -0.02em; }
#header .spacer { flex: 1; }
.save-indicator { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text4); }
.save-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); transition: background 0.3s; }
.save-dot.saved { background: var(--green); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; border: none; border-radius: 8px; padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity 0.15s, transform 0.1s; white-space: nowrap; font-family: inherit; }
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: #065f46; color: var(--green-dim); border: 1px solid var(--green); }
.btn-danger  { background: #450a0a; color: #fca5a5; border: 1px solid #7f1d1d; }
.btn-ghost   { background: var(--bg3); color: var(--text3); border: 1px solid var(--border2); }

/* ── Stats bar ───────────────────────────────────────────── */
#stats-bar {
  background: var(--bg1); border-bottom: 1px solid #111827;
  padding: 8px 24px; display: flex; gap: 20px; align-items: center;
  flex-shrink: 0; flex-wrap: wrap;
}
.stat-item { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.stat-dot  { width: 6px; height: 6px; border-radius: 50%; }
.stat-label { color: var(--text4); }
.stat-count { font-weight: 700; }
#total-count { margin-left: auto; font-size: 12px; color: var(--text4); }

/* ── Body ────────────────────────────────────────────────── */
#body { display: flex; flex: 1; min-height: 0; }

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: 210px; background: var(--bg1);
  border-right: 1px solid var(--border);
  padding: 16px 12px; flex-shrink: 0;
  overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
#sidebar .section-label { font-size: 10px; color: var(--text4); letter-spacing: 0.1em; text-transform: uppercase; margin: 4px 4px 8px; }
.filter-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; text-align: left;
  background: none; border: 1px solid transparent; border-radius: 7px;
  padding: 8px 12px; font-size: 13px; cursor: pointer; color: var(--text4);
  font-family: inherit; transition: all 0.15s;
}
.filter-btn:hover { background: var(--bg2); color: var(--text3); }
.filter-btn.active { background: #1e293b; color: var(--c-digit); border-color: #334155; font-weight: 600; }
.filter-count { font-size: 11px; color: var(--text4); }

/* ── Main panel ──────────────────────────────────────────── */
#main { flex: 1; overflow-y: auto; padding: 20px 24px; }

#search-row { display: flex; gap: 10px; margin-bottom: 16px; }
#search-input {
  flex: 1; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 16px; font-size: 13px;
  color: var(--text1); outline: none; font-family: inherit;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent); }

/* ── Node Cards ──────────────────────────────────────────── */
.node-card {
  background: var(--bg2); border: 1.5px solid var(--border);
  border-radius: 12px; margin-bottom: 10px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  overflow: hidden;
}
.node-card.expanded {
  border-color: var(--node-accent, var(--accent));
  background: var(--node-bg, var(--bg3));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--node-accent, var(--accent)) 20%, transparent);
}
.node-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; cursor: pointer; user-select: none;
}
.node-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.node-name { flex: 1; font-size: 14px; font-weight: 600; color: var(--text1); }
.node-name input {
  background: transparent; color: var(--text1);
  border: none; border-bottom: 1px solid var(--node-accent, var(--accent));
  outline: none; font-size: 14px; font-weight: 600; font-family: inherit; width: 100%;
}
.badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  border-radius: 4px; padding: 2px 7px;
  border: 1px solid color-mix(in srgb, var(--node-accent, #9ca3af) 30%, transparent);
  color: var(--node-accent, #9ca3af);
  background: color-mix(in srgb, var(--node-accent, #9ca3af) 12%, transparent);
  text-transform: uppercase; white-space: nowrap; flex-shrink: 0;
}
.node-delete {
  background: none; border: none; cursor: pointer;
  color: var(--text4); font-size: 18px; line-height: 1;
  padding: 0 2px; transition: color 0.15s;
}
.node-delete:hover { color: var(--red); }

/* collapsed chips */
.node-chips { padding: 0 16px 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 11px; color: var(--text4); background: var(--bg1); border-radius: 4px; padding: 2px 8px; }
.chip span { color: var(--text3); }

/* attrs panel */
.node-attrs { padding: 4px 16px 14px; border-top: 1px solid color-mix(in srgb, var(--node-accent, #fff) 15%, transparent); }

.attr-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 7px 0;
  border-bottom: 1px solid #ffffff08;
}
.attr-row:last-child { border-bottom: none; }
.attr-label { font-size: 12px; color: var(--text3); flex-shrink: 0; min-width: 140px; }
.attr-input {
  flex: 1; background: var(--bg1); color: var(--text1);
  border: 1px solid var(--border2); border-radius: 6px;
  padding: 5px 10px; font-size: 12px; outline: none; font-family: inherit;
  transition: border-color 0.15s;
}
.attr-input:focus { border-color: var(--node-accent, var(--accent)); }
.attr-input.mono { font-family: 'Consolas', 'Courier New', monospace; }

.attr-textarea {
  width: 100%; background: #0d1117; color: var(--text1);
  border: 1px solid var(--border2); border-radius: 6px;
  padding: 10px 12px; font-size: 11.5px;
  font-family: 'Consolas', 'Courier New', monospace;
  resize: vertical; line-height: 1.6; outline: none;
  transition: border-color 0.15s; min-height: 100px;
}
.attr-textarea:focus { border-color: var(--node-accent, var(--accent)); }

/* toggle */
.toggle-wrap { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle-track {
  position: relative; width: 36px; height: 20px;
  background: var(--border2); border-radius: 10px; transition: background 0.2s; flex-shrink: 0;
}
.toggle-track.on { background: var(--accent); }
.toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left 0.2s;
}
.toggle-track.on .toggle-thumb { left: 19px; }
.toggle-label { font-size: 12px; }

/* ── Empty state ─────────────────────────────────────────── */
#empty { text-align: center; color: var(--text4); padding: 60px 0; font-size: 14px; }

/* ── Modal ───────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; background: #000000cc;
  display: flex; align-items: center; justify-content: center;
  z-index: 100; display: none;
}
#modal-overlay.open { display: flex; }
#modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; width: 380px;
  box-shadow: 0 24px 60px #0008;
}
#modal h2 { font-size: 16px; font-weight: 700; color: var(--text1); margin-bottom: 20px; }
.form-group { margin-bottom: 14px; }
.form-group label { font-size: 12px; color: var(--text3); display: block; margin-bottom: 6px; }
.form-group input, .form-group select {
  width: 100%; background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 8px; padding: 10px 14px; font-size: 13px;
  color: var(--text1); outline: none; font-family: inherit;
}
.form-group select option { background: var(--bg2); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; justify-content: center; }

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #065f46; color: var(--green-dim);
  border: 1px solid var(--green); border-radius: 10px;
  padding: 12px 20px; font-size: 13px; font-weight: 600;
  z-index: 200; opacity: 0; transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text4); }

/* ── Upload Screen ───────────────────────────────────────────── */
#upload-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg0);
}
#upload-card {
  background: var(--bg1); border: 1px solid var(--border);
  border-radius: 20px; padding: 48px 44px;
  width: 100%; max-width: 520px; text-align: center;
  box-shadow: 0 32px 80px #00000060;
}
.upload-logo { margin-bottom: 20px; display: flex; justify-content: center; }
#upload-card h1 { font-size: 22px; font-weight: 700; color: var(--text1); margin-bottom: 10px; letter-spacing: -0.02em; }
#upload-card > p { font-size: 14px; color: var(--text3); margin-bottom: 28px; }
#upload-card code { background: var(--bg3); color: var(--accent); border-radius: 4px; padding: 2px 6px; font-family: 'Consolas', monospace; font-size: 13px; }

#drop-zone {
  border: 2px dashed var(--border2); border-radius: 14px;
  padding: 40px 24px; margin-bottom: 20px; cursor: pointer;
  color: var(--text4); transition: all 0.2s;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
#drop-zone:hover, #drop-zone.drag-over {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-dim);
}
.drop-text { font-size: 15px; font-weight: 500; color: var(--text2); }
.drop-text strong { color: var(--accent); }
.drop-sub { font-size: 12px; color: var(--text4); }

.upload-error {
  background: #3b0a0a; border: 1px solid #7f1d1d;
  color: #fca5a5; border-radius: 8px; padding: 10px 14px;
  font-size: 13px; margin-bottom: 16px; text-align: left;
}
.upload-hint { font-size: 12px; color: var(--text4); line-height: 1.6; margin-top: 8px; }
