    :root {
      --bg: #f5f7fb;
      --panel: #ffffff;
      --border: #d9e2ec;
      --text: #172033;
      --muted: #64748b;
      --primary: #2563eb;
      --primary-soft: #dbeafe;
      --green: #16a34a;
      --green-soft: #dcfce7;
      --orange: #f59e0b;
      --orange-soft: #fef3c7;
      --red: #ef4444;
      --red-soft: #fee2e2;
      --purple: #7c3aed;
      --purple-soft: #ede9fe;
      --shadow: 0 10px 24px rgba(15, 23, 42, 0.10);
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      background: var(--bg);
      color: var(--text);
      overflow: hidden;
    }

    .topbar {
      height: 66px;
      padding: 0 18px;
      background: var(--panel);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 14px;
    }

    .brand {
      display: flex;
      align-items: center;
      gap: 12px;
      min-width: 260px;
    }

    .logo {
      width: 38px;
      height: 38px;
      border-radius: 13px;
      background: linear-gradient(135deg, #2563eb, #16a34a);
      box-shadow: var(--shadow);
    }

    .brand h1 { margin: 0; font-size: 17px; }
    .brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

    .tabs {
      display: flex;
      gap: 6px;
      background: #eef2f7;
      border-radius: 14px;
      padding: 5px;
    }

    .tab {
      border: 0;
      background: transparent;
      border-radius: 11px;
      padding: 10px 16px;
      font-size: 12px;
      font-weight: 800;
      cursor: pointer;
      color: #475569;
    }

    .tab.active {
      background: #fff;
      color: var(--primary);
      box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
    }

    .main { height: calc(100vh - 66px); padding: 14px; }
    .view { display: none; height: 100%; }
    .view.active { display: block; }

    .grid {
      height: 100%;
      display: grid;
      grid-template-columns: 360px 1fr 360px;
      gap: 14px;
    }

    .panel {
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 18px;
      box-shadow: var(--shadow);
      overflow: hidden;
      min-height: 0;
      display: flex;
      flex-direction: column;
    }

    .panel-header {
      padding: 15px 17px;
      border-bottom: 1px solid var(--border);
      background: linear-gradient(180deg, #fff, #f8fafc);
    }

    .panel-header h2 { margin: 0; font-size: 15px; }
    .panel-header p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }

    .panel-body {
      padding: 14px;
      overflow: auto;
      min-height: 0;
    }

    .section {
      border: 1px solid var(--border);
      border-radius: 15px;
      background: #fff;
      padding: 13px;
      margin-bottom: 12px;
    }

    .section h3 { margin: 0 0 11px; font-size: 13px; }

    .row { display: grid; gap: 6px; margin-bottom: 10px; }
    .two { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

    label { font-size: 12px; color: #334155; font-weight: 800; }

    input, textarea, select {
      width: 100%;
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 9px 10px;
      font-size: 13px;
      outline: none;
      background: #fff;
    }

    textarea { min-height: 72px; resize: vertical; }

    input:focus, textarea:focus, select:focus {
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
    }

    .btns { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }

    button {
      border: 0;
      border-radius: 10px;
      padding: 9px 12px;
      font-size: 12px;
      font-weight: 800;
      cursor: pointer;
    }

    .btn-primary { background: var(--primary); color: #fff; }
    .btn-green { background: var(--green); color: #fff; }
    .btn-light { background: #eef2f7; color: #334155; }
    .btn-red { background: var(--red-soft); color: #b91c1c; }
    .btn-orange { background: var(--orange-soft); color: #92400e; }
    .btn-purple { background: var(--purple-soft); color: #5b21b6; }

    .hint {
      color: var(--muted);
      font-size: 12px;
      line-height: 1.45;
      background: #f8fafc;
      border: 1px dashed var(--border);
      border-radius: 12px;
      padding: 10px;
      margin-top: 8px;
    }

    .canvas-wrap {
      position: relative;
      flex: 1;
      min-height: 0;
      overflow: hidden;
      background:
        radial-gradient(circle at 1px 1px, #dbe3ef 1px, transparent 0);
      background-size: 22px 22px;
      cursor: grab;
    }

    .canvas-wrap.panning { cursor: grabbing; }

    .canvas-toolbar {
      position: absolute;
      top: 12px;
      left: 12px;
      z-index: 20;
      display: flex;
      align-items: center;
      gap: 7px;
      background: rgba(255,255,255,.92);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 7px;
      box-shadow: var(--shadow);
      backdrop-filter: blur(8px);
    }

    .canvas-toolbar button { padding: 7px 10px; background: #eef2f7; color: #334155; }

    .zoom-label {
      font-size: 12px;
      font-weight: 900;
      color: #334155;
      padding: 0 4px;
      min-width: 48px;
      text-align: center;
    }

    .connect-hint {
      position: absolute;
      top: 12px;
      right: 12px;
      z-index: 20;
      background: rgba(255,255,255,.92);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 10px 12px;
      box-shadow: var(--shadow);
      font-size: 12px;
      color: var(--muted);
      max-width: 360px;
      line-height: 1.4;
      backdrop-filter: blur(8px);
    }

    .flow-viewport {
      position: absolute;
      left: 0;
      top: 0;
      width: 2600px;
      height: 1700px;
      transform-origin: 0 0;
      overflow: visible;
    }

    .edges-layer {
      position: absolute;
      inset: 0;
      width: 2600px;
      height: 1700px;
      z-index: 1;
      overflow: visible;
    }

    .edge-hit {
      stroke: transparent;
      stroke-width: 18;
      fill: none;
      pointer-events: stroke;
      cursor: pointer;
    }

    .edge {
      stroke: #94a3b8;
      stroke-width: 2;
      fill: none;
      opacity: .72;
      marker-end: url(#arrow);
      pointer-events: none;
    }

    .edge.active {
      stroke: var(--primary);
      stroke-width: 4;
      opacity: 1;
      marker-end: url(#arrowActive);
    }

    .edge.done {
      stroke: var(--green);
      stroke-width: 4;
      opacity: 1;
      marker-end: url(#arrowDone);
    }

    .edge.selected {
      stroke: var(--red);
      stroke-width: 5;
      opacity: 1;
      marker-end: url(#arrowSelected);
    }

    .edge.temp {
      stroke: var(--orange);
      stroke-width: 3;
      stroke-dasharray: 8 6;
      opacity: .9;
      marker-end: url(#arrowTemp);
    }

    .node {
      position: absolute;
      width: 220px;
      min-height: 118px;
      background: #fff;
      border: 2px solid var(--border);
      border-radius: 18px;
      box-shadow: var(--shadow);
      z-index: 2;
      cursor: grab;
      user-select: none;
      overflow: visible;
      transition: opacity .2s, border-color .2s, transform .2s, background .2s;
    }

    .node:active { cursor: grabbing; }

    .node.active {
      border-color: var(--primary) !important;
      background: var(--primary-soft);
    }

    .node.done {
      border-color: var(--green) !important;
      background: var(--green-soft);
    }

    .node.dim {
      opacity: .22;
      filter: grayscale(.5);
    }

    .node.selected {
      outline: 4px solid rgba(37, 99, 235, .22);
    }

    .node-head {
      padding: 10px 12px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      border-radius: 16px 16px 0 0;
      background: #f8fafc;
    }

    .node-title { font-size: 13px; font-weight: 900; line-height: 1.25; }
    .node-sub { font-size: 10px; color: var(--muted); margin-top: 3px; font-weight: 800; }

    .node-body {
      padding: 10px 12px 12px;
      font-size: 12px;
      color: #475569;
      line-height: 1.35;
      overflow: hidden;
      border-radius: 0 0 16px 16px;
    }

    .handle {
      position: absolute;
      width: 16px;
      height: 16px;
      border-radius: 999px;
      background: var(--primary);
      border: 3px solid white;
      box-shadow: 0 2px 8px rgba(15,23,42,.25);
      z-index: 5;
      cursor: crosshair;
    }

    .handle.out { right: -9px; top: 50%; transform: translateY(-50%); }
    .handle.in { left: -9px; top: 50%; transform: translateY(-50%); background: var(--green); }
    .handle:hover { transform: translateY(-50%) scale(1.25); }

    .chip-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }

    .chip {
      font-size: 10px;
      font-weight: 900;
      padding: 4px 7px;
      border-radius: 999px;
      background: #e2e8f0;
      color: #334155;
    }

    .chip.survey { background: var(--orange-soft); color: #92400e; }
    .chip.done-chip { background: var(--green-soft); color: #166534; }
    .chip.edge-chip { background: var(--red-soft); color: #991b1b; }

    .list { display: grid; gap: 9px; }

    .card {
      border: 1px solid var(--border);
      background: #f8fafc;
      border-radius: 13px;
      padding: 11px;
    }

    .card.active-card {
      border-color: var(--primary);
      background: #eff6ff;
    }

    .card h4 { margin: 0; font-size: 13px; }
    .card p { margin: 5px 0 0; font-size: 12px; color: var(--muted); line-height: 1.35; }

    .card-actions { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }

    .tiny {
      padding: 5px 7px;
      border-radius: 8px;
      background: #fff;
      border: 1px solid var(--border);
      color: #334155;
      font-size: 10px;
    }

    .json {
      background: #0f172a;
      color: #e5e7eb;
      border-radius: 13px;
      padding: 12px;
      font-size: 12px;
      white-space: pre;
      overflow: auto;
      max-height: 300px;
    }

    .empty {
      color: var(--muted);
      background: #f8fafc;
      border: 1px dashed var(--border);
      border-radius: 13px;
      padding: 14px;
      font-size: 12px;
      line-height: 1.4;
      text-align: center;
    }

    .rtl {
      direction: rtl;
      text-align: right;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    }

    .survey-paper {
      position: absolute;
      width: 460px;
      min-height: 260px;
      background: #fff;
      border: 2px solid #cbd5e1;
      border-radius: 18px;
      box-shadow: var(--shadow);
      z-index: 3;
      overflow: hidden;
    }

    .survey-paper.selected {
      outline: 4px solid rgba(37, 99, 235, .22);
      border-color: var(--primary);
    }

    .survey-paper.active {
      border-color: var(--primary);
      background: #eff6ff;
    }

    .survey-paper-head {
      padding: 12px 14px;
      border-bottom: 1px solid var(--border);
      background: linear-gradient(135deg, #eff6ff, #ecfdf5);
      cursor: move;
    }

    .survey-paper-title { font-size: 14px; font-weight: 900; line-height: 1.25; }
    .survey-paper-subtitle { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.3; }

    .survey-paper-body {
      padding: 12px;
      height: 515px;
      max-height: 515px;
      overflow-y: auto;
      overflow-x: hidden;
      overscroll-behavior: contain;
    }

    .paper-question {
      border: 1px solid var(--border);
      background: #fff;
      border-radius: 13px;
      padding: 10px;
      margin-bottom: 10px;
    }

    .paper-question h4 { margin: 0 0 4px; font-size: 12px; }
    .paper-question-ar { margin: 0 0 8px; font-size: 11px; color: var(--muted); }

    .paper-option {
      display: flex;
      align-items: flex-start;
      gap: 8px;
      padding: 7px;
      border-radius: 10px;
      background: #f8fafc;
      border: 1px solid transparent;
      margin-bottom: 6px;
      cursor: pointer;
      font-size: 12px;
      font-weight: 800;
      color: #334155;
    }

    .paper-option:hover { border-color: var(--border); background: #f1f5f9; }

    .paper-option input {
      width: 15px;
      height: 15px;
      padding: 0;
      margin-top: 0;
      flex-shrink: 0;
    }

    .survey-paper-footer {
      padding: 9px 12px;
      border-top: 1px solid var(--border);
      background: #f8fafc;
      font-size: 11px;
      color: var(--muted);
      line-height: 1.35;
    }

    .node-checks {
      display: flex;
      flex-direction: column;
      gap: 5px;
      margin-top: 8px;
      background: rgba(255,255,255,.55);
      border-radius: 10px;
      padding: 7px;
      border: 1px solid rgba(148,163,184,.35);
    }

    .check-line {
      display: flex;
      align-items: center;
      gap: 7px;
      font-size: 11px;
      font-weight: 800;
      color: #334155;
    }

    .check-line input { width: 15px; height: 15px; padding: 0; margin: 0; }


    .survey-paper {
      resize: none;
      width: 460px !important;
      height: 640px;
      min-width: 460px;
      min-height: 640px;
      max-width: 460px;
      max-height: 640px;
    }

    .paper-options-wrap {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }

    .paper-option {
      width: auto;
      min-width: 92px;
      margin-bottom: 0 !important;
      align-items: center;
    }

    .node-done-btn {
      width: 30px;
      height: 30px;
      border-radius: 10px;
      background: rgba(255,255,255,.85);
      border: 1px solid var(--border);
      color: #166534;
      padding: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 15px;
      flex-shrink: 0;
    }

    .node-done-btn:hover {
      background: var(--green-soft);
      border-color: #86efac;
    }

    .node-type-title {
      font-size: 12px;
      font-weight: 950;
      letter-spacing: .4px;
      text-transform: uppercase;
      color: #334155;
    }

    .node-desc-main {
      font-size: 12px;
      color: #334155;
      font-weight: 700;
      line-height: 1.35;
    }

    .node-desc-ar {
      margin-top: 7px;
      color: #475569;
      font-size: 12px;
      line-height: 1.35;
      border-top: 1px dashed rgba(148,163,184,.45);
      padding-top: 7px;
    }


    .node.focused {
      outline: 4px solid rgba(245, 158, 11, .32);
      border-color: var(--orange) !important;
    }

    .node.collapsed-feature .node-desc-main,
    .node.collapsed-feature .node-desc-ar {
      display: none;
    }

    .sim-node-row {
      border: 1px solid var(--border);
      background: #f8fafc;
      border-radius: 13px;
      padding: 11px;
      cursor: pointer;
      transition: .2s;
    }

    .sim-node-row.focused-row {
      border-color: var(--orange);
      background: var(--orange-soft);
    }

    .sim-node-row.done-row {
      border-color: #86efac;
      background: var(--green-soft);
    }

    .sim-node-row.focused-row.done-row {
      background: linear-gradient(135deg, var(--orange-soft), var(--green-soft));
    }

    .sim-node-row h4 {
      margin: 0;
      font-size: 13px;
    }

    .sim-node-row p {
      margin: 5px 0 0;
      font-size: 12px;
      color: var(--muted);
      line-height: 1.35;
    }

    .focus-line {
      display: flex;
      align-items: flex-start;
      gap: 8px;
    }

    .focus-line input {
      width: 16px;
      height: 16px;
      margin-top: 1px;
      flex-shrink: 0;
    }


    .node.sim-feature-compact {
      min-height: 64px;
      width: 210px;
      overflow: hidden;
    }

    .node.sim-feature-compact .node-head {
      border-bottom: 0;
      border-radius: 16px;
      min-height: 60px;
    }

    .node.sim-feature-compact .node-body {
      display: none !important;
    }

    .sim-feature-title {
      font-size: 10px;
      font-weight: 950;
      letter-spacing: .45px;
      text-transform: uppercase;
      color: #64748b;
      margin-bottom: 4px;
    }

    .sim-feature-name {
      font-size: 13px;
      font-weight: 950;
      color: #172033;
      line-height: 1.25;
    }

    .done-filter-card {
      border: 1px solid var(--border);
      background: #f8fafc;
      border-radius: 13px;
      padding: 11px;
      margin-bottom: 10px;
    }

    .done-filter-card.active {
      border-color: #86efac;
      background: var(--green-soft);
    }

    .todo-filter-card.active {
      border-color: var(--orange);
      background: var(--orange-soft);
    }

    .todo-check {
      display: flex;
      align-items: flex-start;
      gap: 8px;
      width: 100%;
      cursor: pointer;
    }

    .todo-check input {
      width: 16px;
      height: 16px;
      margin-top: 1px;
      flex-shrink: 0;
    }

    .sim-node-row.todo-row {
      border-color: var(--orange);
      background: var(--orange-soft);
    }

    .sim-node-row.done-row {
      border-color: #86efac;
      background: var(--green-soft);
    }

    .sim-node-row.todo-row.done-row {
      background: linear-gradient(135deg, var(--orange-soft), var(--green-soft));
    }


    .node-todo-btn {
      width: 30px;
      height: 30px;
      border-radius: 10px;
      background: rgba(255,255,255,.85);
      border: 1px solid var(--border);
      color: #92400e;
      padding: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      flex-shrink: 0;
    }

    .node-todo-btn:hover,
    .node-todo-btn.active {
      background: var(--orange-soft);
      border-color: var(--orange);
    }

    .node-head-actions {
      display: flex;
      align-items: center;
      gap: 6px;
      flex-shrink: 0;
    }

    .node-todo-check {
      position: absolute;
      right: 10px;
      bottom: 10px;
      z-index: 6;
      display: inline-flex;
      align-items: center;
      gap: 5px;
      background: rgba(255,255,255,.92);
      border: 1px solid var(--border);
      border-radius: 999px;
      padding: 4px 7px;
      font-size: 10px;
      font-weight: 900;
      color: #92400e;
      box-shadow: 0 2px 8px rgba(15,23,42,.10);
      cursor: pointer;
    }

    .node-todo-check input {
      width: 13px;
      height: 13px;
      margin: 0;
      padding: 0;
    }

    .node-todo-check.active {
      background: var(--orange-soft);
      border-color: var(--orange);
    }


    .node.partial {
      border-color: #f59e0b !important;
      background: #fff7ed;
    }

    .chip.partial-chip {
      background: var(--orange-soft);
      color: #92400e;
    }


    .tool-palette {
      display: grid;
      gap: 10px;
    }

    .drag-tool {
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 12px;
      background: #f8fafc;
      cursor: grab;
      user-select: none;
    }

    .drag-tool:active {
      cursor: grabbing;
    }

    .drag-tool.question-tool {
      border-color: #fdba74;
      background: #fff7ed;
    }

    .drag-tool.feature-tool {
      border-color: #93c5fd;
      background: #eff6ff;
    }

    .drag-tool h4 {
      margin: 0;
      font-size: 13px;
    }

    .drag-tool p {
      margin: 5px 0 0;
      font-size: 12px;
      color: var(--muted);
      line-height: 1.35;
    }

    .canvas-drop-active {
      outline: 4px solid rgba(37, 99, 235, .18);
      outline-offset: -4px;
    }

    .node-collapse-btn {
      width: 28px;
      height: 28px;
      border-radius: 9px;
      background: rgba(255,255,255,.85);
      border: 1px solid var(--border);
      color: #334155;
      padding: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      flex-shrink: 0;
    }

    .node-collapse-btn:hover {
      background: #eef2f7;
    }

    .node.hidden-by-collapse,
    .edge.hidden-by-collapse,
    .edge-hit.hidden-by-collapse {
      display: none;
    }


    .sim-badge-row {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      margin-top: 10px;
      padding-top: 8px;
      border-top: 1px dashed rgba(148, 163, 184, .45);
    }

    .sim-badge {
      font-size: 10px;
      font-weight: 950;
      padding: 5px 8px;
      border-radius: 999px;
      background: #e0f2fe;
      color: #075985;
      border: 1px solid #bae6fd;
    }


    .save-toast {
      position: fixed;
      right: 20px;
      bottom: 20px;
      z-index: 9999;
      background: #16a34a;
      color: white;
      padding: 12px 16px;
      border-radius: 14px;
      box-shadow: var(--shadow);
      font-size: 13px;
      font-weight: 900;
      opacity: 0;
      transform: translateY(10px);
      pointer-events: none;
      transition: .2s;
    }

    .save-toast.show {
      opacity: 1;
      transform: translateY(0);
    }


    .badge-editor-row {
      display: flex;
      gap: 8px;
      align-items: center;
    }

    .badge-editor-row input {
      flex: 1;
    }

    .editable-badges {
      display: flex;
      flex-wrap: wrap;
      gap: 7px;
      margin-top: 8px;
      min-height: 30px;
    }

    .editable-badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      border-radius: 999px;
      padding: 5px 8px;
      background: #e0f2fe;
      color: #075985;
      border: 1px solid #bae6fd;
      font-size: 11px;
      font-weight: 900;
    }

    .editable-badge button {
      width: 18px;
      height: 18px;
      border-radius: 999px;
      padding: 0;
      background: #fff;
      color: #b91c1c;
      border: 1px solid #fecaca;
      font-size: 11px;
      line-height: 1;
    }


    .canvas-toolbar button.lang-active {
      background: var(--primary);
      color: white;
    }

    .hidden { display: none !important; }

    @media (max-width: 1180px) {
      body { overflow: auto; }
      .main { height: auto; }
      .grid { grid-template-columns: 1fr; height: auto; }
      .panel { min-height: 430px; }
      .canvas-wrap { min-height: 620px; }
    }
