:root {
  /* Modern color system - Light mode */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --surface-elevated: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #eff6ff;
  --primary-soft: #dbeafe;

  /* Semantic colors */
  --green: #10b981;
  --green-bg: #ecfdf5;
  --green-soft: #d1fae5;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --red-soft: #fee2e2;
  --amber: #f59e0b;
  --amber-bg: #fffbeb;
  --amber-soft: #fef3c7;
  --blue: #3b82f6;
  --blue-bg: #eff6ff;
  --blue-soft: #dbeafe;
  --purple: #8b5cf6;
  --purple-bg: #f5f3ff;
  --purple-soft: #ede9fe;
  --indigo: #6366f1;

  /* Sidebar */
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #334155;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #f8fafc;
  --sidebar-width: 240px;
  --sidebar-accent: #3b82f6;

  /* Layout */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.08);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode */
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #334155;
  --surface-elevated: #27354f;
  --text: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #1e293b;
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --primary-light: rgba(59, 130, 246, 0.15);
  --primary-soft: rgba(59, 130, 246, 0.25);

  --green-bg: rgba(16, 185, 129, 0.12);
  --green-soft: rgba(16, 185, 129, 0.2);
  --red-bg: rgba(239, 68, 68, 0.12);
  --red-soft: rgba(239, 68, 68, 0.2);
  --amber-bg: rgba(245, 158, 11, 0.12);
  --amber-soft: rgba(245, 158, 11, 0.2);
  --blue-bg: rgba(59, 130, 246, 0.12);
  --blue-soft: rgba(59, 130, 246, 0.2);
  --purple-bg: rgba(139, 92, 246, 0.12);
  --purple-soft: rgba(139, 92, 246, 0.2);

  --sidebar-bg: #020617;
  --sidebar-hover: #1e293b;
  --sidebar-active: #334155;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #f8fafc;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
  transition: background-color var(--transition), color var(--transition);
}
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); text-decoration: none; }

/* Layout */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: background-color var(--transition);
}
.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-header h1 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-header h1 .logo-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
  font-weight: 800;
  letter-spacing: -0.02em;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}
