    /* ─── Reset & root ──────────────────────────────── */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --nav-h: 70px;
      --sidebar-w: 268px;
      --bg: #f5f6f8;
      --surface: #ffffff;
      --surface-2: #f0f1f4;
      --border: #e4e6eb;
      --text-1: #0f1117;
      --text-2: #5a5f72;
      --text-3: #9095a8;
      --accent: #2563eb;
      --accent-2: #3b82f6;
      --accent-glow: rgba(37,99,235,0.18);
      --user-bubble: #2563eb;
      --bot-bubble: #ffffff;
      --bot-bubble-border: #e4e6eb;
      --danger: #ef4444;
      --radius-sm: 8px;
      --radius-md: 14px;
      --radius-lg: 20px;
      --radius-xl: 28px;
      --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
      --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
      --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
      --font-body:'Open Sans', sans-serif;
      --font-display: 'Open Sans', serif;
      --sidebar-bg: #ffffff;
      --sidebar-hover: #f3f4f7;
      --sidebar-active: #eff3ff;
    }

    [data-theme="dark"] {
      --bg: #0d0f14;
      --surface: #161921;
      --surface-2: #1e2230;
      --border: #2a2f3d;
      --text-1: #eef0f6;
      --text-2: #9095a8;
      --text-3: #5a5f72;
      --accent: #3b82f6;
      --accent-2: #60a5fa;
      --accent-glow: rgba(59,130,246,0.2);
      --user-bubble: #2563eb;
      --bot-bubble: #1e2230;
      --bot-bubble-border: #2a2f3d;
      --sidebar-bg: #161921;
      --sidebar-hover: #1e2230;
      --sidebar-active: #1e2d4a;
    }

    html, body {
      height: 100%;
      font-family: var(--font-body);
      background: var(--bg);
      color: var(--text-1);
      overflow: hidden;
    }

    /* ─── Layout shell ──────────────────────────────── */
    .compass-shell {
      display: flex;
      height: calc(100vh - var(--nav-h));
      margin-top: var(--nav-h);
      position: relative;
    }

    /* ─── Sidebar ───────────────────────────────────── */
    .sidebar {
      width: var(--sidebar-w);
      flex-shrink: 0;
      background: var(--sidebar-bg);
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      height: 100%;
      transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
      z-index: 200;
    }

    .sidebar-top {
      padding: 18px 14px 10px;
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    /* New chat button */
    .new-chat-btn {
      display: flex;
      align-items: center;
      gap: 10px;
      width: 100%;
      padding: 10px 14px;
      background: var(--accent);
      color: #fff;
      border: none;
      border-radius: var(--radius-md);
      font-family: var(--font-body);
      font-size: 0.88rem;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.18s ease;
      letter-spacing: 0.01em;
    }

    .new-chat-btn:hover {
      background: var(--accent-2);
      transform: translateY(-1px);
      box-shadow: 0 4px 14px var(--accent-glow);
    }

    .new-chat-btn i { font-size: 0.82rem; }

    /* Search */
    .sidebar-search {
      margin-top: 10px;
      position: relative;
    }

    .sidebar-search input {
      width: 100%;
      padding: 8px 12px 8px 34px;
      background: var(--surface-2);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      font-family: var(--font-body);
      font-size: 0.83rem;
      color: var(--text-1);
      outline: none;
      transition: border-color 0.18s;
    }

    .sidebar-search input::placeholder { color: var(--text-3); }
    .sidebar-search input:focus { border-color: var(--accent); }

    .sidebar-search i {
      position: absolute;
      left: 10px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--text-3);
      font-size: 0.78rem;
    }

    /* History list */
    .sidebar-history {
      flex: 1;
      overflow-y: auto;
      padding: 10px 8px;
      scrollbar-width: thin;
      scrollbar-color: var(--border) transparent;
    }

    .sidebar-history::-webkit-scrollbar { width: 4px; }
    .sidebar-history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

    .history-group-label {
      font-size: 0.7rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--text-3);
      padding: 8px 8px 4px;
    }

    .history-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 10px;
      border-radius: var(--radius-sm);
      cursor: pointer;
      position: relative;
    }

    .history-item:hover { background: var(--sidebar-hover); }
    .history-item.active { background: var(--sidebar-active); }

    .history-item-icon {
      width: 28px;
      height: 28px;
      border-radius: 7px;
      background: var(--surface-2);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.78rem;
      color: var(--text-2);
      flex-shrink: 0;
    }

    .history-item.active .history-item-icon {
      background: var(--accent-glow);
      color: var(--accent);
    }

    .history-item-text {
      flex: 1;
      min-width: 0;
    }

    .history-item-title {
      font-size: 0.84rem;
      font-weight: 500;
      color: var(--text-1);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      line-height: 1.3;
    }

    .history-item-preview {
      font-size: 0.75rem;
      color: var(--text-3);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-top: 1px;
    }

    .history-item-actions {
      display: none;
      gap: 4px;
      flex-shrink: 0;
    }

    .history-item:hover .history-item-actions { display: flex; }

    .history-action-btn {
      width: 22px;
      height: 22px;
      border: none;
      background: transparent;
      color: var(--text-3);
      cursor: pointer;
      border-radius: 5px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.72rem;
      transition: all 0.15s;
    }

    .history-action-btn:hover { background: var(--border); color: var(--text-1); }
    .history-action-btn.danger:hover { background: rgba(239,68,68,0.12); color: var(--danger); }

    /* Sidebar footer */
    .sidebar-footer {
      padding: 12px 14px;
      border-top: 1px solid var(--border);
      flex-shrink: 0;
    }

    .sidebar-footer-info {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px 10px;
      border-radius: var(--radius-sm);
      transition: background 0.15s;
      cursor: default;
    }

    .compass-badge {
      width: 32px;
      height: 32px;
      border-radius: 9px;
      background: linear-gradient(135deg, var(--accent), var(--accent-2));
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      font-size: 0.85rem;
      flex-shrink: 0;
    }

    .sidebar-footer-text {
      flex: 1;
      min-width: 0;
    }

    .sidebar-footer-name {
      font-size: 0.83rem;
      font-weight: 600;
      color: var(--text-1);
    }

    .sidebar-footer-sub {
      font-size: 0.72rem;
      color: var(--text-3);
    }

    /* ─── Main chat area ────────────────────────────── */
    .chat-main {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-width: 0;
      height: 100%;
      background: var(--bg);
      position: relative;
    }

    /* Top bar */
    .chat-topbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 24px;
      height: 56px;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }

    .topbar-left {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .mobile-sidebar-toggle {
      display: none;
      background: none;
      border: none;
      color: var(--text-2);
      cursor: pointer;
      font-size: 1rem;
      padding: 6px;
      border-radius: 6px;
      transition: background 0.15s, color 0.15s;
    }

    .mobile-sidebar-toggle:hover { background: var(--surface-2); color: var(--text-1); }

    .chat-title-area { display: flex; flex-direction: column; }

    .chat-title {
      font-family: var(--font-body);
      font-size: 0.9rem;
      font-weight: 600;
      color: var(--text-1);
      line-height: 1.2;
    }

    .chat-subtitle {
      font-size: 0.73rem;
      color: var(--text-3);
      margin-top: 1px;
    }

    .topbar-right {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .topbar-btn {
      width: 34px;
      height: 34px;
      border: none;
      background: transparent;
      color: var(--text-2);
      cursor: pointer;
      border-radius: var(--radius-sm);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.88rem;
      transition: all 0.15s;
    }

    .topbar-btn:hover { background: var(--surface-2); color: var(--text-1); }

    /* ─── Welcome screen ────────────────────────────── */
    .welcome-screen {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 40px 24px;
      gap: 32px;
      overflow-y: auto;
    }

    .welcome-screen.hidden { display: none; }

    .welcome-hero {
      text-align: center;
      max-width: 480px;
    }

    .welcome-compass-icon {
      width: 64px;
      height: 64px;
      background: linear-gradient(135deg, var(--accent), var(--accent-2));
      border-radius: 20px;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 0 auto 20px;
      font-size: 1.6rem;
      color: white;
      box-shadow: 0 8px 28px var(--accent-glow);
    }

    .welcome-title {
      font-family: var(--font-display);
      font-size: 2.2rem;
      color: var(--text-1);
      margin-bottom: 10px;
      line-height: 1.15;
    }

    .welcome-sub {
      font-size: 0.95rem;
      color: var(--text-2);
      line-height: 1.65;
      max-width: 380px;
      margin: 0 auto;
    }

    /* Suggestion chips */
    .suggestion-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      width: 100%;
      max-width: 560px;
    }

    .suggestion-chip {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius-md);
      padding: 14px 16px;
      cursor: pointer;
      transition: all 0.2s ease;
      text-align: left;
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .suggestion-chip:hover {
      border-color: var(--accent);
      background: var(--sidebar-active);
      transform: translateY(-2px);
      box-shadow: var(--shadow-md);
    }

    .chip-icon {
      font-size: 1.1rem;
      margin-bottom: 2px;
    }

    .chip-title {
      font-size: 0.85rem;
      font-weight: 600;
      color: var(--text-1);
      line-height: 1.3;
    }

    .chip-sub {
      font-size: 0.76rem;
      color: var(--text-3);
      line-height: 1.4;
    }

    /* ─── Messages area ─────────────────────────────── */
    .chat-messages {
      flex: 1;
      overflow-y: auto;
      padding: 24px 0 16px;
      display: flex;
      flex-direction: column;
      gap: 4px;
      scrollbar-width: thin;
      scrollbar-color: var(--border) transparent;
    }

    .chat-messages.hidden { display: none; }

    .chat-messages::-webkit-scrollbar { width: 4px; }
    .chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

    /* Message row */
    .msg-row {
      display: flex;
      padding: 4px 24px;
      gap: 12px;
      animation: msgIn 0.22s ease both;
    }

    @keyframes msgIn {
      from { opacity: 0; transform: translateY(8px); }
      to   { opacity: 1; transform: translateY(0); }
    }

    .msg-row.user { justify-content: flex-end; }
    .msg-row.bot  { justify-content: flex-start; }

    /* Avatar */
    .msg-avatar {
      width: 32px;
      height: 32px;
      border-radius: 10px;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.82rem;
      font-weight: 700;
      margin-top: 2px;
    }

    .msg-row.bot .msg-avatar {
      background: linear-gradient(135deg, var(--accent), var(--accent-2));
      color: white;
    }

    .msg-row.user .msg-avatar {
      background: var(--surface-2);
      color: var(--text-2);
      order: 2;
    }

    /* Bubble */
    .msg-bubble-wrap {
      display: flex;
      flex-direction: column;
      max-width: min(640px, 72%);
      gap: 4px;
    }

    .msg-row.user .msg-bubble-wrap { align-items: flex-end; }
    .msg-row.bot  .msg-bubble-wrap { align-items: flex-start; }

    .msg-bubble {
      padding: 12px 16px;
      border-radius: var(--radius-lg);
      font-size: 0.91rem;
      line-height: 1.7;
      word-break: break-word;
    }

    .msg-row.user .msg-bubble {
      background: var(--user-bubble);
      color: #fff;
      border-bottom-right-radius: 5px;
    }

    .msg-row.bot .msg-bubble {
      background: var(--bot-bubble);
      color: var(--text-1);
      border: 1px solid var(--bot-bubble-border);
      border-bottom-left-radius: 5px;
      box-shadow: var(--shadow-sm);
    }

    .msg-bubble ul, .msg-bubble ol {
      padding-left: 1.4em;
      margin: 6px 0;
    }

    .msg-bubble li { margin: 4px 0; }
    .msg-bubble p  { margin: 4px 0; }

    .msg-bubble strong { font-weight: 600; }

    .msg-row.bot .msg-bubble strong { color: var(--accent); }

    .msg-meta {
      font-size: 0.7rem;
      color: var(--text-3);
      padding: 0 4px;
    }

    /* Typing indicator */
    .typing-bubble {
      background: var(--bot-bubble);
      border: 1px solid var(--bot-bubble-border);
      border-radius: var(--radius-lg);
      border-bottom-left-radius: 5px;
      padding: 14px 18px;
      display: flex;
      gap: 5px;
      align-items: center;
      box-shadow: var(--shadow-sm);
    }

    .typing-dot {
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: var(--text-3);
      animation: typePulse 1.3s infinite ease-in-out;
    }

    .typing-dot:nth-child(2) { animation-delay: 0.15s; }
    .typing-dot:nth-child(3) { animation-delay: 0.30s; }

    @keyframes typePulse {
      0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
      30% { transform: translateY(-5px); opacity: 1; }
    }

    /* ─── Input bar ─────────────────────────────────── */
    .chat-input-bar {
      padding: 12px 24px 20px;
      background: var(--bg);
      flex-shrink: 0;
    }

    .input-shell {
      max-width: 780px;
      margin: 0 auto;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius-xl);
      display: flex;
      flex-direction: column;
      box-shadow: var(--shadow-md);
      transition: border-color 0.2s, box-shadow 0.2s;
      overflow: hidden;
    }

    .input-shell:focus-within {
      border-color: var(--accent);
      box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow-md);
    }

    .input-textarea {
      width: 100%;
      border: none;
      background: transparent;
      font-family: var(--font-body);
      font-size: 0.92rem;
      color: var(--text-1);
      resize: none;
      padding: 14px 18px 6px;
      max-height: 180px;
      outline: none;
      line-height: 1.6;
    }

    .input-textarea::placeholder { color: var(--text-3); }

    .input-toolbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 6px 10px 10px;
    }

    .input-left-tools {
      display: flex;
      align-items: center;
      gap: 4px;
    }

    .input-tool-btn {
      width: 30px;
      height: 30px;
      border: none;
      background: transparent;
      color: var(--text-3);
      cursor: pointer;
      border-radius: 7px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.82rem;
      transition: all 0.15s;
    }

    .input-tool-btn:hover { background: var(--surface-2); color: var(--text-2); }

    .char-count {
      font-size: 0.72rem;
      color: var(--text-3);
      padding: 0 6px;
    }

    .send-btn {
      width: 34px;
      height: 34px;
      border: none;
      background: var(--accent);
      color: white;
      border-radius: 10px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.85rem;
      transition: all 0.18s ease;
      flex-shrink: 0;
    }

    .send-btn:hover:not(:disabled) {
      background: var(--accent-2);
      transform: scale(1.05);
    }

    .send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

    .input-hint {
      text-align: center;
      font-size: 0.72rem;
      color: var(--text-3);
      margin-top: 8px;
    }

    /* ─── Rename modal ──────────────────────────────── */
    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.5);
      backdrop-filter: blur(4px);
      z-index: 9000;
      display: none;
      align-items: center;
      justify-content: center;
    }

    .modal-overlay.show { display: flex; }

    .modal-box {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      padding: 24px;
      width: min(360px, 90vw);
      box-shadow: var(--shadow-lg);
      animation: popIn 0.22s ease;
    }

    @keyframes popIn {
      from { opacity:0; transform:scale(0.94) translateY(8px); }
      to   { opacity:1; transform:scale(1) translateY(0); }
    }

    .modal-title {
      font-size: 1rem;
      font-weight: 600;
      color: var(--text-1);
      margin-bottom: 14px;
    }

    .modal-input {
      width: 100%;
      padding: 10px 14px;
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      background: var(--surface-2);
      color: var(--text-1);
      font-family: var(--font-body);
      font-size: 0.9rem;
      outline: none;
      transition: border-color 0.18s;
    }

    .modal-input:focus { border-color: var(--accent); }

    .modal-actions {
      display: flex;
      gap: 8px;
      margin-top: 16px;
      justify-content: flex-end;
    }

    .modal-cancel {
      padding: 8px 18px;
      border: 1px solid var(--border);
      background: transparent;
      color: var(--text-2);
      border-radius: var(--radius-sm);
      font-family: var(--font-body);
      font-size: 0.87rem;
      cursor: pointer;
      transition: all 0.15s;
    }

    .modal-cancel:hover { background: var(--surface-2); }

    .modal-save {
      padding: 8px 18px;
      background: var(--accent);
      color: white;
      border: none;
      border-radius: var(--radius-sm);
      font-family: var(--font-body);
      font-size: 0.87rem;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.15s;
    }

    .modal-save:hover { background: var(--accent-2); }

    /* ─── Mobile sidebar overlay ────────────────────── */
    .sidebar-overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.4);
      z-index: 190;
    }

    /* ─── Responsive ────────────────────────────────── */
    @media (max-width: 768px) {
      :root { --nav-h: 64px; }

      .sidebar {
        position: fixed;
        top: var(--nav-h);
        left: 0;
        height: calc(100vh - var(--nav-h));
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
      }

      .sidebar.mobile-open { transform: translateX(0); }
      .sidebar-overlay.show { display: block; }
      .mobile-sidebar-toggle { display: flex; }

      .chat-input-bar { padding: 10px 14px 16px; }
      .msg-row { padding: 3px 14px; }
      .suggestion-grid { grid-template-columns: 1fr; }
      .welcome-title { font-size: 1.7rem; }
    }
