:root {
    --bg-0: #000;
    --bg-1: rgba(255,255,255,0.025);
    --bg-2: rgba(0,0,0,0.35);
    --border: rgba(255,255,255,0.08);
    --border-strong: rgba(255,255,255,0.16);
    --text: #f8fafc;
    --text-dim: rgba(255,255,255,0.6);
    --text-muted: rgba(255,255,255,0.4);
    --accent: #38bdf8;
    --accent-2: #a855f7;
    --accent-3: #ec4899;
    --danger: #f87171;
    --ok: #4ade80;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  html, body { height: 100%; width: 100%; overflow: hidden; }
  body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: #000;
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
  }

  /* ===== AMBIENT LAYER (black base, subtle glows, noise) ===== */
  .ambient {
    position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  }
  .ambient .glow {
    position: absolute; border-radius: 50%; filter: blur(120px); opacity: 0.12;
  }
  .ambient .glow.g1 { width: 500px; height: 500px; background: #38bdf8; top: -200px; left: 10%; animation: drift 24s infinite ease-in-out; }
  .ambient .glow.g2 { width: 420px; height: 420px; background: #a855f7; top: 40%; right: -150px; animation: drift 30s infinite ease-in-out reverse; }
  .ambient .glow.g3 { width: 380px; height: 380px; background: #ec4899; bottom: -150px; left: 30%; animation: drift 36s infinite ease-in-out; animation-delay: -12s; }
  @keyframes drift { 0%,100% { transform: translate(0,0); } 50% { transform: translate(60px,-40px); } }
  .ambient .noise {
    position: absolute; inset: 0; opacity: 0.04; mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  }

  /* ===== APP GRID (Crystal OS) ===== */
  .app {
    position: relative; z-index: 1;
    display: grid;
    grid-template-columns: 340px 1fr 380px;
    grid-template-rows: 54px 1fr 68px;
    grid-template-areas:
      "topbar topbar topbar"
      "left   graph  right"
      "bottom bottom bottom";
    height: 100vh; width: 100vw;
    padding: 12px; gap: 10px;
    animation: app-fade-in 0.7s cubic-bezier(.2,.8,.2,1) both;
  }
  @keyframes app-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* ===== GLASS PANEL (edge-lit, works on pure black) ===== */
  .glass {
    background: rgba(255,255,255,0.025);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 18px;
    box-shadow:
      0 8px 32px rgba(0,0,0,0.6),
      inset 0 1px 0 rgba(255,255,255,0.08),
      inset 0 0 0 1px rgba(255,255,255,0.02);
    position: relative;
  }
  .glass::before {
    content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
    padding: 1px;
    background: linear-gradient(135deg, rgba(56,189,248,0.25), rgba(168,85,247,0.15) 50%, rgba(236,72,153,0.15));
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor; mask-composite: exclude;
    opacity: 0.6;
  }

  /* ===== TOPBAR ===== */
  .topbar {
    grid-area: topbar;
    display: flex; align-items: center; gap: 18px; padding: 0 20px;
  }
  .brand {
    display: flex; align-items: center; gap: 12px;
    font-weight: 700; letter-spacing: 0.04em; font-size: 14px;
  }
  .brand .dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: conic-gradient(from 0deg, #38bdf8, #a855f7, #ec4899, #38bdf8);
    box-shadow: 0 0 18px rgba(168,85,247,0.55);
    animation: spin-dot 6s linear infinite;
  }
  @keyframes spin-dot { to { transform: rotate(360deg); } }
  .brand .sub { color: rgba(255,255,255,0.45); font-weight: 400; font-size: 12px; letter-spacing: 0; }

  .stats {
    display: flex; gap: 24px; margin-left: auto;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 13px; color: var(--text-dim);
  }
  .stats span { display: inline-flex; align-items: baseline; gap: 6px; }
  .stats b {
    font-size: 15px; font-weight: 600;
    background: linear-gradient(135deg, #e0f2fe, #c4b5fd);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
    display: inline-block; min-width: 14px; text-align: right;
    transition: transform 0.25s ease;
  }
  .stats b.bump {
    animation: stat-bump 0.55s cubic-bezier(.2,.9,.3,1.3);
  }
  @keyframes stat-bump {
    0% { transform: scale(1); }
    40% { transform: scale(1.28); filter: drop-shadow(0 0 12px rgba(236,72,153,0.7)); }
    100% { transform: scale(1); }
  }
  .btn-top {
    padding: 8px 14px; border-radius: 10px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff; cursor: pointer; font-size: 12px; font-weight: 500;
    backdrop-filter: blur(10px);
    transition: all 0.15s;
    display: inline-flex; align-items: center; gap: 6px;
  }
  .btn-top:hover { background: rgba(255,255,255,0.1); transform: translateY(-1px); }
  /* Push-to-talk: stato registrazione attiva (rosso pulsante) */
  .btn-top.recording {
    background: rgba(239, 68, 68, 0.18);
    border-color: #ef4444; color: #fecaca;
    animation: rec-pulse 1.2s infinite;
  }
  @keyframes rec-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55); }
    50%      { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
  }
  .btn-top .rec-dot {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%;
    background: currentColor; vertical-align: middle;
  }
  .btn-top.recording .rec-dot { background: #ef4444; }

  /* ===== LEFT PANEL (chat) ===== */
  .left {
    grid-area: left;
    display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  }
  .panel-title {
    padding: 14px 18px 10px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 11px; font-weight: 600; letter-spacing: 0.15em;
    text-transform: uppercase; color: rgba(255,255,255,0.4);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    display: flex; align-items: center; gap: 8px;
  }
  .panel-title .glow-line {
    flex: 1; height: 1px;
    background: linear-gradient(90deg, rgba(255,255,255,0.05), transparent);
  }
  .chat-log {
    flex: 1; overflow-y: auto; padding: 14px 16px;
    display: flex; flex-direction: column; gap: 12px;
  }
  .msg {
    padding: 11px 13px; border-radius: 14px;
    font-size: 13px; line-height: 1.55; max-width: 94%;
  }
  .msg.user {
    background: linear-gradient(135deg, rgba(56,189,248,0.18), rgba(168,85,247,0.15));
    border: 1px solid rgba(255,255,255,0.1);
    align-self: flex-end; border-bottom-right-radius: 4px;
  }
  .msg.bot {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.85);
    border-bottom-left-radius: 4px;
  }
  .msg .cites { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 5px; }
  .msg .cite-chip {
    font-size: 11px; padding: 3px 9px; border-radius: 99px;
    background: rgba(168,85,247,0.13); color: #c4b5fd;
    border: 1px solid rgba(168,85,247,0.28); cursor: pointer;
  }
  .msg .cite-chip:hover { background: rgba(168,85,247,0.22); }
  .chat-input {
    padding: 12px; border-top: 1px solid rgba(255,255,255,0.05);
    display: flex; gap: 8px;
  }
  .chat-input input {
    flex: 1; background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.08); color: #fff;
    padding: 11px 14px; border-radius: 12px;
    font-family: inherit; font-size: 13px; outline: none;
  }
  .chat-input input:focus { border-color: rgba(168,85,247,0.5); box-shadow: 0 0 0 3px rgba(168,85,247,0.15); }
  .chat-input button {
    padding: 11px 16px; border-radius: 12px; border: none;
    background: linear-gradient(135deg, #38bdf8, #a855f7);
    color: #fff; font-weight: 600; cursor: pointer; font-size: 13px;
    box-shadow: 0 4px 16px rgba(168,85,247,0.35);
  }
  .chat-input button:disabled { opacity: 0.5; cursor: not-allowed; }

  /* ===== CENTER (graph) ===== */
  .graph-wrap {
    grid-area: graph; position: relative; overflow: hidden;
  }
  #graph { width: 100%; height: 100%; position: absolute; inset: 0; }
  .graph-overlay {
    position: absolute; top: 14px; left: 14px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 12px; color: rgba(255,255,255,0.7);
    background: rgba(0,0,0,0.5); backdrop-filter: blur(16px);
    padding: 7px 12px; border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.08); font-weight: 500;
    display: inline-flex; align-items: center; gap: 8px;
    z-index: 5;
  }
  .graph-overlay::before {
    content: ''; width: 6px; height: 6px; border-radius: 50%;
    background: linear-gradient(135deg, #38bdf8, #a855f7);
  }
  .empty-state {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 16px; color: var(--text-dim); text-align: center; padding: 40px;
    pointer-events: none;
  }
  .empty-state h2 {
    font-size: 22px; font-weight: 700; font-family: 'Space Grotesk', sans-serif;
    background: linear-gradient(135deg, #fff, #c4b5fd);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  }
  .empty-state p { max-width: 420px; font-size: 14px; color: rgba(255,255,255,0.55); }
  .empty-state .pill {
    font-family: 'JetBrains Mono', monospace; font-size: 11px;
    padding: 3px 8px; border-radius: 6px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1); color: #93c5fd;
  }

  /* ===== RIGHT PANEL (concept detail) ===== */
  .right {
    grid-area: right;
    display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  }
  .concept-body {
    flex: 1; overflow-y: auto; padding: 16px 18px; font-size: 13px;
  }
  .concept-body h1, .concept-body h2, .concept-body h3 { margin: 18px 0 8px; }
  .concept-body h1 {
    font-size: 22px; font-weight: 700; margin-bottom: 12px;
    background: linear-gradient(135deg, #fff, #c4b5fd);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
    font-family: 'Space Grotesk', sans-serif;
  }
  .concept-body h2 {
    font-size: 11px; font-weight: 600; color: rgba(168,85,247,0.9);
    text-transform: uppercase; letter-spacing: 0.15em;
    font-family: 'Space Grotesk', sans-serif;
  }
  .concept-body h3 {
    font-size: 12px; font-weight: 600; color: #93c5fd;
    text-transform: uppercase; letter-spacing: 0.1em;
  }
  .concept-body p { color: rgba(255,255,255,0.72); line-height: 1.65; margin: 6px 0; font-size: 13px; }
  .concept-body ul, .concept-body ol { color: rgba(255,255,255,0.72); padding-left: 20px; margin: 8px 0; font-size: 13px; }
  .concept-body a.wiki-link {
    color: #93c5fd; text-decoration: none; cursor: pointer;
    border-bottom: 1px dashed rgba(147,197,253,0.4);
  }
  .concept-body a.wiki-link:hover { background: rgba(147,197,253,0.08); }
  .concept-body code {
    background: rgba(0,0,0,0.4); padding: 1px 6px; border-radius: 4px;
    font-family: 'JetBrains Mono', monospace; font-size: 12px;
    color: #fbcfe8; border: 1px solid rgba(255,255,255,0.06);
  }
  .concept-placeholder {
    color: rgba(255,255,255,0.35); font-size: 13px;
    padding: 40px 20px; text-align: center;
  }
  .concept-meta {
    padding: 10px 18px; border-top: 1px solid rgba(255,255,255,0.05);
    font-size: 10px; color: rgba(255,255,255,0.35);
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.08em; text-transform: uppercase;
  }

  /* ===== BOTTOM (quick note) ===== */
  .bottom {
    grid-area: bottom;
    display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  }
  .bottom .label {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase;
    color: rgba(255,255,255,0.5); font-weight: 600;
  }
  .bottom input {
    flex: 1; background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.08); color: #fff;
    padding: 11px 16px; border-radius: 12px;
    font-family: inherit; font-size: 13px; outline: none;
  }
  .bottom input:focus { border-color: rgba(236,72,153,0.5); box-shadow: 0 0 0 3px rgba(236,72,153,0.15); }
  .bottom button {
    padding: 11px 20px; border-radius: 12px; border: none;
    background: linear-gradient(135deg, #ec4899, #a855f7);
    color: #fff; font-weight: 600; cursor: pointer; font-size: 13px;
    box-shadow: 0 4px 16px rgba(236,72,153,0.3);
    transition: all 0.2s ease;
  }
  .bottom button:hover { box-shadow: 0 6px 20px rgba(236,72,153,0.45); transform: translateY(-1px); }
  .bottom input.has-text + button {
    box-shadow: 0 4px 16px rgba(236,72,153,0.3), 0 0 0 0 rgba(236,72,153,0.5);
    animation: note-ready 1.8s ease-in-out infinite;
  }
  @keyframes note-ready {
    0%, 100% { box-shadow: 0 4px 16px rgba(236,72,153,0.3), 0 0 0 0 rgba(236,72,153,0.35); }
    50%      { box-shadow: 0 4px 16px rgba(236,72,153,0.3), 0 0 0 6px rgba(236,72,153,0); }
  }
  .bottom .flash {
    font-size: 12px; color: var(--ok); opacity: 0;
    transition: opacity 0.3s ease;
  }
  .bottom .flash.visible { opacity: 1; }

  /* ===== utility ===== */
  .scroll::-webkit-scrollbar,
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  .scroll::-webkit-scrollbar-track,
  ::-webkit-scrollbar-track { background: transparent; }
  .scroll::-webkit-scrollbar-thumb,
  ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
  .scroll::-webkit-scrollbar-thumb:hover,
  ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

  .hint { font-size: 11px; color: var(--text-muted); padding: 8px 18px 0; }

  /* ===== DRAG & DROP OVERLAY ===== */
  #drop-overlay {
    position: fixed; inset: 0; z-index: 9999;
    display: none;
    align-items: center; justify-content: center;
    background: rgba(3, 7, 18, 0.88);
    backdrop-filter: blur(8px);
    pointer-events: none;
  }
  #drop-overlay.visible { display: flex; }
  #drop-overlay .drop-card {
    border: 2px dashed rgba(56, 189, 248, 0.55);
    border-radius: 18px;
    padding: 60px 80px;
    text-align: center;
    background: linear-gradient(135deg, rgba(56,189,248,0.08), rgba(129,140,248,0.08));
    box-shadow: 0 0 60px rgba(56,189,248,0.18);
    max-width: 560px;
  }
  #drop-overlay .drop-icon {
    font-size: 42px; margin-bottom: 14px; color: var(--accent);
  }
  #drop-overlay .drop-title {
    font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: 0.02em;
    margin-bottom: 8px;
  }
  #drop-overlay .drop-sub {
    color: var(--text-dim); font-size: 13px;
  }

  /* ===== TOAST ===== */
  #toast-list {
    position: fixed; right: 18px; bottom: 90px; z-index: 9000;
    display: flex; flex-direction: column; gap: 10px;
    max-width: 380px;
    pointer-events: none;
  }
  .toast {
    background: rgba(10, 15, 30, 0.96);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    padding: 12px 14px;
    color: var(--text);
    font-size: 13px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.45);
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: auto;
  }
  .toast.visible { opacity: 1; transform: translateX(0); }
  .toast.ok { border-left-color: var(--ok); }
  .toast.err { border-left-color: var(--danger); }
  .toast.work { border-left-color: var(--accent); }
  .toast.life { border-left-color: var(--accent-3); }
  .toast.hybrid { border-left-color: var(--accent-2); }
  .toast .t-title { font-weight: 600; margin-bottom: 4px; }
  .toast .t-meta {
    color: var(--text-dim); font-size: 11px;
    display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px;
  }
  .toast .t-tag {
    background: rgba(148,163,184,0.1); padding: 2px 8px;
    border-radius: 10px; font-size: 10px; letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  .toast .t-tag.dom-lavoro { background: rgba(56,189,248,0.15); color: var(--accent); }
  .toast .t-tag.dom-vita { background: rgba(244,114,182,0.15); color: var(--accent-3); }
  .toast .t-tag.dom-ibrido { background: rgba(129,140,248,0.15); color: var(--accent-2); }

  /* ===== INGEST PANEL (persistente, mostra progresso file-per-file) ===== */
  #ingest-panel {
    position: fixed; right: 18px; top: 80px; z-index: 9500;
    width: 420px; max-height: calc(100vh - 160px);
    background: rgba(10, 15, 30, 0.98);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.55);
    display: none;
    flex-direction: column;
    overflow: hidden;
  }
  #ingest-panel.visible { display: flex; }
  #ingest-panel .ip-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, rgba(56,189,248,0.08), rgba(129,140,248,0.08));
    position: relative;
  }
  /* Barra di avanzamento globale dell'ingest: riempie dall'inizio alla fine. */
  #ingest-panel .ip-progress {
    position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
    background: rgba(148,163,184,0.08); overflow: hidden;
  }
  #ingest-panel .ip-progress-bar {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3));
    background-size: 200% 100%;
    animation: ip-bar-shine 2.4s linear infinite;
    transition: width 0.35s cubic-bezier(.2,.8,.2,1);
    box-shadow: 0 0 10px rgba(56,189,248,0.5);
  }
  @keyframes ip-bar-shine {
    from { background-position: 0% 0; }
    to   { background-position: 200% 0; }
  }
  #ingest-panel.done .ip-progress-bar {
    animation: none;
    background: linear-gradient(90deg, var(--ok), var(--ok));
  }
  #ingest-panel .ip-title { font-size: 13px; font-weight: 600; color: var(--text); }
  #ingest-panel .ip-counter { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
  #ingest-panel .ip-close {
    background: transparent; border: 1px solid var(--border-strong);
    color: var(--text-dim); border-radius: 6px;
    width: 26px; height: 26px; cursor: pointer; font-size: 14px;
    display: none;
  }
  #ingest-panel .ip-close:hover { color: var(--text); border-color: var(--accent); }
  #ingest-panel.done .ip-close { display: inline-block; }
  #ingest-panel .ip-body {
    overflow-y: auto; padding: 6px 8px;
    max-height: calc(100vh - 260px);
  }
  #ingest-panel .ip-foot {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    font-size: 11px; color: var(--text-dim);
    display: flex; gap: 12px; flex-wrap: wrap;
  }
  #ingest-panel .ip-foot b { color: var(--text); }
  .ip-row {
    display: flex; align-items: flex-start; gap: 8px;
    padding: 8px 8px; border-radius: 8px;
    font-size: 12px;
    border-left: 2px solid transparent;
  }
  .ip-row + .ip-row { margin-top: 2px; }
  .ip-row:hover { background: rgba(148,163,184,0.04); }
  .ip-row.queued { border-left-color: rgba(148,163,184,0.3); color: var(--text-dim); }
  .ip-row.running { border-left-color: var(--accent); background: rgba(56,189,248,0.04); }
  .ip-row.ok { border-left-color: var(--ok); }
  .ip-row.err { border-left-color: var(--danger); }
  .ip-row.dup { border-left-color: #f59e0b; background: rgba(245,158,11,0.06); }
  .ip-row.dup .ip-icon { color: #f59e0b; }
  .ip-row.dup .ip-detail { color: #f59e0b; }
  .ip-row .ip-icon { width: 16px; flex: 0 0 16px; text-align: center; line-height: 16px; }
  .ip-row .ip-body-col { flex: 1; min-width: 0; }
  .ip-row .ip-name {
    font-weight: 500; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .ip-row.queued .ip-name { color: var(--text-dim); }
  .ip-row .ip-detail {
    font-size: 11px; color: var(--text-dim); margin-top: 2px;
    word-break: break-word;
  }
  .ip-row.err .ip-detail { color: var(--danger); }
  .ip-row .ip-tags {
    display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px;
  }
  .ip-row .ip-tag {
    background: rgba(148,163,184,0.1); padding: 1px 6px;
    border-radius: 8px; font-size: 10px; letter-spacing: 0.03em;
    text-transform: uppercase; color: var(--text-dim);
  }
  .ip-row .ip-tag.dom-lavoro { background: rgba(56,189,248,0.15); color: var(--accent); }
  .ip-row .ip-tag.dom-vita { background: rgba(244,114,182,0.15); color: var(--accent-3); }
  .ip-row .ip-tag.dom-ibrido { background: rgba(129,140,248,0.15); color: var(--accent-2); }
  @keyframes ip-spin { to { transform: rotate(360deg); } }
  .ip-row.running .ip-icon {
    display: inline-block; animation: ip-spin 1s linear infinite;
  }

  /* ===== MOBILE RESPONSIVE (PWA) ===== */
  .tab-bar { display: none; }

  @media (max-width: 768px) {
    html, body { overflow: hidden; }

    .app {
      grid-template-columns: 1fr;
      grid-template-rows: 48px 1fr 52px 56px;
      grid-template-areas:
        "topbar"
        "main-panel"
        "bottom"
        "tabs";
      padding: 6px; gap: 6px;
    }

    /* topbar compatta su mobile */
    .topbar { padding: 0 12px; gap: 10px; }
    .stats { gap: 12px; font-size: 12px; }
    #stat-last { display: none; }
    .btn-top span:not(.rec-dot) { display: none; }
    .btn-top { padding: 6px 10px; min-width: 34px; justify-content: center; }

    /* bottom note rimane accessibile */
    .bottom {
      grid-area: bottom;
      padding: 8px 12px;
    }

    /* tab bar in fondo */
    .tab-bar {
      display: flex;
      grid-area: tabs;
      background: rgba(255,255,255,0.04);
      border-top: 1px solid var(--border);
      border-radius: 14px;
      overflow: hidden;
    }
    .tab-btn {
      flex: 1; display: flex; flex-direction: column; align-items: center;
      justify-content: center; gap: 3px;
      background: none; border: none; color: var(--text-dim);
      cursor: pointer; padding: 6px 4px; font-size: 10px;
      transition: color .2s, background .2s;
      font-family: inherit; letter-spacing: 0.04em; text-transform: uppercase;
    }
    .tab-btn svg { width: 20px; height: 20px; stroke-width: 1.5; }
    .tab-btn.active { color: var(--accent); background: rgba(56,189,248,0.08); }

    /* pannelli: nascosti di default su mobile, visibili solo se .panel-active */
    .left, .graph-wrap, .right {
      display: none;
      grid-area: main-panel;
      min-height: 0;
      max-height: 100%;
      overflow: hidden;
    }
    .left.panel-active, .graph-wrap.panel-active, .right.panel-active {
      display: flex;
    }
    .graph-wrap.panel-active { display: block; }

    /* graph a piena altezza su mobile */
    .graph-wrap { height: 100%; }

    /* chat log più alto */
    .chat-log { flex: 1; }

    /* ingest panel più piccolo su mobile */
    #ingest-panel { width: calc(100vw - 24px); right: 12px; top: 56px; }

    /* toast in basso */
    #toast-list { bottom: 130px; right: 12px; max-width: calc(100vw - 24px); }
  }

/* ===== MOBILE NAV (nascosta su desktop) ===== */
.mob-nav { display: none; }

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {
  #bg-neural { display: none; }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr 62px;
    grid-template-areas: "topbar" "panel" "mobnav";
    overflow: hidden;
  }
  .left, .graph-wrap, .right {
    grid-area: panel; display: none !important; width: 100%; min-width: 0; border: none;
  }
  .left.mob-active, .right.mob-active  { display: flex !important; }
  .graph-wrap.mob-active               { display: block !important; }
  .bottom { display: none; }
  .stats  { display: none !important; }
  .mob-nav {
    grid-area: mobnav; display: flex !important;
    background: rgba(10,15,30,0.98); border-top: 1px solid var(--border);
    backdrop-filter: blur(12px); z-index: 20;
  }
  .mob-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 4px; font-size: 10px; letter-spacing: .07em;
    text-transform: uppercase; font-weight: 500; color: var(--text-muted);
    cursor: pointer; padding: 8px 4px 6px; border: none; background: none;
    font-family: 'Inter', system-ui, sans-serif; transition: color .18s;
    position: relative; -webkit-tap-highlight-color: transparent;
  }
  .mob-tab .mob-icon { font-size: 22px; line-height: 1; transition: transform .18s; }
  .mob-tab.active { color: var(--accent); }
  .mob-tab.active .mob-icon { transform: scale(1.15); }
  .mob-tab.active::after {
    content: ''; position: absolute; top: 0; left: 25%; right: 25%;
    height: 2px; background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-radius: 0 0 3px 3px;
  }
  .left { flex-direction: column; }
  .chat-input { flex-shrink: 0; }
  .right { flex-direction: column; overflow: hidden; }
  .concept-body { flex: 1; }
}