.sidebar-header .subtitle {
  font-size: 11px;
  color: #64748b;
  margin-top: 6px;
}
.sidebar-nav {
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
}
.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
  text-decoration: none;
}
.sidebar-nav a.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-active);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
.sidebar-nav a.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--sidebar-accent);
}
.sidebar-nav a svg { flex-shrink: 0; opacity: 0.55; width: 17px; height: 17px; transition: opacity var(--transition); }
.sidebar-nav a:hover svg { opacity: 0.85; }
.sidebar-nav a.active svg { opacity: 1; color: var(--sidebar-accent); }
.sidebar-nav .nav-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
  padding: 16px 12px 6px;
}
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 11px;
  color: #475569;
}
.sidebar-lang {
  padding: 10px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-lang a {
  color: #64748b;
  padding: 3px 6px;
  border-radius: 5px;
  transition: all var(--transition);
}
.sidebar-lang a:hover { color: #e2e8f0; text-decoration: none; background: var(--sidebar-hover); }
.sidebar-lang a.active { color: #fff; font-weight: 600; background: var(--sidebar-active); }
.sidebar-lang svg { opacity: 0.4; }

/* Main content */
.content {
  flex: 1;
  padding: 28px 32px;
  margin-left: var(--sidebar-width);
  max-width: calc(var(--sidebar-width) + 1280px);
  min-width: 0;
}

/* Theme toggle */
.theme-toggle {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--sidebar-text);
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
}
.theme-toggle:hover { background: var(--sidebar-hover); color: #e2e8f0; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-header .page-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Flash messages */
.flash {
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: flashIn 0.25s ease;
  border: 1px solid;
  box-shadow: var(--shadow-md);
}
@keyframes flashIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes flashOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }
.flash-info { background: var(--blue-bg); color: var(--blue); border-color: var(--blue-soft); }
.flash-success { background: var(--green-bg); color: var(--green); border-color: var(--green-soft); }
.flash-error { background: var(--red-bg); color: var(--red); border-color: var(--red-soft); }
.flash .flash-icon { flex-shrink: 0; width: 16px; height: 16px; }
.flash .dismiss {
  margin-left: auto;
  cursor: pointer;
  opacity: 0.5;
  background: none;
  border: none;
  padding: 2px;
  font-size: 18px;
  line-height: 1;
  color: inherit;
}
.flash .dismiss:hover { opacity: 1; }

/* KPI Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.card-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
  transition: transform var(--transition);
}
.card:hover .card-icon { transform: scale(1.05); }
.card-icon.blue { background: var(--blue-bg); color: var(--blue); }
.card-icon.indigo { background: var(--purple-bg); color: var(--indigo); }
.card-icon.green { background: var(--green-bg); color: var(--green); }
.card-icon.amber { background: var(--amber-bg); color: var(--amber); }
.card-icon.red { background: var(--red-bg); color: var(--red); }
.card-icon.purple { background: var(--purple-bg); color: var(--purple); }
.card .label { color: var(--text-muted); font-size: 12px; font-weight: 600; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.card .value { font-size: 28px; font-weight: 800; line-height: 1.2; letter-spacing: -0.03em; }
.card .delta {
  font-size: 12px;
  font-weight: 600;
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.card .delta.up { color: var(--green); }
.card .delta.down { color: var(--red); }
.dashboard-section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 14px;
}
.dashboard-section-heading h3 { margin: 0; font-size: 16px; }
.dashboard-section-heading p { margin: 4px 0 0; font-size: 12px; color: var(--text-muted); }
.dashboard-section-heading .text-link { color: var(--primary); font-size: 12px; text-decoration: none; white-space: nowrap; }
.dashboard-ops-cards { margin-bottom: 24px; }
.dashboard-ops-cards .card-icon { display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; }
.dashboard-ops-cards .card-icon span { line-height: 1; }

/* Panels */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: background-color var(--transition), border-color var(--transition);
}
.panel h3 {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel h3 svg { opacity: 0.5; width: 16px; height: 16px; }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }

/* Tables */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th:first-child { border-radius: 8px 0 0 0; }
thead th:last-child { border-radius: 0 8px 0 0; }
tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
tbody tr { transition: background-color var(--transition); }
tbody tr:hover { background: var(--surface-alt); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:last-child td:first-child { border-radius: 0 0 0 8px; }
tbody tr:last-child td:last-child { border-radius: 0 0 8px 0; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge-green { background: var(--green-bg); color: #047857; }
.badge-red { background: var(--red-bg); color: #b91c1c; }
.badge-amber { background: var(--amber-bg); color: #b45309; }
.badge-blue { background: var(--blue-bg); color: #1d4ed8; }
.badge-purple { background: var(--purple-bg); color: #6d28d9; }

/* Status dot */
.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  box-shadow: 0 0 0 2px currentColor;
  opacity: 0.9;
}
.status-dot.online { background: var(--green); color: rgba(16, 185, 129, 0.25); }
.status-dot.offline { background: var(--red); color: rgba(239, 68, 68, 0.25); }

/* Buttons */
.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
  line-height: 1.5;
  font-family: inherit;
  white-space: nowrap;
  background: var(--surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn:hover, button:hover {
  background: var(--border-light);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.btn-primary, button[type="submit"] {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 1px 2px rgba(59, 130, 246, 0.2);
}
.btn-primary:hover, button[type="submit"]:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-alt); color: var(--text); }
.btn-danger {
  background: var(--red-bg);
  color: #991b1b;
  border: 1px solid var(--red-soft);
}
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }
.btn[disabled], button[disabled] {
  opacity: 0.65;
  cursor: wait;
  transform: none !important;
}
.button-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: buttonSpin 0.8s linear infinite;
}
@keyframes buttonSpin {
  to { transform: rotate(360deg); }
}

/* Forms */
input[type="text"], input[type="password"], input[type="number"], input[type="email"], input[type="url"], select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  width: 100%;
  transition: all var(--transition);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
input::placeholder { color: var(--text-muted); }
textarea { resize: vertical; min-height: 80px; }
.form-vertical { display: flex; flex-direction: column; gap: 12px; }
.form-vertical label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* Filters */
.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.filters select, .filters input {
  width: auto;
  min-width: 140px;
}

/* Settings sections */
.settings-section {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.settings-section-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-alt);
}
.settings-section-header h3 { margin: 0; font-size: 14px; font-weight: 700; }
.settings-section-header .section-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.settings-section-body { padding: 18px; }

/* Message Feed */
.msg-feed { display: flex; flex-direction: column; gap: 4px; }
.msg-card {
  display: flex;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius);
  transition: all var(--transition);
  border: 1px solid transparent;
}
.msg-card:hover {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow);
}
.msg-avatar {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  box-shadow: var(--shadow);
}
.msg-content { flex: 1; min-width: 0; }
.msg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.msg-sender {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.msg-chat {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.msg-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
}
.msg-body { padding-left: 0; }
.msg-text {
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
}
.msg-text-empty {
  color: var(--text-muted);
  font-style: italic;
}
.msg-media {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.msg-media-item {
  position: relative;
  display: block;
  width: 128px;
  height: 96px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform var(--transition), box-shadow var(--transition);
}
.msg-media-item:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow-lg);
}
.msg-media-item img,
.msg-media-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.msg-media-video { position: relative; }
.msg-media-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.35);
  color: #fff;
  opacity: 0;
  transition: opacity var(--transition);
}
.msg-media-video:hover .msg-media-play { opacity: 1; }
.msg-media-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--surface-alt);
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  text-decoration: none;
  transition: all var(--transition);
}
.msg-media-file:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
  text-decoration: none;
}
.msg-media-file svg { flex-shrink: 0; opacity: 0.6; }
.msg-media-file span {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-media-type {
  cursor: default;
  opacity: 0.7;
}

/* Legacy message styles (for chat_detail page) */
.message-cell { max-width: 480px; white-space: pre-wrap; word-break: break-word; }
.message-item {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.message-item:hover { background: var(--surface-alt); }
.message-item .meta {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}
.message-item .meta .highlight { color: var(--text-secondary); font-weight: 600; }
.message-item .body .sender {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 2px;
}
.message-item .body .text {
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
}

/* Media (legacy) */
.media-preview {
  width: 72px; height: 72px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.media-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 8px;
  background: var(--surface-alt);
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.media-link:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

/* Pagination */
.pagination {
  display: flex;
  gap: 6px;
  align-items: center;
}
.pagination .info { font-size: 12px; color: var(--text-muted); margin-right: 6px; }

/* Keywords */
.keyword-list { display: flex; flex-wrap: wrap; gap: 6px; }
.keyword-list span {
  background: var(--primary-light);
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.keyword-list .weight { color: var(--text-muted); font-size: 10px; margin-left: 3px; }

/* Charts */
.chart-container {
  position: relative;
  height: 260px;
  width: 100%;
}

/* Empty state */
.empty-state {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 48px 24px;
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.35; }
.empty-state .empty-title { font-weight: 700; color: var(--text-secondary); margin-bottom: 4px; font-size: 15px; }

/* Summary cards */
.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  transition: all var(--transition);
}
.summary-card:hover {
  box-shadow: var(--shadow-md);
}
.summary-card .summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 10px;
  flex-wrap: wrap;
}
.summary-card .summary-body {
  padding: 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

/* Market intelligence timeline */
.intel-timeline {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-left: 14px;
}
.intel-timeline::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  background: var(--border);
  border-radius: 1px;
}
.intel-card {
  position: relative;
  margin-left: 28px;
}
.intel-marker {
  position: absolute;
  left: -36px;
  top: 20px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  background: var(--primary);
  box-shadow: 0 0 0 1px var(--border);
}
.intel-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.intel-trend {
  margin-bottom: 14px;
}
.intel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.intel-section {
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
}
.intel-section-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.intel-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}
.intel-list li {
  margin-bottom: 5px;
}

/* URL list */
.url-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}
.url-item:last-child { border-bottom: none; }
.url-item a { font-size: 13px; word-break: break-all; }
.url-item .url-date { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* Filter tabs */
.filter-tabs {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  align-items: center;
  padding: 3px;
  background: var(--surface-alt);
  border-radius: 10px;
  border: 1px solid var(--border);
  width: fit-content;
}
.filter-tab {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition);
  cursor: pointer;
  text-decoration: none;
  border: none;
  background: none;
}
.filter-tab:hover { color: var(--text); text-decoration: none; }
.filter-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.filter-tab .count {
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--border);
  font-size: 10px;
  font-weight: 700;
  margin-left: 5px;
  align-items: center;
  justify-content: center;
}
.filter-tab.active .count { background: var(--primary-light); color: var(--primary); }
.chat-filters {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.chat-type-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 3px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.chat-type-filter {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.chat-type-filter:hover {
  color: var(--text);
  background: var(--surface);
}
.chat-type-filter input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--primary);
}
.chat-type-filter .count {
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--border);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
}
.chat-type-filter:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.chat-type-filter:has(input:checked) .count {
  background: var(--primary-light);
  color: var(--primary);
}

