/* HD 智動化 AI Agent SaaS — Enterprise Design System
   Brand: HD Smarter (smarter.tw)
   Layout: 2-column SaaS (collapsible nav-sidebar + main content with routing)
   Dual theme (light default / dark toggle)
   Zero hardcoded colors — all via CSS custom properties */

/* ═══════════════════════════════════════════════
   Design Tokens (Light Theme — Default)
   ═══════════════════════════════════════════════ */
:root {
  /* Brand */
  --brand-primary: #004896;
  --brand-secondary: #f4a026;
  --brand-accent: #009fde;
  --brand-text: #1a1a2e;
  --brand-bg: #f5f7fa;

  /* Surfaces */
  --bg: #f5f7fa;
  --bar-bg: rgba(255, 255, 255, 0.97);
  --bar-border: rgba(0, 72, 150, 0.08);
  --text: #1a1a2e;
  --text-dim: #5a6577;
  --green: #16a34a;
  --yellow: #ca8a04;
  --red: #dc2626;
  --accent: #004896;
  --accent-light: #009fde;
  --surface: #ffffff;
  --surface-hover: rgba(0, 72, 150, 0.04);
  --input-bg: #f0f4f8;
  --input-border: rgba(0, 72, 150, 0.12);
  --input-focus: #004896;
  --overlay: rgba(0, 0, 0, 0.3);

  /* Chat */
  --chat-bg: #ffffff;
  --chat-border: rgba(0, 72, 150, 0.06);
  --chat-user-bg: #004896;
  --chat-user-text: #ffffff;
  --chat-agent-bg: #f0f4f8;
  --chat-agent-text: #1a1a2e;

  /* Modal */
  --modal-bg: #ffffff;
  --modal-border: rgba(0, 72, 150, 0.1);

  /* Pills */
  --pill-bg: rgba(0, 72, 150, 0.05);
  --pill-border: rgba(0, 72, 150, 0.08);
  --pill-ok-bg: rgba(22, 163, 74, 0.08);
  --pill-ok-border: rgba(22, 163, 74, 0.3);
  --pill-warn-bg: rgba(202, 138, 4, 0.08);
  --pill-warn-border: rgba(202, 138, 4, 0.3);
  --pill-err-bg: rgba(220, 38, 38, 0.08);
  --pill-err-border: rgba(220, 38, 38, 0.3);

  /* Toasts */
  --toast-info-bg: rgba(0, 72, 150, 0.12);
  --toast-info-border: rgba(0, 72, 150, 0.3);
  --toast-ok-bg: rgba(22, 163, 74, 0.12);
  --toast-ok-border: rgba(22, 163, 74, 0.3);
  --toast-warn-bg: rgba(202, 138, 4, 0.12);
  --toast-warn-border: rgba(202, 138, 4, 0.3);
  --toast-err-bg: rgba(220, 38, 38, 0.12);
  --toast-err-border: rgba(220, 38, 38, 0.3);

  /* Fonts */
  --font-zh: 'Noto Sans TC', 'PingFang TC', sans-serif;
  --font-en: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-sans: 'Noto Sans TC', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --shadow: 0 2px 12px rgba(0, 72, 150, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 72, 150, 0.12);

  /* Layout */
  --navbar-h: 56px;
  --nav-sidebar-w: 260px;
  --nav-sidebar-collapsed-w: 64px;

  /* Office Scene V2 */
  --office-floor: #f0ebe4;
  --office-floor-alt: #e8e2d8;
  --office-wall: #c8bfa8;
  --office-wall-stroke: rgba(0, 0, 0, 0.12);
  --office-carpet: #7a9aba;
  --office-kitchen: #f5f0e8;
  --office-factory: #e0d8d0;
  --office-lobby: #f8f4ee;
  --office-desk: #c4a050;
  --office-label: var(--text-dim);
  --office-agent-size: 56px;
  --office-agent-glow: rgba(74, 144, 217, 0.4);
}

/* ═══════════════════════════════════════════════
   Dark Theme Override
   ═══════════════════════════════════════════════ */
:root[data-theme="dark"] {
  --brand-bg: #0f1923;
  --brand-text: #e0e6ed;
  --bg: #0f1923;
  --bar-bg: rgba(13, 17, 23, 0.95);
  --bar-border: rgba(255, 255, 255, 0.06);
  --text: #e0e6ed;
  --text-dim: #8b949e;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --accent: #58a6ff;
  --accent-light: #79c0ff;
  --surface: #161b22;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --input-bg: rgba(255, 255, 255, 0.06);
  --input-border: rgba(255, 255, 255, 0.1);
  --input-focus: #58a6ff;
  --overlay: rgba(0, 0, 0, 0.5);
  --chat-bg: #161b22;
  --chat-border: rgba(255, 255, 255, 0.06);
  --chat-user-bg: #1f6feb;
  --chat-user-text: #ffffff;
  --chat-agent-bg: rgba(255, 255, 255, 0.06);
  --chat-agent-text: #e0e6ed;
  --modal-bg: #1c2128;
  --modal-border: rgba(255, 255, 255, 0.1);
  --pill-bg: rgba(255, 255, 255, 0.06);
  --pill-border: rgba(255, 255, 255, 0.08);
  --pill-ok-bg: rgba(63, 185, 80, 0.08);
  --pill-ok-border: rgba(63, 185, 80, 0.3);
  --pill-warn-bg: rgba(210, 153, 34, 0.08);
  --pill-warn-border: rgba(210, 153, 34, 0.3);
  --pill-err-bg: rgba(248, 81, 73, 0.08);
  --pill-err-border: rgba(248, 81, 73, 0.3);
  --toast-info-bg: rgba(88, 166, 255, 0.15);
  --toast-info-border: rgba(88, 166, 255, 0.3);
  --toast-ok-bg: rgba(63, 185, 80, 0.15);
  --toast-ok-border: rgba(63, 185, 80, 0.3);
  --toast-warn-bg: rgba(210, 153, 34, 0.15);
  --toast-warn-border: rgba(210, 153, 34, 0.3);
  --toast-err-bg: rgba(248, 81, 73, 0.15);
  --toast-err-border: rgba(248, 81, 73, 0.3);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);

  /* Office Scene V2 — Dark */
  --office-floor: #1e1a16;
  --office-floor-alt: #241f1a;
  --office-wall: #2a2a4a;
  --office-wall-stroke: rgba(255, 255, 255, 0.08);
  --office-carpet: #3a5a7a;
  --office-kitchen: #2a2520;
  --office-factory: #1a1a1a;
  --office-lobby: #252220;
  --office-desk: #8B6914;
  --office-label: var(--text-dim);
  --office-agent-glow: rgba(88, 166, 255, 0.4);
}

