/* ============================================================
   SpawnClaw Dashboard — Sleek Glassmorphism Redesign
   Modern, responsive, mobile-first
   ============================================================ */

/* ---- Light theme (default) ---- */
:root {
  --bg: #f0f2f5;
  --bg-gradient: linear-gradient(135deg, #e8ecf4 0%, #f0f2f5 50%, #e8edf6 100%);
  --bg-surface: rgba(255, 255, 255, 0.72);
  --bg-card: rgba(255, 255, 255, 0.88);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-active: rgba(0, 0, 0, 0.07);
  --border: rgba(0, 0, 0, 0.08);
  --border-light: rgba(0, 0, 0, 0.05);
  --glass-blur: 20px;
  --glass-border: 1px solid rgba(255, 255, 255, 0.5);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.05), 0 0 1px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.12), 0 8px 20px rgba(0, 0, 0, 0.06);
  --shadow-glow: 0 0 20px rgba(37, 99, 235, 0.1);
  --text: #1a1d24;
  --text-secondary: #4a5068;
  --text-muted: #8892a8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: rgba(37, 99, 235, 0.08);
  --accent-glow: rgba(37, 99, 235, 0.15);
  --accent-text: #ffffff;
  --green: #16a34a;
  --green-bg: rgba(22, 163, 74, 0.08);
  --green-glow: rgba(22, 163, 74, 0.2);
  --red: #dc2626;
  --red-bg: rgba(220, 38, 38, 0.08);
  --yellow: #ca8a04;
  --yellow-bg: rgba(202, 138, 4, 0.08);
  --orange: #ea580c;
  --purple: #7c3aed;
  --purple-bg: rgba(124, 58, 237, 0.08);
  --code-bg: rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Menlo, monospace;
  --sidebar-width: 280px;
  --topbar-height: 60px;
  --chat-width: 420px;
  --transition: 0.2s ease;
  --transition-slow: 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- Dark theme ---- */
[data-theme="dark"] {
  --bg: #0a0b10;
  --bg-gradient: linear-gradient(135deg, #0d0e16 0%, #0a0b10 50%, #0f1018 100%);
  --bg-surface: rgba(22, 24, 32, 0.75);
  --bg-card: rgba(28, 30, 40, 0.88);
  --bg-card-hover: rgba(36, 38, 50, 0.95);
  --bg-hover: rgba(255, 255, 255, 0.05);
  --bg-active: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.04);
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 1px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 30px rgba(91, 141, 239, 0.15);
  --text: #e8eaef;
  --text-secondary: #a0a8b8;
  --text-muted: #5c6478;
  --accent: #5b8def;
  --accent-hover: #7aa5ff;
  --accent-light: rgba(91, 141, 239, 0.1);
  --accent-glow: rgba(91, 141, 239, 0.2);
  --accent-text: #ffffff;
  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, 0.1);
  --green-glow: rgba(74, 222, 128, 0.25);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.1);
  --yellow: #fbbf24;
  --yellow-bg: rgba(251, 191, 36, 0.1);
  --orange: #fb923c;
  --purple: #a78bfa;
  --purple-bg: rgba(167, 139, 250, 0.1);
  --code-bg: rgba(0, 0, 0, 0.3);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--bg-gradient);
  z-index: -2;
}

/* ---- Background Decoration ---- */
.bg-decor {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.bg-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.15;
  /* Static blobs — no continuous animation to save GPU */
  will-change: auto;
}
[data-theme="dark"] .bg-blob { opacity: 0.08; }
.bg-blob-1 {
  width: 500px; height: 500px;
  background: var(--accent);
  top: -150px; right: -100px;
}
.bg-blob-2 {
  width: 400px; height: 400px;
  background: var(--purple);
  bottom: -100px; left: -80px;
}
.bg-blob-3 {
  width: 350px; height: 350px;
  background: var(--green);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.08;
}

/* ---- Top Bar ---- */
#topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
  border-bottom: var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 16px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Hamburger */
.btn-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px; height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.btn-hamburger:hover { background: var(--bg-hover); }
.btn-hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: all 0.3s ease;
  transform-origin: center;
}
.btn-hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
.btn-hamburger.active span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.btn-hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

.logo-mark {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
  color: var(--accent-text);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text);
  background: linear-gradient(135deg, var(--text) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.health-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
  transition: all var(--transition);
}
.health-dot.ok {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
}
.health-dot.error {
  background: var(--red);
  box-shadow: 0 0 8px rgba(220, 38, 38, 0.4);
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.stat-pills {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: var(--bg-hover);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all var(--transition);
}
.pill:hover { background: var(--bg-active); }

.pill-label {
  color: var(--text-muted);
  font-weight: 400;
}

.pill-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.pill-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.pill-dot.running { background: var(--green); box-shadow: 0 0 4px var(--green-glow); }
.pill-dot.stopped { background: var(--red); }

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

.btn-icon {
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.btn-icon:hover {
  background: var(--bg-active);
  color: var(--text);
  border-color: var(--border);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.btn-icon-sm { width: 32px; height: 32px; }
.btn-icon-xs {
  width: 26px; height: 26px;
  margin-left: auto;
  border: none;
  background: transparent;
}
.btn-icon-xs:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.btn-chat-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  color: var(--accent-text);
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}
.btn-chat-toggle:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}
.btn-chat-toggle.active {
  background: var(--bg-hover);
  color: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.btn-chat-toggle svg { flex-shrink: 0; }

/* ---- Activity Status Bar ---- */
.status-bar {
  position: fixed;
  top: var(--topbar-height);
  left: 0; right: 0;
  z-index: 95;
  background: var(--accent-light);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--accent);
  padding: 0 20px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  transition: all var(--transition);
}
.status-bar.idle {
  background: var(--bg-surface);
  border-bottom-color: var(--border);
  color: var(--text-muted);
}
.status-bar.idle .status-bar-spinner { display: none; }

.status-bar-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
}

.status-bar-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-bar-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-bar-count {
  background: var(--accent);
  color: var(--accent-text);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.status-bar.idle .status-bar-count { background: var(--text-muted); }

.status-bar-toggle {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: all var(--transition);
}
.status-bar-toggle:hover { background: var(--bg-hover); }
.status-bar-toggle.expanded svg { transform: rotate(180deg); }

.activity-feed {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border);
  border-top: none;
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
  z-index: 94;
}

.activity-list { padding: 4px 0; }

.activity-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  font-size: 12px;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}
.activity-item:last-child { border-bottom: none; }
.activity-item:hover { background: var(--bg-hover); }

.activity-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.activity-dot.active { background: var(--accent); animation: pulse 1.5s infinite; }
.activity-dot.finished { background: var(--green); }
.activity-dot.failed { background: var(--red); }
.activity-dot.queued { background: var(--yellow); }

.activity-app {
  font-weight: 600;
  color: var(--text);
  min-width: 80px;
}
.activity-status {
  color: var(--text-muted);
  flex: 1;
  text-transform: capitalize;
}
.activity-time {
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.activity-empty {
  padding: 16px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

body.has-status-bar #main-layout { top: calc(var(--topbar-height) + 36px); }
body.has-status-bar .chat-drawer { top: calc(var(--topbar-height) + 36px); }

/* ---- Main Layout ---- */
#main-layout {
  display: flex;
  position: fixed;
  top: var(--topbar-height);
  left: 0; right: 0; bottom: 0;
}

/* ---- Sidebar ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 89;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.6);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.6);
  border-right: var(--glass-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--transition-slow), box-shadow var(--transition);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px;
  border-bottom: 1px solid var(--border-light);
}
.sidebar-header h2 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.sidebar-actions {
  display: flex;
  gap: 4px;
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  margin: 10px 10px 0;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  transition: all var(--transition);
}
.sidebar-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-card);
}
.sidebar-search svg { flex-shrink: 0; }
.sidebar-search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  width: 100%;
}
.sidebar-search input::placeholder { color: var(--text-muted); }

.instance-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
}

.instance-item {
  padding: 11px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
  border: 1px solid transparent;
}
.instance-item:hover {
  background: var(--bg-hover);
  transform: translateX(2px);
}
.instance-item.selected {
  background: var(--accent-light);
  border-color: transparent;
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}
[data-theme="dark"] .instance-item.selected {
  background: var(--accent-light);
}

.instance-avatar {
  width: 28px; height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.instance-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-left: -6px;
  margin-bottom: -14px;
  z-index: 1;
  border: 2px solid var(--bg-card);
  transition: box-shadow var(--transition);
}
.instance-dot.running { background: var(--green); box-shadow: 0 0 6px var(--green-glow); animation: pulse-green 2.5s ease-in-out infinite; }
.instance-dot.stopped { background: var(--red); }
.instance-dot.unknown { background: var(--yellow); }
.instance-dot.building { background: var(--orange); animation: pulse 1.5s infinite; }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 4px var(--green-glow); }
  50% { box-shadow: 0 0 10px var(--green-glow), 0 0 16px var(--green-glow); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.instance-info {
  flex: 1;
  min-width: 0;
}
.instance-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.instance-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.instance-channels {
  display: flex;
  gap: 3px;
  margin-left: auto;
}
.instance-channel-icon {
  font-size: 11px;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-weight: 600;
  transition: all var(--transition);
}
.instance-channel-icon.connected {
  background: var(--green-bg);
  color: var(--green);
}

.instance-badge-host {
  font-size: 9px;
  background: linear-gradient(135deg, var(--purple) 0%, #6d28d9 100%);
  color: #fff;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* ---- Sidebar Enhancements ---- */
.instance-name-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.instance-name-row .instance-name { flex: 1; min-width: 0; }

.instance-fav {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 2px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}
.instance-item:hover .instance-fav,
.instance-item.selected .instance-fav { opacity: 0.5; }
.instance-fav.active { opacity: 1 !important; color: #f59e0b; }
.instance-fav:hover { opacity: 1 !important; }

.instance-model {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 1px 6px;
  border-radius: 8px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}

.instance-item.stale .instance-dot { opacity: 0.4; }
.instance-item.stale .instance-name { opacity: 0.6; }
.instance-stale-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--yellow);
  flex-shrink: 0;
  margin-left: auto;
}

