@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap");

/* HarmonyOS Sans SC - 鸿蒙字体，中英文兼顾 */
@font-face {
  font-family: 'HarmonyOS Sans SC';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('https://cdn.jsdelivr.net/npm/@ayahub/webfont-harmony-sans-sc@1.0.0/fonts/HarmonyOS_Sans_SC_Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'HarmonyOS Sans SC';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('https://cdn.jsdelivr.net/npm/@ayahub/webfont-harmony-sans-sc@1.0.0/fonts/HarmonyOS_Sans_SC_Medium.woff2') format('woff2');
}
@font-face {
  font-family: 'HarmonyOS Sans SC';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('https://cdn.jsdelivr.net/npm/@ayahub/webfont-harmony-sans-sc@1.0.0/fonts/HarmonyOS_Sans_SC_Bold.woff2') format('woff2');
}

@tailwind base;
@tailwind components;
@tailwind utilities;

/* ===========================================
   CSS Variables - JiuwenClaw Design System
   =========================================== */

:root {
  /* Background - Warmer dark with depth */
  --bg: #0f1320;
  --bg-accent: #131a2a;
  --bg-elevated: #1a2234;
  --bg-hover: #232f46;
  --bg-muted: #202b42;
  --bg-content: #f5f5f5;

  /* Card / Surface - More contrast between levels */
  --card: #171f30;
  --card-foreground: #f4f4f5;
  --card-highlight: rgba(255, 255, 255, 0.05);
  --popover: #171f30;
  --popover-foreground: #f4f4f5;

  /* Panel */
  --panel: #101728;
  --panel-strong: #182134;
  --panel-hover: #25334d;
  --chrome: rgba(15, 19, 32, 0.92);
  --chrome-strong: rgba(15, 19, 32, 0.97);

  /* Text - Slightly warmer */
  --text: #e4e4e7;
  --text-strong: #fafafa;
  --chat-text: #e4e4e7;
  --muted: #71717a;
  --muted-strong: #52525b;
  --muted-foreground: #71717a;

  /* Border - Subtle but defined */
  --border: #243049;
  --border-strong: #33456b;
  --border-hover: #47618f;
  --border-accent: rgba(96, 165, 250, 0.5);
  --border-ok: rgba(34, 197, 94, 0.5);
  --border-danger: rgba(239, 68, 68, 0.5);
  --input: #283550;
  --ring: #60a5fa;

  /* Accent - Blue theme (brighter for dark mode visibility) */
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-muted: #60a5fa;
  --accent-subtle: rgba(96, 165, 250, 0.18);
  --accent-foreground: #1e293b;
  --accent-glow: rgba(96, 165, 250, 0.3);
  --primary: #60a5fa;
  --primary-foreground: #1e293b;

  /* Secondary - Teal accent for variety */
  --secondary: #1e2028;
  --secondary-foreground: #f4f4f5;
  --accent-2: #14b8a6;
  --accent-2-muted: rgba(20, 184, 166, 0.7);
  --accent-2-subtle: rgba(20, 184, 166, 0.15);

  /* Semantic - More saturated */
  --ok: #22c55e;
  --ok-muted: rgba(34, 197, 94, 0.75);
  --ok-subtle: rgba(34, 197, 94, 0.12);
  --destructive: #ef4444;
  --destructive-foreground: #fafafa;
  --warn: #f59e0b;
  --warn-muted: rgba(245, 158, 11, 0.75);
  --warn-subtle: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-muted: rgba(239, 68, 68, 0.75);
  --danger-subtle: rgba(239, 68, 68, 0.12);
  --info: #3b82f6;

  /* Focus - With glow */
  --focus: rgba(96, 165, 250, 0.25);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring);
  --focus-glow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring), 0 0 20px var(--accent-glow);

  /* Grid */
  --grid-line: rgba(255, 255, 255, 0.04);

  /* Typography - HarmonyOS Sans SC 鸿蒙字体，JetBrains Mono 等宽 */
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --font-body: "HarmonyOS Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-display: "HarmonyOS Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;

  /* Shadows - Richer with subtle color */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.03);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.03);
  --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.03);
  --shadow-glow: 0 0 30px var(--accent-glow);

  /* Radii - Slightly larger for friendlier feel */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  --radius: 8px;

  /* Transitions - Snappy but smooth */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 120ms;
  --duration-normal: 200ms;
  --duration-slow: 350ms;

  /* Shell Layout */
  --shell-pad: 16px;
  --shell-gap: 16px;
  --shell-nav-width: 220px;
  --tool-panel-width: var(--shell-nav-width);
  --statusbar-right-space: var(--tool-panel-width);
  --shell-topbar-height: 56px;
  --shell-focus-duration: 200ms;
  --shell-focus-ease: var(--ease-out);

  /* Typography scale (desktop baseline) */
  --font-size-base: 14px;
  --font-size-sm: 13px;
  --font-size-xs: 12px;
  --font-size-2xs: 11px;

  color-scheme: dark;
}

