    :root {
      --bg: #12141a;
      --bg-accent: #14161d;
      --bg-elevated: #1a1d25;
      --bg-hover: #262a35;
      --card: #181b22;
      --secondary: #1e2028;
      --text: #e4e4e7;
      --text-strong: #fafafa;
      --muted: #71717a;
      --border: #27272a;
      --border-strong: #3f3f46;
      --accent: #ff5c5c;
      --accent-subtle: rgba(255, 92, 92, .15);
      --accent-2: #14b8a6;
      --accent-2-subtle: rgba(20, 184, 166, 0.12);
      --ok: #22c55e;
      --ok-subtle: rgba(34, 197, 94, .12);
      --warn: #f59e0b;
      --warn-subtle: rgba(245, 158, 11, .12);
      --danger: #ef4444;
      --danger-subtle: rgba(239, 68, 68, .12);
      --info: #3b82f6;
      --info-subtle: rgba(59, 130, 246, .12);
      --card-highlight: rgba(255, 255, 255, .05);
      --shadow-sm: 0 1px 2px rgba(0, 0, 0, .2);
      --shadow-md: 0 4px 12px rgba(0, 0, 0, .25), 0 0 0 1px rgba(255, 255, 255, .03);
      --shadow-lg: 0 8px 24px rgba(0, 0, 0, .4), 0 0 0 1px rgba(255, 255, 255, .03);
      --radius-sm: 6px;
      --radius-md: 8px;
      --radius-lg: 12px;
      --radius-full: 9999px;
      --duration-fast: 0.12s;
      --duration-normal: 0.2s;
      --duration-slow: 0.35s;
      --ease-out: cubic-bezier(.16, 1, .3, 1);
      --sidebar-width: 220px;
      --status-open: #888;
      --status-in-progress: #f0c000;
      --status-review: #e07020;
      --status-done: #d04040;
      --tree-line: #3f3f46;
    }

    * { margin: 0; padding: 0; box-sizing: border-box; }

    body {
      font-family: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      color: var(--text);
      background: var(--bg);
      height: 100vh;
      overflow: hidden;
    }

    .mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }

    /* Scrollbar — matches Gateway Dashboard */
    /* Hide ALL native scrollbars globally */
    ::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }
    * { scrollbar-width: none !important; }

    /* Custom scrollbar — wrapper approach */
    .cscroll-wrap {
      position: relative; overflow: hidden;
      display: flex; flex-direction: column;
    }
    .cscroll-wrap > .cscroll-inner {
      flex: 1; overflow-y: auto; overflow-x: hidden;
    }
    .cscroll-track {
      position: absolute; top: 16px; right: 4px; bottom: 16px; width: 5px;
      border-radius: 9999px; z-index: 50;
    }
    .cscroll-track.hidden { display: none; }
    /* In file-preview, track should not overlap the header */
    .file-preview > .cscroll-track { top: 54px; }
    .cscroll-thumb {
      width: 100%; border-radius: 9999px;
      background: var(--border); position: absolute; min-height: 24px;
      cursor: grab; transition: background 0.15s;
    }
    .cscroll-thumb:hover, .cscroll-thumb.dragging { background: var(--muted); }

    /* Layout */
    .app {
      display: grid;
      grid-template-rows: auto auto 1fr;
      grid-template-columns: var(--sidebar-width) 1fr;
      height: 100dvh;
      transition: grid-template-columns var(--duration-normal) var(--ease-out);
    }
    /* Sidebar spans tab-bar + content rows */
    .sidebar { grid-row: 2 / 4; }
    .app.sidebar-collapsed { grid-template-columns: 0px 1fr; }

    /* Header — matches Gateway Dashboard */
    .header {
      grid-row: 1;
      grid-column: 1 / -1;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 12px 14px;
      height: 56px;
      background: var(--bg);
      border-bottom: 1px solid var(--border);
    }

    .header-left { display: flex; align-items: center; gap: 12px; }

    .sidebar-toggle {
      width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
      border: none; background: none; color: var(--muted); cursor: pointer;
      border-radius: var(--radius-sm); transition: all var(--duration-normal);
      font-size: 18px;
    }
    .sidebar-toggle:hover { color: var(--text); background: var(--bg-hover); }

    .header-logo { line-height: 1; display: flex; align-items: center; }
    .header-logo img { height: 30px; width: auto; vertical-align: middle; }
    .header-brand { display: flex; flex-direction: column; }
    .header-title {
      font-size: 15px; font-weight: 700; letter-spacing: 0.05em;
      color: var(--text-strong); text-transform: uppercase;
    }
    .header-subtitle {
      font-size: 10px; color: var(--muted); text-transform: uppercase;
      letter-spacing: 0.06em; font-weight: 500;
    }

    .header-right { display: flex; align-items: center; gap: 10px; }
    .header-project {
      font-size: 13px; font-weight: 600; color: var(--text-strong);
      letter-spacing: 0.02em;
    }
    .badge-active {
      display: inline-flex; padding: 3px 10px; border-radius: var(--radius-full);
      font-size: 10px; font-weight: 600; color: var(--accent);
      border: 1px solid #ff5c5c59; background: var(--accent-subtle);
      text-transform: uppercase; letter-spacing: 0.04em;
    }

    /* Sidebar */
    .sidebar {
      background: var(--bg);
      padding: 10px 14px 12px 14px;
      overflow-y: auto;
      overflow-x: hidden;
      transition: opacity var(--duration-normal);
    }
    .app.sidebar-collapsed .sidebar { opacity: 0; pointer-events: none; }

    .sidebar-label {
      font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
      color: var(--muted); font-weight: 600; margin-bottom: 8px; padding: 0;
    }

    .project-item {
      display: flex; align-items: center; justify-content: space-between;
      padding: 8px 14px; border-radius: var(--radius-md);
      font-size: 13px; font-weight: 500; color: var(--muted);
      cursor: pointer; transition: all var(--duration-normal);
      border: 1px solid transparent; margin-bottom: 2px;
    }

    .project-item:hover { 
      background: var(--bg-hover); 
      color: var(--text-strong);
    }
    .project-item.viewed { 
      background: var(--accent-subtle);
      color: var(--text-strong);
    }
    .project-item.agent-active {
      border: 1px solid var(--accent);
      color: var(--text-strong);
      box-shadow: 0 0 12px rgba(255, 92, 92, .15);
    }
    .project-item.agent-active.viewed {
      background: var(--accent-subtle);
      border: 1px solid var(--accent);
      color: var(--text-strong);
      box-shadow: 0 0 12px rgba(255, 92, 92, .15), inset 0 1px 0 rgba(255, 92, 92, .1);
    }

    .project-badge {
      background: var(--secondary); border-radius: var(--radius-full);
      padding: 2px 8px; font-size: 11px; font-weight: 500; color: var(--muted);
    }

    .sidebar-empty { color: var(--muted); font-size: 12px; padding: 12px; text-align: center; }

    .sidebar-actions { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }

    .btn {
      display: inline-flex; align-items: center; justify-content: center;
      padding: 7px 14px; border-radius: var(--radius-md);
      font-size: 12px; font-weight: 500; cursor: pointer;
      border: 1px solid var(--border); background: var(--card);
      color: var(--text); transition: all var(--duration-normal);
      font-family: inherit;
    }
    .btn:hover { border-color: var(--border-strong); background: var(--bg-hover); }

    .btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
    .btn-primary:hover { background: #ff4040; }

    .btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
    .btn-danger:hover { background: #dc2626; }

    .btn-secondary { background: transparent; border-color: var(--border); color: var(--muted); }
    .btn-secondary:hover { color: var(--text); }

    .btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
    .btn-ghost:hover { color: var(--text); background: var(--bg-hover); }

    .btn-sm { padding: 4px 10px; font-size: 11px; }
    .btn-full { width: 100%; }

    /* Content area */
    .content {
      padding: 12px 18px 16px 22px;
    }
    /* Content wrapper (created by cscrollWrap) */
    .cscroll-wrap.content-wrapper {
      grid-row: 3;
    }

    .empty-state {
      display: flex; align-items: center; justify-content: center;
      min-height: 60vh; color: var(--muted); font-size: 14px;
    }

    /* Kanban */
    .kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

    .column {
      background: var(--bg-accent); border: 1px solid var(--border);
      border-radius: var(--radius-lg); padding: 12px;
      min-height: 200px; min-width: 0;
      display: flex; flex-direction: column;
      transition: background var(--duration-normal), border-color var(--duration-normal);
    }
    .column.drag-over { border-color: var(--accent); background: rgba(255, 92, 92, .05); }

    .column-header {
      display: flex; align-items: center; justify-content: space-between;
      margin-bottom: 12px;
    }
    .column-title {
      font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em;
      font-weight: 600; color: var(--text);
    }

    .column-count {
      background: var(--secondary); border-radius: var(--radius-full);
      padding: 2px 8px; font-size: 11px; font-weight: 600; color: var(--muted);
    }

    .column-body { display: flex; flex-direction: column; gap: 8px; flex: 1; }
    .column-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 24px 0; opacity: 0.5; }

    /* Task Cards */
    .task-card {
      background: var(--card); border: 1px solid var(--border);
      border-radius: var(--radius-md); padding: 12px; position: relative;
      overflow-wrap: break-word; word-break: break-word; min-width: 0;
      box-shadow: var(--shadow-sm), inset 0 1px 0 var(--card-highlight);
      transition: border-color var(--duration-normal), box-shadow var(--duration-normal), opacity var(--duration-normal);
      cursor: grab;
    }
    .task-card.new-card { animation: rise var(--duration-slow) var(--ease-out) both; }
    .task-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
    .task-card.dragging { opacity: 0.4; }
    .task-card.removing { animation: shrink 0.25s var(--ease-out) forwards; }

    .task-id { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
    .task-title {
      font-size: 13px; font-weight: 500; color: var(--text);
      margin-bottom: 8px; line-height: 1.4; cursor: pointer;
    }
    .task-title-input {
      font-size: 13px; font-weight: 500; color: var(--text);
      background: var(--bg-elevated); border: 1px solid var(--border-strong);
      border-radius: var(--radius-sm); padding: 4px 6px; width: 100%;
      margin-bottom: 8px; font-family: inherit; outline: none;
    }
    .task-title-input:focus { border-color: var(--accent); }

    .task-meta { display: flex; align-items: center; justify-content: space-between; }

    .spec-badge {
      cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
      width: 26px; height: 26px; border-radius: var(--radius-sm);
      color: var(--accent); background: var(--accent-subtle);
      border: 1px solid rgba(255, 92, 92, 0.2);
      transition: all var(--duration-fast);
    }
    .spec-badge:hover { background: rgba(255, 92, 92, 0.25); border-color: rgba(255, 92, 92, 0.4); }
    .spec-badge-add {
      opacity: 0; color: var(--muted); background: transparent;
      border: 1px solid transparent;
    }
    .task-card:hover .spec-badge-add { opacity: 0.5; border-color: var(--border); }
    .task-card:hover .spec-badge-add:hover { opacity: 1; color: var(--text); background: #ffffff0f; border-color: var(--border-strong); }

    .task-meta-actions { display: flex; gap: 4px; align-items: center; }

    .subtask-add-btn {
      cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
      width: 26px; height: 26px; border-radius: var(--radius-sm);
      opacity: 0; color: var(--muted); background: transparent;
      border: 1px solid transparent; transition: all var(--duration-fast);
    }
    .task-card:hover .subtask-add-btn { opacity: 0.5; border-color: var(--border); }
    .task-card:hover .subtask-add-btn:hover { opacity: 1; color: var(--text); background: #ffffff0f; border-color: var(--border-strong); }

    .add-subtask-form {
      position: relative;
      margin-left: 0;
      padding: 8px 12px; background: var(--card);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
    }
    /* Tree-line for add-subtask form — matches subtask-card exactly */
    .subtask-container .add-subtask-form::before {
      content: '';
      position: absolute;
      left: -15px;
      top: -4px;
      bottom: 50%;
      width: 1.5px;
      background: var(--tree-line);
      pointer-events: none;
    }
    .subtask-container .add-subtask-form::after {
      content: '';
      position: absolute;
      left: -14px;
      top: 50%;
      width: 10px;
      height: 1.5px;
      background: var(--tree-line);
      transform: translateY(-50%);
    }
    .subtask-container .add-subtask-form .tree-dot-form {
      position: absolute;
      left: -6px;
      top: 50%;
      width: 5px;
      height: 5px;
      border-radius: 50%;
      background: var(--tree-line);
      transform: translateY(-50%);
      pointer-events: none;
    }
    .add-subtask-form .subtask-input {
      width: 100%; background: var(--bg-elevated); border: 1px solid var(--border);
      border-radius: var(--radius-sm); padding: 6px 8px; color: var(--text);
      font-size: 12px; font-family: inherit; outline: none;
    }
    .add-subtask-form .subtask-input:focus { border-color: var(--accent); }

    .priority-pill {
      display: inline-flex; padding: 4px 10px; border-radius: var(--radius-full);
      font-size: 11px; font-weight: 500; cursor: pointer;
      transition: all var(--duration-normal);
    }
    .priority-high { color: var(--danger); border: 1px solid #ef444459; background: var(--danger-subtle); }
    .priority-medium { color: var(--warn); border: 1px solid #f59e0b59; background: var(--warn-subtle); }
    .priority-low { color: var(--ok); border: 1px solid #22c55e59; background: var(--ok-subtle); }

    .priority-popover {
      position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
      display: flex; flex-direction: row; flex-wrap: nowrap; gap: 4px; padding: 6px;
      width: max-content;
      background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md);
      box-shadow: 0 12px 28px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.03);
      z-index: 1200;
      animation: popIn var(--duration-fast) var(--ease-out);
    }
    .priority-popover .priority-pill { opacity: 0.5; transition: opacity var(--duration-fast); white-space: nowrap; }
    .priority-popover .priority-pill:hover { opacity: 1; }
    .priority-popover .priority-pill.current { opacity: 1; }
    .priority-pill-wrap { position: relative; }
    @keyframes popIn { from { opacity: 0; transform: translateX(-50%) translateY(4px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

    .delete-btn {
      opacity: 0; width: 24px; height: 24px; display: flex; align-items: center;
      justify-content: center; border: none; background: none; cursor: pointer;
      color: var(--muted); border-radius: var(--radius-sm);
      transition: all var(--duration-normal);
    }
    .task-card:hover .delete-btn { opacity: 1; }
    .file-preview-actions .delete-btn { opacity: 0.6; }
    .file-preview-actions .delete-btn:hover { opacity: 1; }
    .delete-btn:hover { color: var(--danger); background: var(--danger-subtle); }

    /* Subtask Progress Bar (on parent cards) */
    .subtask-progress {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-top: 8px;
      padding-top: 8px;
      border-top: 1px solid var(--border);
      cursor: pointer;
      user-select: none;
    }
    .expand-chevron {
      font-size: 10px;
      color: var(--muted);
      transition: transform var(--duration-fast);
      width: 12px;
      flex-shrink: 0;
    }
    .expand-chevron.expanded { transform: rotate(90deg); }

    .progress-bar {
      flex: 1;
      height: 4px;
      background: var(--secondary);
      border-radius: 2px;
      overflow: hidden;
      display: flex;
    }
    .progress-done {
      background: var(--status-done);
      height: 100%;
      transition: width var(--duration-normal);
    }
    .progress-review {
      background: var(--status-review);
      height: 100%;
      transition: width var(--duration-normal);
    }
    .progress-active {
      background: var(--status-in-progress);
      height: 100%;
      transition: width var(--duration-normal);
    }
    .progress-text {
      font-size: 10px;
      color: var(--muted);
      white-space: nowrap;
      font-family: "JetBrains Mono", monospace;
    }

    /* Subtask container — wraps all subtask cards for a parent */
    .subtask-container {
      position: relative;
      margin-left: 14px;
      padding-left: 22px;
      display: flex;
      flex-direction: column;
      gap: 4px;
    }
    /* Vertical trunk line — drawn per-card so it always spans first to last dot */

    /* Each subtask card draws a vertical segment from above to its bottom */
    .subtask-card::before {
      content: '';
      position: absolute;
      left: -15px;
      top: -4px;
      bottom: 0;
      width: 1.5px;
      background: var(--tree-line);
      pointer-events: none;
    }
    /* Last card: line stops at center (where horizontal branch connects) */
    .subtask-card:last-child::before {
      bottom: 50%;
    }

    /* Subtask Cards — compact mini-cards with card outline */
    .subtask-card {
      position: relative;
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 7px 10px;
      min-height: 34px;
      background: var(--bg-accent);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      transition: background var(--duration-normal);
    }
    .subtask-card:hover { background: var(--bg-hover); }

    /* Tree-line: horizontal branch from trunk to card */
    .subtask-card::after {
      content: '';
      position: absolute;
      left: -14px;
      top: 50%;
      width: 10px;
      height: 1.5px;
      background: var(--tree-line);
      transform: translateY(-50%);
    }

    /* Tree-line: dot connector */
    .tree-dot {
      position: absolute;
      left: -6px;
      top: 50%;
      width: 5px;
      height: 5px;
      border-radius: 50%;
      background: var(--tree-line);
      transform: translateY(-50%);
      pointer-events: none;
    }

    .subtask-card .subtask-title {
      flex: 1;
      min-width: 0;
      font-size: 12px;
      color: var(--text);
      line-height: 1.4;
      word-break: break-word;
    }
    .subtask-title-input {
      flex: 1;
      min-width: 0;
      font-size: 12px;
      color: var(--text);
      background: var(--bg);
      border: 1px solid var(--accent);
      border-radius: 3px;
      padding: 2px 6px;
      outline: none;
      font-family: inherit;
      line-height: 1.4;
      resize: none;
      overflow: hidden;
    }
    .subtask-actions {
      display: flex;
      gap: 4px;
      align-items: center;
      flex-shrink: 0;
    }
    /* Hide actions when subtask card is in edit mode */
    .subtask-card.editing { align-items: flex-start; }
    .subtask-card.editing .subtask-actions { display: none; }
    .subtask-card.editing .subtask-title-input { flex: 1; }

    /* Status dots (subtask status indicator) */
    .status-dot {
      width: 8px;
      height: 8px;
      border-radius: var(--radius-full);
      flex-shrink: 0;
    }
    .status-dot-done { background: var(--status-done); }
    .status-dot-in-progress { background: var(--status-in-progress); }
    .status-dot-open { background: var(--status-open); }
    .status-dot-review { background: var(--status-review); }

    /* Clickable status dot wrapper */
    .status-dot-wrap {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 20px;
      height: 20px;
      border-radius: var(--radius-sm);
      cursor: pointer;
      position: relative;
      transition: background var(--duration-fast);
    }
    .status-dot-wrap:hover { background: rgba(255,255,255,.08); }

    /* Status popover */
    .status-popover {
      position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
      display: flex; flex-direction: column; gap: 2px; padding: 6px;
      width: max-content;
      background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md);
      box-shadow: 0 12px 28px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.03);
      z-index: 100;
      animation: popIn var(--duration-fast) var(--ease-out);
    }
    .status-option {
      display: flex; align-items: center; gap: 8px;
      padding: 5px 10px; border-radius: var(--radius-sm);
      font-size: 11px; color: var(--muted); cursor: pointer;
      white-space: nowrap; transition: all var(--duration-fast);
    }
    .status-option:hover { background: var(--bg-hover); color: var(--text); }
    .status-option.current { color: var(--text-strong); }

    /* Smaller spec badges on subtask cards */
    .spec-badge-sm { width: 22px; height: 22px; }
    .spec-badge-sm svg { width: 12px; height: 12px; }
    .subtask-card .spec-badge-add { opacity: 0; }
    .subtask-card:hover .spec-badge-add { opacity: 0.5; }
    .subtask-card:hover .spec-badge-add:hover { opacity: 1; color: var(--text); background: #ffffff0f; border-color: var(--border-strong); }

    /* Subtask delete button */
    .subtask-card .delete-btn { width: 20px; height: 20px; opacity: 0; }
    .subtask-card:hover .delete-btn { opacity: 0.6; }
    .subtask-card:hover .delete-btn:hover { opacity: 1; }

    /* Add Task */
    .add-task-btn {
      border: 1px dashed var(--border-strong); border-radius: var(--radius-md);
      padding: 12px; text-align: center; color: var(--muted); font-size: 12px;
      cursor: pointer; transition: all var(--duration-normal); background: none;
      width: 100%; font-family: inherit;
    }
    .add-task-btn:hover { border-color: var(--accent); color: var(--accent); }

    .add-task-form {
      background: var(--card); border: 1px solid var(--border-strong);
      border-radius: var(--radius-md); padding: 12px;
    }
    .add-task-form input {
      width: 100%; background: var(--bg-elevated); border: 1px solid var(--border);
      border-radius: var(--radius-sm); padding: 8px 10px; color: var(--text);
      font-size: 13px; font-family: inherit; outline: none; margin-bottom: 10px;
    }
    .add-task-form input:focus { border-color: var(--accent); }

    .priority-selector { display: flex; gap: 6px; margin-bottom: 10px; }
    .priority-option {
      padding: 4px 10px; border-radius: var(--radius-full);
      font-size: 11px; font-weight: 500; cursor: pointer;
      border: 1px solid var(--border); background: var(--card);
      color: var(--muted); transition: all var(--duration-normal); font-family: inherit;
    }
    .priority-option.selected { color: var(--text-strong); }
    .priority-option[data-p="high"].selected { color: var(--danger); border-color: #ef444459; background: var(--danger-subtle); }
    .priority-option[data-p="medium"].selected { color: var(--warn); border-color: #f59e0b59; background: var(--warn-subtle); }
    .priority-option[data-p="low"].selected { color: var(--ok); border-color: #22c55e59; background: var(--ok-subtle); }

    .form-actions { display: flex; gap: 8px; }

    /* Toast — bottom-right */
    .toast-container {
      position: fixed; bottom: 16px; right: 16px; z-index: 900;
      display: flex; flex-direction: column-reverse; gap: 8px;
    }
    .toast {
      background: var(--bg-elevated); border: 1px solid var(--border);
      border-radius: var(--radius-md); padding: 10px 16px;
      box-shadow: var(--shadow-md); font-size: 12px; color: var(--text);
      border-left: 3px solid var(--info); min-width: 200px;
      animation: slideUp 0.25s var(--ease-out);
    }
    .toast.success { border-left-color: var(--ok); }
    .toast.error { border-left-color: var(--danger); }
    .toast.info { border-left-color: var(--info); }
    .toast.warn { border-left-color: #f0ad4e; }
    .toast.loading { border-left-color: var(--accent); display: flex; align-items: center; gap: 8px; }
    .toast.removing { animation: slideDown 0.2s var(--ease-out) forwards; }
    .toast-spinner {
      width: 14px; height: 14px; border: 2px solid var(--border-strong);
      border-top-color: var(--accent); border-radius: 50%;
      animation: spin 0.8s linear infinite; flex-shrink: 0;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* Modal */
    .modal-overlay {
      position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
      display: flex; align-items: center; justify-content: center;
      z-index: 1000; backdrop-filter: blur(4px);
      animation: fadeIn 0.15s ease-out;
    }
    .modal {
      background: var(--bg-elevated); border: 1px solid var(--border);
      border-radius: var(--radius-lg); padding: 24px;
      max-width: 360px; width: 90%; box-shadow: var(--shadow-lg);
      animation: modalIn 0.2s var(--ease-out);
    }
    .modal-title { font-size: 15px; font-weight: 600; color: var(--text-strong); margin-bottom: 8px; }
    .modal-body { font-size: 13px; color: var(--muted); margin-bottom: 20px; line-height: 1.5; }
    .modal-options { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
    .modal-checkbox { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--fg); cursor: pointer; user-select: none; }
    .modal-checkbox input[type="checkbox"] { display: none; }
    .modal-checkbox .check-box {
      width: 18px; height: 18px; border-radius: 4px; border: 1.5px solid var(--border-strong);
      background: var(--bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0;
      transition: background 0.15s, border-color 0.15s;
    }
    .modal-checkbox .check-box svg { opacity: 0; transition: opacity 0.15s; }
    .modal-checkbox input:checked + .check-box { background: var(--accent); border-color: var(--accent); }
    .modal-checkbox input:checked + .check-box svg { opacity: 1; }
    .modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

    @keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
    @keyframes shrink { to { opacity: 0; transform: scale(0.95) translateY(-4px); height: 0; padding: 0; margin: 0; border: 0; overflow: hidden; } }
    @keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
    @keyframes slideDown { to { opacity: 0; transform: translateY(10px); } }
    @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
    @keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

    /* --- Tab Bar --- */
    .tab-bar {
      grid-column: 2;
      grid-row: 2;
      display: flex;
      align-items: center;
      gap: 4px;
      padding: 12px 22px 0;
      background: var(--bg);
    }
    .tab-bar-spacer { flex: 1; }

    .tab {
      display: flex; align-items: center; gap: 6px;
      padding: 6px 16px; font-size: 12px; font-weight: 500;
      color: var(--text); cursor: pointer;
      border: 1px solid var(--border);
      border-radius: var(--radius-full);
      transition: all var(--duration-normal);
      background: var(--card);
      font-family: inherit;
    }
    .tab:hover { background: var(--bg-hover); border-color: var(--border-strong); }
    .tab.active {
      color: #fff;
      background: var(--accent);
      border-color: var(--accent);
    }
    .tab.active:hover { background: #ff4040; }
    .tab-icon { font-size: 13px; }

    /* --- File Explorer --- */
    .file-explorer {
      display: grid;
      grid-template-columns: 260px 1fr;
      gap: 0;
      height: 100%;
      min-height: 0;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      overflow: hidden;
    }

    .file-tree {
      border-right: 1px solid var(--border);
      overflow: hidden;
      padding: 12px 0;
      display: flex;
      flex-direction: column;
      background: var(--bg-accent);
      position: relative;
    }

    .file-tree-items { flex: 1; overflow-y: auto; }

    .file-tree-footer {
      padding: 12px 14px;
      border-top: 1px solid var(--border);
      font-size: 11px; color: var(--muted);
    }

    .context-bar {
      height: 4px; border-radius: 2px;
      background: var(--secondary);
      margin-top: 6px; overflow: hidden;
    }
    .context-bar-fill {
      height: 100%; border-radius: 2px;
      transition: width var(--duration-normal);
    }

    .tree-item {
      display: flex; align-items: center; gap: 8px;
      padding: 6px 14px 6px 14px;
      font-size: 13px; color: var(--text);
      cursor: pointer; transition: all var(--duration-normal);
      border-left: 2px solid transparent;
      user-select: none;
    }
    .tree-item:hover { background: var(--bg-hover); }
    .tree-item.selected {
      background: var(--accent-subtle);
      border-left-color: var(--accent);
      color: var(--text-strong);
    }
    .tree-item.directory { color: var(--muted); font-weight: 500; }
    .tree-item.directory:hover { color: var(--text); }

    .tree-indent { display: inline-block; }
    .tree-icon { font-size: 14px; flex-shrink: 0; width: 18px; text-align: center; }
    .tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .tree-meta { font-size: 10px; color: var(--muted); flex-shrink: 0; }

    .tree-badge {
      width: 6px; height: 6px; border-radius: 50%;
      flex-shrink: 0;
    }
    .tree-badge.always { background: var(--ok); }
    .tree-badge.lazy { background: var(--warn); }
    .tree-badge.optional { background: var(--info); }

    /* --- File Preview --- */
    .file-preview {
      overflow: hidden;
      display: flex;
      flex-direction: column;
      background: var(--card);
      position: relative;
    }
    .file-preview.editing .file-preview-body {
      overflow: hidden;
    }

    .file-back-btn {
      display: none;
      align-items: center; gap: 4px;
      background: none; border: 1px solid var(--border); border-radius: var(--radius-md);
      color: var(--text); font-size: 13px; font-family: inherit;
      padding: 4px 10px; cursor: pointer; margin-right: 8px;
      transition: all var(--duration-normal);
    }
    .file-back-btn:hover { border-color: var(--border-strong); background: var(--bg-hover); }

    .file-preview-header {
      display: flex; align-items: center; justify-content: space-between;
      padding: 10px 18px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }
    .file-preview-info {
      display: flex; align-items: center; gap: 10px;
      font-size: 13px;
    }
    .file-preview-name { font-weight: 600; color: var(--text-strong); }
    .file-preview-size { color: var(--muted); font-size: 11px; }
    .file-preview-badge {
      display: inline-flex; padding: 2px 8px; border-radius: var(--radius-full);
      font-size: 10px; font-weight: 500; text-transform: uppercase;
      letter-spacing: 0.04em;
    }
    .file-preview-badge.always { color: var(--ok); border: 1px solid #22c55e59; background: var(--ok-subtle); }
    .file-preview-badge.lazy { color: var(--warn); border: 1px solid #f59e0b59; background: var(--warn-subtle); }
    .file-preview-badge.optional { color: var(--info); border: 1px solid #3b82f659; background: var(--info-subtle); }

    .file-preview-actions { display: flex; gap: 6px; }

    .file-preview-body {
      flex: 1; overflow-y: auto; padding: 18px 24px;
    }

    .file-preview-empty {
      display: flex; align-items: center; justify-content: center;
      height: 100%; color: var(--muted); font-size: 14px;
    }

    /* --- Markdown Styles --- */
    .md-content { line-height: 1.65; color: var(--text); }
    .md-content h1 { font-size: 22px; font-weight: 700; color: var(--text-strong); margin: 0 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
    .md-content h2 { font-size: 17px; font-weight: 600; color: var(--text-strong); margin: 24px 0 10px; }
    .md-content h3 { font-size: 14px; font-weight: 600; color: var(--text-strong); margin: 18px 0 8px; }
    .md-content h4 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 0.03em; }
    .md-content p { margin: 0 0 12px; }
    .md-content a { color: var(--accent); text-decoration: none; }
    .md-content a:hover { text-decoration: underline; }
    .md-content strong { color: var(--text-strong); font-weight: 600; }
    .md-content em { font-style: italic; }
    .md-content ul, .md-content ol { margin: 0 0 12px; padding-left: 24px; }
    .md-content li { margin: 4px 0; }
    .md-content li::marker { color: var(--muted); }
    .md-content blockquote {
      border-left: 3px solid var(--accent);
      padding: 8px 16px; margin: 0 0 12px;
      background: var(--accent-subtle); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
      color: var(--text); font-size: 13px;
    }
    .md-content code {
      font-family: "JetBrains Mono", monospace; font-size: 12px;
      background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px;
      color: var(--accent);
    }
    .md-content pre {
      background: var(--bg-elevated); border: 1px solid var(--border);
      border-radius: var(--radius-md); padding: 14px 16px;
      overflow-x: auto; margin: 0 0 14px;
    }
    .md-content pre code {
      background: none; padding: 0; color: var(--text);
      font-size: 12px; line-height: 1.5;
    }
    .md-content table {
      width: 100%; border-collapse: collapse; margin: 0 0 14px;
      font-size: 13px;
    }
    .md-content th {
      text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border);
      color: var(--text-strong); font-weight: 600; font-size: 11px;
      text-transform: uppercase; letter-spacing: 0.04em;
    }
    .md-content td {
      padding: 6px 12px; border-bottom: 1px solid var(--border);
    }
    .md-content tr:hover td { background: var(--bg-hover); }
    .md-content hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
    .md-content img { max-width: 100%; border-radius: var(--radius-md); }

    /* JSON preview */
    .json-content {
      font-family: "JetBrains Mono", monospace; font-size: 12px;
      line-height: 1.5; white-space: pre-wrap; color: var(--text);
    }
    .json-key { color: var(--accent); }
    .json-string { color: var(--ok); }
    .json-number { color: var(--info); }
    .json-bool { color: var(--warn); }
    .json-null { color: var(--muted); }

    /* Edit mode */
    .file-editor {
      width: 100%; height: 100%; resize: none;
      background: var(--bg); color: var(--text);
      border: none; outline: none;
      font-family: "JetBrains Mono", monospace;
      font-size: 13px; line-height: 1.6;
      padding: 18px 24px;
      overflow-y: auto;
    }
    .file-editor:focus { outline: none; }

    .unsaved-dot {
      width: 8px; height: 8px; border-radius: 50%;
      background: var(--warn); display: inline-block;
      margin-left: 6px;
    }

    @media (max-width: 900px) {
      .app { grid-template-columns: 0px 1fr; }
      .file-explorer { grid-template-columns: 1fr; display: block; height: 100%; overflow: hidden; }
      /* Mobile file nav: show tree OR preview, not both */
      .file-explorer .file-tree { display: flex; flex-direction: column; border-right: none; height: 100%; overflow-y: auto; }
      .file-explorer .file-preview { display: none; }
      .file-explorer.show-preview .file-tree { display: none; }
      .file-explorer.show-preview .file-preview { display: flex; flex-direction: column; height: 100%; overflow: auto; }
      /* Back button — only visible on mobile */
      .file-back-btn { display: flex !important; }

      /* File preview header: two rows on mobile */
      .file-preview-header {
        flex-wrap: wrap;
        gap: 4px;
        padding: 8px 12px;
      }
      .file-back-btn { order: 0; }
      .file-preview-actions { order: 1; margin-left: auto; }
      .file-preview-info {
        order: 2;
        flex: 1 1 100%;
      }
      .file-preview-name { font-size: 12px; }
      .file-preview-size { display: none; }
      .file-preview-badge { font-size: 9px; }

      /* Sidebar: slide-in overlay (same as mobile) */
      .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 260px;
        z-index: 200;
        transform: translateX(-100%);
        opacity: 1;
        pointer-events: none;
        transition: transform 0.25s ease, box-shadow 0.25s ease;
        box-shadow: none;
      }
      .app:not(.sidebar-collapsed) .sidebar {
        transform: translateX(0);
        pointer-events: auto;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
      }
      .sidebar-backdrop {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 199;
      }
      .app:not(.sidebar-collapsed) .sidebar-backdrop {
        display: block;
      }

      /* Span full width — sidebar is out of grid flow (position:fixed) */
      .cscroll-wrap.content-wrapper { grid-column: 1 / -1; }
      .tab-bar { grid-column: 1 / -1; }

      /* Allow horizontal scroll through the cscroll wrapper */
      .cscroll-wrap > .cscroll-inner { overflow-x: auto; }
      /* Hide custom scrollbar track (not useful with horizontal kanban) */
      .cscroll-wrap.content-wrapper > .cscroll-track { display: none; }

      /* Kanban: horizontal scroll on tablet + Telegram Desktop side panel */
      .kanban {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 10px;
        padding: 0 12px 16px;
        height: 100%;
      }
      .column {
        width: 300px;
        min-width: 300px;
        max-width: 300px;
        scroll-snap-align: start;
        flex-shrink: 0;
        height: 100%;
        overflow-y: auto;
      }
    }

    /* Mobile: Telegram Mini App + small screens */
    @media (max-width: 600px) {
      /* CRITICAL: span full width — sidebar is out of grid flow (position:fixed) */
      .cscroll-wrap.content-wrapper { grid-column: 1 / -1; }
      .tab-bar { grid-column: 1 / -1; }

      /* Narrower columns on small phones */
      .column { min-width: 82vw; max-width: 82vw; }

      /* Touch-friendly task cards */
      .task-card {
        padding: 12px 14px;
        min-height: 44px;
      }
      .task-card .task-actions { opacity: 1; } /* Always show on mobile */

      /* Header */
      .header { padding: 8px 12px; }
      .header-logo { display: none; }

      /* Sidebar toggle: more prominent */
      .sidebar-toggle {
        width: 36px; height: 36px;
        font-size: 18px;
      }
    }

    /* ============================================================
       IDEA CANVAS
       ============================================================ */

    /* Canvas container */
    .canvas-wrap {
      width: 100%; height: 100%;
      position: relative; overflow: hidden;
      background: var(--bg);
      cursor: default;
      user-select: none;
    }
    .canvas-viewport {
      position: absolute; top: 0; left: 0; width: 100%; height: 100%;
      transform-origin: 0 0;
    }
    .canvas-svg {
      position: absolute; top: 0; left: 0;
      width: 100%; height: 100%; overflow: visible;
      pointer-events: none;
    }
    .canvas-svg .conn-line {
      stroke: var(--border-strong); stroke-width: 2;
      fill: none; cursor: pointer;
      pointer-events: stroke;
    }
    .canvas-svg .conn-line:hover { stroke: var(--accent); }
    .canvas-svg .conn-line-temp {
      stroke: var(--muted); stroke-width: 2;
      stroke-dasharray: 6 4; fill: none;
      pointer-events: none;
    }

    /* Empty state */
    .canvas-empty {
      position: absolute; top: 50%; left: 50%;
      transform: translate(-50%, -50%);
      display: flex; flex-direction: column; align-items: center; gap: 12px;
      color: var(--muted); font-size: 14px;
      pointer-events: none; text-align: center;
    }
    .canvas-empty-icon { font-size: 32px; opacity: 0.4; }

    /* Canvas toolbar (top-right) */
    .canvas-toolbar {
      position: absolute; top: 12px; right: 12px;
      display: flex; gap: 6px; z-index: 10;
    }

    /* Notes */
    .note {
      position: absolute; width: 160px;
      border-radius: var(--radius-md);
      border: 1px solid var(--border);
      border-left-width: 4px;
      box-shadow: var(--shadow-md);
      display: flex; flex-direction: column;
      transition: box-shadow var(--duration-normal);
    }
    .note:hover { box-shadow: var(--shadow-lg); }
    .note.selected { outline: 2px solid var(--accent); outline-offset: 2px; }

    /* Note color variants */
    .note.color-yellow { background: var(--warn-subtle);  border-left-color: var(--warn); }
    .note.color-blue   { background: rgba(59,130,246,.12); border-left-color: var(--info); }
    .note.color-green  { background: var(--ok-subtle);    border-left-color: var(--ok); }
    .note.color-red    { background: var(--danger-subtle); border-left-color: var(--danger); }
    .note.color-teal   { background: var(--accent-2-subtle); border-left-color: var(--accent-2); }

    /* Note header (drag handle) */
    .note-header {
      display: flex; align-items: center; justify-content: space-between;
      padding: 5px 6px 5px 8px; height: 28px;
      cursor: grab; user-select: none; flex-shrink: 0;
    }
    .note-header:active { cursor: grabbing; }

    /* Color dot in header */
    .note-color-dot {
      width: 12px; height: 12px; border-radius: 50%;
      cursor: pointer; flex-shrink: 0;
      transition: transform var(--duration-normal);
    }
    .note-color-dot:hover { transform: scale(1.2); }
    .note.color-yellow .note-color-dot { background: var(--warn); }
    .note.color-blue   .note-color-dot { background: var(--info); }
    .note.color-green  .note-color-dot { background: var(--ok); }
    .note.color-red    .note-color-dot { background: var(--danger); }
    .note.color-teal   .note-color-dot { background: var(--accent-2); }

    /* Note ID label */
    .note-id {
      font-size: 9px; color: var(--muted);
      font-family: "JetBrains Mono", monospace;
      opacity: 0.5; flex: 1; margin-left: 4px;
    }

    /* Note body (text area) */
    .note-body {
      padding: 4px 10px 8px;
      min-height: 40px; cursor: grab; flex: 1;
    }
    .note-text {
      font-size: 12px; line-height: 1.5; color: var(--text);
      min-height: 20px; white-space: pre-wrap; word-break: break-word;
    }
    /* Compact md-content overrides for notes */
    .note-text.md-content p  { margin: 0; }
    .note-text.md-content br { display: block; content: ''; }
    .note-text.md-content ul { margin: 2px 0; padding-left: 14px; }
    .note-text.md-content li { margin: 1px 0; }

    .note-textarea {
      width: 100%; min-height: 60px;
      /* Fill full available note-body height when editing */
      height: 100%;
      background: transparent; border: none; outline: none;
      font-size: 12px; line-height: 1.5; color: var(--text);
      font-family: inherit; resize: none;
      display: block;
    }

    /* Edit mode: body sizes freely to textarea content (grows + shrinks) */
    .note.editing .note-body {
      max-height: none !important;
      overflow: visible !important;
      padding-bottom: 0 !important;
      cursor: text !important;
    }
    .note.editing .note-body::after,
    .note.editing .note-body::before {
      display: none !important;
    }
    .note.editing .note-textarea {
      padding-bottom: 10px !important;
      display: block !important;
      width: 100% !important;
      box-sizing: border-box !important;
      min-height: 60px !important;
    }

    /* Note delete button: hidden until hover/selected */
    .note .delete-btn { width: 18px; height: 18px; opacity: 0; }
    .note:hover .delete-btn,
    .note.selected .delete-btn { opacity: 0.5; }
    .note .delete-btn:hover { opacity: 1 !important; }

    /* Connection dots — base styles (visibility managed by canvas.css) */
    .conn-dot {
      position: absolute; width: 8px; height: 8px;
      border-radius: 50%; background: var(--accent);
      box-sizing: border-box; /* border included in 10px — fixes translate(-50%) centering */
      cursor: crosshair; z-index: 5;
      transform: translate(-50%, -50%);
      transition: opacity var(--duration-normal), transform var(--duration-normal);
      opacity: 0;
    }
    .conn-dot:hover { transform: translate(-50%, -50%) scale(1.5); }
    /* 44px touch targets on mobile */
    .conn-dot::after {
      content: ''; position: absolute;
      top: 50%; left: 50%; transform: translate(-50%, -50%);
      width: 44px; height: 44px;
    }

    /* Selection promote button */
    .canvas-promote-btn {
      position: absolute;
      display: flex;
      align-items: center;
      gap: 4px;
      background: var(--accent); color: #fff;
      border: none; border-radius: var(--radius-full);
      padding: 5px 12px; font-size: 11px; font-weight: 600;
      cursor: pointer; font-family: inherit;
      box-shadow: var(--shadow-md);
      transition: background var(--duration-normal);
      z-index: 10; white-space: nowrap;
    }
    .canvas-promote-btn:hover { background: #ff4040; }

    /* Color popover */
    .color-popover {
      position: absolute; z-index: 200;
      background: var(--card); border: 1px solid var(--border);
      border-radius: var(--radius-md); padding: 8px;
      display: flex; gap: 6px;
      box-shadow: var(--shadow-lg);
      animation: popIn var(--duration-normal) var(--ease-out);
    }
    .color-swatch {
      width: 18px; height: 18px; border-radius: 50%;
      cursor: pointer; border: 2px solid transparent;
      transition: transform var(--duration-normal), border-color var(--duration-normal);
    }
    .color-swatch:hover { transform: scale(1.2); }
    .color-swatch.selected { border-color: var(--text-strong); }
    .color-swatch-yellow { background: var(--warn); }
    .color-swatch-blue   { background: var(--info); }
    .color-swatch-green  { background: var(--ok); }
    .color-swatch-red    { background: var(--danger); }
    .color-swatch-teal   { background: var(--accent-2); }
    .color-swatch-grey   { background: var(--border-strong); }

    /* Lasso selection rectangle */
    .canvas-lasso {
      position: absolute; border: 1px dashed var(--accent);
      background: var(--accent-subtle);
      pointer-events: none; z-index: 5;
      display: none;
    }

    @media (max-width: 600px) {
      .conn-dot { width: 12px; height: 12px; box-sizing: border-box; }
    }