/* ═══════════════════════════════════════════════
   Reset
   ═══════════════════════════════════════════════ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  overflow: hidden;
  cursor: default;
  font-family: var(--font-sans);
  color: var(--text);
}

/* ═══════════════════════════════════════════════
   Top Navbar (56px)
   ═══════════════════════════════════════════════ */
.top-navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--navbar-h);
  background: var(--bar-bg);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  border-bottom: 1px solid var(--bar-border);
  gap: 12px;
}

.navbar-left,
.navbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.navbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

/* Hamburger */
.navbar-hamburger {
  display: block;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  line-height: 0;
  transition: color 0.2s, background 0.2s;
}
.navbar-hamburger:hover {
  color: var(--text);
  background: var(--surface-hover);
}

/* Logo */
.navbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  flex-shrink: 0;
}
.navbar-logo-icon {
  flex-shrink: 0;
  line-height: 0;
}
.navbar-logo-text {
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
  color: var(--accent);
}

/* Search */
.navbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 6px 12px;
  max-width: 280px;
  width: 100%;
  transition: border-color 0.2s;
}
.navbar-search:focus-within {
  border-color: var(--input-focus);
}
.navbar-search-icon {
  color: var(--text-dim);
  flex-shrink: 0;
  line-height: 0;
}
.navbar-search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  flex: 1;
  min-width: 0;
}
.navbar-search input::placeholder {
  color: var(--text-dim);
}
.navbar-search-kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--bar-border);
  border-radius: 4px;
  padding: 1px 6px;
  flex-shrink: 0;
}

/* Breadcrumb */
.navbar-breadcrumb {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Clock */
.navbar-clock {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Icon buttons */
.navbar-icon-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  line-height: 0;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.navbar-icon-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--input-border);
}
.navbar-icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Avatar */
.navbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s;
  flex-shrink: 0;
}
.navbar-avatar:hover { opacity: 0.85; }
.navbar-avatar:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════════
   App Shell — 2 Column (nav-sidebar + main)
   ═══════════════════════════════════════════════ */
.app-shell {
  position: fixed;
  top: var(--navbar-h);
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: var(--nav-sidebar-w) 1fr;
  overflow: hidden;
  transition: grid-template-columns 0.25s ease;
}
.app-shell.sidebar-collapsed {
  grid-template-columns: var(--nav-sidebar-collapsed-w) 1fr;
}

/* ═══════════════════════════════════════════════
   Navigation Sidebar
   ═══════════════════════════════════════════════ */
.nav-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--bar-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease;
}

.nav-sidebar-menu {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

/* Menu items */
.nav-menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  color: var(--text-dim);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  font-size: 15px;
  font-family: inherit;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  position: relative;
  white-space: nowrap;
}
.nav-menu-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.nav-menu-item.active {
  color: var(--accent);
  background: rgba(0, 72, 150, 0.06);
}
:root[data-theme="dark"] .nav-menu-item.active {
  background: rgba(88, 166, 255, 0.08);
}
.nav-menu-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.nav-menu-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.nav-menu-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.nav-menu-icon svg {
  width: 20px;
  height: 20px;
}

.nav-menu-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-menu-chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: transform 0.2s;
  line-height: 0;
  opacity: 0.5;
}
.nav-menu-chevron svg {
  width: 14px;
  height: 14px;
}
.nav-menu-item.expanded .nav-menu-chevron {
  transform: rotate(90deg);
}

/* Divider */
.nav-menu-divider {
  height: 1px;
  background: var(--bar-border);
  margin: 8px 16px;
}

/* Section label */
.nav-menu-section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  padding: 14px 20px 6px;
  opacity: 0.7;
}

/* Submenu */
.nav-submenu {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}
.nav-submenu.open {
  max-height: 200px;
}

.nav-submenu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px 10px 56px;
  color: var(--text-dim);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.nav-submenu-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.nav-submenu-item.active {
  color: var(--accent);
}

.nav-submenu-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.nav-submenu-icon svg {
  width: 16px;
  height: 16px;
}

/* Sidebar footer */
.nav-sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--bar-border);
  flex-shrink: 0;
}

