
    :root {
      --font: "Inter", ui-sans-serif, system-ui, sans-serif;
      --font-display: "Newsreader", Georgia, "Times New Roman", serif;
      --radius-lg: 24px;
      --radius-md: 12px;
      --radius-sm: 8px;
      --shadow-soft: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
      --sidebar-w: 288px;
      --content-max: 56rem;
      --composer-empty-max: 52rem;
      --space: 1rem;
      color-scheme: dark;
      --bg-app: #0d0d0d;
      --bg-main: #0d0d0d;
      --bg-elevated: #131313;
      --bg-sidebar: #121212;
      --bg-composer: #131313;
      --bg-bubble-user: #1a1919;
      --bg-bubble-assistant: #20201f;
      --border: rgba(255, 255, 255, 0.06);
      --text: rgba(255, 255, 255, 0.92);
      --text-muted: #a3a3a3;
      --accent: #fb9270;
      --accent-soft: rgba(251, 146, 112, 0.12);
      --user-accent: #fb9270;
      --tool: #fcd34d;
      --err: #f87171;
      --success: #4ade80;
      --f-sb-w: 288px;
      --f-sb-bg: #121212;
      --f-border: rgba(72, 72, 71, 0.14);
      --f-text: rgba(255, 255, 255, 0.92);
      --f-muted: #adaaaa;
      --f-muted-2: #737373;
      --f-accent: #fb9270;
      --f-accent-2: #eb8564;
      --f-accent-ink: #5a1701;
      --f-nav: #a3a3a3;
      --f-nav-hover-bg: rgba(255, 255, 255, 0.04);
      --f-brand-wordmark: #d97757;
      --f-panel-2: #1a1919;
    }

    html[data-theme="light"] {
      --bg-app: #faf9f7;
      --bg-main: #faf9f7;
      --bg-elevated: #ffffff;
      /* Cùng nền với vùng app để cả cột sidebar một màu (tránh vệt trắng vs be cam #f3f1ed). */
      --bg-sidebar: #faf9f7;
      --bg-composer: #ffffff;
      --bg-bubble-user: #fff5f0;
      --bg-bubble-assistant: #f4f4f5;
      --border: rgba(15, 23, 42, 0.08);
      --text: #0f172a;
      --text-muted: #64748b;
      --accent: #ea580c;
      --accent-soft: rgba(234, 88, 12, 0.12);
      --user-accent: #c2410c;
      --tool: #b45309;
      --err: #dc2626;
      --success: #16a34a;
      color-scheme: light;
      background-color: #faf9f7;
      --f-sb-bg: #faf9f7;
      --f-border: rgba(15, 23, 42, 0.08);
      --f-text: #0f172a;
      --f-muted: #64748b;
      --f-muted-2: #94a3b8;
      --f-accent: #ea580c;
      --f-accent-2: #c2410c;
      --f-accent-ink: #ffffff;
      --f-nav: #64748b;
      --f-nav-hover-bg: rgba(15, 23, 42, 0.04);
      --f-brand-wordmark: #ea580c;
      --f-panel-2: #f4f4f5;
    }

    html {
      font-size: 16px;
      background-color: #0d0d0d;
    }
    html[data-font="sm"] { font-size: 14px; }
    html[data-font="lg"] { font-size: 17px; }

    * { box-sizing: border-box; }
    body {
      margin: 0;
      font-family: var(--font);
      background: var(--bg-app);
      color: var(--text);
      height: 100vh;
      height: 100dvh;
      overflow: hidden;
      -webkit-font-smoothing: antialiased;
    }

    .app {
      display: flex;
      height: 100%;
      min-height: 0;
    }

    /* —— Sidebar (đồng bộ shell Figma: figma-shell .f-sb / system.html) —— */
    .sidebar {
      width: var(--f-sb-w);
      min-width: var(--f-sb-w);
      background: var(--f-sb-bg);
      border-right: 1px solid var(--f-border);
      display: flex;
      flex-direction: column;
      padding: 1.5rem 1rem 1rem;
      gap: 0;
      min-height: 0;
      overflow-x: hidden;
      overflow-y: hidden;
    }
    [data-theme="dark"] .sidebar {
      background: #121212;
      border-right-color: rgba(72, 72, 71, 0.14);
    }
    .sidebar-inner {
      display: flex;
      flex-direction: column;
      gap: 0;
      padding: 0;
      flex-shrink: 0;
    }
    .brand {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      padding: 0 0.5rem;
      text-decoration: none;
      color: inherit;
    }
    .brand-logo {
      width: 32px;
      height: 32px;
      border-radius: 0;
      object-fit: contain;
      flex-shrink: 0;
      background: var(--bg-sidebar);
    }
    .brand-wordmark {
      font-family: var(--f-serif);
      font-style: italic;
      font-size: 1.25rem;
      line-height: 1.4;
      color: var(--f-brand-wordmark);
      font-weight: 400;
      letter-spacing: -0.02em;
    }
    .sidebar-nav {
      display: flex;
      flex-direction: column;
      gap: 4px;
      width: 100%;
    }
    /* CTA New Chat — đồng bộ figma-shell.css (khác sidebar-nav-item phẳng) */
    .sidebar .f-sb-nav .nav-new-chat,
    .sidebar .f-sb-nav #btn-new-chat {
      margin-bottom: 6px;
      font-weight: 600;
      font-size: 0.8125rem;
      letter-spacing: 0.01em;
      border-radius: 10px;
      padding: 10px 14px;
      border: 1px solid rgba(255, 255, 255, 0.12);
      background: linear-gradient(135deg, var(--f-accent) 0%, var(--f-accent-2) 100%);
      color: var(--f-accent-ink);
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
    }
    .sidebar .f-sb-nav .nav-new-chat:hover,
    .sidebar .f-sb-nav #btn-new-chat:hover {
      color: var(--f-accent-ink);
      filter: brightness(1.07);
    }
    .sidebar .f-sb-nav .nav-new-chat svg,
    .sidebar .f-sb-nav #btn-new-chat svg {
      width: 16px;
      height: 16px;
      flex-shrink: 0;
      opacity: 1;
    }
    [data-theme="light"] .sidebar .f-sb-nav .nav-new-chat,
    [data-theme="light"] .sidebar .f-sb-nav #btn-new-chat {
      border-color: rgba(15, 23, 42, 0.08);
      color: #fff;
      box-shadow: 0 2px 10px rgba(234, 88, 12, 0.28);
    }
    [data-theme="light"] .sidebar .f-sb-nav .nav-new-chat:hover,
    [data-theme="light"] .sidebar .f-sb-nav #btn-new-chat:hover {
      color: #fff;
      filter: brightness(1.05);
    }
    .sidebar .f-sb-nav #btn-new-chat[data-active="true"] {
      outline: 2px solid rgba(251, 146, 112, 0.45);
      outline-offset: 2px;
    }
    [data-theme="light"] .sidebar .f-sb-nav #btn-new-chat[data-active="true"] {
      outline-color: rgba(234, 88, 12, 0.4);
    }
    .sidebar-nav-item {
      display: flex;
      align-items: center;
      gap: 0.65rem;
      padding: 10px 16px;
      border-radius: 4px;
      border: none;
      background: transparent;
      color: var(--f-nav);
      font-family: inherit;
      font-size: 0.875rem;
      text-align: left;
      cursor: pointer;
      text-decoration: none;
      line-height: 1.25;
      position: relative;
    }
    a.sidebar-nav-item { color: var(--f-nav); }
    .sidebar-nav-item:hover {
      color: var(--text);
      background: var(--f-nav-hover-bg);
    }
    .sidebar-nav-item[aria-current="page"] {
      background: var(--f-panel-2);
      color: var(--f-accent);
    }
    .sidebar-nav-item svg {
      width: 16px;
      height: 16px;
      flex-shrink: 0;
      opacity: 0.9;
    }
    .sidebar-cred-dot {
      position: absolute;
      top: 50%;
      right: 10px;
      transform: translateY(-50%);
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: var(--err);
      box-shadow: 0 0 0 2px #121212;
    }
    .sidebar-meta-compact {
      display: none;
    }
    .sidebar-meta-compact h3 {
      margin: 0 0 0.5rem;
      font-size: 0.65rem;
      font-weight: 600;
      letter-spacing: 0.12em;
      text-transform: uppercase;
      color: var(--f-muted-2);
    }
    .sidebar-meta-compact .sidebar-meta-box {
      font-size: 0.78rem;
      color: var(--text-muted);
      line-height: 1.45;
      word-break: break-all;
      padding: 0.35rem 0;
      border-bottom: 1px solid var(--border);
    }
    .sidebar-meta-compact code {
      font-size: 0.72rem;
      color: var(--text);
    }
    .sidebar-chat-sessions {
      margin-top: 10px;
      padding: 0 6px;
    }
    .sidebar-chat-sessions h3 {
      margin: 0 0 8px;
      font-size: 0.75rem;
      letter-spacing: 0.08em;
      text-transform: uppercase;
      color: var(--text-muted);
      font-weight: 600;
      padding: 0 8px;
    }
    .sidebar-session-tools {
      display: flex;
      justify-content: flex-end;
      margin: 0 0 6px;
      padding: 0 8px;
    }
    .sidebar-session-tools button {
      border: 1px solid var(--border);
      background: transparent;
      color: var(--text-muted);
      border-radius: 6px;
      font-size: 0.68rem;
      padding: 0.12rem 0.4rem;
      cursor: pointer;
    }
    .sidebar-session-list {
      display: flex;
      flex-direction: column;
      gap: 4px;
      overflow: visible;
      padding-right: 0;
    }
    .sidebar-session-item {
      border: 1px solid transparent;
      border-radius: 8px;
      padding: 8px;
      background: transparent;
      color: var(--text-muted);
      text-align: left;
      cursor: pointer;
    }
    .sidebar-session-item:hover {
      background: rgba(255, 255, 255, 0.04);
      color: var(--text);
    }
    .sidebar-session-item.is-active {
      border-color: var(--border);
      background: rgba(251, 146, 112, 0.08);
      color: var(--text);
    }
    .sidebar-session-title {
      display: block;
      font-size: 0.8rem;
      font-weight: 500;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .sidebar-session-meta {
      margin-top: 3px;
      font-size: 0.72rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      opacity: 0.85;
    }
    .sidebar-up {
      margin-top: auto;
      padding: 0 0.5rem 0;
    }
    .sidebar-up-card {
      background: var(--f-panel-2);
      border-radius: 8px;
      padding: 1rem;
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
    }
    .sidebar-up-card p {
      margin: 0;
      font-size: 0.75rem;
      color: var(--text-muted);
      line-height: 1.35;
    }
    .sidebar-up-btn {
      width: 100%;
      padding: 8px;
      border: none;
      border-radius: 4px;
      font-family: inherit;
      font-size: 0.75rem;
      font-weight: 500;
      cursor: pointer;
      color: var(--f-accent-ink);
      background: linear-gradient(90deg, var(--f-accent), var(--f-accent-2));
    }
    .sidebar-user {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      padding: 1rem 0.5rem 0.25rem;
      margin-top: 0.5rem;
      text-decoration: none;
      color: inherit;
      border-radius: 8px;
    }
    .sidebar-user:hover {
      background: rgba(255, 255, 255, 0.04);
    }
    .sidebar-user-av {
      width: 32px;
      height: 32px;
      border-radius: 12px;
      background: rgba(251, 146, 112, 0.15);
      color: var(--f-accent);
      display: grid;
      place-items: center;
      font-size: 0.75rem;
      font-weight: 700;
      flex-shrink: 0;
    }
    .sidebar-user-info {
      min-width: 0;
      flex: 1;
    }
    .sidebar-user-info .name {
      font-size: 0.875rem;
      font-weight: 500;
      color: var(--text);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .sidebar-user-info .plan {
      font-size: 0.6875rem;
      color: var(--text-muted);
    }
    .sidebar-spacer { flex: 1; min-height: 0.5rem; }

    /* —— Main —— */
    .main {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-width: 0;
      min-height: 0;
      position: relative;
      background: var(--bg-main, var(--bg-app));
    }
    [data-theme="dark"] .main {
      background: #0d0d0d;
    }
    .chat-wrap {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-height: 0;
      overflow: hidden;
      background: var(--bg-main, var(--bg-app));
    }
    [data-theme="dark"] .chat-wrap {
      background: #0d0d0d;
    }
    .main::before {
      content: "";
      position: absolute;
      left: 50%;
      top: 0;
      transform: translateX(-50%);
      width: 800px;
      height: 800px;
      max-width: 100%;
      pointer-events: none;
      background: rgba(251, 146, 112, 0.05);
      filter: blur(60px);
      border-radius: 12px;
      z-index: 0;
    }
    .main > * {
      position: relative;
      z-index: 1;
    }
    .btn-mini {
      font-family: inherit;
      font-size: 0.72rem;
      font-weight: 600;
      padding: 0.28rem 0.5rem;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border);
      background: var(--bg-app);
      color: var(--text-muted);
      cursor: pointer;
    }
    .btn-mini:hover:not(:disabled) {
      color: var(--text);
      border-color: var(--text-muted);
    }
    .btn-mini:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }
    .pill {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
      padding: 0.2rem 0.55rem;
      border-radius: 999px;
      background: var(--accent-soft);
      color: var(--accent);
      font-weight: 600;
      font-size: 0.72rem;
    }
    .pill.warn {
      background: rgba(248, 113, 113, 0.12);
      color: var(--err);
    }
    .icon-btn {
      width: 40px;
      height: 40px;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border);
      background: var(--bg-app);
      color: var(--text);
      cursor: pointer;
      display: grid;
      place-items: center;
      transition: background 0.15s, border-color 0.15s;
    }
    .icon-btn:hover {
      background: var(--bg-bubble-assistant);
      border-color: var(--text-muted);
    }
    .icon-btn svg { width: 20px; height: 20px; opacity: 0.85; }

    .messages-scroll {
      flex: 1;
      overflow-y: auto;
      padding: 1.25rem 1rem 1rem;
      scroll-behavior: smooth;
    }
    .messages-scroll.is-empty {
      padding: 1.5rem 1.25rem 2rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
    .messages-inner {
      max-width: var(--content-max);
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      gap: 1rem;
    }
    .stream-placeholder {
      margin: 0;
      color: var(--text-muted);
      font-size: 0.9rem;
    }
    .row.assistant.is-streaming .bubble {
      border: 1px dashed var(--border);
    }
    @keyframes spin-crewai {
      from { transform: rotate(0deg); }
      to   { transform: rotate(360deg); }
    }
    .row.assistant.is-streaming .bubble .body::after {
      content: "";
      display: inline-block;
      width: 16px;
      height: 16px;
      margin-left: 5px;
      vertical-align: middle;
      background: url('/crewai.png') center / contain no-repeat;
      animation: spin-crewai 0.75s linear infinite;
    }
    .scroll-bottom-btn {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      bottom: 6.5rem;
      border: 1px solid var(--border);
      background: var(--bg-elevated);
      color: var(--text);
      border-radius: 999px;
      width: 36px;
      height: 36px;
      padding: 0;
      font-family: inherit;
      cursor: pointer;
      box-shadow: 0 10px 24px -16px rgba(0, 0, 0, 0.6);
      display: inline-grid;
      place-items: center;
      z-index: 5;
    }
    .scroll-bottom-btn[hidden] {
      display: none;
    }

    .empty-state {
      text-align: center;
      padding: 0;
      width: 100%;
      max-width: var(--composer-empty-max);
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .empty-composer-anchor {
      width: 100%;
      max-width: var(--composer-empty-max);
      margin: 0 auto 1.5rem;
    }
    .empty-state .empty-hero {
      font-family: var(--font-display);
      font-weight: 400;
      font-size: clamp(2.25rem, 5vw, 3.25rem);
      line-height: 1.12;
      letter-spacing: -0.03em;
      margin: 0 0 2rem;
      color: #ffffff;
    }
    [data-theme="dark"] .empty-state .empty-hero {
      font-size: clamp(2.5rem, 4.5vw, 3.25rem);
      line-height: 1.12;
    }
    @media (max-width: 720px) {
      [data-theme="dark"] .empty-state .empty-hero {
        font-size: clamp(1.75rem, 8vw, 3.5rem);
        line-height: 1.2;
      }
    }
    [data-theme="light"] .empty-state .empty-hero {
      color: var(--text);
    }
    .empty-state .empty-lead {
      display: none;
    }
    .quick-actions {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 0.5rem;
      margin: 0 auto 2.25rem;
      max-width: var(--composer-empty-max);
    }
    .quick-actions button {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
      padding: 8px 14px;
      border-radius: 999px;
      border: none;
      background: #1a1a1a;
      color: #a3a3a3;
      font-family: inherit;
      font-size: 0.8125rem;
      font-weight: 500;
      cursor: pointer;
    }
    .quick-actions button:hover {
      color: #f5f5f5;
      background: #242424;
    }
    [data-theme="light"] .quick-actions button {
      background: rgba(15, 23, 42, 0.06);
      color: var(--text-muted);
    }
    .main-chrome-footer {
      max-width: 64rem;
      margin: 3rem auto 0;
      padding: 2rem 0 1.5rem;
      border-top: 1px solid rgba(255, 255, 255, 0.05);
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: 1rem;
    }
    [data-theme="light"] .main-chrome-footer {
      border-top-color: var(--border);
    }
    .main-chrome-footer nav {
      display: flex;
      gap: 1.5rem;
      flex-wrap: wrap;
    }
    .main-chrome-footer a {
      font-size: 0.625rem;
      letter-spacing: 0.06em;
      text-transform: uppercase;
      color: #525252;
      text-decoration: none;
    }
    .main-chrome-footer a:hover {
      color: var(--text-muted);
    }
    .main-chrome-footer .lang {
      display: inline-flex;
      align-items: center;
      gap: 0.5rem;
      font-size: 0.625rem;
      letter-spacing: 0.06em;
      text-transform: uppercase;
      color: #525252;
    }
    .bento-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 1rem;
      text-align: left;
      margin-top: 0;
      width: 100%;
      max-width: var(--composer-empty-max);
    }
    @media (max-width: 900px) {
      .bento-grid { grid-template-columns: 1fr; }
    }
    .bento-card {
      background: #141414;
      border: 1px solid rgba(255, 255, 255, 0.06);
      border-radius: 16px;
      padding: 1.35rem 1.25rem;
      cursor: pointer;
      transition: border-color 0.15s, transform 0.12s;
      text-align: left;
    }
    [data-theme="light"] .bento-card {
      background: var(--bg-elevated);
      border-color: var(--border);
    }
    .bento-card:hover {
      border-color: rgba(251, 146, 112, 0.25);
      transform: translateY(-1px);
    }
    .bento-card .bento-icon {
      width: 40px;
      height: 40px;
      border-radius: 4px;
      display: grid;
      place-items: center;
      margin-bottom: 0.45rem;
      font-size: 1.1rem;
    }
    .bento-card .bento-icon.a { background: rgba(251, 146, 112, 0.1); }
    .bento-card .bento-icon.b { background: rgba(249, 122, 116, 0.1); }
    .bento-card .bento-icon.c { background: rgba(241, 171, 255, 0.1); }
    .bento-card h3 {
      margin: 0.35rem 0 0.4rem;
      font-family: var(--font-display);
      font-size: 1.25rem;
      font-weight: 400;
      color: #fff;
      line-height: 1.4;
    }
    [data-theme="light"] .bento-card h3 {
      color: var(--text);
    }
    .bento-card p {
      margin: 0;
      font-size: 0.875rem;
      line-height: 1.42;
      color: #737373;
    }
    [data-theme="light"] .bento-card p {
      color: var(--text-muted);
    }

    .row {
      display: flex;
      gap: 0.65rem;
      align-items: flex-start;
      max-width: 100%;
    }
    .row.user { flex-direction: row-reverse; }
    html[data-density="compact"] .messages-inner { gap: 0.6rem; }

    .avatar {
      width: 34px;
      height: 34px;
      border-radius: 10px;
      flex-shrink: 0;
      display: grid;
      place-items: center;
      font-size: 0.75rem;
      font-weight: 700;
      margin-top: 2px;
    }
    .avatar.user {
      background: linear-gradient(135deg, var(--user-accent), #22d3ee);
      color: #0f172a;
    }
    .avatar.assistant {
      background: var(--accent-soft);
      color: var(--accent);
      border: 1px solid var(--border);
    }
    .avatar.assistant img {
      width: 100%;
      height: 100%;
      object-fit: contain;
      border-radius: 10px;
      display: block;
    }

    .bubble {
      max-width: min(100%, 85%);
      padding: 0.85rem 1rem;
      border-radius: var(--radius-lg);
      border: 1px solid var(--border);
      line-height: 1.55;
      font-size: 0.92rem;
      box-shadow: var(--shadow-soft);
    }
    .row.user .bubble {
      background: var(--bg-bubble-user);
      border-bottom-right-radius: 6px;
    }
    .row.assistant .bubble {
      background: var(--bg-bubble-assistant);
      border-bottom-left-radius: 6px;
    }
    .bubble .role-label {
      font-size: 0.68rem;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: var(--text-muted);
      margin-bottom: 0.35rem;
      font-weight: 600;
    }
    .bubble .assistant-actions {
      display: flex;
      gap: 0.35rem;
      margin-top: 0.55rem;
      flex-wrap: wrap;
    }
    .bubble .msg-action-btn {
      border: 1px solid var(--border);
      background: transparent;
      color: var(--text-muted);
      border-radius: 999px;
      padding: 0.2rem 0.55rem;
      font-size: 0.72rem;
      cursor: pointer;
    }
    .bubble .msg-action-btn:hover {
      color: var(--text);
      background: rgba(255, 255, 255, 0.04);
    }
    .bubble .msg-action-btn.is-active {
      color: var(--accent);
      border-color: var(--accent);
      background: var(--accent-soft);
    }
    .bubble .copy-output-btn {
      width: 28px;
      height: 28px;
      padding: 0;
      display: inline-grid;
      place-items: center;
      border-radius: 999px;
    }
    .bubble .copy-output-btn svg {
      width: 14px;
      height: 14px;
      display: block;
    }
    .bubble .copy-output-btn.copied {
      color: #fbbf24;
      border-color: #fbbf24;
      background: rgba(251,191,36,0.10);
    }
    .bubble .body {
      word-break: break-word;
      margin: 0;
      font-family: inherit;
    }
    .bubble .reasoning-wrap {
      margin-top: 0.7rem;
      border-top: 1px dashed var(--border);
      padding-top: 0.5rem;
    }
    .bubble .reasoning-toggle {
      cursor: pointer;
      font-size: 0.78rem;
      color: var(--text-muted);
      user-select: none;
      list-style: none;
    }
    .bubble .reasoning-toggle::-webkit-details-marker {
      display: none;
    }
    .bubble .reasoning-body {
      margin-top: 0.45rem;
      font-size: 0.88rem;
      color: var(--text-muted);
    }
    .bubble .body.md-body {
      white-space: normal;
      line-height: 1.6;
    }
    .md-body > *:first-child { margin-top: 0; }
    .md-body > *:last-child { margin-bottom: 0; }
    .md-body p { margin: 0.5em 0; }
    .md-body h1, .md-body h2, .md-body h3, .md-body h4 {
      margin: 0.75em 0 0.35em;
      font-weight: 600;
      line-height: 1.25;
    }
    .md-body h1 { font-size: 1.25rem; }
    .md-body h2 { font-size: 1.1rem; }
    .md-body h3, .md-body h4 { font-size: 1rem; }
    .md-body ul, .md-body ol { margin: 0.5em 0; padding-left: 1.35rem; }
    .md-body li { margin: 0.2em 0; }
    .md-body blockquote {
      margin: 0.5em 0;
      padding-left: 0.85rem;
      border-left: 3px solid var(--border);
      color: var(--text-muted);
    }
    .md-body code {
      font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
      font-size: 0.84em;
      background: var(--bg-app);
      padding: 0.12em 0.35em;
      border-radius: 4px;
      border: 1px solid var(--border);
    }
    .md-body pre {
      margin: 0.65em 0;
      padding: 0.65rem 0.75rem;
      background: var(--bg-app);
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      overflow-x: auto;
      font-size: 0.82rem;
    }
    /* Wrapper bọc ngoài <pre> — thoát khỏi overflow context của pre */
    .md-body .code-wrapper {
      position: relative;
      margin: 0.65em 0;
    }
    .md-body .code-wrapper > pre {
      margin: 0;
      padding-top: 2.2rem; /* chừa chỗ cho label + nút */
    }
    /* Label ngôn ngữ: luôn hiển thị */
    .md-body .code-lang {
      position: absolute;
      top: 0.55rem;
      left: 0.75rem;
      font-size: 0.72rem;
      color: var(--text-muted);
      font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
      pointer-events: none;
      user-select: none;
      z-index: 2;
    }
    /* Nút copy: ẩn mặc định, hiện khi hover vào wrapper */
    .md-body .copy-code-btn {
      position: absolute;
      top: 0.4rem;
      right: 0.4rem;
      width: 28px;
      height: 28px;
      padding: 0;
      display: inline-grid;
      place-items: center;
      border: 1px solid transparent;
      background: transparent;
      color: var(--text-muted);
      border-radius: 6px;
      cursor: pointer;
      z-index: 2;
      opacity: 0;
      transition: opacity 0.12s, color 0.12s, background 0.12s, border-color 0.12s;
    }
    .md-body .code-wrapper:hover .copy-code-btn {
      opacity: 1;
    }
    .md-body .copy-code-btn:hover {
      background: var(--bg-elevated);
      border-color: var(--border);
      color: var(--text);
    }
    .md-body .copy-code-btn.copied {
      opacity: 1;
      color: #fbbf24;
      border-color: #fbbf24;
      background: rgba(251,191,36,0.10);
    }
    .md-body .copy-code-btn svg {
      width: 14px;
      height: 14px;
      display: block;
      pointer-events: none;
    }
    .md-body pre code {
      background: transparent;
      border: none;
      padding: 0;
      font-size: inherit;
      white-space: pre;
      display: block;
      overflow-x: auto;
    }
    .md-body a { color: var(--accent); word-break: break-word; }
    .md-body table { border-collapse: collapse; margin: 0.65em 0; font-size: 0.88em; width: 100%; }
    .md-body th, .md-body td { border: 1px solid var(--border); padding: 0.35em 0.5rem; text-align: left; }
    .md-body th { background: var(--bg-app); }
    .md-body hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
    .md-body img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
    html[data-density="compact"] .bubble { padding: 0.55rem 0.75rem; font-size: 0.88rem; }

    /* ── Reasoning block (Claude-style) ─────────────────── */
    .reasoning-block {
      margin-bottom: 0.55rem;
      font-size: 0.8rem;
    }
    .reasoning-pill {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
      color: var(--text-muted);
      cursor: pointer;
      padding: 0.18rem 0.3rem;
      border-radius: 4px;
      user-select: none;
      transition: background 0.12s;
    }
    .reasoning-pill:hover { background: var(--bg-elevated); }
    .reasoning-pill-label { font-size: 0.8rem; }
    .reasoning-pill-chevron { font-size: 0.78rem; color: var(--text-muted); transition: transform 0.15s; }
    .reasoning-block.is-open .reasoning-pill-chevron { transform: rotate(90deg); }
    .reasoning-body {
      margin: 0.3rem 0 0 0.1rem;
      padding: 0.5rem 0.65rem;
      border-left: 2px solid var(--border);
      font-size: 0.78rem;
      color: var(--text-muted);
      line-height: 1.55;
      white-space: pre-wrap;
      word-break: break-word;
      max-height: 220px;
      overflow-y: auto;
    }
    @keyframes reason-pulse { 0%,100%{opacity:1} 50%{opacity:0.45} }
    .reasoning-running .reasoning-pill-label { animation: reason-pulse 1.4s ease-in-out infinite; }

    /* ── Tool pills (Claude-style) ───────────────────────── */
    .tc-track {
      display: flex;
      flex-direction: column;
      gap: 0.05rem;
      margin-bottom: 0.45rem;
    }
    .tc-pill {
      display: inline-flex;
      align-items: center;
      gap: 0.38rem;
      font-size: 0.8rem;
      color: var(--text-muted);
      cursor: pointer;
      padding: 0.18rem 0.3rem;
      border-radius: 4px;
      user-select: none;
      transition: background 0.12s;
      max-width: 100%;
    }
    .tc-pill:hover { background: var(--bg-elevated); }
    .tc-pill.tc-running { color: var(--accent); }
    .tc-pill.tc-error   { color: #f87171; }
    .tc-pill.tc-done    { color: var(--text-muted); }
    .tc-done-summary {
      display: inline-flex;
      align-items: center;
      gap: 0.3rem;
      font-size: 0.75rem;
      color: var(--text-muted);
      opacity: 0.55;
      padding: 0.1rem 0.3rem;
      cursor: pointer;
      border-radius: 4px;
      user-select: none;
    }
    .tc-done-summary:hover { opacity: 0.9; background: var(--bg-elevated); }
    .tc-done-summary.is-expanded { opacity: 0.85; }
    .tc-pill-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .tc-pill-chevron { font-size: 0.78rem; color: var(--text-muted); transition: transform 0.15s; flex-shrink: 0; }
    .tc-pill.is-open .tc-pill-chevron { transform: rotate(90deg); }
    /* Turn-grouped tool steps */
    .tc-turn-group { display: flex; flex-direction: column; gap: 0; margin-bottom: 0.2rem; }
    .tc-turn-note {
      font-size: 0.78rem;
      color: var(--text);
      opacity: 0.8;
      line-height: 1.45;
      padding: 0.25rem 0.3rem 0.12rem 0.3rem;
      word-break: break-word;
    }
    .tc-turn-tools {
      display: flex;
      flex-direction: column;
      padding-left: 0.55rem;
      border-left: 2px solid var(--border);
      margin-left: 0.25rem;
    }
    .tc-detail {
      margin: 0.15rem 0 0.2rem 0.3rem;
      padding: 0.4rem 0.55rem;
      border-left: 2px solid var(--border);
      display: flex;
      flex-direction: column;
      gap: 0.3rem;
    }
    .tc-detail-label {
      font-size: 0.65rem;
      font-weight: 600;
      letter-spacing: 0.05em;
      text-transform: uppercase;
      color: var(--text-muted);
      margin-bottom: 0.15rem;
    }
    .tc-detail pre {
      margin: 0;
      font-family: ui-monospace, "Cascadia Code", monospace;
      font-size: 0.71rem;
      white-space: pre-wrap;
      word-break: break-all;
      color: var(--text);
      max-height: 160px;
      overflow-y: auto;
      background: var(--bg-app);
      border: 1px solid var(--border);
      border-radius: 4px;
      padding: 0.28rem 0.4rem;
    }
    .tc-detail pre.is-err { color: #f87171; }
    @keyframes tc-spin { to { transform: rotate(360deg); } }
    .tc-spinner {
      display: inline-block;
      width: 9px; height: 9px;
      border: 1.5px solid currentColor;
      border-top-color: transparent;
      border-radius: 50%;
      animation: tc-spin 0.65s linear infinite;
      vertical-align: middle;
      flex-shrink: 0;
    }

    /* Activity / stream */
    /* Luồng / tool log: ẩn khỏi giao diện, vẫn giữ #stream-log cho JS */
    #activity-wrap {
      display: none !important;
      height: 0 !important;
      overflow: hidden !important;
      margin: 0 !important;
      padding: 0 !important;
      border: none !important;
    }
    .activity-wrap {
      border-top: 1px solid var(--border);
      background: var(--bg-elevated);
      max-height: 160px;
      display: flex;
      flex-direction: column;
      flex-shrink: 0;
    }
    .activity-wrap.hidden { display: none; }
    .activity-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0.35rem 0.75rem;
      font-size: 0.7rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--text-muted);
      border-bottom: 1px solid var(--border);
    }
    .activity-log {
      flex: 1;
      overflow: auto;
      padding: 0.5rem 0.75rem;
      font-family: ui-monospace, "Cascadia Code", monospace;
      font-size: 0.72rem;
      color: var(--text-muted);
      line-height: 1.45;
    }
    .activity-log .tool-line { color: var(--tool); }
    .activity-log .err-line { color: var(--err); }
    .activity-log .done-line { color: var(--text-muted); }
    .activity-log .tool-file-att {
      margin: 0.5rem 0;
      padding: 0.45rem 0.5rem;
      border: 1px solid var(--border);
      border-radius: var(--radius-sm);
      background: var(--bg-elevated);
      color: var(--text);
    }
    .activity-log .tool-file-att-head {
      font-size: 0.72rem;
      line-height: 1.4;
      margin-bottom: 0.35rem;
    }
    .activity-log .tool-file-att-head code.path-hint {
      font-size: 0.68rem;
      word-break: break-all;
      color: var(--text-muted);
    }
    .activity-log .tool-file-att-head .muted { color: var(--text-muted); font-weight: 400; }
    .activity-log .tool-file-att-actions { margin-bottom: 0.35rem; }
    .activity-log .tool-file-att-pre {
      margin: 0;
      max-height: 14rem;
      overflow: auto;
      padding: 0.4rem 0.45rem;
      border-radius: 6px;
      background: var(--bg-app);
      border: 1px solid var(--border);
      font-size: 0.68rem;
      white-space: pre-wrap;
      word-break: break-word;
      color: var(--text);
    }

    .composer-host {
      flex-shrink: 0;
      width: 100%;
    }
    /* Composer — màn trống: nhóm cùng hero; có tin: cố định đáy */
    .composer-outer {
      padding: 0.75rem 1rem 1rem;
      background: linear-gradient(to top, var(--bg-app), rgba(13, 13, 13, 0));
      flex-shrink: 0;
    }
    .composer-outer.composer-outer--empty {
      padding: 0;
      margin: 0;
      background: transparent;
      max-width: none;
    }
    .composer-outer.composer-outer--empty .composer-hint {
      margin-top: 0.45rem;
    }
    [data-theme="light"] .composer-outer {
      background: linear-gradient(to top, var(--bg-app), transparent);
    }
    [data-theme="light"] .composer-outer.composer-outer--empty {
      background: transparent;
    }
    .composer-box {
      max-width: min(var(--content-max), 768px);
      margin: 0 auto;
      display: flex;
      gap: 12px;
      align-items: center;
      background: #141414;
      border: 1px solid rgba(72, 72, 71, 0.12);
      border-radius: 28px;
      padding: 14px 18px;
      box-shadow: 0 20px 50px -18px rgba(0, 0, 0, 0.55);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
    }
    .composer-outer--empty .composer-box {
      max-width: var(--composer-empty-max);
      width: 100%;
    }
    [data-theme="light"] .composer-box {
      background: var(--bg-composer);
      border-color: var(--border);
    }
    .composer-attach {
      flex-shrink: 0;
      margin-top: 4px;
      width: 40px;
      height: 40px;
      border: none;
      border-radius: 12px;
      background: transparent;
      color: var(--text-muted);
      cursor: pointer;
      display: grid;
      place-items: center;
    }
    .composer-attach:hover {
      color: var(--text);
      background: rgba(255, 255, 255, 0.04);
    }
    .composer-main {
      flex: 1;
      min-width: 0;
      display: flex;
      flex-direction: column;
      gap: 8px;
      padding: 2px 6px 0;
      overflow: visible;
    }
    .composer-input-wrap {
      display: flex;
      align-items: center;
      flex: 1;
      min-height: 0;
      max-height: 12rem;
      overflow-y: auto;
    }
    .attachment-chips {
      display: flex;
      flex-wrap: wrap;
      gap: 0.35rem;
      align-items: center;
      flex-shrink: 0;
      min-height: 0;
    }
    .attachment-chips:empty {
      display: none;
    }
    .attachment-chip {
      display: inline-flex;
      align-items: center;
      gap: 0.25rem;
      font-size: 0.72rem;
      padding: 0.2rem 0.45rem 0.2rem 0.55rem;
      border-radius: 999px;
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: #1a1919;
      color: #d4d4d4;
      max-width: 100%;
    }
    [data-theme="light"] .attachment-chip {
      border-color: var(--border);
      background: var(--bg-app);
      color: var(--text-muted);
    }
    .attachment-chip .chip-x {
      font: inherit;
      font-size: 0.85rem;
      line-height: 1;
      padding: 0 0.15rem;
      border: none;
      background: transparent;
      color: var(--text-muted);
      cursor: pointer;
      border-radius: 4px;
    }
    .attachment-chip .chip-x:hover { color: var(--err); }
    .attachment-chip .chip-name {
      max-width: 12rem;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .composer-box:focus-within {
      border-color: var(--accent);
      box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-soft);
    }
    #input {
      display: block;
      width: 100%;
      box-sizing: border-box;
      border: none;
      background: transparent;
      color: var(--text);
      font-family: inherit;
      font-size: 1rem;
      line-height: 1.5;
      resize: none;
      min-height: 2rem;
      max-height: 10rem;
      padding: 6px 0;
      outline: none;
    }
    #input::placeholder {
      color: #737373;
    }
    .composer-trail {
      flex-shrink: 0;
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      gap: 6px;
      margin-top: 0;
    }
    .composer-trail-row {
      display: flex;
      align-items: center;
      gap: 4px;
    }
    .composer-model-select {
      flex: 1 1 auto;
      min-width: 5.5rem;
      max-width: 12.5rem;
      padding: 8px 12px;
      border-radius: 999px;
      border: 1px solid rgba(255, 255, 255, 0.14);
      background: #1f1f1f;
      color: #d4d4d4;
      font-family: inherit;
      font-size: 0.75rem;
      font-weight: 500;
      cursor: pointer;
      line-height: 1.2;
      box-sizing: border-box;
    }
    .composer-model-select:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }
    html[data-theme="light"] .composer-model-select {
      background: #ffffff;
      color: #0f172a;
      border-color: rgba(15, 23, 42, 0.12);
    }
    .composer-icon-btn {
      width: 40px;
      height: 40px;
      border: none;
      border-radius: 12px;
      background: transparent;
      color: var(--text-muted);
      cursor: pointer;
      display: grid;
      place-items: center;
    }
    .composer-icon-btn:hover {
      color: var(--text);
    }
    .composer-send {
      width: 40px;
      height: 40px;
      border: none;
      border-radius: 12px;
      background: linear-gradient(90deg, #fb9270, #eb8564);
      color: #5a1701;
      cursor: pointer;
      display: grid;
      place-items: center;
    }
    .composer-send:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }
    /* Trạng thái đang sinh: nút đổi thành Stop */
    .composer-send.is-generating {
      background: var(--bg-elevated);
      border: 1.5px solid var(--border);
      color: var(--text-muted);
      opacity: 1;
      cursor: pointer;
      transition: background 0.15s, color 0.15s, border-color 0.15s;
    }
    .composer-send.is-generating:hover {
      border-color: #f87171;
      color: #f87171;
      background: rgba(248,113,113,0.08);
    }
    /* Textarea bị khóa khi đang sinh */
    #input:disabled {
      opacity: 0.55;
      cursor: not-allowed;
      resize: none;
    }
    /* Ẩn nút cancel riêng — chức năng gộp vào nút Send */
    .composer-cancel { display: none !important; }
    .btn {
      font-family: inherit;
      font-weight: 600;
      font-size: 0.82rem;
      border-radius: var(--radius-sm);
      cursor: pointer;
      border: none;
      padding: 0.45rem 0.9rem;
      transition: opacity 0.15s, transform 0.1s;
    }
    .btn:active:not(:disabled) { transform: scale(0.98); }
    .btn-primary {
      background: linear-gradient(90deg, #fb9270, #eb8564);
      color: #5a1701;
    }
    [data-theme="light"] .btn-primary {
      background: linear-gradient(90deg, #ea580c, #c2410c);
      color: #fff;
    }
    .btn-ghost {
      background: transparent;
      color: var(--text-muted);
      border: 1px solid transparent;
    }
    .btn-ghost:hover { color: var(--text); background: var(--bg-app); }
    .btn:disabled { opacity: 0.45; cursor: not-allowed; }
    .btn-voice.recording {
      color: var(--err) !important;
      border-color: rgba(248, 113, 113, 0.45) !important;
      animation: pulse-voice 1.2s ease-in-out infinite;
    }
    @keyframes pulse-voice {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.55; }
    }
    .composer-hint {
      max-width: var(--content-max);
      margin: 0.35rem auto 0;
      font-size: 0.7rem;
      color: var(--text-muted);
      text-align: center;
      min-height: 1.2em;
    }
    .composer-hint.is-error {
      color: var(--err);
    }

    .chat-drawer-backdrop {
      display: none;
    }
    .chat-mobile-header {
      display: none;
    }
    @media (max-width: 720px) {
      :root { --content-max: 100%; }
      html[data-sb-collapsed="1"] .sidebar {
        width: min(288px, 88vw) !important;
        min-width: 0 !important;
      }
      html[data-sb-collapsed="1"] .sidebar .brand-wordmark,
      html[data-sb-collapsed="1"] .sidebar .sb-label,
      html[data-sb-collapsed="1"] .sidebar .f-sb-recent,
      html[data-sb-collapsed="1"] .sidebar .sidebar-meta-compact,
      html[data-sb-collapsed="1"] .sidebar .f-sb-up,
      html[data-sb-collapsed="1"] .sidebar .sidebar-user-info {
        display: revert !important;
      }
      html[data-sb-collapsed="1"] .sidebar .f-sb-brand {
        display: flex !important;
      }
      .main > .chat-mobile-header {
        z-index: 60;
      }
      .chat-mobile-header {
        display: flex;
        align-items: center;
        gap: 0.65rem;
        flex-shrink: 0;
        padding: calc(0.55rem + env(safe-area-inset-top, 0px)) calc(0.75rem + env(safe-area-inset-right, 0px)) 0.55rem calc(0.65rem + env(safe-area-inset-left, 0px));
        border-bottom: 1px solid var(--f-border);
        background: var(--bg-app);
        position: sticky;
        top: 0;
        z-index: 60;
      }
      .chat-mobile-menu-btn {
        width: 44px;
        height: 44px;
        border-radius: 10px;
        border: 1px solid var(--f-border);
        background: var(--f-panel-2);
        color: var(--text);
        display: grid;
        place-items: center;
        cursor: pointer;
        flex-shrink: 0;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
      }
      .chat-mobile-menu-btn svg {
        width: 22px;
        height: 22px;
      }
      .chat-mobile-title {
        font-family: var(--f-serif);
        font-style: italic;
        font-size: 1.15rem;
        color: var(--f-brand-wordmark);
      }
      .chat-drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 45;
        background: rgba(0, 0, 0, 0.48);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
        -webkit-tap-highlight-color: transparent;
      }
      html[data-theme="light"] .chat-drawer-backdrop {
        background: rgba(15, 23, 42, 0.35);
      }
      html.chat-drawer-open .chat-drawer-backdrop {
        opacity: 1;
        pointer-events: auto;
      }
      .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100dvh;
        max-height: 100dvh;
        width: min(288px, 88vw);
        min-width: 0;
        z-index: 50;
        transform: translateX(-105%);
        transition: transform 0.22s ease;
        box-shadow: 8px 0 36px rgba(0, 0, 0, 0.35);
        padding-top: calc(1rem + env(safe-area-inset-top, 0px));
        padding-left: calc(1rem + env(safe-area-inset-left, 0px));
        padding-right: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        overflow-x: hidden;
        overflow-y: auto;
      }
      html.chat-drawer-open .sidebar {
        transform: translateX(0);
      }
      .main {
        min-width: 0;
        min-height: 0;
      }
      .composer-outer {
        padding-left: max(0.65rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.65rem, env(safe-area-inset-right, 0px));
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
      }
      .composer-box {
        flex-wrap: wrap;
        border-radius: 22px;
        padding: 10px 12px;
        gap: 8px;
      }
      .composer-trail-row {
        flex-wrap: wrap;
        width: 100%;
        justify-content: flex-end;
        gap: 0.35rem;
      }
      .composer-main {
        width: 100%;
        min-width: 0;
      }
      .messages-scroll {
        padding-left: max(0.35rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.35rem, env(safe-area-inset-right, 0px));
      }
    }
  