.loading {
  color: var(--text-muted);
  padding: 24px;
  text-align: center;
  font-size: 13px;
}

/* Skeleton shimmer loading */
.skeleton-wrap { padding: 16px; }
.skeleton-line {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-active) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  margin-bottom: 10px;
}
.skeleton-line:nth-child(2) { width: 75%; }
.skeleton-line:nth-child(3) { width: 60%; }
.skeleton-line:nth-child(4) { width: 85%; }
.skeleton-line:last-child { margin-bottom: 0; }
.skeleton-line-short { width: 40%; }
.skeleton-line-med { width: 65%; }
.skeleton-block {
  height: 48px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-active) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  margin-bottom: 10px;
}
.skeleton-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.skeleton-row .skeleton-line { flex: 1; margin-bottom: 0; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Detail Panel ---- */
#detail-panel {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  background: transparent;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 16px;
  text-align: center;
}
.empty-graphic {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-icon {
  font-size: 56px;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.1));
}
.empty-rings {
  position: absolute;
  inset: 0;
  border: 2px solid var(--border);
  border-radius: 50%;
  animation: ring-pulse 3s ease-in-out infinite;
}
@keyframes ring-pulse {
  0%, 100% { transform: scale(1); opacity: 0.4; }
  50% { transform: scale(1.15); opacity: 0.1; }
}
.empty-state h2 { font-size: 22px; color: var(--text); font-weight: 700; }
.empty-state p { font-size: 14px; line-height: 1.7; color: var(--text-secondary); }

.detail-header {
  margin-bottom: 28px;
}
.detail-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.detail-title-row h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.detail-badges {
  display: flex;
  gap: 8px;
}

.badge {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 600;
  text-transform: capitalize;
  backdrop-filter: blur(8px);
}
.badge.running {
  background: var(--green-bg);
  color: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
}
.badge.stopped { background: var(--red-bg); color: var(--red); }
.badge.unknown { background: var(--yellow-bg); color: var(--yellow); }
.badge.building { background: var(--yellow-bg); color: var(--orange); }
.badge-type { background: var(--purple-bg); color: var(--purple); }

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.action-row-danger {
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition);
  box-shadow: var(--shadow);
}
.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; transform: none; }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn-start:hover { border-color: var(--green); color: var(--green); box-shadow: 0 4px 16px var(--green-glow); }
.btn-stop:hover { border-color: var(--red); color: var(--red); }
.btn-restart:hover { border-color: var(--yellow); color: var(--yellow); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  color: var(--accent-text);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover {
  filter: brightness(1.1);
  border-color: transparent;
  color: var(--accent-text);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}

.btn-secondary {
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 12px;
  box-shadow: none;
  background: var(--bg-hover);
}
.btn-secondary:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 12px var(--accent-glow);
}

.btn-danger {
  color: var(--red);
  border-color: rgba(220, 38, 38, 0.3);
  background: var(--red-bg);
}
.btn-danger:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
  box-shadow: 0 4px 16px rgba(220, 38, 38, 0.25);
}
.btn-danger:disabled { opacity: 0.35; cursor: not-allowed; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), background var(--transition), transform var(--transition);
  contain: layout style;
  animation: cardFadeIn 0.25s ease-out;
}
@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.card:hover {
  box-shadow: var(--shadow-md);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}
.card:active { transform: translateY(0); }

.card-full { grid-column: 1 / -1; }

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--text-muted);
}
.card-header h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* ---- Skeleton Shimmer Loading ---- */
.skeleton { position: relative; overflow: hidden; background: var(--bg-hover); border-radius: var(--radius-sm); }
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, var(--bg-active) 50%, transparent 100%);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.skel-line { height: 12px; margin-bottom: 8px; border-radius: 6px; }
.skel-line:last-child { margin-bottom: 0; }
.skel-line.w-60 { width: 60%; }
.skel-line.w-80 { width: 80%; }
.skel-line.w-40 { width: 40%; }
.skel-line.w-full { width: 100%; }
.skel-line.h-8 { height: 8px; }
.skel-circle { width: 32px; height: 32px; border-radius: 50%; }
.skel-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.skel-row:last-child { margin-bottom: 0; }
.skel-block { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.skel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.skel-card { height: 80px; border-radius: var(--radius); }

/* ---- Card Navigation Tab Bar ---- */
.card-tab-bar {
  display: flex;
  gap: 2px;
  padding: 0 4px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background: transparent;
  align-items: center;
}
.card-tab-bar::-webkit-scrollbar { display: none; }
.card-tab {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-hover);
  border: 1px solid transparent;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  flex-shrink: 0;
}
.card-tab:hover { color: var(--text); background: var(--bg-active); border-color: var(--border); }
.card-tab.active {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* ---- Card Tab Groups ---- */
.card-tab-group-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 6px 6px 6px 2px;
  white-space: nowrap;
  flex-shrink: 0;
  pointer-events: none;
  user-select: none;
  opacity: 0.7;
}
.card-tab-separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 4px;
  align-self: center;
}

/* Scroll fade for card tab bar */
.card-tab-bar-wrap {
  position: sticky;
  top: 0;
  z-index: 5;
}
.card-tab-fade-right {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 40px;
  background: linear-gradient(to right, transparent, var(--bg-card) 80%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 6;
  border-radius: 0 0 var(--radius) 0;
}
.card-tab-bar.has-overflow-right + .card-tab-fade-right {
  opacity: 1;
}

/* ---- Health Dot Pulse ---- */
@keyframes healthPulse {
  0%, 100% { box-shadow: 0 0 8px var(--green-glow); }
  50% { box-shadow: 0 0 14px var(--green-glow), 0 0 4px var(--green); }
}
.health-dot.ok.live {
  animation: healthPulse 2s ease-in-out infinite;
}
.health-dot.dim {
  opacity: 0.4;
  animation: none;
}

/* ---- Notification Center ---- */
.btn-notif {
  position: relative;
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.btn-notif:hover { background: var(--bg-active); color: var(--text); transform: translateY(-1px); box-shadow: var(--shadow); }
.notif-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 16px; height: 16px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.4);
  animation: notifPop 0.3s ease;
}
@keyframes notifPop {
  0% { transform: scale(0); }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); }
}
.notif-badge:empty, .notif-badge[data-count="0"] { display: none; }
.notif-dropdown {
  position: absolute;
  top: calc(var(--topbar-height) - 4px);
  right: 12px;
  width: 360px;
  max-height: 420px;
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 110;
  overflow: hidden;
  animation: notifSlideIn 0.2s ease;
}
@keyframes notifSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 600; color: var(--text);
}
.notif-header button { font-size: 11px; color: var(--accent); background: none; border: none; cursor: pointer; }
.notif-header button:hover { text-decoration: underline; }
.notif-list {
  max-height: 360px; overflow-y: auto;
  scrollbar-width: thin;
}
.notif-item {
  display: flex; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
  cursor: pointer;
}
.notif-item:hover { background: var(--bg-hover); }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--accent-light); }
.notif-icon {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.notif-icon.crit { background: var(--red-bg); color: var(--red); }
.notif-icon.warn { background: var(--yellow-bg); color: var(--yellow); }
.notif-icon.info { background: var(--accent-light); color: var(--accent); }
.notif-icon.ok { background: var(--green-bg); color: var(--green); }
.notif-body { flex: 1; min-width: 0; }
.notif-text { font-size: 12px; color: var(--text); line-height: 1.4; }
.notif-meta { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.notif-empty { padding: 32px 16px; text-align: center; color: var(--text-muted); font-size: 12px; }

/* ---- Suggestion Chips ---- */
.suggestion-chips {
  display: flex; gap: 6px; padding: 6px 16px; flex-wrap: wrap;
  overflow: hidden; max-height: 60px;
}
.suggestion-chip {
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}
.suggestion-chip:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 14px;
  font-size: 13px;
}
dt {
  color: var(--text-muted);
  font-weight: 500;
}
dd {
  color: var(--text);
  word-break: break-all;
  font-weight: 500;
}

.config-pre, .logs-pre {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  background: var(--code-bg);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  max-height: 400px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  backdrop-filter: blur(8px);
}
.config-redacted {
  background: color-mix(in srgb, var(--yellow) 15%, transparent);
  color: var(--yellow);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: help;
}

.logs-pre {
  max-height: 300px;
  overflow-y: auto;
  font-size: 11px;
  line-height: 1.5;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}
.channel-item:last-child { border-bottom: none; }
.channel-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.channel-name { font-weight: 600; text-transform: capitalize; color: var(--text); flex: 1; }
.channel-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.channel-actions .btn-xs { font-size: 10px; padding: 2px 6px; }
.channel-status {
  font-size: 11px;
  color: var(--text-muted);
  padding: 3px 10px;
  background: var(--bg-hover);
  border-radius: 10px;
  font-weight: 500;
}
.channel-status.connected { color: var(--green); background: var(--green-bg); }

.btn-sm {
  padding: 4px 12px;
  font-size: 11px;
}

.btn-qr {
  color: var(--accent);
  border-color: var(--accent);
  margin-left: auto;
}
.btn-qr:hover { background: var(--accent); color: #fff; }

/* ---- WhatsApp QR Modal ---- */
.qr-modal-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px;
}
.qr-instructions {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  margin: 0;
}
.qr-image-container {
  width: 280px;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 2px solid var(--border);
}
.qr-image {
  width: 264px;
  height: 264px;
  image-rendering: pixelated;
}
.qr-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
}
.qr-loading .spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.qr-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}
.qr-timer {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.qr-instance-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

/* ---- Identity Tabs ---- */
.identity-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
  overflow-x: auto;
  padding-bottom: 0;
  -webkit-overflow-scrolling: touch;
}