.nav-footer-stats {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-footer-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.nav-footer-stat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.nav-footer-brand {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.6;
  margin-top: 8px;
  text-align: center;
}

/* Collapsed sidebar */
.sidebar-collapsed .nav-sidebar {
  width: var(--nav-sidebar-collapsed-w);
}
.sidebar-collapsed .nav-menu-label,
.sidebar-collapsed .nav-menu-chevron,
.sidebar-collapsed .nav-menu-section,
.sidebar-collapsed .nav-submenu,
.sidebar-collapsed .nav-sidebar-footer {
  display: none;
}
.sidebar-collapsed .nav-menu-item {
  justify-content: center;
  padding: 12px;
}
.sidebar-collapsed .nav-menu-item.active::before {
  display: none;
}
.sidebar-collapsed .nav-menu-divider {
  margin: 8px 12px;
}

/* ═══════════════════════════════════════════════
   Main Content
   ═══════════════════════════════════════════════ */
.main-content {
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

.view-container {
  height: 100%;
  overflow-y: auto;
  padding: 24px;
}

.view-chat-container {
  padding: 0;
  overflow: hidden;
}

.view-office-container {
  padding: 0;
  overflow: hidden;
  position: relative;
}
.view-office-container .office-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Office overlay status bar */
.office-overlay {
  position: absolute; top: 8px; right: 8px;
  background: var(--card-bg-alpha, rgba(255,255,255,0.85));
  border-radius: 8px; padding: 8px 12px;
  font-size: 13px; pointer-events: auto;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; gap: 14px; align-items: center;
  z-index: 10;
  border: 1px solid var(--bar-border);
}
.office-overlay .status-indicator {
  display: flex; align-items: center; gap: 4px;
  white-space: nowrap;
}
.office-overlay .status-indicator.responding {
  color: var(--green); font-weight: 600;
}
.office-overlay .status-indicator.idle {
  color: var(--text-dim);
}

/* ═══════════════════════════════════════════════
   Dashboard View (GWS style)
   ═══════════════════════════════════════════════ */

/* Welcome banner */
.dash-welcome {
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-accent) 100%);
  border-radius: 16px;
  padding: 28px 32px;
  margin-bottom: 24px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
.dash-welcome-greeting {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.dash-welcome-sub {
  font-size: 13px;
  opacity: 0.85;
}
.dash-welcome-time {
  position: absolute;
  top: 20px;
  right: 28px;
  text-align: right;
}
.dash-welcome-clock {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
}
.dash-welcome-date {
  font-size: 12px;
  opacity: 0.8;
}

/* Quick actions */
.dash-quick-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.dash-quick-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--bar-border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}
.dash-quick-btn:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.dash-quick-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.dash-quick-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Stat cards */
.dash-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.dash-stat-card {
  background: var(--surface);
  border: 1px solid var(--bar-border);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: box-shadow 0.2s;
}
.dash-stat-card:hover {
  box-shadow: var(--shadow);
}
.dash-stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.dash-stat-icon svg {
  width: 20px;
  height: 20px;
}
.dash-stat-info {
  flex: 1;
  min-width: 0;
}
.dash-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.dash-stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Agent Carousel */
.dash-carousel { margin-bottom: 24px; }
.dash-carousel-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.dash-carousel-title {
  font-size: 15px; font-weight: 600; color: var(--text);
}
.dash-carousel-nav { display: flex; gap: 6px; }
.dash-carousel-arrow {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--bar-border); background: var(--surface);
  color: var(--text); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.dash-carousel-arrow:hover { background: var(--surface-hover); }
.dash-carousel-track {
  display: flex; gap: 16px; overflow-x: auto;
  scroll-snap-type: x mandatory; scroll-behavior: smooth;
  padding-bottom: 8px;
}
.dash-carousel-track::-webkit-scrollbar { height: 4px; }
.dash-carousel-track::-webkit-scrollbar-thumb {
  background: var(--bar-border); border-radius: 2px;
}
.dash-carousel-card {
  min-width: 200px; max-width: 200px;
  scroll-snap-align: start; flex-shrink: 0;
  border-radius: 12px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--bar-border);
  cursor: pointer; transition: transform 0.2s, box-shadow 0.2s;
}
.dash-carousel-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}
.dash-carousel-card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.dash-carousel-card-header {
  height: 40px; display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.dash-carousel-card-header svg { width: 22px; height: 22px; }
.dash-carousel-card-body { padding: 12px 14px; }
.dash-carousel-card-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  margin-bottom: 4px;
}
.dash-carousel-card-role {
  font-size: 12px; color: var(--text-dim); line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 10px;
}
.dash-carousel-chat-btn {
  width: 100%; padding: 6px 0; border-radius: 6px;
  border: 1px solid var(--accent); background: transparent;
  color: var(--accent); font-size: 12px; font-weight: 500;
  cursor: pointer; transition: background 0.15s, color 0.15s;
}
.dash-carousel-chat-btn:hover {
  background: var(--accent); color: #fff;
}