/* Sidebar status */
.sidebar-status {
  padding: 10px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.sidebar-status .status-indicator {
  width: 5px; height: 5px;
  border-radius: 50%;
}
.sidebar-status .status-indicator.connected { background: var(--green); }
.sidebar-status .status-indicator.disconnected { background: var(--red); }

/* Items list (products, contacts) */
.items-list { display: flex; flex-direction: column; gap: 2px; }
.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  transition: all var(--transition);
}
.item-card:hover { box-shadow: var(--shadow-md); }
.item-card .item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.item-card .item-title { font-weight: 700; font-size: 15px; }
.item-card .item-details {
  display: flex;
  gap: 18px;
  margin-top: 8px;
  font-size: 13px;
}
.item-card .item-price .price-amount { font-weight: 700; }
.item-card .item-meta {
  display: flex;
  gap: 18px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Trend indicators */
.trend { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; }
.trend.up { color: var(--green); }
.trend.down { color: var(--red); }
.trend.neutral { color: var(--text-muted); }

/* Table responsive wrapper */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
}
.table-responsive table {
  min-width: 600px;
}

/* Inline price sparkline canvas */
canvas[id^="priceChart"] {
  display: block;
  max-width: 100%;
}

/* User profile tags */
.profile-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Responsive */
@media (max-width: 1024px) {
  .content { padding: 22px; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0;
    height: auto;
  }
  .sidebar-header { padding: 12px 16px; border: none; }
  .sidebar-header .subtitle { display: none; }
  .sidebar-nav {
    flex-direction: row;
    padding: 0 8px 8px;
    gap: 2px;
    flex-wrap: nowrap;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: thin;
  }
  .sidebar-nav .nav-section { display: none; }
  .sidebar-nav a { padding: 6px 10px; font-size: 12px; gap: 5px; flex: 0 0 auto; border-radius: 8px; }
  .sidebar-nav a svg { width: 15px; height: 15px; }
  .sidebar-nav a.active::before { display: none; }
  .sidebar-footer, .sidebar-status, .sidebar-lang { display: none; }
  .layout { flex-direction: column; }
  .content {
    margin-left: 0;
    padding: 14px;
    max-width: 100%;
  }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .message-item { grid-template-columns: 1fr; }
  .msg-header { flex-wrap: wrap; }
  .msg-time { margin-left: 0; width: 100%; }
  .msg-chat { max-width: 120px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .dashboard-section-heading { align-items: flex-start; flex-direction: column; gap: 6px; }
  .filter-tabs, .chat-filters, .chat-type-filters { width: 100%; }
  .chat-filters { justify-content: flex-start; }
}
@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 14px; }
  .card .value { font-size: 22px; }
  .grid-4 { grid-template-columns: 1fr; }
}

