*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --bg: #ffffff;
      --surface: #f8f9fa;
      --surface2: #f1f3f5;
      --border: #e5e7eb;
      --text: #111827;
      --muted: #6b7280;
      --accent: #0ea5e9;
      --accent-dim: #cffafe;
      --accent-hover: #06b6d4;
      --user-bubble: #fff0f1;
      --agent-bubble: #f8f9fa;
      --cursor: #0ea5e9;
      --green: #10b981;
      --danger: #e63946;
      --gold: #f59e0b;
      --shadow: 0 2px 8px rgba(0,0,0,0.06);
      --shadow-hover: 0 4px 16px rgba(0,0,0,0.1);
    }

    [data-theme="dark"] {
      --bg: #0a0e17;
      --surface: #111827;
      --surface2: #1a2332;
      --border: #1f2937;
      --text: #f3f4f6;
      --muted: #9ca3af;
      --accent: #06b6d4;
      --accent-dim: #164e63;
      --accent-hover: #0891b2;
      --user-bubble: #1e1b20;
      --agent-bubble: #13161f;
      --cursor: #06b6d4;
      --green: #34d399;
      --danger: #ef4444;
      --gold: #fbbf24;
      --shadow: 0 2px 8px rgba(0,0,0,0.3);
      --shadow-hover: 0 4px 16px rgba(0,0,0,0.4);
    }

    html, body {
      height: 100%;
      background: var(--bg);
      color: var(--text);
      font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
      font-size: 15px;
      line-height: 1.6;
      overflow: hidden;
    }

    /* Hide scrollbars */
    ::-webkit-scrollbar { display: none; }
    * { -ms-overflow-style: none; scrollbar-width: none; }

    /* ── Layout ── */
    .app {
      display: flex;
      flex-direction: row;
      height: 100vh;
      height: 100dvh;
      width: 100%;
      overflow: hidden;
    }
    /* Main column: nav + chat + input */
    .app-main {
      display: flex;
      flex-direction: column;
      flex: 1 1 0;
      min-width: 0;
      overflow: hidden;
    }

    /* ── Header ── */
    header {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 20px 10px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }
    .back-link {
      text-decoration: none;
      color: var(--muted);
      font-size: 1.1rem;
      margin-right: 4px;
      transition: color 0.15s;
    }
    .back-link:hover { color: var(--text); }
    .logo {
      width: 34px;
      height: 34px;
      background: var(--accent);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 18px;
      flex-shrink: 0;
    }
    .title-block h1 {
      font-size: 1rem;
      font-weight: 600;
      letter-spacing: 0.01em;
      margin: 0;
    }
    .title-block p {
      font-size: 0.78rem;
      color: var(--muted);
    }
    .app-version {
      font-size: 0.78rem;
      color: var(--muted);
      text-decoration: none;
      cursor: pointer;
      transition: color 0.15s;
    }
    .app-version:hover { color: var(--text); }
    .status-dot {
      margin-left: auto;
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: 0.75rem;
      color: var(--muted);
    }

    /* Agent selector */
    .selector-row {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-left: auto;
    }
    .selector-row select {
      background: var(--surface);
      border: 1px solid var(--border);
      color: var(--text);
      font-size: 0.78rem;
      padding: 8px 10px;
      border-radius: 8px;
      outline: none;
      cursor: pointer;
      min-height: 44px;
    }
    .selector-row select:focus { border-color: var(--accent); }
    .mcp-toggle {
      background: var(--surface);
      border: 1px solid var(--border);
      color: var(--text);
      border-radius: 10px;
      padding: 8px 12px;
      font-size: 0.72rem;
      cursor: pointer;
      transition: all 0.15s;
      font-family: inherit;
      min-width: 44px;
      min-height: 44px;
    }
    .mcp-toggle:hover { border-color: var(--accent); color: var(--accent); }
    .mcp-toggle.active {
      background: #0a1a0e;
      border-color: #4caf82;
      color: #4caf82;
    }
    .input-area.mcp-mode { gap: 6px; }
    .input-area.mcp-mode .voice-btn,
    .input-area.mcp-mode .ctf-popup,
    .app.mcp-mode .debug-toggle,
    .app.mcp-mode .debug-panel { display: none !important; }
    .dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: var(--muted);
    }
    .dot.online { background: var(--green); }
    .dot.thinking {
      background: var(--accent);
      animation: pulse 0.9s ease-in-out infinite;
    }

    @keyframes pulse {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.3; }
    }

    /* ── System status bar ── */
    .system-bar {
      flex-shrink: 0;
      display: none;
      align-items: center;
      gap: 4px;
      padding: 0 20px;
      height: 24px;
      border-bottom: 1px solid var(--border);
      background: var(--surface);
      overflow-x: auto;
      white-space: nowrap;
      -webkit-overflow-scrolling: touch;
      font-size: 0.65rem;
    }
    .sbar-chip {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      font-size: 0.72rem;
      color: var(--muted);
      cursor: default;
      padding: 2px 4px;
      border-radius: 4px;
      transition: color 0.15s, background 0.15s;
      white-space: nowrap;
    }
    .sbar-chip:hover { color: var(--text); background: var(--surface2); }
    .sbar-chip span { font-size: 0.72rem; }
    .sbar-chip.ok span { color: var(--green); }
    .sbar-chip.warn span { color: var(--gold); }
    .sbar-chip.err span { color: var(--danger); }
    .sbar-sep {
      color: var(--border);
      font-size: 0.72rem;
      user-select: none;
      flex-shrink: 0;
    }

    /* ── Convergence Models 3 cube panel ── */
    .model-cube-overlay {
      position: fixed; inset: 0; z-index: 200;
      background: rgba(0,0,0,0.4);
    }
    .model-cube-overlay.hidden { display: none; }
    .model-cube-panel {
      position: fixed;
      top: 50%; left: 50%;
      transform: translate(-50%, -50%);
      z-index: 201;
      width: min(680px, 96vw);
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 16px;
      box-shadow: 0 8px 40px rgba(0,0,0,0.5);
      padding: 0;
      overflow: hidden;
    }
    .model-cube-panel.hidden { display: none; }
    .model-cube-header {
      display: flex; align-items: center; justify-content: space-between;
      padding: 14px 20px 12px;
      border-bottom: 1px solid var(--border);
      background: var(--surface2);
    }
    .model-cube-title {
      font-size: 0.82rem; font-weight: 700;
      letter-spacing: 0.06em; text-transform: uppercase;
      color: var(--accent);
    }
    .model-cube-close {
      background: none; border: none; color: var(--muted);
      font-size: 1.4rem; cursor: pointer; line-height: 1;
      padding: 0 4px; transition: color 0.15s;
    }
    .model-cube-close:hover { color: var(--text); }
    .model-cube-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 1px;
      background: var(--border);
    }
    .model-card {
      background: var(--surface);
      padding: 20px 16px;
      display: flex; flex-direction: column; gap: 6px;
      transition: background 0.15s;
    }
    .model-card:hover { background: var(--surface2); }
    .mc-icon { font-size: 1.6rem; line-height: 1; }
    .mc-name {
      font-size: 0.78rem; font-weight: 700;
      color: var(--text); word-break: break-all;
    }
    .mc-role {
      font-size: 0.68rem; text-transform: uppercase;
      letter-spacing: 0.08em; color: var(--muted);
    }
    .mc-base {
      font-size: 0.68rem; color: var(--muted);
      font-family: ui-monospace, monospace;
    }
    .mc-status {
      font-size: 0.72rem; margin-top: 4px;
      padding: 3px 8px; border-radius: 10px;
      background: var(--surface2); color: var(--muted);
      display: inline-block; align-self: flex-start;
    }
    .model-card.loaded .mc-status {
      background: rgba(16,185,129,0.12); color: var(--green);
    }
    .model-card.missing .mc-status {
      background: rgba(255,66,77,0.1); color: var(--danger);
    }
    .model-card.loading .mc-status { color: var(--muted); }
    .mc-size { font-size: 0.68rem; color: var(--muted); font-family: ui-monospace, monospace; }
    .model-cube-footer {
      padding: 10px 20px;
      font-size: 0.72rem; color: var(--muted);
      border-top: 1px solid var(--border);
      background: var(--surface2);
    }
    @media (max-width: 520px) {
      .model-cube-grid { grid-template-columns: 1fr; }
    }

    /* ── Messages ── */
    .messages {
      flex: 1;
      overflow-y: auto;
      padding: 16px 20px 8px;
      display: flex;
      flex-direction: column;
      gap: 4px;
      scroll-behavior: smooth;
    }
    .messages::-webkit-scrollbar { width: 4px; }
    .messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

    .msg-row {
      display: flex;
      flex-direction: column;
      gap: 2px;
      margin-bottom: 16px;
    }
    .msg-row.user { align-items: flex-end; }
    .msg-row.agent { align-items: flex-start; }

    .msg-label {
      font-size: 0.72rem;
      color: var(--muted);
      padding: 0 4px;
      letter-spacing: 0.04em;
      text-transform: uppercase;
    }

    .bubble {
      max-width: 75%;
      padding: 12px 16px;
      border-radius: 16px;
      line-height: 1.58;
      white-space: pre-wrap;
      word-break: break-word;
    }
    .msg-row.user .bubble {
      background: var(--user-bubble);
      border: 1px solid var(--border);
      border-bottom-right-radius: 4px;
      margin-right: 4px;
    }
    .msg-row.agent .bubble {
      background: var(--agent-bubble);
      border: 1px solid var(--border);
      border-bottom-left-radius: 4px;
      margin-left: 4px;
    }

    /* Typing cursor */
    .cursor {
      display: inline-block;
      width: 2px;
      height: 1.1em;
      background: var(--cursor);
      margin-left: 2px;
      vertical-align: text-bottom;
      animation: blink 0.7s step-end infinite;
    }
    @keyframes blink {
      0%, 100% { opacity: 1; }
      50% { opacity: 0; }
    }

    /* Images in bubbles */
    .bubble-images {
      display: flex;
      flex-direction: column;
      gap: 8px;
      margin-top: 8px;
    }
    .bubble-image {
      max-width: 100%;
      height: auto;
      border-radius: 6px;
      box-shadow: var(--shadow);
      transition: transform 0.2s, box-shadow 0.2s;
    }
    .bubble-image:hover {
      transform: scale(1.02);
      box-shadow: var(--shadow-hover);
    }

    /* Image modal overlay */
    .image-modal-overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.9);
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 10000;
    }

    /* Suggestions */
    .suggestions {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      padding: 2px 4px;
      margin-top: 4px;
    }
    .suggestion {
      background: var(--surface2);
      border: 1px solid var(--border);
      color: var(--text);
      font-size: 0.82rem;
      padding: 5px 12px;
      border-radius: 20px;
      cursor: pointer;
      transition: background 0.15s, border-color 0.15s;
    }
    .suggestion:hover {
      background: var(--accent-dim);
      border-color: var(--accent);
    }

    /* Message footer (source + latency + turn) */
    .msg-footer {
      font-size: 0.67rem;
      color: var(--muted);
      padding: 0 4px;
      align-self: flex-start;
      opacity: 0.65;
      letter-spacing: 0.02em;
    }
    .msg-footer.offline { opacity: 0.5; }
    .msg-footer.anthropic { color: var(--accent); opacity: 0.8; }
    .msg-footer.ollama { color: var(--green); opacity: 0.8; }
    .msg-footer.grok { color: #e2c97e; opacity: 0.8; }
    .msg-footer.gemini { color: #4fc3f7; opacity: 0.8; }

    /* Keep source-badge alias for any legacy rows */
    .source-badge { font-size: 0.67rem; color: var(--muted); padding: 0 4px; opacity: 0.65; align-self: flex-start; }

    /* Thinking indicator */
    .thinking-row {
      display: flex;
      align-items: center;
      gap: 8px;
      color: var(--muted);
      font-size: 0.85rem;
      padding: 8px 4px;
    }
    .thinking-dots span {
      display: inline-block;
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: var(--accent);
      margin: 0 2px;
      animation: bounce 1.2s ease-in-out infinite;
    }
    .thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
    .thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
    @keyframes bounce {
      0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
      40% { transform: translateY(-5px); opacity: 1; }
    }

    /* Error notice */
    .error-notice {
      font-size: 0.78rem;
      color: var(--muted);
      font-style: italic;
      padding: 2px 4px;
    }

    /* ── Input area ── */
    .input-area {
      flex-shrink: 0;
      padding: 8px 16px 16px;
      padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
      border-top: 1px solid var(--border);
      background: var(--bg);
    }
    .input-row {
      display: flex;
      align-items: flex-end;
      gap: 10px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 10px 12px 10px 16px;
      transition: border-color 0.2s;
    }
    .input-row:focus-within {
      border-color: var(--accent);
    }
    .input-row input[type="text"] {
      flex: 1;
      background: none;
      border: none;
      color: var(--text);
      font-family: inherit;
      font-size: 0.95rem;
      line-height: 1.5;
      outline: none;
      height: 24px;
    }
    .input-row input[type="text"]::placeholder { color: var(--muted); }
    .send-btn {
      flex-shrink: 0;
      width: 44px;
      height: 44px;
      border: none;
      border-radius: 10px;
      background: var(--accent);
      color: white;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: background 0.15s, opacity 0.15s;
    }
    .send-btn:hover { background: var(--accent-hover); }
    .send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
    .send-btn svg { width: 16px; height: 16px; }

    .input-hint {
      font-size: 0.72rem;
      color: var(--muted);
      text-align: center;
      margin-top: 8px;
    }

    /* ── Voice button ── */
    .voice-btn {
      flex-shrink: 0;
      width: 36px;
      height: 36px;
      border: 1px solid var(--border);
      border-radius: 10px;
      background: none;
      color: var(--muted);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.15s;
      font-size: 16px;
    }
    .voice-btn:hover { border-color: var(--accent); color: var(--accent); }
    .voice-btn.listening {
      background: var(--accent-dim);
      border-color: var(--accent);
      color: var(--accent);
      animation: pulse 0.9s ease-in-out infinite;
    }

    /* ── CTF symbol popup ── */
    .ctf-popup {
      position: absolute;
      bottom: calc(100% + 8px);
      left: 0;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 6px;
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      max-width: 320px;
      z-index: 50;
      box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    }
    .ctf-popup.hidden { display: none; }
    .ctf-sym {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 3px 8px;
      font-size: 1rem;
      cursor: pointer;
      transition: background 0.1s;
      color: var(--text);
      white-space: nowrap;
    }
    .ctf-sym:hover { background: var(--accent-dim); border-color: var(--accent); }

    /* ── TTS speaking indicator ── */
    .tts-badge {
      font-size: 0.68rem;
      color: var(--accent);
      padding: 2px 6px;
      background: var(--accent-dim);
      border-radius: 4px;
      margin-top: 4px;
      display: none;
    }
    .tts-badge.speaking { display: inline-block; }

    /* ── CTF converted text ── */
    .bubble .ctf-symbol { color: var(--accent); letter-spacing: 0.05em; }

    /* ── Settings button ── */
    .settings-btn {
      flex-shrink: 0;
      width: 44px;
      height: 44px;
      border: 1px solid var(--border);
      border-radius: 8px;
      background: none;
      color: var(--muted);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: border-color 0.15s, color 0.15s;
    }
    .settings-btn:hover { border-color: var(--accent); color: var(--accent); }
    .settings-btn svg { width: 15px; height: 15px; }
    .settings-btn.has-error { border-color: var(--danger); color: var(--danger); }
    #logdream-btn { margin-left: 4px; }
    .theme-toggle {
      width: 44px;
      height: 44px;
      margin-left: 4px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      background: none;
      border: 1px solid var(--border);
      border-radius: 8px;
      color: var(--accent);
      cursor: pointer;
      transition: border-color 0.15s, color 0.15s;
      padding: 0;
    }
    .theme-toggle:hover { border-color: var(--accent); color: var(--accent-hover); }
    .drawer-close { width: 44px; height: 44px; font-size: 1.6rem; }
    .provider-getkey { display: inline-flex; align-items: center; min-height: 44px; padding: 4px 10px; }

    /* ── Settings drawer ── */
    .settings-overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.55);
      z-index: 100;
    }
    .settings-overlay.open { display: block; }
    .settings-drawer {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      width: min(400px, 100vw);
      background: var(--surface);
      border-left: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      z-index: 101;
      transform: translateX(100%);
      transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .settings-drawer.open { transform: translateX(0); }
    .drawer-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 20px 20px 16px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }
    .drawer-header h2 { font-size: 1rem; font-weight: 600; }
    .drawer-close {
      background: none;
      border: none;
      color: var(--muted);
      cursor: pointer;
      font-size: 1.4rem;
      line-height: 1;
      padding: 2px 6px;
    }
    .drawer-close:hover { color: var(--text); }
    .drawer-body {
      flex: 1;
      overflow-y: auto;
      padding: 20px;
      display: flex;
      flex-direction: column;
      gap: 12px;
    }
    .drawer-hint {
      font-size: 0.78rem;
      color: var(--muted);
      line-height: 1.5;
      margin-bottom: 4px;
    }
    /* Provider card */
    .provider-card {
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 14px 16px;
      display: flex;
      flex-direction: column;
      gap: 10px;
      transition: border-color 0.15s;
    }
    .provider-card.connected { border-color: #2e5c42; }
    .provider-top {
      display: flex;
      align-items: center;
      gap: 10px;
    }
    .provider-icon {
      width: 32px;
      height: 32px;
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      flex-shrink: 0;
    }
    .provider-name { font-size: 0.9rem; font-weight: 600; flex: 1; }
    .provider-status {
      font-size: 0.72rem;
      padding: 3px 8px;
      border-radius: 20px;
      font-weight: 500;
    }
    .provider-status.ok { background: #1a3d2a; color: var(--green); }
    .provider-status.missing { background: var(--surface); color: var(--muted); }
    .provider-key-row {
      display: flex;
      gap: 8px;
    }
    .provider-key-input {
      flex: 1;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 8px;
      color: var(--text);
      font-size: 0.82rem;
      font-family: monospace;
      padding: 7px 10px;
      outline: none;
      transition: border-color 0.15s;
    }
    .provider-key-input:focus { border-color: var(--accent); }
    .provider-key-input::placeholder { font-family: inherit; color: var(--muted); }
    .provider-save-btn {
      flex-shrink: 0;
      background: var(--accent);
      border: none;
      color: #fff;
      font-size: 0.8rem;
      font-weight: 700;
      padding: 8px 16px;
      border-radius: 8px;
      cursor: pointer;
      transition: background 0.15s, opacity 0.15s;
      min-width: 44px;
      min-height: 44px;
    }
    .provider-save-btn:hover { background: var(--accent-hover); }
    .provider-save-btn:disabled { opacity: 0.45; cursor: not-allowed; }
    .provider-actions {
      display: flex;
      gap: 8px;
      align-items: center;
    }
    .provider-getkey {
      font-size: 0.78rem;
      color: var(--accent);
      text-decoration: none;
      border: 1px solid var(--accent-dim);
      padding: 4px 10px;
      border-radius: 6px;
      transition: background 0.15s;
    }
    .provider-getkey:hover { background: var(--accent-dim); }
    .provider-clear {
      font-size: 0.78rem;
      color: var(--muted);
      background: none;
      border: 1px solid var(--border);
      padding: 4px 10px;
      border-radius: 6px;
      cursor: pointer;
      transition: color 0.15s, border-color 0.15s;
      min-height: 44px;
    }
    .provider-clear:hover { color: var(--danger); border-color: var(--danger); }
    .voice-card {
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 14px;
      display: flex;
      flex-direction: column;
      gap: 10px;
      margin-top: 8px;
    }
    .voice-card h3 { font-size: 0.92rem; margin: 0; }
    .voice-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
    .voice-row label { font-size: 0.78rem; color: var(--muted); min-width: 40px; }
    .voice-select {
      flex: 1;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 8px 10px;
      color: var(--text);
      font-size: 0.8rem;
      min-width: 180px;
      min-height: 44px;
    }
    .voice-slider {
      flex: 1;
      accent-color: var(--accent);
    }
    .voice-value {
      font-size: 0.78rem;
      color: var(--muted);
      min-width: 32px;
      text-align: right;
    }
    .voice-test-btn {
      font-size: 0.78rem;
      background: var(--accent);
      border: 1px solid var(--accent);
      color: #fff;
      padding: 8px 14px;
      border-radius: 8px;
      cursor: pointer;
      transition: background 0.15s;
      min-width: 44px;
      min-height: 44px;
    }
    .voice-test-btn:hover { background: var(--accent-hover); color: #fff; }
    .save-feedback {
      font-size: 0.75rem;
      padding: 2px 4px;
      display: none;
    }
    .save-feedback.ok { color: var(--green); display: inline; }
    .save-feedback.err { color: var(--danger); display: inline; }

    /* ── Log Dream drawer ── */
    .logdream-overlay {
      display: none; position: fixed; inset: 0;
      background: rgba(0,0,0,0.55); z-index: 100;
    }
    .logdream-overlay.open { display: block; }
    .logdream-drawer {
      position: fixed; top: 0; right: 0; bottom: 0;
      width: min(420px, 100vw);
      background: var(--surface);
      border-left: 1px solid var(--border);
      display: flex; flex-direction: column;
      z-index: 101;
      transform: translateX(100%);
      transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .logdream-drawer.open { transform: translateX(0); }
    .logdream-body {
      flex: 1; overflow-y: auto; padding: 20px;
      display: flex; flex-direction: column; gap: 14px;
    }
    .form-group { display: flex; flex-direction: column; gap: 6px; }
    .form-group label { font-size: 0.78rem; color: var(--muted); font-weight: 500; }
    .form-group input[type="text"],
    .form-group textarea,
    .form-group select {
      background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
      color: var(--text); font-size: 0.9rem; font-family: inherit;
      padding: 10px 12px; outline: none; transition: border-color 0.15s;
      min-height: 44px;
    }
    .form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: var(--accent); }
    .form-group textarea { min-height: 80px; resize: vertical; }
    .form-row { display: flex; gap: 12px; }
    .form-row .form-group { flex: 1; }
    .range-val { font-size: 0.78rem; color: var(--accent); margin-left: 6px; }
    .checkbox-row { display: flex; align-items: center; gap: 8px; }
    .checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); }
    .tag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
    .tag-chip {
      background: var(--surface2); border: 1px solid var(--border); border-radius: 14px;
      padding: 3px 10px; font-size: 0.78rem; color: var(--text); cursor: pointer; transition: all 0.15s;
    }
    .tag-chip:hover { border-color: var(--danger); color: var(--danger); }
    .tag-chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }
    .logdream-actions { display: flex; gap: 10px; margin-top: 4px; }
    .logdream-actions button {
      flex: 1; background: var(--accent); border: none; color: white;
      font-size: 0.9rem; font-weight: 600; padding: 10px 14px; border-radius: 10px;
      cursor: pointer; transition: background 0.15s;
      min-height: 44px;
    }
    .logdream-actions button:hover { background: var(--accent-hover); }
    .logdream-actions button.secondary { background: var(--surface2); border: 1px solid var(--border); color: var(--text); }
    .logdream-actions button.secondary:hover { background: var(--border); }

    /* ── Debug / Analytics Panel ── */
    .debug-toggle {
      position: fixed;
      bottom: 12px;
      right: 12px;
      z-index: 9000;
      width: 44px; height: 44px;
      border-radius: 50%;
      border: 1px solid var(--border);
      background: var(--surface2);
      color: var(--text);
      font-size: 14px;
      cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      opacity: 0.7; transition: opacity 0.2s;
    }
    .debug-toggle:hover { opacity: 1; color: var(--accent); }
    .debug-panel {
      position: fixed;
      bottom: 52px; right: 12px;
      width: 340px; max-height: 420px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 14px 16px;
      z-index: 9001;
      font-size: 0.78rem;
      line-height: 1.5;
      overflow-y: auto;
      display: none;
      box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    }
    .debug-panel.open { display: block; }
    .debug-panel h3 { font-size: 0.82rem; font-weight: 600; margin-bottom: 8px; color: var(--accent); }
    .debug-row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid var(--border); }
    .debug-row:last-child { border-bottom: none; }
    .debug-label { color: var(--muted); }
    .debug-val { font-family: ui-monospace, "SF Mono", monospace; color: var(--text); }
    .debug-val.ok { color: var(--green); }
    .debug-val.warn { color: #e2c97e; }
    .debug-val.err { color: var(--danger); }
    .debug-log { margin-top: 10px; max-height: 180px; overflow-y: auto; font-size: 0.72rem; }
    .debug-log-entry { padding: 2px 0; border-bottom: 1px solid var(--border); }
    .debug-log-entry:last-child { border-bottom: none; }

    /* ── Empty state ── */
    .empty-state {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 16px;
      text-align: center;
      padding: 40px 20px;
      color: var(--muted);
    }
    .empty-state .icon { font-size: 48px; }
    .empty-state h2 { font-size: 1.2rem; color: var(--text); }
    .empty-state p { font-size: 0.88rem; max-width: 380px; }
    .starter-chips {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 8px;
      margin-top: 8px;
    }

/* ── Moon door empty state ── */
.empty-state .moon-door {
  font-size: 96px;
  line-height: 1;
  margin-bottom: 16px;
  color: var(--accent);
  filter: drop-shadow(0 0 24px rgba(6,182,212,0.35));
}

.empty-state h2 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.empty-state h2 span {
  color: var(--accent);
}

.empty-state p {
  font-size: 0.9rem;
  max-width: 380px;
  color: var(--muted);
}

/* ── Moon heartbeat ─────────────────────────────────────────────────────── */
@keyframes moon-drift {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.moon-heartbeat {
  display: inline-block;
  animation: moon-drift 9s linear infinite;
  will-change: transform;
}

/* lag: server responded slowly — moon quickens a little */
.moon-heartbeat.lag {
  animation-duration: 3.5s;
  filter: drop-shadow(0 0 10px rgba(244,199,107,0.5));
}

/* critical: server unreachable or very slow — moon flutters visibly */
.moon-heartbeat.critical {
  animation-duration: 1.4s;
  filter: drop-shadow(0 0 14px rgba(255,100,50,0.55));
}

/* Mandala Convergence Icon */
.mandala-icon {
  --mandala-svg: url('/mandala-network.svg');
  display: inline-block;
  width: 1em;
  height: 1em;
  -webkit-mask: var(--mandala-svg) no-repeat center / contain;
  mask: var(--mandala-svg) no-repeat center / contain;
  background-color: currentColor;
  vertical-align: -0.125em;
  font-size: inherit;
  color: var(--text);
  filter: drop-shadow(0 0 3px currentColor);
}
/* Health colors */
.mandala-icon.healthy { color: var(--green); }
.mandala-icon.warning { color: var(--gold); }
.mandala-icon.critical { color: var(--accent); }
/* Speed indicates lag: slow=lag, fast=healthy */
.mandala-icon.spin-slow {
  animation: mandala-spin 6s linear infinite;
}
.mandala-icon.spin-normal {
  animation: mandala-spin 2.5s linear infinite;
}
.mandala-icon.spin-fast {
  animation: mandala-spin 1s linear infinite;
}
.mandala-icon.wobble {
  animation: mandala-wobble 2s ease-in-out infinite;
}
@keyframes mandala-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes mandala-wobble {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
/* Dark mode: glow stronger */
[data-theme="dark"] .mandala-icon {
  filter: drop-shadow(0 0 6px currentColor);
}

/* ── Observer Side Panel ──────────────────────────────────────────────────── */
.observer-panel {
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.22s ease, min-width 0.22s ease, opacity 0.18s ease;
}
.observer-panel.collapsed {
  width: 0;
  min-width: 0;
  max-width: 0;
  opacity: 0;
  border-left: none;
}
.observer-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface2);
}
.observer-panel-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.observer-panel-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0 2px;
  transition: color 0.15s;
  line-height: 1;
}
.observer-panel-close:hover { color: var(--text); }
.observer-panel-body {
  flex: 1;
  overflow-y: hidden;
  overflow-x: hidden;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 0.78rem;
}
.obs-section-title {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.obs-value {
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.5;
}
.obs-arc-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin-top: 6px;
  overflow: hidden;
}
.obs-arc-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 0.4s ease;
}
.obs-symbol-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.obs-symbol-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.7rem;
  color: var(--muted);
}
.obs-symbol-chip.hot {
  border-color: var(--accent);
  color: var(--accent);
}
/* Toggle button in nav */
.nav-btn.observer-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
}
@media (max-width: 700px) {
  .observer-panel { display: none; }
}