/* Panels (recent chats + activity) */
.dash-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.dash-panel {
  background: var(--surface);
  border: 1px solid var(--bar-border);
  border-radius: 12px;
  overflow: hidden;
}
.dash-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--bar-border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.dash-panel-body {
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}
.dash-panel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--bar-border);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.dash-panel-item:last-child {
  border-bottom: none;
}
.dash-panel-item:hover {
  background: var(--surface-hover);
}
.dash-panel-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dash-panel-item-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.dash-panel-item-time {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.dash-panel-empty {
  padding: 24px 18px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ═══════════════════════════════════════════════
   Agent Cards View (GWS style)
   ═══════════════════════════════════════════════ */

/* Toolbar */
.agents-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.agents-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 7px 12px;
  flex: 1;
  max-width: 320px;
  min-width: 160px;
  transition: border-color 0.2s;
}
.agents-search:focus-within {
  border-color: var(--input-focus);
}
.agents-search svg {
  width: 15px;
  height: 15px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.agents-search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  flex: 1;
  min-width: 0;
}
.agents-search input::placeholder {
  color: var(--text-dim);
}

.agents-filter {
  display: flex;
  gap: 4px;
}
.agents-filter-btn {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--input-border);
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.agents-filter-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}
.agents-filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Agent cards grid */
.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.agent-card-gws {
  background: var(--surface);
  border: 1px solid var(--bar-border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
}
.agent-card-gws:hover {
  box-shadow: var(--shadow);
  border-color: var(--accent);
  transform: translateY(-2px);
}
.agent-card-gws.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 72, 150, 0.15);
}

/* Card gradient header */
.agent-card-header {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  position: relative;
}
.agent-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.agent-card-icon svg {
  width: 18px;
  height: 18px;
}

.agent-card-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-weight: 500;
  z-index: 1;
}

.agent-card-header-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  position: relative;
  z-index: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Card body */
.agent-card-body {
  padding: 14px 16px;
}
.agent-card-org {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.agent-card-desc {
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.agent-card-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.agent-card-tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--pill-bg);
  color: var(--text-dim);
  border: 1px solid var(--pill-border);
}

/* Card footer */
.agent-card-footer {
  padding: 0 16px 14px;
  display: flex;
  justify-content: flex-end;
}
.agent-card-chat-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: none;
  color: var(--accent);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.agent-card-chat-btn:hover {
  background: var(--accent);
  color: #fff;
}
.agent-card-chat-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.agent-card-chat-btn svg {
  width: 14px;
  height: 14px;
}

/* ═══════════════════════════════════════════════
   Chat View (botrun.ai split layout)
   ═══════════════════════════════════════════════ */
.chat-split {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* Left panel — agent list */
.chat-agent-list-panel {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--chat-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
.chat-agent-list-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--chat-border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}
.chat-agent-list-header svg {
  width: 20px;
  height: 20px;
  color: var(--accent);
}

.chat-agent-search {
  padding: 10px 14px;
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
}
.chat-agent-search input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 20px;
  padding: 8px 14px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.chat-agent-search input:focus {
  border-color: var(--input-focus);
}

.chat-agent-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
}
.chat-agent-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--bar-border);
  transition: background 0.15s;
}
.chat-agent-list-item:hover {
  background: var(--surface-hover);
}
.chat-agent-list-item.active {
  background: rgba(0, 72, 150, 0.06);
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}
:root[data-theme="dark"] .chat-agent-list-item.active {
  background: rgba(88, 166, 255, 0.08);
}

.chat-agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.chat-agent-avatar svg {
  width: 20px;
  height: 20px;
}

.chat-agent-info {
  flex: 1;
  min-width: 0;
}
.chat-agent-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-agent-last-msg {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}

.chat-agent-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}
.chat-agent-status-dot.active { background: var(--green); }
.chat-agent-status-dot.idle { background: var(--yellow); }

/* Right area — main chat */
.chat-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--chat-bg);
  position: relative;
  min-width: 0;
}

/* Chat header */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
  gap: 12px;
  background: var(--surface);
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.chat-header-avatar svg {
  width: 18px;
  height: 18px;
}
.chat-header-info {
  min-width: 0;
}
.chat-header-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-role {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 1px;
}
.chat-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}

.chat-header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.chat-action-btn {
  background: none;
  border: 1px solid var(--input-border);
  color: var(--text-dim);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
  line-height: 0;
}
.chat-action-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.chat-action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chat-action-btn svg {
  width: 14px;
  height: 14px;
}

/* Offline banner */
.chat-offline-banner {
  padding: 8px 16px;
  font-size: 12px;
  color: #fff;
  background: var(--red);
  border-bottom: 1px solid var(--red);
  display: none;
  text-align: center;
  font-weight: 500;
}

/* Telegram fallback */
.chat-tg-link {
  display: block;
  text-align: center;
  padding: 10px 16px;
  margin: 8px 16px;
  background: #0088cc;
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.2s;
}
.chat-tg-link:hover { opacity: 0.85; }
.chat-tg-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-msg { display: flex; }
.chat-msg-system { justify-content: center; flex-direction: column; align-items: center; }

.chat-msg-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 3px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-msg-copy {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  line-height: 0;
  opacity: 0;
  transition: opacity 0.2s;
}
.chat-msg:hover .chat-msg-copy { opacity: 1; }
.chat-msg-copy:hover { color: var(--accent); }
.chat-msg-copy svg { width: 12px; height: 12px; }

.chat-bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
  overflow: hidden;
}