/* Light theme - Clean with subtle warmth */
:root[data-theme="light"] {
  --bg: #fafafa;
  --bg-accent: #f5f5f5;
  --bg-elevated: #ffffff;
  --bg-hover: #f0f0f0;
  --bg-muted: #f0f0f0;
  --bg-content: #f5f5f5;

  --card: #ffffff;
  --card-foreground: #18181b;
  --card-highlight: rgba(0, 0, 0, 0.03);
  --popover: #ffffff;
  --popover-foreground: #18181b;

  --panel: #fafafa;
  --panel-strong: #f5f5f5;
  --panel-hover: #ebebeb;
  --chrome: rgba(250, 250, 250, 0.95);
  --chrome-strong: rgba(250, 250, 250, 0.98);

  --text: #3f3f46;
  --text-strong: #18181b;
  --chat-text: #3f3f46;
  --muted: #71717a;
  --muted-strong: #52525b;
  --muted-foreground: #71717a;

  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --border-hover: #a1a1aa;
  --border-accent: rgba(37, 99, 235, 0.5);
  --border-ok: rgba(22, 163, 74, 0.5);
  --border-danger: rgba(220, 38, 38, 0.5);
  --input: #e4e4e7;
  --ring: #2563eb;

  --accent: #2563eb;
  --accent-hover: #3b82f6;
  --accent-muted: #2563eb;
  --accent-subtle: rgba(37, 99, 235, 0.12);
  --accent-foreground: #ffffff;
  --accent-glow: rgba(37, 99, 235, 0.15);
  --primary: #2563eb;
  --primary-foreground: #ffffff;

  --secondary: #f4f4f5;
  --secondary-foreground: #3f3f46;
  --accent-2: #0d9488;
  --accent-2-muted: rgba(13, 148, 136, 0.75);
  --accent-2-subtle: rgba(13, 148, 136, 0.12);

  --ok: #16a34a;
  --ok-muted: rgba(22, 163, 74, 0.75);
  --ok-subtle: rgba(22, 163, 74, 0.1);
  --destructive: #dc2626;
  --destructive-foreground: #fafafa;
  --warn: #d97706;
  --warn-muted: rgba(217, 119, 6, 0.75);
  --warn-subtle: rgba(217, 119, 6, 0.1);
  --danger: #dc2626;
  --danger-muted: rgba(220, 38, 38, 0.75);
  --danger-subtle: rgba(220, 38, 38, 0.1);
  --info: #2563eb;

  --focus: rgba(37, 99, 235, 0.2);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring);
  --focus-glow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ring), 0 0 16px var(--accent-glow);

  --grid-line: rgba(0, 0, 0, 0.05);

  /* Light shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 24px var(--accent-glow);

  color-scheme: light;
}

/* ===========================================
   Base Styles
   =========================================== */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font: 400 var(--font-size-base)/1.55 var(--font-body);
  letter-spacing: -0.02em;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:root:not([data-theme="light"]) body {
  background:
    radial-gradient(1200px 480px at 55% -20%, rgba(37, 99, 235, 0.16), transparent 60%),
    radial-gradient(720px 320px at 18% 8%, rgba(20, 184, 166, 0.08), transparent 65%),
    var(--bg);
}