.identity-tab {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font);
  transition: all var(--transition);
  letter-spacing: 0.2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.identity-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.identity-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-light);
}
.identity-tab.empty { opacity: 0.4; }
.identity-tab .tab-icon {
  margin-right: 5px;
  font-size: 12px;
}

.identity-content { min-height: 80px; }

.identity-markdown {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  max-height: 500px;
  overflow-y: auto;
  padding: 4px 0;
}
.identity-markdown h1 { font-size: 18px; font-weight: 700; margin: 0 0 12px; color: var(--text); border-bottom: 1px solid var(--border-light); padding-bottom: 8px; }
.identity-markdown h2 { font-size: 15px; font-weight: 600; margin: 16px 0 8px; color: var(--text); }
.identity-markdown h3 { font-size: 13px; font-weight: 600; margin: 12px 0 6px; color: var(--text-secondary); }
.identity-markdown p { margin: 0 0 10px; }
.identity-markdown ul, .identity-markdown ol { margin: 4px 0 10px 20px; }
.identity-markdown li { margin-bottom: 4px; }
.identity-markdown strong { color: var(--accent); font-weight: 600; }
.identity-markdown em { color: var(--text-secondary); }
.identity-markdown code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-secondary);
}
.identity-markdown pre {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--code-bg);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--border-light);
  line-height: 1.5;
}
.identity-markdown pre code { background: none; padding: 0; }
.identity-markdown blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin: 8px 0;
  color: var(--text-secondary);
}
.identity-markdown a { color: var(--accent); text-decoration: none; }
.identity-markdown a:hover { text-decoration: underline; }
.identity-markdown hr { border: none; border-top: 1px solid var(--border-light); margin: 16px 0; }
.identity-markdown table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 12px; }
.identity-markdown th, .identity-markdown td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; }
.identity-markdown th { background: var(--bg-hover); font-weight: 600; color: var(--text-secondary); }

.identity-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
[data-theme="dark"] .modal-overlay { background: rgba(0, 0, 0, 0.6); }
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
  border: var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 420px;
  max-width: 90vw;
  animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalSlideUp {
  from { transform: translateY(30px) scale(0.97); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.modal-body { padding: 24px; }

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}
.form-label + .form-label { margin-top: 16px; }
.form-input + .form-label { margin-top: 16px; }

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-hover);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: all var(--transition);
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-card);
}
select.form-input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238890a0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.modal-wide { width: 620px; }

.modal-header-actions { display: flex; gap: 4px; }

.modal-description {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.modal-warning {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--red-bg);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: var(--radius);
}
.modal-warning strong { color: var(--red); }

.text-danger { color: var(--red); }

.form-input-danger:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.result-pre {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  background: var(--code-bg);
  border-radius: var(--radius);
  padding: 16px;
  overflow: auto;
  max-height: 50vh;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
}

/* ---- Toast Notifications ---- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.5);
  border: var(--glass-border);
  border-radius: var(--radius);
  padding: 12px 18px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 360px;
}
.toast.leaving { animation: toastOut 0.25s ease forwards; }

.toast-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.toast.success .toast-dot { background: var(--green); box-shadow: 0 0 6px var(--green-glow); }
.toast.error .toast-dot { background: var(--red); }
.toast.info .toast-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }

@keyframes toastIn {
  from { transform: translateY(16px) scale(0.95); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes toastOut {
  from { transform: translateY(0) scale(1); opacity: 1; }
  to { transform: translateY(16px) scale(0.95); opacity: 0; }
}

/* ---- Chat Drawer ---- */
.chat-drawer {
  position: fixed;
  right: -460px;
  top: var(--topbar-height);
  bottom: 0;
  width: var(--chat-width);
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.6);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.6);
  border-left: var(--glass-border);
  display: flex;
  flex-direction: column;
  transition: right 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 90;
  box-shadow: var(--shadow-lg);
}
.chat-drawer.open { right: 0; }

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

.chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.chat-title svg { color: var(--accent); }

.chat-header-actions { display: flex; gap: 4px; }

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

.message {
  max-width: 92%;
  line-height: 1.5;
  display: flex;
  gap: 10px;
  animation: messageFadeIn 0.3s ease;
}
@keyframes messageFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.message-avatar {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}
.message.user .message-avatar {
  background: var(--text-muted);
}

.message-content {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.6;
}
.message.user .message-content {
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  color: var(--accent-text);
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
}
.message.assistant .message-content {
  background: var(--bg-hover);
  color: var(--text);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
  border: 1px solid var(--border-light);
}

.message-content p { margin: 0 0 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 4px 0 8px 18px; }
.message-content code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
}
.message.user .message-content code { background: rgba(255, 255, 255, 0.2); }
.message-content pre {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--code-bg);
  padding: 10px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--border-light);
}
.message-content pre code { background: none; padding: 0; }
.message-content strong { color: var(--accent); font-weight: 600; }
.message-content a { color: var(--accent); text-decoration: none; }
.message-content a:hover { text-decoration: underline; }

.tool-indicator {
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 12px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  margin: 2px 0 2px 40px;
  font-family: var(--mono);
  border-left: 3px solid var(--accent);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tool-indicator summary {
  cursor: pointer; list-style: none; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
}
.tool-indicator summary::-webkit-details-marker { display: none; }
.tool-indicator .tool-detail {
  margin-top: 6px; font-family: var(--font-mono); font-size: 11px;
  white-space: pre-wrap; max-height: 120px; overflow-y: auto;
  background: var(--code-bg); padding: 6px 8px; border-radius: var(--radius-sm);
}
/* Drawer copy buttons */
.message-content { position: relative; }
.drawer-msg-copy {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  display: none; align-items: center; justify-content: center;
  font-size: 12px; transition: all var(--transition); z-index: 5;
}
.drawer-msg-copy:hover { color: var(--accent); border-color: var(--accent); }
.drawer-msg-copy.copied { color: var(--green); border-color: var(--green); }
.message:hover .drawer-msg-copy { display: flex; }
.message-content pre { position: relative; }
.drawer-code-copy {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: var(--radius-sm);
  background: var(--bg-hover); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  display: none; align-items: center; justify-content: center;
  font-size: 11px; transition: all var(--transition);
}
.drawer-code-copy:hover { color: var(--accent); border-color: var(--accent); }
.drawer-code-copy.copied { color: var(--green); border-color: var(--green); }
.message-content pre:hover .drawer-code-copy { display: flex; }
/* Drawer message timestamp */
.drawer-msg-time {
  font-size: 9px; color: var(--text-muted); opacity: 0;
  transition: opacity 0.2s; margin-top: 2px;
}
.message:hover .drawer-msg-time { opacity: 1; }
.message.user .drawer-msg-time { text-align: right; }
/* Drawer hints */
.chat-input-wrap { position: relative; }
.chat-hints {
  display: flex; gap: 10px; padding: 4px 18px 6px; flex-wrap: wrap;
  font-size: 10px; color: var(--text-muted); opacity: 0.5;
}
.chat-hints kbd {
  font-family: var(--font-mono); font-size: 9px; padding: 1px 4px;
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: 3px;
}

.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 12px 14px;
  align-self: flex-start;
  margin-left: 40px;
}
.typing-indicator span {
  width: 7px; height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.chat-input-area {
  padding: 16px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg-surface);
}

#chat-input {
  flex: 1;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  outline: none;
  transition: all var(--transition);
}
#chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-card);
}