.chat-msg-user .chat-bubble {
  background: var(--chat-user-bg);
  color: var(--chat-user-text);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.chat-msg-agent .chat-bubble {
  background: var(--chat-agent-bg);
  color: var(--chat-agent-text);
  border-bottom-left-radius: 4px;
}
.chat-msg-agent .chat-bubble pre {
  white-space: pre-wrap;
  margin: 8px 0;
}

.chat-msg-system .chat-bubble {
  background: var(--surface-hover);
  color: var(--text-dim);
  font-size: 11px;
}

/* Failed message */
.chat-msg-failed .chat-bubble {
  border: 1px solid var(--red);
  opacity: 0.8;
}

.chat-retry-btn {
  font-size: 11px;
  color: var(--red);
  background: none;
  border: 1px solid var(--pill-err-border);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  margin-top: 4px;
}
.chat-retry-btn:hover { background: var(--pill-err-bg); }

/* Message grouping — consecutive same-role within 2min */
.chat-msg-grouped .chat-msg-avatar { visibility: hidden; height: 0; margin: 0; }
.chat-msg-grouped .chat-msg-meta { display: none; }
.chat-msg-grouped .chat-bubble { border-radius: 8px; }
.chat-msg-grouped { margin-top: -6px; }
.chat-msg-grouped.chat-msg-agent .chat-bubble { border-top-left-radius: 8px; }
.chat-msg-grouped.chat-msg-user .chat-bubble { border-top-right-radius: 8px; }

/* Time separator between message groups */
.chat-msg-time-separator {
  justify-content: center;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 8px 0;
  opacity: 0.7;
}

/* Suggestion chips */
.chat-suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px 12px 52px;
}
.chat-suggestion-chip {
  background: var(--surface);
  border: 1px solid var(--input-border);
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  font-family: inherit;
  white-space: nowrap;
}
.chat-suggestion-chip:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

/* Markdown in chat bubbles */
.chat-bubble code {
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
}
:root[data-theme="dark"] .chat-bubble code {
  background: rgba(255, 255, 255, 0.1);
}
.chat-bubble pre {
  background: rgba(0, 0, 0, 0.06);
  padding: 8px 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
}
:root[data-theme="dark"] .chat-bubble pre {
  background: rgba(255, 255, 255, 0.06);
}
/* Tables in agent bubbles — responsive with horizontal scroll */
.chat-bubble .table-wrapper {
  overflow-x: auto;
  margin: 4px -4px;
  -webkit-overflow-scrolling: touch;
}
.chat-bubble table {
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.4;
  width: 100%;
  min-width: 300px;
}
.chat-bubble th, .chat-bubble td {
  border: 1px solid var(--chat-border);
  padding: 6px 10px;
  text-align: left;
}
.chat-bubble th {
  background: rgba(0, 0, 0, 0.05);
  font-weight: 600;
  white-space: nowrap;
}
:root[data-theme="dark"] .chat-bubble th {
  background: rgba(255, 255, 255, 0.08);
}
/* Allow cell content to auto-wrap within table bounds */
.chat-bubble td {
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
}

.chat-bubble ul, .chat-bubble ol {
  padding-left: 18px;
  margin: 4px 0;
}
.chat-bubble a {
  color: var(--accent-light);
  text-decoration: underline;
}
/* Headers in agent bubbles */
.chat-h {
  font-size: 14px;
  font-weight: 600;
  margin: 8px 0 2px;
  line-height: 1.4;
}
h3.chat-h { font-size: 15px; }
.chat-hr {
  border: none;
  border-top: 1px solid var(--chat-border);
  margin: 6px 0;
}
.chat-bubble code {
  background: var(--surface-hover);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

/* Tables in chat bubbles */
.chat-table {
  border-collapse: collapse;
  font-size: 12px;
  margin: 8px 0;
  width: 100%;
}
.chat-table th, .chat-table td {
  border: 1px solid var(--chat-border);
  padding: 4px 8px;
  text-align: left;
  white-space: nowrap;
}
.chat-table th {
  background: var(--surface-hover);
  font-weight: 600;
}
:root[data-theme="dark"] .chat-table th,
:root[data-theme="dark"] .chat-table td {
  border-color: rgba(255,255,255,0.1);
}

/* CSV download button */
.chat-csv-btn {
  font-size: 11px;
  color: var(--accent);
  background: none;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  margin-top: 4px;
  font-family: inherit;
}
.chat-csv-btn:hover { background: var(--surface-hover); border-color: var(--accent); }

/* Scroll-to-bottom floating button */
.chat-scroll-bottom-btn {
  position: absolute;
  bottom: 80px;
  right: 20px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--chat-border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  color: var(--text-dim);
  transition: background 0.2s, box-shadow 0.2s;
}
.chat-scroll-bottom-btn:hover {
  background: var(--surface-hover);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.chat-scroll-bottom-btn svg { width: 16px; height: 16px; }

/* Typing indicator */
.chat-typing {
  padding: 4px 20px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  display: none;
}

/* File upload preview */
.chat-file-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  margin: 0 20px 8px;
  font-size: 12px;
  color: var(--text);
}
.chat-file-preview img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
}
.chat-file-preview-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-file-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 2px;
  line-height: 0;
}
.chat-file-remove:hover { color: var(--red); }

/* Input area */
.chat-input-area {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 24px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
  align-items: flex-end;
  background: var(--surface);
}
.chat-input-area > .chat-input-hint {
  flex-basis: 100%;
}

.chat-input-wrap {
  flex: 1;
  position: relative;
}

.chat-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
  resize: none;
  min-height: 42px;
  max-height: 150px;
  line-height: 1.5;
}
.chat-input:focus { border-color: var(--input-focus); }
.chat-input:disabled { opacity: 0.4; }

.chat-char-count {
  position: absolute;
  bottom: 4px;
  right: 10px;
  font-size: 10px;
  color: var(--text-dim);
  display: none;
}
.chat-char-count.warn { color: var(--yellow); }
.chat-char-count.over { color: var(--red); }

.chat-input-actions {
  display: flex;
  gap: 4px;
  align-items: flex-end;
}

.chat-upload-btn {
  background: none;
  border: 1px solid var(--input-border);
  border-radius: 50%;
  color: var(--text-dim);
  cursor: pointer;
  padding: 9px;
  line-height: 0;
  transition: color 0.2s, border-color 0.2s;
}
.chat-upload-btn:hover { color: var(--text); border-color: var(--accent); }
.chat-upload-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-upload-btn svg { width: 16px; height: 16px; }