#root {
  height: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--accent-subtle);
  color: var(--text-strong);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ===========================================
   Animations
   =========================================== */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes scale-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes pulse-subtle {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

@keyframes glow-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(255, 92, 92, 0);
  }
  50% {
    box-shadow: 0 0 20px var(--accent-glow);
  }
}

@keyframes chatStreamPulse {
  0%,
  100% {
    border-color: var(--border);
  }
  50% {
    border-color: var(--accent);
  }
}

@keyframes chatReadingDot {
  0%,
  80%,
  100% {
    opacity: 0.4;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ===========================================
   Focus visible styles
   =========================================== */

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ===========================================
   Component Layer
   =========================================== */

@layer components {
  /* Shell Layout */
  .shell {
    height: 100vh;
    display: grid;
    grid-template-columns: minmax(var(--shell-nav-width), var(--shell-nav-width)) minmax(0, 1fr);
    grid-template-rows: var(--shell-topbar-height) 1fr;
    grid-template-areas:
      "topbar topbar"
      "nav content";
    gap: 0;
    animation: rise 0.4s var(--ease-out);
    transition: grid-template-columns var(--shell-focus-duration) var(--shell-focus-ease);
    overflow: hidden;
    background: var(--bg);
  }

  @supports (height: 100dvh) {
    .shell {
      height: 100dvh;
    }
  }

  /* Topbar */
  .topbar {
    grid-area: topbar;
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 0 20px;
    height: var(--shell-topbar-height);
    border-bottom: 1px solid var(--border);
    background: var(--chrome);
    backdrop-filter: blur(10px);
  }

  /* Brand */
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 14px;
  }

  .brand-logo-img {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    object-fit: contain;
    color: white;
  }

  .brand-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
  }

  .brand-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--text-strong);
  }

  .brand-sub {
    font-size: var(--font-size-2xs);
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    line-height: 1;
  }

  /* Navigation Sidebar */
  .nav {
    grid-area: nav;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 12px;
    background: var(--panel);
    scrollbar-width: none;
    min-height: 0;
    border-right: 1px solid var(--border);
    max-width: var(--shell-nav-width);
    width: 100%;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  /* Nav items */
  .nav-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    text-decoration: none;
    transition:
      border-color var(--duration-fast) ease,
      background var(--duration-fast) ease,
      color var(--duration-fast) ease;
  }

  .nav-item:hover {
    color: var(--text);
    background: var(--bg-hover);
    text-decoration: none;
  }

  .nav-item.active {
    color: var(--text-strong);
    background: var(--accent-subtle);
  }

  .nav-item.active .nav-item__icon {
    color: var(--accent);
  }

  /* Content Area */
  .content {
    grid-area: content;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    background: linear-gradient(180deg, var(--bg-accent), var(--bg));
  }

  :root[data-theme="light"] .content {
    background: var(--bg-content);
  }

  /* Cards */
  .card {
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 20px;
    animation: rise 0.35s var(--ease-out) backwards;
    transition:
      border-color var(--duration-normal) var(--ease-out),
      box-shadow var(--duration-normal) var(--ease-out);
    box-shadow: var(--shadow-sm), inset 0 1px 0 var(--card-highlight);
  }

  .card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md), inset 0 1px 0 var(--card-highlight);
  }

  /* Pills */
  .pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: var(--secondary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: border-color var(--duration-fast) ease;
  }

  .pill:hover {
    border-color: var(--border-strong);
  }

  /* Status Dot */
  .statusDot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--danger);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
    animation: pulse-subtle 2s ease-in-out infinite;
  }

  .statusDot.ok {
    background: var(--ok);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
    animation: none;
  }

  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    padding: 9px 16px;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: 500;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition:
      border-color var(--duration-fast) var(--ease-out),
      background var(--duration-fast) var(--ease-out),
      box-shadow var(--duration-fast) var(--ease-out),
      transform var(--duration-fast) var(--ease-out);
  }

  .btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
  }

  .btn:active {
    background: var(--secondary);
    transform: translateY(0);
    box-shadow: none;
  }

  .btn.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--primary-foreground);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  }

  .btn.primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: var(--shadow-md), 0 0 20px var(--accent-glow);
  }

  .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
    box-shadow: none;
  }

  .btn:disabled:hover,
  .btn.primary:disabled:hover {
    background: var(--bg-elevated);
    border-color: var(--border);
    transform: none;
    box-shadow: none;
  }

  .btn.primary:disabled {
    background: color-mix(in oklab, var(--accent) 55%, var(--bg-elevated));
    border-color: color-mix(in oklab, var(--accent) 55%, var(--border));
  }

  /* Form Fields */
  .field input,
  .field textarea,
  .field select {
    border: 1px solid var(--input);
    background: var(--card);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    outline: none;
    box-shadow: inset 0 1px 0 var(--card-highlight);
    transition:
      border-color var(--duration-fast) ease,
      box-shadow var(--duration-fast) ease;
  }

  .field input:focus,
  .field textarea:focus,
  .field select:focus {
    border-color: var(--ring);
    box-shadow: var(--focus-ring);
  }

  /* Chat Bubbles */
  .chat-bubble {
    border: 1px solid transparent;
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 10px 14px;
    min-width: 0;
  }

  :root[data-theme="light"] .chat-bubble {
    border-color: var(--border);
    background: var(--bg);
  }

  .chat-bubble.user {
    border-color: transparent;
    background: var(--accent-subtle);
  }

  :root[data-theme="light"] .chat-bubble.user {
    border-color: rgba(59, 130, 246, 0.2);
    background: rgba(59, 130, 246, 0.12);
  }

  .chat-bubble.assistant {
    border-color: transparent;
    background: var(--secondary);
  }

  :root[data-theme="light"] .chat-bubble.assistant {
    border-color: var(--border);
    background: var(--bg-muted);
  }

  .chat-bubble.streaming {
    animation: chatStreamPulse 1.5s ease-in-out infinite;
  }

  /* Reading indicator */
  .chat-reading-indicator {
    width: fit-content;
    padding: 10px 16px;
  }

  .chat-reading-indicator__dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 12px;
  }

  .chat-reading-indicator__dots > span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--muted);
    opacity: 0.6;
    transform: translateY(0);
    animation: chatReadingDot 1.2s ease-in-out infinite;
    will-change: transform, opacity;
  }

  .chat-reading-indicator__dots > span:nth-child(2) {
    animation-delay: 0.15s;
  }

  .chat-reading-indicator__dots > span:nth-child(3) {
    animation-delay: 0.3s;
  }

  /* Chat text */
  .chat-text {
    overflow-wrap: anywhere;
    word-break: break-word;
    color: var(--chat-text);
    line-height: 1.5;
    white-space: pre-wrap;
  }

  /* Chat input task queue */
  .chat-input-task-queue {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--card);
    box-shadow: var(--shadow-sm);
    animation: rise 0.3s var(--ease-out);
  }

  .chat-input-task-queue-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-strong);
  }

  .chat-input-task-queue-list {
    max-height: 150px;
    overflow-y: auto;
    padding: 4px 0;
  }

  .chat-input-task-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    transition: background var(--duration-fast) ease;
  }

  .chat-input-task-item:hover {
    background: var(--bg-hover);
  }

  .chat-input-task-content {
    flex: 1;
    font-size: var(--font-size-sm);
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-input-task-remove {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: all var(--duration-fast) ease;
  }

  .chat-input-task-remove:hover {
    background: var(--danger-subtle);
    color: var(--danger);
  }

  .chat-text :where(p) {
    margin: 0.5em 0;
  }

  .chat-text :where(p:first-child) {
    margin-top: 0;
  }

  .chat-text :where(p:last-child) {
    margin-bottom: 0;
  }

  .chat-text :where(ul, ol) {
    margin: 0.5em 0;
    padding-left: 1.25em;
  }

  .chat-text :where(li) {
    margin: 0.2em 0;
  }

  .chat-text :where(h1, h2, h3, h4, h5, h6) {
    margin: 0.8em 0 0.4em;
    font-weight: 600;
    line-height: 1.35;
  }

  .chat-text :where(h1) { font-size: 1.15em; }
  .chat-text :where(h2) { font-size: 1.1em; }
  .chat-text :where(h3, h4, h5, h6) { font-size: 1em; }

  .chat-text :where(blockquote) {
    margin: 0.75em 0;
    padding-left: 0.75em;
    border-left: 3px solid var(--border);
    color: var(--text-muted);
  }

  .chat-text :where(a) {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
  }

  .chat-text :where(pre) {
    margin-top: 0.75em;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--secondary);
    overflow: auto;
  }

  :root[data-theme="light"] .chat-text :where(pre) {
    background: var(--bg-muted);
  }

  .chat-text :where(pre code) {
    font-size: 12px;
    white-space: pre;
  }

  .chat-text :where(code) {
    font-family: var(--mono);
    font-size: 0.9em;
  }

  .chat-text :where(:not(pre) > code) {
    padding: 0.15em 0.35em;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--secondary);
  }

  /* Chat compose wrapper */
  .chat-compose {
    padding-top: 4px;
  }

  /* Tool cards (legacy single) */
  .chat-tool-card {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--secondary);
    display: grid;
    gap: 4px;
  }

  :root[data-theme="light"] .chat-tool-card {
    background: var(--bg-muted);
  }

  /* ====== Tool Group Container ====== */
  .tool-group-container {
    margin: 8px 0;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--secondary);
    overflow: hidden;
  }

  :root[data-theme="light"] .tool-group-container {
    background: var(--bg-muted);
    border-color: var(--border);
  }

  /* Header */
  .tool-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
    color: var(--muted);
    font-size: var(--font-size-xs);
    user-select: none;
  }

  :root[data-theme="light"] .tool-group-header {
    background: var(--bg);
  }

  .tool-group-header-left {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-strong);
    font-weight: 500;
  }

  .tool-group-pending {
    color: var(--warn);
    font-weight: 400;
  }

  /* Scrollable list — 最多显示约 5 条 */
  .tool-group-scroll {
    max-height: 200px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
    position: relative;
  }

  .tool-group-scroll::-webkit-scrollbar {
    width: 4px;
  }

  .tool-group-scroll::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-full);
  }

  .tool-group-scroll::-webkit-scrollbar-track {
    background: transparent;
  }

  /* "Scroll to bottom" button */
  .tool-group-scroll-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 4px 0;
    border: none;
    border-top: 1px solid var(--border);
    background: var(--card);
    color: var(--accent);
    font-size: var(--font-size-2xs);
    cursor: pointer;
    transition: background var(--duration-fast) ease;
  }

  .tool-group-scroll-btn:hover {
    background: var(--bg-hover);
  }

  /* ====== Tool Pair Item ====== */
  .tool-pair-item {
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
  }

  .tool-pair-item:last-child {
    border-bottom: none;
  }

  .tool-pair-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    min-height: 24px;
  }

  .tool-pair-header:hover .tool-pair-name {
    color: var(--accent);
  }

  /* Status icon */
  .tool-pair-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tool-pair-icon.success {
    background: var(--ok-subtle);
    color: var(--ok);
  }

  .tool-pair-icon.error {
    background: var(--danger-subtle);
    color: var(--danger);
  }

  .tool-pair-icon.pending {
    background: var(--accent-subtle);
    color: var(--accent);
  }

  .tool-pair-icon.warning {
    background: var(--warn-subtle);
    color: var(--warn);
  }

  .tool-pair-name {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    flex-shrink: 0;
    transition: color var(--duration-fast) ease;
  }

  .tool-pair-summary {
    font-family: var(--mono);
    font-size: var(--font-size-xs);
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
  }

  .tool-pair-toggle {
    flex-shrink: 0;
    font-size: 10px;
    color: var(--muted);
    margin-left: auto;
  }

  .tool-pair-subtitle {
    font-family: var(--mono);
    font-size: var(--font-size-2xs);
    color: var(--muted);
    padding-left: 26px;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Detail panel */
  .tool-pair-detail {
    margin-top: 6px;
    padding-left: 26px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .tool-pair-section-label {
    font-size: var(--font-size-2xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 2px;
  }

  .tool-pair-pre {
    font-family: var(--mono);
    font-size: var(--font-size-2xs);
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    margin: 0;
  }

  :root[data-theme="light"] .tool-pair-pre {
    background: var(--bg-muted);
  }

  .tool-pair-pre.error {
    color: var(--danger);
  }

  /* Result badge inline */
  .tool-pair-result-badge {
    flex-shrink: 0;
    font-family: var(--mono);
    font-size: var(--font-size-2xs);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tool-pair-result-badge.success {
    background: var(--ok-subtle);
    color: var(--ok);
  }

  .tool-pair-result-badge.error {
    background: var(--danger-subtle);
    color: var(--danger);
  }

  .tool-pair-result-badge.warning {
    background: var(--warn-subtle);
    color: var(--warn);
  }

  .tool-group-pending.warning {
    color: var(--warn);
  }

  /* Theme Toggle */
  .theme-toggle {
    --theme-item: 28px;
    --theme-gap: 2px;
    --theme-pad: 4px;
    position: relative;
  }

  .theme-toggle__track {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, var(--theme-item));
    gap: var(--theme-gap);
    padding: var(--theme-pad);
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--secondary);
  }

  .theme-toggle__indicator {
    position: absolute;
    top: 50%;
    left: var(--theme-pad);
    width: var(--theme-item);
    height: var(--theme-item);
    border-radius: var(--radius-full);
    transform: translateY(-50%)
      translateX(calc(var(--theme-index, 0) * (var(--theme-item) + var(--theme-gap))));
    background: var(--accent);
    transition: transform var(--duration-normal) var(--ease-out);
    z-index: 0;
  }

  .theme-toggle__button {
    height: var(--theme-item);
    width: var(--theme-item);
    display: grid;
    place-items: center;
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    position: relative;
    z-index: 1;
    transition: color var(--duration-fast) ease;
  }

  .theme-toggle__button:hover {
    color: var(--text);
  }

  .theme-toggle__button.active {
    color: var(--accent-foreground);
  }

  /* Keyboard shortcut badge */
  .kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 5px;
    font-family: var(--mono);
    font-size: var(--font-size-2xs);
    font-weight: 500;
    line-height: 1;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.15);
    color: var(--muted);
  }

  :root[data-theme="light"] .kbd {
    background: rgba(0, 0, 0, 0.08);
  }

  /* Streaming cursor */
  .streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--accent);
    animation: blink 1s step-end infinite;
    margin-left: 2px;
    vertical-align: text-bottom;
  }
}