.btn-send {
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  color: var(--accent-text);
  border: none;
  width: 40px; height: 40px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}
.btn-send:hover {
  filter: brightness(1.1);
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3);
}
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- Transitions ---- */
body, #topbar, #sidebar, #detail-panel, .chat-drawer, .card, .btn, .instance-item {
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

/* ---- Settings Hub ---- */
.settings-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
  overflow-x: auto;
  padding-bottom: 0;
  -webkit-overflow-scrolling: touch;
}

.settings-tab {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font);
  transition: all var(--transition);
  letter-spacing: 0.2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.settings-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.settings-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-light);
}
.settings-tab .tab-icon {
  margin-right: 5px;
  font-size: 12px;
}

.settings-tab .tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 6px;
  font-size: 10px;
  font-weight: 700;
  border-radius: 9px;
  background: var(--border);
  color: var(--text-muted);
  line-height: 1;
}
.settings-tab.active .tab-badge {
  background: var(--accent-light);
  color: var(--accent);
}

.settings-content { min-height: 80px; }

.settings-section {
  max-height: 70vh;
  overflow-y: auto;
  padding: 2px 0;
}

.settings-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.settings-row label {
  flex-shrink: 0;
  width: 120px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-top: 10px;
}

.settings-row .settings-input-wrap {
  flex: 1;
  max-width: 400px;
}

.settings-row input,
.settings-row select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-hover);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: all var(--transition);
}
.settings-row input:focus,
.settings-row select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-card);
}
.settings-row select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238890a0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.settings-textarea {
  width: 100%;
  min-height: 200px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-hover);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  transition: all var(--transition);
}
.settings-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-card);
}

.env-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.env-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
}
.env-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.env-table tr:last-child td { border-bottom: none; }
.env-table .env-key {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.env-table .env-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.env-table .env-value.masked { color: var(--text-muted); letter-spacing: 2px; }
.env-table .env-actions { white-space: nowrap; }

.env-edit-inline {
  display: flex;
  align-items: center;
  gap: 6px;
}
.env-edit-input {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.btn-primary-xs {
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  transition: all var(--transition);
}
.btn-primary-xs:hover { filter: brightness(1.1); }

.env-search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  margin-bottom: 12px;
  transition: all var(--transition);
}
.env-search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.env-search-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
}
.env-search-wrap input::placeholder { color: var(--text-muted); }
.env-search-wrap svg { color: var(--text-muted); flex-shrink: 0; }

.settings-custom-model-wrap {
  margin-top: 10px;
  animation: fadeSlideDown 0.2s ease;
}
@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Model Fallback Chain */
.model-chain-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
  min-height: 36px;
}
.model-chain-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  cursor: grab;
  transition: background 0.15s, box-shadow 0.15s, opacity 0.15s, transform 0.15s;
  user-select: none;
}
.model-chain-item:hover { background: var(--bg-hover); }
.model-chain-item.model-chain-primary {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--bg));
}
.model-chain-item.dragging {
  opacity: 0.4;
  transform: scale(0.97);
}
.model-chain-item.drag-over {
  box-shadow: 0 -2px 0 0 var(--accent);
}
.model-chain-handle {
  font-size: 16px;
  line-height: 1;
  color: var(--text-muted);
  cursor: grab;
  flex-shrink: 0;
  opacity: 0.5;
}
.model-chain-item:hover .model-chain-handle { opacity: 1; }
.model-chain-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 3px;
  flex-shrink: 0;
  min-width: 65px;
  text-align: center;
}
.model-chain-primary .model-chain-badge {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.model-chain-name {
  flex: 1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-provider-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 8px;
  flex-shrink: 0;
  letter-spacing: 0.3px;
}
.model-provider-tag.tag-free {
  background: color-mix(in srgb, var(--green) 15%, transparent);
  color: var(--green);
}
.model-provider-tag.tag-api {
  background: color-mix(in srgb, var(--yellow) 15%, transparent);
  color: var(--yellow);
}
.model-provider-tag.tag-unknown {
  background: var(--bg-hover);
  color: var(--text-muted);
}
.model-chain-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.4;
  transition: opacity 0.15s, color 0.15s;
}
.model-chain-remove:hover { opacity: 1; color: var(--red); }
.model-chain-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}
.model-chain-add {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}
.model-chain-add select {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}
.model-chain-add .settings-custom-model-wrap {
  flex: 1;
  margin-top: 0;
}
.model-chain-add .settings-custom-model-wrap input {
  width: 100%;
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

/* Move up/down arrows */
.model-chain-arrows {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex-shrink: 0;
}
.model-chain-arrow {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 9px;
  line-height: 1;
  padding: 1px 3px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, color 0.15s;
  border-radius: 2px;
}
.model-chain-arrow:hover:not(:disabled) { opacity: 1; color: var(--accent); background: var(--bg-hover); }
.model-chain-arrow:disabled { opacity: 0.15; cursor: default; }

/* Duplicate provider warning */
.model-chain-dupe {
  border-color: rgba(202, 138, 4, 0.35);
}
.model-chain-dupe-icon {
  font-size: 13px;
  color: var(--yellow);
  flex-shrink: 0;
  line-height: 1;
}
.model-chain-dupe-warn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--yellow) 8%, transparent);
  border: 1px solid rgba(202, 138, 4, 0.2);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--yellow);
  font-weight: 500;
  margin-bottom: 8px;
}
.model-chain-dupe-warn svg { flex-shrink: 0; }

/* Count badge on section header */
.model-chain-count-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  margin-left: 6px;
  vertical-align: middle;
  text-transform: none;
  letter-spacing: 0;
}

/* Preset / reset toolbar */
.model-chain-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 4px;
}
.model-chain-toolbar select {
  flex: 1;
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-muted);
  font-family: var(--font);
}

.btn-xs {
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-weight: 500;
  transition: all var(--transition);
  margin-left: 4px;
}
.btn-xs:hover { background: var(--bg-active); color: var(--text); }
.btn-xs.danger { color: var(--red); border-color: rgba(220, 38, 38, 0.3); }
.btn-xs.danger:hover { background: var(--red); color: #fff; }

.task-list { list-style: none; padding: 0; margin: 0; }
.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  color: var(--text);
}
.task-item:last-child { border-bottom: none; }
.task-item .task-bullet { color: var(--accent); font-weight: 700; flex-shrink: 0; }
.task-item .task-text { flex: 1; line-height: 1.5; }

.settings-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--yellow-bg);
  border: 1px solid rgba(202, 138, 4, 0.2);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--yellow);
  font-weight: 500;
  margin-bottom: 14px;
}
.settings-warning svg { flex-shrink: 0; }

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--border-light);
}

.settings-group-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}
.settings-group-label:first-child { margin-top: 0; }

.settings-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

.channel-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}
.channel-list-item:last-child { border-bottom: none; }
.channel-list-item.channel-disabled { opacity: 0.5; }
.channel-list-item .channel-type {
  font-weight: 600;
  text-transform: capitalize;
  color: var(--text);
  min-width: 80px;
}
.channel-list-item .channel-policy {
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
}

.ch-dm-warn {
  color: var(--warning, #e6a817);
  font-weight: 600;
  font-size: 11px;
  cursor: help;
}

.ch-status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  opacity: 0.5;
}
.ch-status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 6px var(--green-glow);
  opacity: 1;
}

.settings-whatsapp-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(37, 99, 235, 0.15);
}
.settings-whatsapp-hint strong { color: var(--accent); }

.add-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-top: 12px;
  flex-wrap: wrap;
}
.add-row .add-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.add-row .add-field label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.add-row input,
.add-row select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-hover);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  outline: none;
}
.add-row input:focus,
.add-row select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ---- Command Palette ---- */
.cmd-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  z-index: 250;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  animation: fadeIn 0.15s ease;
}
[data-theme="dark"] .cmd-palette-overlay { background: rgba(0, 0, 0, 0.55); }

.cmd-palette {
  width: 520px;
  max-width: 90vw;
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.8);
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modalSlideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.cmd-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.cmd-input-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
}
.cmd-input-wrap input::placeholder { color: var(--text-muted); }

.cmd-kbd {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.cmd-results {
  max-height: 320px;
  overflow-y: auto;
  padding: 4px 0;
}

.cmd-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.1s ease;
  font-size: 13px;
}
.cmd-item:hover,
.cmd-item.active {
  background: var(--accent-light);
}
.cmd-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.cmd-item-icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  color: var(--text-muted);
}
.cmd-item-icon.accent { background: var(--accent-light); color: var(--accent); }
.cmd-item-icon.green { background: var(--green-bg); color: var(--green); }
.cmd-item-icon.red { background: var(--red-bg); color: var(--red); }