.chat-send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  font-family: inherit;
  white-space: nowrap;
}
.chat-send-btn:hover { opacity: 0.85; }
.chat-send-btn:disabled { opacity: 0.4; cursor: default; }
.chat-send-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Send button loading state */
.chat-send-btn.loading {
  pointer-events: none;
  opacity: 0.6;
  position: relative;
}
.chat-send-btn.loading::after {
  content: '';
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }
.chat-send-btn svg { width: 14px; height: 14px; }
.chat-send-btn span { margin-left: 4px; }

/* Input hint */
.chat-input-hint {
  font-size: 10px;
  color: var(--text-dim);
  padding: 2px 0 0 4px;
  opacity: 0.6;
}

/* Header skill tags */
.chat-header-tags {
  display: flex;
  gap: 4px;
  margin-top: 3px;
  flex-wrap: wrap;
}
.chat-header-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-hover);
  color: var(--text-dim);
  border: 1px solid var(--bar-border);
  white-space: nowrap;
}

/* Header status dot (inline after name) */
.chat-header-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 6px;
  vertical-align: middle;
  background: var(--text-dim);
}
.chat-header-status.active { background: var(--green); }
.chat-header-status.idle { background: var(--yellow); }

/* Chat message avatar */
.chat-msg-agent {
  flex-direction: row;
  gap: 10px;
}
.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
}
.chat-msg-avatar svg { width: 16px; height: 16px; }
.chat-msg-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}
.chat-msg-user { flex-direction: row-reverse; }
.chat-msg-user .chat-msg-content { align-items: flex-end; }

/* Copy success state */
.chat-msg-copy.copied { color: var(--green); }
.chat-msg-copy.copied svg { opacity: 0.5; }

/* Empty state */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  text-align: center;
}
.chat-empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}
.chat-empty-icon svg { width: 28px; height: 28px; }
.chat-empty-text {
  font-size: 14px;
  color: var(--text-dim);
}

/* Drag-over state */
.chat-main-area.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: var(--surface-hover);
}

/* Shake animation (send without agent) */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}
.chat-input.shake {
  animation: shake 0.3s ease;
  border-color: var(--red);
}

/* File preview wrap */
.chat-file-preview-wrap {
  padding: 0 20px;
}

/* Download modal */
.download-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.download-modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  min-width: 260px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.download-modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}
.download-option {
  display: block;
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 6px;
  background: var(--surface-hover);
  border: 1px solid var(--bar-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.download-option:hover {
  background: rgba(0, 72, 150, 0.08);
  border-color: var(--accent);
}
.download-close {
  display: block;
  width: 100%;
  padding: 8px;
  margin-top: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.download-close:hover { color: var(--text); }

/* ═══════════════════════════════════════════════
   Settings View (inline page with tabs)
   ═══════════════════════════════════════════════ */
.settings-page {
  max-width: 640px;
  margin: 0 auto;
}
.settings-page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
}

.settings-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--bar-border);
  margin-bottom: 24px;
}
.settings-tab {
  padding: 10px 20px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.settings-tab:hover {
  color: var(--text);
}
.settings-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.settings-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.settings-tab svg {
  width: 16px;
  height: 16px;
}

.settings-tab-content {
  display: none;
}
.settings-tab-content.active {
  display: block;
}

.settings-field {
  margin-bottom: 16px;
}
.settings-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.settings-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
}
.settings-input:focus { border-color: var(--input-focus); }

.settings-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--input-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b949e'/%3E%3C/svg%3E") no-repeat right 10px center;
  background-size: 10px 6px;
  padding-right: 28px;
  cursor: pointer;
}

.settings-status {
  font-size: 12px;
  padding: 6px 0;
  margin-bottom: 8px;
}
.settings-status-connected { color: var(--green); }
.settings-status-connecting { color: var(--yellow); }
.settings-status-disconnected { color: var(--text-dim); }

/* ── Service Status Cards (Connection tab) ── */
.settings-status-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.settings-status-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--chat-border);
  flex: 1;
  min-width: 140px;
}

.settings-status-card-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.settings-status-card-icon svg {
  width: 16px;
  height: 16px;
}

.settings-status-card-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.settings-status-card-label {
  font-size: 11px;
  color: var(--text-dim);
}

.settings-mode-fields {
  transition: opacity 0.2s;
}

.settings-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}