/* Chat list enhancements */
.chats-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.chat-search {
  position: relative;
  flex: 1 1 260px;
  min-width: 200px;
}
.chat-search svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}
.chat-search input {
  padding-left: 34px;
  width: 100%;
}
.chat-table {
  margin: -4px;
}
.chat-table thead th {
  white-space: nowrap;
}
.chat-table tbody tr {
  transition: background-color var(--transition), box-shadow var(--transition);
}
.chat-table tbody tr:hover {
  background: var(--surface-alt);
}
.chat-table tbody tr.selected {
  background: var(--primary-light);
}
.chat-table tbody tr.selected:hover {
  background: var(--primary-soft);
}
.chat-table tbody tr.hidden-row {
  display: none;
}
.chat-title-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-type-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-size: 14px;
}
.chat-type-icon.channel { background: linear-gradient(135deg, var(--purple), #a78bfa); }
.chat-type-icon.group { background: linear-gradient(135deg, var(--green), #34d399); }
.chat-type-icon.supergroup { background: linear-gradient(135deg, var(--blue), #60a5fa); }
.chat-type-icon.private { background: linear-gradient(135deg, var(--amber), #fbbf24); }
.chat-type-icon.unknown { background: linear-gradient(135deg, var(--text-muted), #cbd5e1); }
.chat-title-main {
  min-width: 0;
}
.chat-title-main strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-title-main .chat-username {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.chat-title-main .chat-username code {
  color: var(--primary);
  background: var(--primary-light);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}
.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chat-stats {
  display: flex;
  gap: 14px;
}
.chat-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-stat .value {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}
.chat-stat .label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}
.icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.icon-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--primary);
}
.icon-btn svg {
  width: 15px;
  height: 15px;
}
.icon-btn.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.icon-btn.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.icon-btn.btn-danger {
  background: var(--red-bg);
  color: #991b1b;
  border-color: var(--red-soft);
}
.icon-btn.btn-danger:hover {
  background: var(--red-soft);
}
.batch-bar {
  display: none;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--primary-light);
  border: 1px solid var(--primary-soft);
  border-radius: var(--radius);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.batch-bar .batch-info {
  font-size: 13px;
  color: var(--primary);
  font-weight: 700;
}
.batch-bar .batch-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
}
.relative-time {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Settings page */
.card .value.small { font-size: 16px; }
.help-text {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
  line-height: 1.45;
}
.settings-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.settings-nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  transition: all var(--transition);
}
.settings-nav a:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}
.settings-section {
  scroll-margin-top: 20px;
}
.settings-section-header .section-icon {
  background: var(--surface-alt) !important;
  color: var(--text-secondary) !important;
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}
.info-card {
  padding: 16px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}
.info-card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
.info-row .info-label { color: var(--text-muted); }
.info-row .info-value {
  color: var(--text-secondary);
  word-break: break-all;
  text-align: right;
  max-width: 260px;
}
.info-badge-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  align-items: center;
}
.info-badge-row .info-label { color: var(--text-muted); }


/* ==================== AI Chat ==================== */

.chat-layout {
  display: flex;
  height: calc(100vh - 56px);
  margin: -28px -32px;
  width: calc(100% + 64px);
  gap: 0;
  box-sizing: border-box;
}

.chat-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.chat-sidebar-header {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-sidebar-header h3 {
  margin: 0;
  font-size: 15px;
  color: var(--text-primary);
}

.chat-sessions {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.chat-session-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  margin-bottom: 4px;
  transition: background 0.15s ease;
}

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

.chat-session-item.active {
  background: var(--primary-bg);
  color: var(--primary-color);
}

.chat-session-item .session-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-session-item .session-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.chat-header h2 {
  margin: 0 0 4px 0;
  font-size: 18px;
  color: var(--text-primary);
}

.chat-desc {
  font-size: 13px;
  color: var(--text-muted);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.chat-empty-state .empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
}

.chat-empty-state h3 {
  margin: 0 0 8px 0;
  font-size: 20px;
  color: var(--text-primary);
}

.chat-empty-state p {
  margin: 0 0 24px 0;
  font-size: 14px;
  color: var(--text-muted);
}

.chat-empty-state .example-questions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  max-width: 480px;
}

.chat-empty-state .example-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.chat-empty-state .quick-chip {
  font-size: 13px;
  padding: 8px 16px;
}

.chat-message {
  display: flex;
  gap: 10px;
  max-width: 90%;
}

.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-message {
  align-self: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-color);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.6;
  font-size: 14px;
}

.user-message .message-bubble {
  background: var(--primary-color);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-message .message-bubble {
  background: var(--bg-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.message-content {
  word-break: break-word;
  white-space: pre-wrap;
}

.message-error {
  color: var(--danger-color, #ef4444);
}

.typing-cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--primary-color);
  margin-left: 2px;
  animation: blink 1s step-end infinite;
  vertical-align: middle;
}

@keyframes blink {
  50% { opacity: 0; }
}

.message-tools {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-color);
  font-size: 12px;
}

.tools-toggle {
  color: var(--primary-color);
  cursor: pointer;
  user-select: none;
}

.tools-details {
  margin-top: 8px;
  background: var(--bg-color);
  border-radius: 8px;
  padding: 10px;
  max-height: 240px;
  overflow-y: auto;
}

.tool-item {
  margin-bottom: 10px;
}

.tool-name {
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.tool-input,
.tool-output {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 4px 0;
  max-height: 160px;
  overflow-y: auto;
}

/* Markdown content styling in AI messages */
.message-content p {
  margin: 0 0 8px 0;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content ul,
.message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-content li {
  margin-bottom: 4px;
}

.message-content pre {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}

.message-content pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  color: var(--text-primary);
}

.message-content code {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 2px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  color: var(--text-secondary);
}

.message-content blockquote {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--primary-color);
  background: var(--bg-color);
  border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}

.message-content th,
.message-content td {
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  text-align: left;
}

.message-content th {
  background: var(--bg-color);
  font-weight: 600;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  margin: 16px 0 8px 0;
  font-size: 15px;
}

.message-content hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 12px 0;
}

.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  background: var(--card-bg);
}

.quick-questions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.quick-chip {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-chip:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-color);
}

.chat-input-wrap:focus-within {
  border-color: var(--primary-color);
}

.chat-input {
  flex: 1;
  resize: none;
  min-height: 32px;
  max-height: 200px;
  padding: 4px 0;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

.chat-input:focus {
  outline: none;
}

.input-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.chat-send,
.chat-stop {
  height: 36px;
  width: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.chat-status {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  min-height: 16px;
}

.loading-skeleton .card,
.loading-skeleton .panel {
  position: relative;
  overflow: hidden;
}

.loading-skeleton .card::after,
.loading-skeleton .panel::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.4) 50%,
    transparent 100%
  );
  animation: skeleton-shine 1.5s infinite;
}

@keyframes skeleton-shine {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
}

.message-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.message-placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.message-tools {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-color);
  font-size: 12px;
}