.cmd-item-text {
  flex: 1;
  min-width: 0;
}
.cmd-item-label {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmd-item-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.cmd-item-shortcut {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
  padding: 2px 6px;
  border-radius: 4px;
}

.cmd-category {
  padding: 8px 18px 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.cmd-empty {
  padding: 24px 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.cmd-footer {
  display: flex;
  gap: 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--border-light);
  font-size: 11px;
  color: var(--text-muted);
}
.cmd-footer kbd {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 3px;
}

/* ---- Template Grid ---- */
.template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.template-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-hover);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.template-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 12px var(--accent-glow);
  transform: translateY(-1px);
}
.template-card.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.template-icon {
  font-size: 24px;
  margin-bottom: 4px;
}
.template-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.template-desc {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- Collapsible Cards ---- */
.card-header.collapsible {
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius);
  margin: -4px -4px 12px;
  padding: 4px;
  transition: background var(--transition);
}
.card-header.collapsible:hover {
  background: var(--bg-hover);
}
.card-header .collapse-chevron {
  margin-left: auto;
  transition: transform 0.25s ease;
  color: var(--text-muted);
  flex-shrink: 0;
}
.card.collapsed .collapse-chevron {
  transform: rotate(-90deg);
}
.card.collapsed .card-body,
.card.collapsed dl,
.card.collapsed pre,
.card.collapsed .identity-tabs,
.card.collapsed .identity-content,
.card.collapsed .settings-tabs,
.card.collapsed .settings-content,
.card.collapsed .channel-item,
.card.collapsed #detail-channels,
.card.collapsed #detail-resources {
  display: none !important;
}
.card.collapsed .card-header {
  margin-bottom: 0;
}

/* ---- Logs Toolbar ---- */
.logs-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.logs-search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--text-muted);
  transition: all var(--transition);
}
.logs-search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.logs-search-wrap input {
  background: none;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 11px;
  color: var(--text);
  width: 100px;
}
.logs-search-wrap input::placeholder { color: var(--text-muted); }
.logs-match-count {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

#btn-autotail.active {
  color: var(--green);
  background: var(--green-bg);
}

.log-highlight {
  background: var(--yellow-bg);
  color: var(--yellow);
  border-radius: 2px;
  padding: 0 1px;
}

/* ---- Copy Config Modal ---- */
.copy-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.copy-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.copy-option:hover { background: var(--bg-hover); }
.copy-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---- Agent Chat (per-instance) ---- */
.agent-chat-card {
  border: 1px solid var(--accent-glow);
  background: var(--bg-card);
}
.agent-chat-card .card-header h3 {
  color: var(--accent);
}
.agent-chat-card .card-header h3 span {
  color: var(--text);
  font-weight: 700;
}
.agent-chat-messages {
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 0;
  scroll-behavior: smooth;
}
.agent-chat-welcome {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.agent-chat-welcome-icon {
  font-size: 40px;
  margin-bottom: 8px;
  opacity: 0.6;
}
.agent-chat-welcome p {
  font-size: 13px;
  margin: 0;
}
.agent-msg {
  display: flex;
  gap: 10px;
  max-width: 95%;
  animation: messageFadeIn 0.3s ease;
}
.agent-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.agent-msg.agent {
  align-self: flex-start;
}
.agent-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}
.agent-msg.user .agent-msg-avatar {
  background: var(--text-muted);
  color: white;
}
.agent-msg.agent .agent-msg-avatar {
  background: linear-gradient(135deg, var(--green) 0%, #059669 100%);
  color: white;
}
.agent-msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}
.agent-msg.user .agent-msg-bubble {
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  color: var(--accent-text);
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
}
.agent-msg.agent .agent-msg-bubble {
  background: var(--bg-hover);
  color: var(--text);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
  border: 1px solid var(--border-light);
}
.agent-msg-bubble p { margin: 0 0 8px; }
.agent-msg-bubble p:last-child { margin-bottom: 0; }
.agent-msg-bubble pre {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--code-bg);
  padding: 10px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--border-light);
}
.agent-msg-bubble pre code { background: none; padding: 0; }
.agent-msg-bubble code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
}
.agent-msg.user .agent-msg-bubble code { background: rgba(255,255,255,0.2); }
.agent-msg-bubble strong { color: var(--accent); font-weight: 600; }
.agent-msg-bubble a { color: var(--accent); text-decoration: none; }
.agent-msg-bubble a:hover { text-decoration: underline; }
.agent-msg-bubble ul, .agent-msg-bubble ol { margin: 4px 0 8px 18px; }

.agent-chat-typing {
  display: flex;
  gap: 5px;
  padding: 12px 14px;
  align-self: flex-start;
  margin-left: 38px;
}
.agent-chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--green);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}
.agent-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.agent-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

.agent-chat-input-area {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
#agent-chat-input {
  flex: 1;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-hover);
  color: var(--text);
  resize: none;
  max-height: 120px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#agent-chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
#agent-chat-input::placeholder { color: var(--text-muted); }
.agent-chat-input-area .btn-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--green) 0%, #059669 100%);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}
.agent-chat-input-area .btn-send:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}
.agent-chat-input-area .btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.agent-chat-error {
  font-size: 11px;
  color: var(--red);
  padding: 6px 12px;
  background: var(--red-bg, rgba(239, 68, 68, 0.1));
  border-radius: var(--radius-sm);
  margin: 2px 0 2px 38px;
  border-left: 3px solid var(--red);
}

/* ---- Agent/Session Picker ---- */
.agent-chat-picker {
  display: flex; gap: 10px; padding: 6px 0 8px; border-bottom: 1px solid var(--border);
  margin-bottom: 4px; flex-wrap: wrap;
}
.picker-group { display: flex; align-items: center; gap: 6px; }
.picker-group label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; font-weight: 600; white-space: nowrap; }
.picker-group select {
  font-family: var(--font); font-size: 12px; padding: 4px 24px 4px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-hover); color: var(--text); cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: 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='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
  max-width: 200px; min-width: 120px;
}
.picker-group select:focus { outline: none; border-color: var(--accent); }

/* ---- Input Wrap & Hints ---- */
.agent-chat-input-wrap { position: relative; }
.agent-chat-hints {
  display: flex; gap: 12px; padding: 4px 2px 0; flex-wrap: wrap;
  font-size: 10px; color: var(--text-muted); opacity: 0.6;
}
.agent-chat-hints kbd {
  font-family: var(--font-mono); font-size: 9px; padding: 1px 4px;
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: 3px;
}

/* ---- Slash Autocomplete ---- */
.slash-autocomplete {
  position: absolute; bottom: 100%; left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-height: 220px; overflow-y: auto; z-index: 50;
  margin-bottom: 4px;
}
.slash-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  transition: background var(--transition);
}
.slash-item:hover, .slash-item.active {
  background: var(--bg-hover);
}
.slash-item-name { font-weight: 600; color: var(--accent); }
.slash-item-desc { color: var(--text-muted); font-size: 11px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Copy Button ---- */
.agent-msg-bubble { position: relative; }
.msg-copy-btn {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  display: none; align-items: center; justify-content: center;
  font-size: 12px; transition: all var(--transition); z-index: 5;
}
.msg-copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.msg-copy-btn.copied { color: var(--green); border-color: var(--green); }
.agent-msg:hover .msg-copy-btn { display: flex; }
.agent-msg-bubble pre { position: relative; }
.code-copy-btn {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: var(--radius-sm);
  background: var(--bg-hover); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
  display: none; align-items: center; justify-content: center;
  font-size: 11px; transition: all var(--transition);
}
.code-copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.code-copy-btn.copied { color: var(--green); border-color: var(--green); }
.agent-msg-bubble pre:hover .code-copy-btn { display: flex; }

/* ---- Tool Use Blocks ---- */
.agent-tool-use {
  margin: 6px 0 6px 38px; padding: 6px 10px;
  background: var(--bg-hover); border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 11px; color: var(--text-muted);
}
.agent-tool-use summary {
  cursor: pointer; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px; list-style: none;
}
.agent-tool-use summary::-webkit-details-marker { display: none; }
.agent-tool-use summary::before {
  content: ''; width: 0; height: 0;
  border-left: 5px solid var(--text-muted); border-top: 4px solid transparent;
  border-bottom: 4px solid transparent; transition: transform 0.15s;
}
.agent-tool-use[open] summary::before { transform: rotate(90deg); }
.agent-tool-use .tool-detail {
  margin-top: 6px; padding: 6px 8px;
  background: var(--code-bg); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: 11px; white-space: pre-wrap;
  max-height: 150px; overflow-y: auto;
}
.tool-icon { font-size: 13px; }

/* ---- Message Timestamp ---- */
.agent-msg-time {
  font-size: 9px; color: var(--text-muted); opacity: 0;
  transition: opacity 0.2s; margin-top: 2px; align-self: flex-end;
}
.agent-msg:hover .agent-msg-time { opacity: 1; }
.agent-msg.user .agent-msg-time { text-align: right; }

/* ---- Panel Content shared ---- */
.panel-content { font-size: 13px; animation: panelFadeIn 0.2s ease-out; }
.panel-empty-hint {
  text-align: center;
  padding: 32px 20px;
  animation: panelFadeIn 0.3s ease-out;
}
.panel-empty-icon {
  font-size: 28px;
  margin-bottom: 8px;
  opacity: 0.7;
}
.panel-empty-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.panel-empty-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 300px;
  margin: 0 auto;
}
@keyframes panelFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.panel-empty { text-align: center; padding: 24px; color: var(--text-muted); font-style: italic; }
.panel-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.panel-table th { text-align: left; font-weight: 600; color: var(--text-muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.panel-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.panel-table tr:last-child td { border-bottom: none; }
.panel-table tr:hover td { background: var(--bg-hover); }
.panel-actions { display: flex; gap: 4px; }
.panel-add-form { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; padding: 12px 0 4px; border-top: 1px solid var(--border); margin-top: 12px; }
.panel-add-form .form-group { display: flex; flex-direction: column; gap: 4px; }
.panel-add-form .form-group label { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.panel-add-form input, .panel-add-form select { font-size: 12px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-hover); color: var(--text); }
.panel-add-form input:focus, .panel-add-form select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-glow); }