.settings-btn-test,
.settings-btn-cancel,
.settings-btn-save {
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
.settings-btn-test:focus-visible, .settings-btn-cancel:focus-visible, .settings-btn-save:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.settings-btn-test { background: none; color: var(--accent); border-color: var(--toast-info-border); }
.settings-btn-test:hover { background: var(--toast-info-bg); }
.settings-btn-cancel { background: none; color: var(--text-dim); }
.settings-btn-cancel:hover { background: var(--surface-hover); }
.settings-btn-save { background: var(--accent); color: #fff; border-color: var(--accent); }
.settings-btn-save:hover { opacity: 0.85; }

.settings-btn-logout {
  background: none;
  color: var(--red);
  border: 1px solid var(--pill-err-border);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
.settings-btn-logout:hover { background: var(--pill-err-bg); }
.settings-btn-logout:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ═══════════════════════════════════════════════
   Agent Info Panel (Office view hover)
   ═══════════════════════════════════════════════ */
.agent-panel {
  position: fixed;
  background: var(--bar-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--modal-border);
  border-radius: 10px;
  padding: 10px 14px;
  z-index: 200;
  pointer-events: none;
  min-width: 140px;
  box-shadow: var(--shadow);
}
.agent-panel-name { font-weight: 700; font-size: 13px; color: var(--text); margin-bottom: 2px; }
.agent-panel-role { font-size: 11px; color: var(--accent); margin-bottom: 4px; }
.agent-panel-status { font-family: var(--font-mono); font-size: 10px; color: var(--green); }

/* ═══════════════════════════════════════════════
   Toast Notifications
   ═══════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  top: calc(var(--navbar-h) + 12px);
  right: 16px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  backdrop-filter: blur(8px);
  pointer-events: auto;
  cursor: pointer;
  transform: translateX(120%);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  max-width: 320px;
  word-break: break-word;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.hide { transform: translateX(120%); opacity: 0; }
.toast-info    { background: var(--toast-info-bg); border: 1px solid var(--toast-info-border); }
.toast-success { background: var(--toast-ok-bg);   border: 1px solid var(--toast-ok-border); }
.toast-warning { background: var(--toast-warn-bg); border: 1px solid var(--toast-warn-border); }
.toast-error   { background: var(--toast-err-bg);  border: 1px solid var(--toast-err-border); }

/* ═══════════════════════════════════════════════
   Auth Gate
   ═══════════════════════════════════════════════ */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s;
}
.auth-overlay.auth-fade-out { opacity: 0; pointer-events: none; }

.auth-box {
  background: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: 16px;
  padding: 36px;
  width: 360px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.auth-logo { font-family: var(--font-en); font-size: 22px; font-weight: 700; margin-bottom: 4px; color: var(--accent); }
.auth-title { font-size: 13px; color: var(--text-dim); margin-bottom: 24px; }
.auth-field { margin-bottom: 14px; text-align: left; }
.auth-field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.auth-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.auth-input:focus { border-color: var(--input-focus); }
.auth-error {
  font-size: 12px;
  color: var(--red);
  margin-bottom: 8px;
  opacity: 0;
  height: 0;
  overflow: hidden;
  transition: opacity 0.2s, height 0.2s;
}
.auth-error.visible { opacity: 1; height: auto; margin-bottom: 12px; }
.auth-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.2s;
}
.auth-btn:hover { opacity: 0.85; }
.auth-btn:disabled { opacity: 0.5; cursor: default; }
.auth-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ═══════════════════════════════════════════════
   Download Modal (in-chat)
   ═══════════════════════════════════════════════ */
.download-modal-overlay {
  position: fixed; inset: 0;
  background: var(--overlay);
  z-index: 350;
  display: flex;
  align-items: center;
  justify-content: center;
}
.download-modal {
  background: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: 12px;
  padding: 24px;
  min-width: 260px;
  box-shadow: var(--shadow-lg);
}
.download-modal h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}
.download-option {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  font-family: inherit;
}
.download-option:hover { border-color: var(--accent); background: var(--surface-hover); }

/* ═══════════════════════════════════════════════
   Mobile Bottom Nav
   ═══════════════════════════════════════════════ */
.mobile-nav {
  display: none;
}

/* ═══════════════════════════════════════════════
   Responsive: ≤1024px — sidebar overlay
   ═══════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .navbar-search { display: none; }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .nav-sidebar {
    position: fixed;
    top: var(--navbar-h);
    left: 0;
    bottom: 0;
    width: var(--nav-sidebar-w);
    z-index: 150;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
  }
  .nav-sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  /* Chat split: hide agent list on tablet */
  .chat-agent-list-panel {
    width: 200px;
  }
}

/* ═══════════════════════════════════════════════
   Responsive: ≤768px — mobile with bottom nav
   ═══════════════════════════════════════════════ */
@media (max-width: 768px) {
  .top-navbar {
    padding: 0 10px;
    padding-top: env(safe-area-inset-top, 0);
    height: auto;
    min-height: 48px;
  }
  .navbar-logo-text { font-size: 13px; }
  .navbar-center { display: none; }
  .navbar-clock { display: none; }
  .navbar-notifications-btn { display: none; }

  .app-shell {
    grid-template-columns: 1fr;
    bottom: 56px;
  }

  .nav-sidebar {
    display: none;
  }

  .view-container {
    padding: 16px;
  }
  .view-office-container {
    padding: 0;
  }

  /* Chat: stack vertically on mobile */
  .chat-split {
    flex-direction: column;
  }
  .chat-agent-list-panel {
    width: 100%;
    height: 140px;
    border-right: none;
    border-bottom: 1px solid var(--chat-border);
  }
  .chat-agent-list {
    display: flex;
    overflow-x: auto;
    gap: 0;
  }
  .chat-agent-list-item {
    flex-direction: column;
    min-width: 80px;
    padding: 8px 12px;
    border-bottom: none;
    border-right: 1px solid var(--bar-border);
    text-align: center;
    gap: 4px;
  }
  .chat-agent-list-item.active {
    border-left: none;
    padding-left: 12px;
    border-bottom: 3px solid var(--accent);
  }
  .chat-agent-last-msg { display: none; }
  .chat-agent-search { display: none; }
  .chat-agent-list-header { display: none; }

  /* Mobile chat bubble/input adjustments */
  .chat-bubble { max-width: 88%; padding: 10px 14px; }
  .chat-input-area { padding: 10px 12px; }
  .chat-msg-avatar { width: 28px; height: 28px; }

  /* Dashboard responsive */
  .dash-welcome {
    padding: 20px;
    border-radius: 12px;
  }
  .dash-welcome-greeting { font-size: 18px; }
  .dash-welcome-time { position: static; text-align: left; margin-top: 8px; }
  .dash-welcome-clock { font-size: 20px; }

  .dash-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .dash-carousel-card {
    min-width: 160px; max-width: 160px;
  }
  .dash-carousel-track { -webkit-overflow-scrolling: touch; }
  .dash-panels {
    grid-template-columns: 1fr;
  }

  /* Agent cards */
  .agents-grid {
    grid-template-columns: 1fr;
  }

  /* Mobile bottom nav */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0; right: 0;
    height: 56px;
    background: var(--bar-bg);
    border-top: 1px solid var(--bar-border);
    backdrop-filter: blur(12px);
    z-index: 100;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mobile-nav-btn {
    background: none;
    border: none;
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 8px;
    color: var(--text-dim);
    opacity: 0.5;
    transition: opacity 0.2s, color 0.2s, background 0.2s;
    line-height: 0;
  }
  .mobile-nav-btn.active {
    opacity: 1;
    color: var(--accent);
    background: var(--surface-hover);
  }
  .mobile-nav-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  /* Toast */
  .toast-container { top: auto; bottom: 68px; right: 8px; left: 8px; }
  .toast { max-width: 100%; }
}