.tool-item {
  margin-bottom: 10px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
}

.tool-item.pending {
  border-left: 3px solid var(--primary-color);
}

.tool-item.done {
  border-left: 3px solid var(--success-color, #22c55e);
}

.tool-item.error {
  border-left: 3px solid var(--danger-color, #ef4444);
}

.tool-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.tool-status-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
}

.tool-status-icon.spinner {
  border: 2px solid var(--border-color);
  border-top-color: var(--primary-color);
  animation: spin 0.8s linear infinite;
}

.tool-status-icon.done {
  background: var(--success-color, #22c55e);
  color: #fff;
}

.tool-status-icon.error {
  background: var(--danger-color, #ef4444);
  color: #fff;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.tool-name {
  font-weight: 600;
  color: var(--text-secondary);
}

.tool-input,
.tool-output {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 6px 0;
  max-height: 160px;
  overflow-y: auto;
}

.tool-toggle {
  background: transparent;
  border: none;
  color: var(--primary-color);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}

.tool-toggle:hover {
  text-decoration: underline;
}

@media (max-width: 1024px) {
  .chat-layout {
    height: calc(100vh - 44px);
    margin: -22px;
    width: calc(100% + 44px);
  }
}

@media (max-width: 768px) {
  .chat-layout {
    flex-direction: column;
    height: calc(100vh - 28px);
    margin: -14px;
    width: calc(100% + 28px);
  }
  .chat-sidebar {
    width: 100%;
    max-height: 160px;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
}