.btn-xs { font-size: 11px; padding: 4px 10px; border-radius: var(--radius-sm); }
.badge-count { background: var(--red); color: white; font-size: 10px; padding: 2px 6px; border-radius: 10px; font-weight: 700; margin-left: 6px; }
.badge-sm { font-size: 10px; padding: 2px 6px; border-radius: var(--radius-sm); font-weight: 600; }
.badge-info { background: var(--accent-glow); color: var(--accent); }
.badge-success { background: var(--green-bg); color: var(--green); }
.badge-warning { background: var(--yellow-bg); color: var(--yellow); }
.badge-danger { background: rgba(239,68,68,.15); color: var(--red); }
.badge-muted { background: var(--bg-hover); color: var(--text-muted); }
.card-header-actions { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.inline-btn { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px 8px; font-size: 11px; color: var(--text-muted); cursor: pointer; transition: all var(--transition); }
.inline-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--accent); }
.inline-btn.danger:hover { border-color: var(--red); color: var(--red); }
.inline-btn.primary { border-color: var(--accent); color: var(--accent); }

/* ---- Sessions Panel ---- */
.session-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); transition: background var(--transition); cursor: pointer; border-radius: var(--radius-sm); }
.session-item:hover { background: var(--bg-hover); }
.session-item:last-child { border-bottom: none; }
.session-key { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--accent); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-meta { display: flex; gap: 8px; font-size: 10px; color: var(--text-muted); flex-shrink: 0; }
.session-detail { padding: 12px; background: var(--bg-hover); border-radius: var(--radius); margin-top: 8px; }
.session-history { max-height: 300px; overflow-y: auto; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 11px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; padding: 8px; }
.session-msg { padding: 4px 0; }
.session-msg.user { color: var(--accent); }
.session-msg.assistant { color: var(--green); }
.session-msg.system { color: var(--text-muted); font-style: italic; }

/* ---- Skills Panel ---- */
.skill-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.skill-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); transition: all var(--transition); }
.skill-item:hover { border-color: var(--accent); background: var(--bg-hover); }
.skill-icon { width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--accent-glow); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.skill-info { flex: 1; min-width: 0; }
.skill-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skill-desc { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skill-install-form { display: flex; gap: 8px; align-items: end; padding: 12px 0 4px; border-top: 1px solid var(--border); margin-top: 12px; flex-wrap: wrap; }

/* ---- Skill Store ---- */
.store-toolbar { display: flex; gap: 12px; align-items: center; padding: 0 16px 12px; flex-wrap: wrap; }
.store-search-wrap { display: flex; align-items: center; gap: 6px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 10px; flex: 1; min-width: 160px; }
.store-search-wrap svg { color: var(--text-muted); flex-shrink: 0; }
.store-search-wrap input { border: none; background: transparent; color: var(--text); font-size: 13px; width: 100%; outline: none; }
.store-filters { display: flex; gap: 4px; flex-shrink: 0; }
.store-filter { background: var(--bg-hover); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: 11px; font-weight: 500; color: var(--text-muted); cursor: pointer; transition: all var(--transition); white-space: nowrap; }
.store-filter:hover { border-color: var(--accent); color: var(--text); }
.store-filter.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.store-summary { display: flex; gap: 16px; padding: 0 16px 10px; font-size: 11px; color: var(--text-muted); flex-wrap: wrap; }
.store-summary .store-stat { display: flex; align-items: center; gap: 4px; }
.store-summary .store-stat-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.store-summary .store-stat-dot.ready { background: var(--green); }
.store-summary .store-stat-dot.setup { background: var(--yellow); }
.store-summary .store-stat-dot.off { background: var(--text-muted); opacity: 0.4; }

.store-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.store-card { display: flex; flex-direction: column; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); transition: all var(--transition); position: relative; }
.store-card:hover { border-color: var(--accent); background: var(--bg-hover); }
.store-card.eligible { border-left: 3px solid var(--green); }
.store-card.needs-setup { border-left: 3px solid var(--yellow); }
.store-card.disabled { border-left: 3px solid var(--text-muted); opacity: 0.65; }
.store-card-top { display: flex; align-items: flex-start; gap: 10px; }
.store-card-icon { width: 36px; height: 36px; border-radius: var(--radius); background: var(--accent-glow); display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.store-card-body { flex: 1; min-width: 0; }
.store-card-name { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.store-card-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.4; }
.store-card-status { margin-top: 8px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.store-card-actions { margin-top: 10px; display: flex; gap: 6px; align-items: center; }
.store-card-actions .btn { font-size: 11px; padding: 4px 10px; }
.store-card-reqs { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.store-card-reqs summary { font-size: 11px; color: var(--text-muted); cursor: pointer; user-select: none; }
.store-card-reqs summary:hover { color: var(--text); }
.store-req-list { list-style: none; padding: 4px 0 0; margin: 0; }
.store-req-list li { font-size: 11px; padding: 2px 0; display: flex; align-items: center; gap: 6px; }
.store-req-list .req-ok { color: var(--green); }
.store-req-list .req-missing { color: var(--red, #e74c3c); }
.store-req-list .req-icon { width: 14px; text-align: center; flex-shrink: 0; }
.store-env-input { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.store-env-input input { font-size: 11px; padding: 3px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); color: var(--text); width: 160px; }
.store-env-input .btn { font-size: 10px; padding: 3px 8px; }
.store-empty { text-align: center; padding: 24px; color: var(--text-muted); font-size: 13px; }
.store-section-header { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.store-section-header .badge-sm { font-weight: 500; }
.explore-sort-select { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 2px 6px; cursor: pointer; }
.store-card.catalog { border-left: 3px solid var(--accent); }
.store-card.catalog .store-card-icon { background: var(--bg-hover); }

/* ---- Multi-Agent Panel ---- */
.agent-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; transition: all var(--transition); }
.agent-item:hover { border-color: var(--accent); background: var(--bg-hover); }
.agent-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-glow); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700; flex-shrink: 0; }
.agent-info { flex: 1; min-width: 0; }
.agent-name { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.agent-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.agent-bindings { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

/* ---- Approvals Panel ---- */
.approval-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; }
.approval-peer { flex: 1; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.approval-channel { font-size: 11px; color: var(--text-muted); }

/* ---- Cron Jobs Panel ---- */
.cron-schedule { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--accent); background: var(--accent-glow); padding: 2px 6px; border-radius: var(--radius-sm); }
.cron-prompt { font-size: 12px; color: var(--text); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Models Panel ---- */
.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.model-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); transition: all var(--transition); }
.model-item:hover { border-color: var(--accent); background: var(--bg-hover); }
.model-item.active { border-color: var(--green); background: var(--green-bg); }
.model-item.missing { opacity: 0.5; border-style: dashed; }
.model-name { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.model-id { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.model-meta { display: flex; gap: 8px; margin-top: 6px; font-size: 10px; color: var(--text-muted); }

/* ---- Resources / Monitoring ---- */
.gauge-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.gauge-item { text-align: center; }
.gauge-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 6px; }
.gauge-bar { height: 8px; background: var(--bg-hover); border-radius: 4px; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.gauge-fill.low { background: var(--green); }
.gauge-fill.medium { background: var(--yellow); }
.gauge-fill.high { background: var(--red); }
.gauge-value { font-size: 16px; font-weight: 700; margin-top: 4px; }
.gauge-detail { font-size: 10px; color: var(--text-muted); }

/* ---- Infrastructure Panel ---- */
.infra-section { margin-bottom: 12px; }
.infra-section-title { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.infra-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 12px; }
.infra-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.infra-dot.green { background: var(--green); }
.infra-dot.yellow { background: var(--yellow); }
.infra-dot.red { background: var(--red); }
.infra-dot.gray { background: var(--text-muted); }

/* ---- Workspace Browser ---- */
.workspace-tree { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.ws-file { display: flex; align-items: center; gap: 8px; padding: 4px 8px; cursor: pointer; border-radius: var(--radius-sm); transition: background var(--transition); }
.ws-file:hover { background: var(--bg-hover); }
.ws-file.active { background: var(--accent-glow); color: var(--accent); }
.ws-file-icon { flex-shrink: 0; color: var(--text-muted); }
.ws-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-file-size { font-size: 10px; color: var(--text-muted); flex-shrink: 0; }
.ws-editor { margin-top: 10px; }
.ws-editor textarea { width: 100%; min-height: 200px; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; line-height: 1.5; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-hover); color: var(--text); resize: vertical; }
.ws-editor textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-glow); }
.ws-editor-actions { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }

/* ---- Memory Search ---- */
.memory-search-wrap { display: flex; gap: 8px; margin-bottom: 12px; }
.memory-search-wrap input { flex: 1; }
.memory-result { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; }
.memory-result-content { font-size: 12px; line-height: 1.5; white-space: pre-wrap; }
.memory-result-meta { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

/* ---- Terminal ---- */
.terminal-mode-toggle { display: flex; gap: 2px; margin-left: auto; background: var(--bg-hover); border-radius: var(--radius-sm); padding: 2px; }
.terminal-mode { background: none; border: none; cursor: pointer; color: var(--text-muted); transition: all var(--transition); border-radius: var(--radius-sm); }
.terminal-mode.active { background: var(--accent); color: white; }
.terminal-output { background: #0d1117; color: #c9d1d9; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; line-height: 1.5; padding: 12px; border-radius: var(--radius); min-height: 150px; max-height: 400px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; margin-bottom: 8px; }
.terminal-input-row { display: flex; gap: 6px; align-items: center; }
.terminal-prompt { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--green); font-weight: 700; }
.terminal-input { flex: 1; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-hover); color: var(--text); }
.terminal-input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-glow); }

/* ---- Deployments Panel ---- */
.deploy-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.deploy-item:last-child { border-bottom: none; }
.deploy-status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.deploy-status-dot.success { background: var(--green); }
.deploy-status-dot.failed { background: var(--red); }
.deploy-status-dot.building { background: var(--yellow); animation: pulse 1.5s infinite; }
.deploy-status-dot.queued { background: var(--text-muted); }
.deploy-info { flex: 1; }
.deploy-status-text { font-size: 12px; font-weight: 600; }
.deploy-time { font-size: 10px; color: var(--text-muted); }

/* ---- Collapsed state for new panels ---- */
.card.collapsed .panel-content,
.card.collapsed .panel-add-form,
.card.collapsed .terminal-mode-toggle,
.card.collapsed .logs-toolbar,
.card.collapsed .card-header-actions,
.card.collapsed .composer-form { display: none !important; }

/* ---- Plugins ---- */
.plugin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.plugin-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); display: flex; align-items: center; gap: 10px; transition: all var(--transition); }
.plugin-item:hover { border-color: var(--accent); background: var(--bg-hover); }
.plugin-item.disabled { opacity: 0.5; }
.plugin-icon { font-size: 20px; min-width: 28px; text-align: center; }
.plugin-info { flex: 1; min-width: 0; }
.plugin-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plugin-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plugin-version { font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); }
.plugin-actions { display: flex; gap: 4px; }