/* ═══════════════════════════════════════════════
   DEPRECATED — reverted to Canvas v1 (office-scene.js)
   Office Scene V2 — SVG Floorplan + DOM Agents
   Kept for reference; no longer used.
   ═══════════════════════════════════════════════ */

.office-scene-v2 {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--office-floor);
}

/* SVG floorplan background */
.office-scene-v2 .office-floorplan {
  width: 100%;
  height: 100%;
  display: block;
}

/* Agent overlay container — positioned over SVG */
.office-scene-v2 .office-agents-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Individual agent button */
.office-agent {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: auto;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  transition: transform 0.8s ease-in-out;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
}

.office-agent:focus-visible {
  z-index: 10;
}

.office-agent:focus-visible .office-agent-avatar {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Avatar circle */
.office-agent-avatar {
  width: var(--office-agent-size);
  height: var(--office-agent-size);
  border-radius: 50%;
  background: var(--agent-color, var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: box-shadow 0.3s, transform 0.3s;
  position: relative;
}

.office-agent-avatar svg {
  width: 55%;
  height: 55%;
}

.office-agent:hover .office-agent-avatar {
  box-shadow: 0 4px 16px var(--office-agent-glow);
  transform: scale(1.08);
}

.office-agent[aria-pressed="true"] .office-agent-avatar {
  box-shadow: 0 0 0 3px var(--accent), 0 4px 16px var(--office-agent-glow);
}

/* Agent name label */
.office-agent-name {
  font-size: 10px;
  font-family: var(--font-sans);
  color: var(--text);
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(255, 255, 255, 0.8);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

:root[data-theme="dark"] .office-agent-name {
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* Status indicator dot */
.office-agent-status {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--text-dim);
  transition: background 0.3s;
}

.office-agent-status[data-status="active"] {
  background: var(--green);
  animation: status-pulse 2s ease-in-out infinite;
}

.office-agent-status[data-status="idle"] {
  background: var(--text-dim);
}

/* Speech bubble */
.office-agent-speech {
  position: absolute;
  bottom: calc(var(--office-agent-size) + 20px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 11px;
  font-family: var(--font-sans);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow);
  border: 1px solid var(--chat-border);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 20;
}

.office-agent-speech::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--surface);
}

.office-agent-speech.visible {
  opacity: 1;
}

/* Typing state — pulse glow */
.office-agent[data-state="typing"] .office-agent-avatar {
  animation: typing-pulse 1.5s ease-in-out infinite;
}

/* Walking state — bob */
.office-agent[data-state="walking"] {
  animation: walking-bob 0.6s ease-in-out infinite;
}

@keyframes status-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(22, 163, 74, 0); }
}

@keyframes typing-pulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); }
  50% { box-shadow: 0 2px 16px var(--office-agent-glow); }
}

@keyframes walking-bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -3px; }
}

/* SVG Room labels */
.office-scene-v2 .room-label {
  font-size: 11px;
  font-family: var(--font-sans);
  fill: var(--office-label);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

/* ── Mobile fallback: agent card list ── */
.office-mobile-list {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
  height: 100%;
}

.office-mobile-group-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 4px 4px;
}

.office-mobile-agent {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--chat-border);
  cursor: pointer;
  transition: background 0.2s;
}

.office-mobile-agent:hover {
  background: var(--surface-hover);
}

.office-mobile-agent .office-agent-avatar {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.office-mobile-agent .office-agent-avatar svg {
  width: 50%;
  height: 50%;
}

.office-mobile-agent-info {
  flex: 1;
  min-width: 0;
}

.office-mobile-agent-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.office-mobile-agent-role {
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Responsive: tablet ── */
@media (min-width: 768px) and (max-width: 1023px) {
  .office-agent {
    --office-agent-size: 48px;
  }
  .office-agent-name {
    font-size: 9px;
  }
}

/* ── Responsive: mobile ── */
@media (max-width: 767px) {
  .office-scene-v2 .office-floorplan,
  .office-scene-v2 .office-agents-layer {
    display: none;
  }
  .office-scene-v2 .office-mobile-list {
    display: flex;
  }
  .office-agent {
    --office-agent-size: 40px;
  }
}

/* ═══════════════════════════════════════════════
   Accessibility: Reduced Motion
   ═══════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