/* ===========================================
   Utilities
   =========================================== */

.mono {
  font-family: var(--mono);
}

.muted {
  color: var(--muted);
}

/* Animation utilities */
.animate-rise {
  animation: rise 0.35s var(--ease-out) backwards;
}

/* Voice recording pulse */
@keyframes voice-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
  }
}

.voice-recording {
  animation: voice-pulse 1.5s ease-in-out infinite;
}

.animate-fade-in {
  animation: fade-in 0.2s ease-out forwards;
}

.animate-scale-in {
  animation: scale-in 0.2s var(--ease-out);
}

/* ===========================================
   Responsive - Tablet
   =========================================== */

@media (max-width: 499px) {
  .shell {
    --shell-pad: 12px;
    --shell-gap: 12px;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "topbar"
      "nav"
      "content";
  }

  .nav {
    position: static;
    max-height: none;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    background: var(--bg);
  }
}

/* ===========================================
   Responsive - Large screens
   =========================================== */

@media (min-width: 1440px) {
  :root {
    --font-size-base: 15px;
    --font-size-sm: 14px;
    --font-size-xs: 13px;
    --font-size-2xs: 12px;
    --shell-nav-width: 248px;
    --tool-panel-width: var(--shell-nav-width);
    --statusbar-right-space: var(--tool-panel-width);
    --shell-topbar-height: 60px;
  }
}

@media (min-width: 1920px) {
  :root {
    --font-size-base: 16px;
    --font-size-sm: 15px;
    --font-size-xs: 14px;
    --font-size-2xs: 13px;
    --shell-nav-width: 272px;
    --tool-panel-width: var(--shell-nav-width);
    --statusbar-right-space: var(--tool-panel-width);
    --shell-topbar-height: 64px;
  }
}