/* ---- Usage & Status ---- */
.usage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.usage-card { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.usage-card h4 { font-size: 12px; color: var(--text-muted); margin: 0 0 8px 0; text-transform: uppercase; letter-spacing: .5px; }
.usage-stat { font-size: 22px; font-weight: 700; color: var(--text); }
.usage-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.channel-probe { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.channel-probe:last-child { border-bottom: none; }
.probe-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.probe-dot.ok { background: var(--green); }
.probe-dot.fail { background: var(--red); }
.probe-dot.warn { background: var(--yellow); }
.probe-name { font-size: 13px; flex: 1; }
.probe-detail { font-size: 11px; color: var(--text-muted); }
.deep-probe-loading { text-align: center; padding: 16px; color: var(--text-muted); }

/* ---- Message Composer ---- */
.composer-form { display: flex; flex-direction: column; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: center; }
.composer-form textarea { font-family: var(--font-mono); font-size: 13px; }

/* ---- Sandbox Policy ---- */
.sandbox-policy { font-family: var(--font-mono); font-size: 12px; white-space: pre-wrap; line-height: 1.5; padding: 8px; background: var(--bg-hover); border-radius: var(--radius); }
.sandbox-policy-grid { display: flex; flex-direction: column; gap: 6px; }
.sandbox-info-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.sandbox-label { color: var(--text-muted); min-width: 140px; font-size: 12px; }

/* ---- Node Devices ---- */
.node-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.node-card { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.node-card:hover { border-color: var(--accent); background: var(--bg-hover); }
.node-name { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.node-type { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.node-caps { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.node-caps .badge-sm { font-size: 9px; }

/* ---- Mobile Responsive ---- */
@media (max-width: 768px) {
  :root {
    --chat-width: 100%;
    --topbar-height: 56px;
  }

  .btn-hamburger { display: flex; }

  .topbar-center { display: none; }

  .logo { font-size: 15px; }

  .btn-chat-toggle span { display: none; }
  .btn-chat-toggle { padding: 8px 10px; }

  /* Sidebar: off-screen left, slides in */
  #sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: 300px;
    min-width: 300px;
    z-index: 90;
    transform: translateX(-100%);
    box-shadow: none;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  body.has-status-bar #sidebar {
    top: calc(var(--topbar-height) + 36px);
  }

  #main-layout {
    flex-direction: column;
  }

  #detail-panel {
    padding: 16px;
    width: 100%;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .detail-title-row h2 {
    font-size: 20px;
  }

  .action-row {
    flex-wrap: wrap;
  }
  .action-row .btn {
    flex: 1;
    min-width: calc(50% - 4px);
    justify-content: center;
    font-size: 12px;
    padding: 8px 10px;
  }

  .chat-drawer {
    right: -100%;
    width: 100%;
  }
  .chat-hints { display: none; }
  #chat-input { font-size: 16px; }
  .drawer-msg-copy { display: flex; opacity: 0.5; }
  .drawer-code-copy { display: flex; opacity: 0.5; }

  .modal {
    width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: var(--radius-lg);
  }

  #toast-container {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }
  .toast { max-width: 100%; }

  /* Settings responsive */
  .settings-row {
    flex-direction: column;
    gap: 6px;
  }
  .settings-row label {
    width: auto;
    padding-top: 0;
  }
  .settings-row .settings-input-wrap {
    max-width: 100%;
  }

  .add-row {
    flex-direction: column;
    align-items: stretch;
  }
  .add-row input,
  .add-row select {
    width: 100% !important;
  }

  .env-table .env-value {
    max-width: 120px;
  }
  .env-edit-inline {
    flex-wrap: wrap;
  }
  .env-edit-input {
    width: 100%;
  }
  .env-search-wrap {
    margin-bottom: 8px;
  }

  /* Identity tabs scroll */
  .identity-tabs,
  .settings-tabs {
    gap: 0;
  }
  .identity-tab,
  .settings-tab {
    padding: 8px 10px;
    font-size: 10px;
  }

  /* Cards animation - faster on mobile */
  .card {
    animation-duration: 0.25s;
  }

  /* Agent chat mobile */
  .agent-chat-card { border-radius: var(--radius) !important; }
  .agent-chat-picker { gap: 6px; }
  .picker-group { flex: 1; min-width: 0; }
  .picker-group select { min-width: 0; width: 100%; max-width: none; font-size: 13px; padding: 6px 24px 6px 8px; }
  .agent-chat-messages { max-height: 60vh; min-height: 150px; }
  .agent-msg { max-width: 98%; }
  .agent-msg-avatar { width: 24px; height: 24px; font-size: 9px; }
  .agent-msg-bubble { padding: 8px 10px; font-size: 13px; }
  .agent-tool-use { margin-left: 32px; }
  #agent-chat-input { font-size: 16px; padding: 10px 12px; }
  .agent-chat-hints { display: none; }
  .slash-autocomplete { max-height: 180px; }
  .slash-item { padding: 10px 12px; }
  .msg-copy-btn { display: flex; opacity: 0.5; }
  .code-copy-btn { display: flex; opacity: 0.5; }

  /* Skill store mobile */
  .store-toolbar { flex-direction: column; gap: 8px; }
  .store-filters { flex-wrap: wrap; }
  .store-grid { grid-template-columns: 1fr; }
  .store-card-icon { width: 30px; height: 30px; font-size: 16px; }
  .store-env-input { flex-direction: column; align-items: stretch; }
  .store-env-input input { width: 100%; }

  /* Card tab bar mobile */
  .card-tab-bar { padding: 0 0 10px; }
  .card-tab { padding: 5px 10px; font-size: 10px; }
  .card-tab-group-label { font-size: 8px; padding: 4px 4px 4px 1px; }

  /* Sidebar enhancements mobile */
  .instance-fav { opacity: 0.3; }
  .instance-model { font-size: 9px; max-width: 80px; }

  /* Notification center mobile */
  .notif-dropdown { right: 4px; width: calc(100vw - 8px); max-width: 400px; }

  /* Suggestion chips mobile */
  .suggestion-chips { padding: 4px 12px; max-height: 36px; }
  .suggestion-chip { font-size: 10px; padding: 3px 8px; }

  /* Background blobs smaller on mobile */
  .bg-blob-1 { width: 300px; height: 300px; }
  .bg-blob-2 { width: 250px; height: 250px; }
  .bg-blob-3 { width: 200px; height: 200px; }

  /* ---- Global overflow containment ---- */
  #detail-panel { overflow-x: hidden; min-width: 0; }
  .card { min-width: 0; overflow: hidden; }
  .detail-grid { grid-template-columns: 1fr; }

  /* ---- Long text / URL / key overflow ---- */
  .usage-sub, .usage-stat { word-break: break-word; overflow-wrap: anywhere; }
  .session-key { white-space: normal; word-break: break-all; }
  .env-table .env-key { word-break: break-all; }
  .env-table .env-value { max-width: none; white-space: normal; word-break: break-all; }
  .terminal-output { word-break: break-word; }
  .sandbox-policy { word-break: break-word; }
  .cron-prompt { max-width: none; white-space: normal; word-break: break-word; }
  .plugin-name, .plugin-desc { white-space: normal; }
  .ws-file-name { white-space: normal; word-break: break-all; }

  /* ---- Env table responsive ---- */
  .env-table { display: block; }
  .env-table thead { display: none; }
  .env-table tbody { display: block; }
  .env-table tr {
    display: flex;
    flex-wrap: wrap;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-light);
    gap: 4px;
    align-items: center;
  }
  .env-table td {
    padding: 2px 4px;
    border-bottom: none;
  }
  .env-table .env-key { width: 100%; font-size: 11px; }
  .env-table .env-value { width: 100%; font-size: 11px; }
  .env-table .env-actions { margin-left: auto; }

  /* ---- Channel list item wrapping ---- */
  .channel-list-item {
    flex-wrap: wrap;
    gap: 6px;
  }
  .channel-list-item .channel-policy {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  /* ---- Usage grid: narrower min ---- */
  .usage-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

  /* ---- Store section header: sort wraps ---- */
  .store-section-header { flex-wrap: wrap; }
  .explore-sort-select { min-width: 0; }

  /* ---- Skill install form ---- */
  .skill-install-form { flex-direction: column; align-items: stretch; }
  .skill-install-form input { width: 100% !important; }

  /* ---- Modal content: pre/code overflow ---- */
  .modal pre, .modal code {
    overflow-x: auto;
    max-width: 100%;
    word-break: break-word;
    white-space: pre-wrap;
  }
  .modal-body { overflow-x: hidden; }
  #result-modal-content { word-break: break-word; }

  /* ---- Settings group labels ---- */
  .settings-group-label { word-break: break-word; }

  /* ---- Badges wrapping ---- */
  .detail-badges { flex-wrap: wrap; }
  .store-card-status { flex-wrap: wrap; }

  /* ---- Memory search results ---- */
  .memory-result-content { word-break: break-word; overflow-wrap: anywhere; }

  /* ---- Node / infrastructure items ---- */
  .node-item, .webhook-item { flex-wrap: wrap; min-width: 0; }
  .node-item * , .webhook-item * { min-width: 0; }
}

/* Small phones */
@media (max-width: 400px) {
  #detail-panel { padding: 12px; }

  .card { padding: 16px; border-radius: var(--radius); }

  .action-row .btn {
    min-width: 100%;
  }

  .detail-title-row { gap: 8px; }

  .modal-body { padding: 16px; }
  .modal-header { padding: 16px; }
  .modal-footer { padding: 12px 16px; }

  /* Hide tab group labels and separators on small phones */
  .card-tab-group-label,
  .card-tab-separator { display: none; }

  /* Hide model pill on small phones */
  .instance-model { display: none; }

  /* Usage grid single column on small phones */
  .usage-grid { grid-template-columns: 1fr; }

  /* Channel items stack on small phones */
  .channel-list-item {
    flex-wrap: wrap;
    gap: 6px;
  }
  .channel-list-item .channel-type { min-width: auto; }
  .channel-list-item .channel-policy { min-width: 100%; order: 10; font-size: 10px; }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }
  #detail-panel {
    padding: 20px 24px;
  }
  .detail-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}

/* Large screens */
@media (min-width: 1400px) {
  :root {
    --sidebar-width: 300px;
  }
  #detail-panel {
    padding: 32px 40px;
  }
}

/* ============================================================
   Discord Components v2 Builder
   ============================================================ */

.component-builder-wrap {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-hover);
  padding: 14px;
}

