    /* ===== RESET & BASE ===== */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    body { font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 13px; background: #f0f0f0; color: #1c1917; height: 100vh; overflow: hidden; }

    /* ===== LAYOUT ===== */
    #app { display: flex; flex-direction: column; height: 100vh; }
    #toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: #1c1917; border-bottom: 1px solid #0d0b09; flex-shrink: 0; }
    #main { display: flex; flex: 1; overflow: hidden; }
    #toolbox { width: 200px; background: #f2f1ef; border-right: 1px solid #d4cdc4; overflow-y: auto; flex-shrink: 0; padding-bottom: 20px; }
    #canvas-container { flex: 1; overflow: hidden; position: relative; background: #e8dcc8; cursor: default; }
    #canvas { width: 100%; height: 100%; display: block; }
    #properties { width: 250px; background: #f2f1ef; border-left: 1px solid #d4cdc4; overflow-y: auto; flex-shrink: 0; padding: 14px; }

    /* ===== TOOLBAR ===== */
    .tb-btn { display: flex; align-items: center; gap: 4px; padding: 5px 10px; background: #2d2824; color: #f0ebe4; border: 1px solid #3d3530; border-radius: 4px; cursor: pointer; font-size: 12px; font-family: inherit; white-space: nowrap; text-decoration: none; }
    .tb-btn:hover { background: #3d3530; }
    .tb-btn:active { background: #1a1614; }
    .tb-sep { width: 1px; background: #3d3530; height: 24px; margin: 0 2px; }
    .tb-label { color: #d97706; font-size: 15px; }
    .zoom-display { color: #9b8c7a; font-size: 12px; min-width: 40px; text-align: center; font-family: 'Geist Mono', ui-monospace, monospace; }
    .tb-dropdown { position: relative; }
    .tb-dropdown-menu { display: none; position: absolute; top: calc(100% + 4px); left: 0; background: #1c1917; border: 1px solid #3d3530; border-radius: 4px; min-width: 220px; z-index: 1000; box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
    .tb-dropdown-menu.open { display: block; }
    .tb-dropdown-item { display: flex; justify-content: space-between; align-items: center; gap: 24px; width: 100%; padding: 8px 14px; background: none; border: none; color: #f0ebe4; font-size: 12px; font-family: inherit; text-align: left; cursor: pointer; white-space: nowrap; text-decoration: none; }
    .tb-dropdown-item:hover { background: #2d2824; }
    .tb-dropdown-item-danger { color: #dc2626; }
    .tb-dropdown-item-danger:hover { background: rgba(220,38,38,0.08); color: #dc2626; }
    .tb-dropdown-sep { height: 1px; background: #3d3530; margin: 4px 0; }
    .tb-shortcut { color: #7c6e5e; font-size: 11px; font-family: 'Geist Mono', ui-monospace, monospace; }
    .tb-dropdown-submenu { position: relative; }
    .tb-dropdown-item-has-sub { cursor: default; }
    .tb-dropdown-item-has-sub:hover { background: #2d2824; }
    .tb-submenu-arrow { font-size: 9px; color: #7c6e5e; }
    .tb-dropdown-submenu-menu { display: none; position: absolute; left: 100%; top: -5px; background: #1c1917; border: 1px solid #3d3530; border-radius: 4px; min-width: 220px; z-index: 1001; box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
    .tb-dropdown-submenu:hover .tb-dropdown-submenu-menu { display: block; }
    .tb-spacer { flex: 1; }
    .tb-btn-accent { background: #d97706; color: white; border-color: #b45309; }
    .tb-btn-accent:hover { background: #b45309; }
    .tb-btn-accent:active { background: #92400e; }

    /* ===== TOOLBOX ===== */
    .toolbox-section { padding: 8px 8px 4px; font-size: 10px; font-weight: 600; color: #9b8c7a; text-transform: uppercase; letter-spacing: 0.7px; border-top: 1px solid #e0d9cf; }
    .toolbox-section:first-child { border-top: none; }
    .toolbox-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; cursor: grab; border-radius: 4px; margin: 1px 4px; user-select: none; }
    .toolbox-item:hover { background: rgba(217,119,6,0.10); }
    .toolbox-item:active { cursor: grabbing; }
    .toolbox-item-label { font-size: 12px; color: #1c1917; }
    .toolbox-preview { flex-shrink: 0; }

    /* ===== PROPERTIES PANEL ===== */
    #properties h3 { font-size: 13px; font-weight: 600; margin-bottom: 10px; color: #3d3530; border-bottom: 1px solid #e0d9cf; padding-bottom: 6px; }
    .prop-group { margin-bottom: 10px; }
    .prop-label { font-size: 11px; color: #6b5e4e; margin-bottom: 3px; display: block; }
    .prop-input { width: 100%; padding: 5px 7px; border: 1px solid #c8bfb2; border-radius: 4px; font-size: 12px; background: white; }
    .prop-input:focus { outline: none; border-color: #d97706; box-shadow: 0 0 0 2px rgba(217,119,6,0.20); }
    textarea.prop-input { resize: vertical; min-height: 60px; font-family: inherit; }
    .prop-checkbox-row { display: flex; align-items: center; gap: 6px; }
    .prop-empty { color: #b5a898; font-size: 12px; text-align: center; padding: 20px 0; }
    select.prop-input { cursor: pointer; }
    .color-picker { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
    .color-swatch { width: 20px; height: 20px; border-radius: 3px; border: 2px solid transparent; cursor: pointer; flex-shrink: 0; }
    .color-swatch:hover { opacity: 0.85; }
    .color-swatch.selected { border-color: #d97706; box-shadow: 0 0 0 1px #d97706; }
    .color-swatch-default { background: white; border: 2px solid #b5a898 !important; position: relative; }
    .color-swatch-default::after { content: '✕'; font-size: 9px; color: #b5a898; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); }
    .key-entry-row { display: flex; align-items: center; gap: 4px; margin-bottom: 3px; }
    .key-entry-type { font-size: 10px; color: #9b8c7a; min-width: 70px; }
    .key-entry-lbl { flex: 1; font-size: 11px; color: #1c1917; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .key-entry-del { font-size: 11px; color: #dc2626; cursor: pointer; background: none; border: none; padding: 1px 4px; line-height: 1; }
    .key-add-row { display: flex; gap: 4px; margin-top: 6px; }
    .key-add-row select { font-size: 11px; padding: 3px 4px; border: 1px solid #c8bfb2; border-radius: 3px; flex: 1; }
    .key-add-lbl { font-size: 11px; padding: 3px 5px; border: 1px solid #c8bfb2; border-radius: 3px; width: 70px; }
    .key-add-btn { font-size: 11px; padding: 3px 7px; background: #d97706; color: white; border: none; border-radius: 3px; cursor: pointer; white-space: nowrap; }
    .prop-info { margin-top: 14px; padding-top: 10px; border-top: 1px solid #e0d9cf; }
    .prop-info-title { font-size: 11px; font-weight: 600; color: #9b8c7a; text-transform: uppercase; letter-spacing: 0.7px; margin-bottom: 6px; }
    .prop-info-text { font-size: 11px; color: #6b5e4e; line-height: 1.5; }

    /* ===== CONTEXT MENU ===== */
    #context-menu { position: fixed; background: #fafaf8; border: 1px solid #ddd8d0; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,0.15); z-index: 1000; min-width: 160px; padding: 4px 0; display: none; }
    .ctx-item { padding: 7px 14px; cursor: pointer; font-size: 12px; color: #1c1917; }
    .ctx-item:hover { background: rgba(217,119,6,0.08); color: #d97706; }
    .ctx-sep { border-top: 1px solid #e0d9cf; margin: 3px 0; }
    .ctx-item.danger:hover { background: #fff0f0; color: #dc2626; }

    /* ===== CANVAS SVG ===== */
    .node-shape { cursor: move; }
    .node-shape.selected .shape-outline { stroke: #d97706 !important; stroke-width: 2.5px !important; }
    .edge-line { cursor: pointer; }
    .edge-line.selected { stroke: #d97706 !important; }
    .edge-line.selected path, .edge-line.selected line { stroke: #d97706 !important; }
    .rubberband { fill: rgba(217,119,6,0.10); stroke: #d97706; stroke-width: 1; stroke-dasharray: 4,2; pointer-events: none; }
    .selection-handle { fill: #d97706; cursor: pointer; }
    .inline-edit-fo { pointer-events: all; }

    /* ===== OVERLAY DROPDOWN ===== */

    /* ===== WELCOME SCREEN ===== */
    #welcome-screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 5; pointer-events: none; }
    #welcome-screen.hidden { display: none; }
    .welcome-inner { pointer-events: all; max-width: 420px; text-align: center; padding: 32px 36px; background: #ffffff; border: 1px solid #d4cdc4; border-radius: 6px; box-shadow: 0 4px 24px rgba(0,0,0,0.10); }
    .welcome-title { font-size: 22px; font-weight: 600; color: #1c1917; margin: 0; letter-spacing: -0.3px; }
    .welcome-subtitle { font-size: 13px; color: #9b8c7a; margin: 4px 0 0; font-weight: 400; }
    .welcome-divider { width: 32px; height: 2px; background: #d97706; margin: 16px auto; border-radius: 1px; }
    .welcome-body { font-size: 12px; color: #6b5e4e; line-height: 1.6; margin: 0 0 10px; text-align: left; }
    .welcome-body strong { color: #1c1917; font-weight: 600; }
    .welcome-actions { margin: 18px 0 20px; display: flex; flex-direction: column; gap: 8px; }
    .welcome-action { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #3d3530; text-align: left; }
    .welcome-action-icon { flex-shrink: 0; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; color: #d97706; }
    .welcome-footer { display: flex; align-items: center; justify-content: center; gap: 12px; }
    .welcome-btn { padding: 6px 18px; background: #d97706; color: white; border: none; border-radius: 4px; font-size: 12px; font-family: inherit; cursor: pointer; }
    .welcome-btn:hover { background: #b45309; }
    .welcome-btn:focus-visible { outline: 2px solid #d97706; outline-offset: 2px; }
    .welcome-btn-link { background: none; border: none; padding: 0; font: inherit; font-size: 12px; color: #9b8c7a; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
    .welcome-btn-link:hover { color: #d97706; }
    .welcome-btn-link:focus-visible { outline: 2px solid #d97706; outline-offset: 2px; }
    .welcome-docs-link { display: inline-block; margin-top: 14px; font-size: 12px; color: #9b8c7a; text-decoration: none; }
    .welcome-docs-link:hover { color: #d97706; text-decoration: underline; text-underline-offset: 2px; }
    .tb-dropdown-submenu.open .tb-dropdown-submenu-menu { display: block; }
    .tb-icon { display: block; flex-shrink: 0; }

    /* ===== FOCUS STYLES ===== */
    .tb-btn:focus-visible, a.tb-btn:focus-visible { outline: 2px solid #d97706; outline-offset: 2px; }
    .toolbox-item:focus-visible { outline: 2px solid #d97706; outline-offset: -2px; border-radius: 4px; background: rgba(217,119,6,0.10); }
    .ctx-item:focus-visible { background: rgba(217,119,6,0.08); color: #d97706; outline: none; }
    .color-swatch:focus-visible { outline: 2px solid #d97706; outline-offset: 1px; }

    /* ===== PROPERTIES TOGGLE (tablet) ===== */
    #props-toggle { display: none; }

    /* ===== RESPONSIVE – TABLET ≤900px ===== */
    @media (max-width: 900px) {
      #main { position: relative; }
      #toolbox { width: 52px; padding-bottom: 20px; }
      .toolbox-section { display: none; }
      .toolbox-item { justify-content: center; padding: 6px 0; }
      .toolbox-item-label { display: none; }
      .toolbox-preview { width: 40px; height: 40px; }

      #properties { display: none; }
      #properties.open { display: block; position: absolute; right: 0; top: 0; height: 100%; z-index: 100; box-shadow: -2px 0 8px rgba(0,0,0,0.18); width: 250px; }

      #props-toggle { display: flex; position: absolute; right: 8px; bottom: 56px; z-index: 50; width: 32px; height: 32px; background: #1c1917; border: 1px solid #3d3530; border-radius: 4px; color: #f0ebe4; cursor: pointer; align-items: center; justify-content: center; font-size: 16px; line-height: 1; }
      #props-toggle:hover { background: #2d2824; }
    }

    /* ===== AI TOOLBAR BUTTON ===== */
    #btn-ai { }
    #btn-ai.ai-active { background: #d97706; color: white; border-color: #d97706; }
    #btn-ai.ai-active:hover { background: #b45309; }

    /* ===== AI PANEL ===== */
    #ai-panel {
      width: 280px;
      background: #fafaf8;
      border-left: 1px solid #ddd8d0;
      display: flex;
      flex-direction: column;
      flex-shrink: 0;
      font-size: 13px;
      overflow: hidden;
      margin-right: -281px;  /* hide off-screen; -281px avoids a 1px border flash */
      transition: margin-right 200ms ease-out;
    }
    #ai-panel.open { margin-right: 0; }

    #ai-panel-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 8px 10px;
      border-bottom: 1px solid #e0d9cf;
      flex-shrink: 0;
      background: #f7f4ef;
    }
    .ai-panel-title { font-size: 12px; font-weight: 600; color: #1c1917; }
    .ai-panel-close { background: none; border: none; font-size: 18px; color: #9b8c7a; cursor: pointer; padding: 0 2px; line-height: 1; }
    .ai-panel-close:hover { color: #1c1917; }

    /* Key section */
    #ai-key-section { border-bottom: 1px solid #e0d9cf; padding: 8px 10px; flex-shrink: 0; background: #fff; }
    #ai-key-input-row { display: flex; flex-direction: column; gap: 4px; }
    .ai-key-label { font-size: 11px; color: #6b5e4e; }
    .ai-key-input { width: 100%; padding: 4px 7px; border: 1px solid #d97706; border-radius: 4px; font-size: 11px; font-family: monospace; background: #fff; }
    .ai-key-input:focus { outline: none; box-shadow: 0 0 0 2px rgba(217,119,6,0.20); }
    .ai-key-hint { font-size: 10px; color: #9b8c7a; }
    #ai-key-stored-row { display: flex; align-items: center; gap: 6px; }
    .ai-key-mask { font-size: 11px; font-family: monospace; color: #6b5e4e; flex: 1; }
    .ai-key-clear { background: none; border: none; font-size: 14px; color: #9b8c7a; cursor: pointer; padding: 0 2px; line-height: 1; }
    .ai-key-clear:hover { color: #dc2626; }

    /* Conversation thread */
    #ai-messages { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
    .ai-msg { display: flex; flex-direction: column; gap: 3px; }
    .ai-msg-role { font-size: 10px; font-weight: 600; color: #9b8c7a; text-transform: uppercase; letter-spacing: 0.4px; }
    .ai-msg-body { font-size: 12px; line-height: 1.5; color: #1c1917; background: #f7f4ef; border-radius: 6px; padding: 7px 9px; }
    .ai-msg.user .ai-msg-body { background: rgba(217,119,6,0.10); }
    .ai-msg.ai .ai-msg-body { background: #f7f4ef; }
    .ai-msg-body .ai-thinking { color: #9b8c7a; font-style: italic; }
    .ai-msg-body .ai-error { color: #c0392b; }
    .ai-confirm-chip {
      color: #d97706;
      background: rgba(217,119,6,0.08);
      border: 1px solid rgba(217,119,6,0.20);
      border-radius: 4px;
      font-size: 11px;
      padding: 4px 8px;
      margin-top: 4px;
      display: inline-block;
      animation: aiFadeIn 0.3s ease;
    }
    @keyframes aiFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

    /* Canvas spinner badge */
    #ai-canvas-spinner {
      position: absolute;
      top: 12px; left: 50%; transform: translateX(-50%);
      background: rgba(255,255,255,0.96);
      border: 1px solid #ddd8d0;
      border-radius: 20px;
      padding: 5px 12px;
      font-size: 12px;
      color: #6b5e4e;
      display: flex; align-items: center; gap: 7px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
      pointer-events: none;
      z-index: 10;
    }

    /* Spinner animation (reused for both canvas badge and send button) */
    .ai-spinner {
      display: inline-block;
      width: 12px; height: 12px;
      border: 2px solid #ddd8d0;
      border-top-color: #d97706;
      border-radius: 50%;
      animation: aiSpin 0.7s linear infinite;
      flex-shrink: 0;
    }
    @keyframes aiSpin { to { transform: rotate(360deg); } }

    /* Input footer */
    #ai-panel-footer { border-top: 1px solid #e0d9cf; padding: 8px 10px; flex-shrink: 0; background: #fff; display: flex; flex-direction: column; gap: 6px; }
    .ai-textarea { width: 100%; resize: none; border: 1px solid #c8bfb2; border-radius: 4px; font-size: 12px; font-family: inherit; padding: 6px 8px; line-height: 1.4; }
    .ai-textarea:focus { outline: none; border-color: #d97706; box-shadow: 0 0 0 2px rgba(217,119,6,0.20); }
    .ai-textarea:disabled { opacity: 0.5; background: #f7f4ef; }
    .ai-footer-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
    .ai-footer-hint { font-size: 10px; color: #9b8c7a; }
    .ai-send-btn { padding: 5px 12px; background: #d97706; color: white; border: none; border-radius: 4px; font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 5px; white-space: nowrap; flex-shrink: 0; }
    .ai-send-btn:hover { background: #b45309; }
    .ai-send-btn:disabled { opacity: 0.6; cursor: not-allowed; background: #d97706; }

    /* Highlight ring for newly AI-generated nodes (applied via JS filter) */
    .ai-new-node .shape-outline { filter: drop-shadow(0 0 4px #d97706); }

    /* ===== AI PANEL RESPONSIVE (≤900px overlay) ===== */
    @media (max-width: 900px) {
      #ai-panel {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        width: 100%;
        height: 60vh;
        margin-right: 0;       /* reset margin-based hiding */
        transform: translateY(100%);
        transition: transform 200ms ease-out;
        z-index: 200;
        border-left: none;
        border-top: 1px solid #ddd8d0;
        box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
      }
      #ai-panel.open { transform: translateY(0); }
    }