.component-section {
  margin-bottom: 16px;
}
.component-section:last-child {
  margin-bottom: 0;
}

.component-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.component-section-header .btn {
  font-size: 11px;
  padding: 2px 8px;
}

.component-block {
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-card);
  padding: 10px;
  margin-bottom: 8px;
}

.component-block-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.component-block-type {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.component-block-header .btn-icon {
  width: 22px;
  height: 22px;
  font-size: 12px;
  border-radius: 4px;
}

.component-block-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.component-button-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.component-button-row .form-input {
  font-size: 12px;
  padding: 4px 8px;
}
.component-button-row select.form-input {
  width: 110px;
}

.component-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 16px 0;
}

.component-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.component-templates {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.component-templates .btn {
  font-size: 11px;
  padding: 3px 10px;
}

/* ---- Preview ---- */

.component-preview-wrap {
  margin-top: 12px;
}

.component-preview-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}
.component-preview-tabs .btn {
  font-size: 11px;
  padding: 3px 10px;
}
.component-preview-tabs .btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

.component-preview {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  min-height: 80px;
  padding: 12px;
}

.component-json {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11px;
  background: var(--bg-hover);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Discord-style preview */
.discord-preview {
  padding: 10px 12px;
  border-radius: 6px;
}
.discord-preview.has-accent {
  border-left: 4px solid var(--discord-accent, var(--accent));
  padding-left: 12px;
}

.discord-text-block {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 8px;
  white-space: pre-wrap;
}

.discord-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.discord-btn {
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: default;
  display: inline-flex;
  align-items: center;
  color: #fff;
}
.discord-btn-primary { background: #5865F2; }
.discord-btn-success { background: #3BA55D; }
.discord-btn-danger { background: #ED4245; }
.discord-btn-secondary { background: #4E5058; }
.discord-btn-link {
  background: transparent;
  color: #00AFF4;
  text-decoration: underline;
  padding: 6px 8px;
}

.discord-separator {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.discord-media-item {
  font-size: 12px;
  color: var(--accent);
  word-break: break-all;
}

.discord-section {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 8px;
  padding: 6px 0;
}

.discord-file-block {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-hover);
  border-radius: 4px;
  padding: 6px 10px;
  margin-bottom: 8px;
}

/* ---- Block type picker ---- */

.block-type-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.block-type-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-hover);
  padding: 12px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.block-type-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

/* ---- Select menu builder ---- */
.component-select-option-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.component-select-option-row .form-input {
  font-size: 12px;
  padding: 4px 8px;
}

/* ---- Mobile responsive ---- */

@media (max-width: 768px) {
  .component-button-row {
    flex-wrap: wrap;
  }
  .block-type-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 400px) {
  .component-section-header {
    font-size: 10px;
  }
  .component-templates {
    flex-wrap: wrap;
  }
  .block-type-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---- Kanban Activity Board ---- */
.kanban-board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  min-height: 200px;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.kanban-column {
  display: flex;
  flex-direction: column;
  min-width: 180px;
  flex: 1;
  background: var(--bg-hover);
  border-radius: var(--radius);
  padding: 10px;
  gap: 8px;
  overflow: hidden;
}
.kanban-col-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-left: 3px solid var(--text-muted);
}
.kanban-col-header .kanban-count {
  font-size: 10px;
  font-weight: 700;
  background: var(--bg-active);
  color: var(--text-muted);
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.kanban-item {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  transition: all var(--transition);
}
.kanban-item:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.kanban-item-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.kanban-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.kanban-kind {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--purple-bg);
  color: var(--purple);
}
.kanban-model {
  font-size: 10px;
  background: var(--bg-hover);
  padding: 1px 6px;
  border-radius: 8px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kanban-aborted {
  color: var(--red);
  font-size: 11px;
  font-weight: 600;
}
.kanban-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 60px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  opacity: 0.6;
}
.kanban-item-extra { font-size: 10px; color: var(--text-muted); margin-top: 2px; display: flex; gap: 6px; }
/* Session detail modal content */
.kanban-detail-info {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}
.kanban-detail-info code { font-family: var(--mono); font-size: 10px; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.kanban-detail-chat {
  max-height: 400px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 10px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  scrollbar-width: thin;
}
.kanban-detail-chat .session-msg { padding: 4px 0; }
.kanban-detail-chat .session-msg.user { color: var(--accent); }
.kanban-detail-chat .session-msg.assistant { color: var(--green); }
.kanban-detail-chat .session-msg.system { color: var(--text-muted); font-style: italic; }
.kanban-detail-empty { color: var(--text-muted); font-size: 12px; font-style: italic; padding: 20px 0; text-align: center; }
.session-modal-footer { display: flex; gap: 8px; align-items: center; }
.session-modal-footer .form-input { flex: 1; }
@media (max-width: 768px) {
  .kanban-board {
    flex-direction: column;
  }
  .kanban-column {
    min-width: unset;
  }
}
