/* ================================================================
   MAP Dashboard v3.0 — World-Class Design System
   Inspired by Linear / Vercel / Raycast
   ================================================================ */

/* --- CSS Reset + Design Tokens --- */
:root {
  --bg-base: #09090b;
  --bg-surface: rgba(17, 17, 19, 0.7);
  --bg-elevated: #18181b;
  --bg-muted: #1e1e22;
  --bg-hover: #27272a;
  --bg-glass: rgba(17, 17, 19, 0.55);
  --border: rgba(39, 39, 42, 0.8);
  --border-subtle: rgba(30, 30, 34, 0.6);
  --border-glow: rgba(99, 102, 241, 0.25);
  --ring: rgba(99, 102, 241, 0.35);

  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-bg: rgba(99, 102, 241, 0.1);
  --primary-glow: rgba(99, 102, 241, 0.15);
  --gradient-primary: linear-gradient(135deg, #818cf8, #6366f1);
  --gradient-accent: linear-gradient(135deg, #a78bfa, #818cf8, #6366f1);

  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.1);
  --green-glow: rgba(52, 211, 153, 0.2);
  --amber: #fbbf24;
  --amber-bg: rgba(251, 191, 36, 0.1);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.1);
  --red-glow: rgba(248, 113, 113, 0.2);
  --blue: #60a5fa;
  --blue-bg: rgba(96, 165, 250, 0.1);

  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #52525b;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.45);
  --shadow-glow: 0 0 20px rgba(99,102,241,.1);
  --shadow-card: 0 1px 3px rgba(0,0,0,.3), 0 0 0 1px rgba(39,39,42,.5);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

  --header-h: 56px;
  --nav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh; min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(99,102,241,.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 90%, rgba(52,211,153,.04) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 50% 50%, rgba(168,85,247,.03) 0%, transparent 50%);
  pointer-events: none;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea { font-family: inherit; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3f3f46; }

/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideRight { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
@keyframes glowPulse { 0%, 100% { box-shadow: 0 0 8px var(--primary-glow); } 50% { box-shadow: 0 0 20px var(--primary-glow); } }
@keyframes borderGlow { 0%, 100% { border-color: var(--border); } 50% { border-color: var(--border-glow); } }
@keyframes countUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-8px); } }
@keyframes ringProgress { from { stroke-dashoffset: var(--ring-circumference); } }

.stagger-enter { animation: fadeInUp var(--duration-slow) var(--ease-out-expo) both; }
.stagger-enter:nth-child(1) { animation-delay: 0ms; }
.stagger-enter:nth-child(2) { animation-delay: 50ms; }
.stagger-enter:nth-child(3) { animation-delay: 100ms; }
.stagger-enter:nth-child(4) { animation-delay: 150ms; }
.stagger-enter:nth-child(5) { animation-delay: 200ms; }
.stagger-enter:nth-child(6) { animation-delay: 250ms; }
.stagger-enter:nth-child(7) { animation-delay: 300ms; }
.stagger-enter:nth-child(8) { animation-delay: 350ms; }

/* --- App Shell --- */
#app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

/* --- Login Page --- */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; padding: var(--space-xl);
  position: relative; overflow: hidden;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-3xl) var(--space-2xl);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  animation: scaleIn var(--duration-slow) var(--ease-out-expo);
  position: relative;
}
.login-card::before {
  content: '';
  position: absolute; inset: -1px;
  border-radius: calc(var(--radius-xl) + 1px);
  background: linear-gradient(135deg, rgba(99,102,241,.3), transparent 40%, transparent 60%, rgba(52,211,153,.2));
  z-index: -1;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude; -webkit-mask-composite: xor;
  padding: 1px;
}
.login-logo { text-align: center; margin-bottom: var(--space-2xl); }
.login-logo h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.5px; }
.login-logo h1 span {
  background: var(--gradient-accent);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.login-logo p { color: var(--text-muted); font-size: 0.85rem; margin-top: var(--space-sm); letter-spacing: 0.3px; }

.form-group { margin-bottom: var(--space-lg); }
.form-group label {
  display: block; font-size: 0.78rem; font-weight: 600;
  color: var(--text-secondary); margin-bottom: var(--space-sm); letter-spacing: 0.3px;
}
.form-input {
  width: 100%; padding: 11px 14px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-md); color: var(--text); font-size: 0.9rem;
  transition: all var(--duration-fast) ease; outline: none;
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring), var(--shadow-glow);
  background: var(--bg-muted);
}
.form-input::placeholder { color: var(--text-muted); }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; font-size: 0.88rem; font-weight: 600;
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) ease;
  position: relative; overflow: hidden;
}
.btn::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.1), transparent);
  opacity: 0; transition: opacity var(--duration-fast);
}
.btn:hover::after { opacity: 1; }

.btn-primary { width: 100%; background: var(--gradient-primary); color: #fff; box-shadow: 0 2px 8px rgba(99,102,241,.3); }
.btn-primary:hover { box-shadow: 0 4px 16px rgba(99,102,241,.4); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0) scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-success { background: linear-gradient(135deg, #34d399, #10b981); color: #000; font-weight: 700; }
.btn-success:hover { box-shadow: 0 4px 16px var(--green-glow); }
.btn-danger { background: linear-gradient(135deg, #f87171, #ef4444); color: #fff; }
.btn-danger:hover { box-shadow: 0 4px 16px var(--red-glow); }
.btn-outline { border: 1px solid var(--border); color: var(--text-secondary); background: transparent; }
.btn-outline:hover { background: var(--bg-hover); color: var(--text); border-color: var(--text-muted); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; border-radius: var(--radius-sm); }
.btn-xs { padding: 4px 10px; font-size: 0.75rem; border-radius: var(--radius-sm); }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); color: var(--text-muted); }
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

.login-error { color: var(--red); font-size: 0.85rem; text-align: center; margin-bottom: var(--space-md); min-height: 1.3em; }

/* --- Top Header --- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h); padding: 0 var(--space-xl);
  background: rgba(9,9,11,.75);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border-subtle);
}
.header-left { display: flex; align-items: center; gap: var(--space-lg); }
.header-brand { font-size: 1rem; font-weight: 700; letter-spacing: -0.3px; display: flex; align-items: center; gap: 6px; }
.header-brand span {
  background: var(--gradient-accent);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.header-right { display: flex; align-items: center; gap: var(--space-md); }

.cmdk-trigger {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: 5px 12px; border-radius: var(--radius-sm);
  background: var(--bg-muted); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.8rem;
  cursor: pointer; transition: all var(--duration-fast); min-width: 180px;
}
.cmdk-trigger:hover { border-color: var(--text-muted); color: var(--text-secondary); }
.cmdk-trigger .cmdk-icon { opacity: 0.5; }
.cmdk-trigger .cmdk-label { flex: 1; }
.cmdk-trigger kbd {
  font-family: var(--font-sans); font-size: 0.65rem; font-weight: 600;
  padding: 2px 5px; border-radius: 4px;
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-muted);
}

.connection-indicator { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--text-muted); }
.connection-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 6px var(--green-glow);
  animation: breathe 3s ease-in-out infinite;
}
.connection-dot.offline { background: var(--red); box-shadow: 0 0 6px var(--red-glow); animation: none; }

.header-user { display: flex; align-items: center; gap: var(--space-sm); color: var(--text-secondary); font-size: 0.85rem; }
.header-avatar {
  width: 30px; height: 30px; border-radius: var(--radius-full);
  background: var(--primary-bg); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
  border: 1px solid rgba(99,102,241,.2);
}

/* --- Main Content --- */
.app-body {
  flex: 1; padding: var(--space-xl) var(--space-lg);
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--space-xl));
  max-width: 1080px; margin: 0 auto; width: 100%;
}
.tab-content { animation: fadeInUp var(--duration-normal) var(--ease-out-expo); }

/* --- Bottom Navigation (mobile) --- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(9,9,11,.88);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-top: 1px solid var(--border-subtle);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 16px; border-radius: var(--radius-md);
  color: var(--text-muted); font-size: 0.65rem; font-weight: 500;
  transition: all var(--duration-fast); position: relative;
  -webkit-tap-highlight-color: transparent;
}
.nav-item svg { width: 22px; height: 22px; transition: transform var(--duration-fast) var(--ease-spring); }
.nav-item.active { color: var(--primary); }
.nav-item.active svg { transform: scale(1.1); }
.nav-item:active { transform: scale(0.9); }
.nav-badge {
  position: absolute; top: 2px; right: 8px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--red); color: #fff;
  font-size: 0.6rem; font-weight: 700;
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center; line-height: 1;
  animation: breathe 2s ease-in-out infinite;
}

/* --- Page --- */
.page-title {
  font-size: 1.35rem; font-weight: 800; letter-spacing: -0.5px;
  margin-bottom: var(--space-xl);
}

/* --- Stat Cards --- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-md); margin-bottom: var(--space-xl); }
.stat-card {
  background: var(--bg-glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-xl) var(--space-lg);
  cursor: pointer; transition: all var(--duration-normal) var(--ease-out-expo);
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--gradient-primary); opacity: 0; transition: opacity var(--duration-normal);
}
.stat-card:hover { border-color: var(--border-glow); transform: translateY(-2px); box-shadow: var(--shadow-md), var(--shadow-glow); }
.stat-card:hover::before { opacity: 1; }
.stat-card:active { transform: translateY(0) scale(0.98); }
.stat-label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: var(--space-sm); }
.stat-value { font-size: 2rem; font-weight: 800; letter-spacing: -1.5px; line-height: 1.1; }
.stat-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: var(--space-xs); display: flex; align-items: center; gap: 4px; }

/* --- Entity Cards --- */
.entity-list { display: flex; flex-direction: column; gap: var(--space-md); }
.entity-card {
  background: var(--bg-glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--space-lg); transition: all var(--duration-normal) var(--ease-out-expo); cursor: pointer;
}
.entity-card:hover { border-color: var(--border-glow); box-shadow: var(--shadow-sm), 0 0 12px var(--primary-glow); transform: translateY(-1px); }
.entity-card:active { transform: translateY(0) scale(0.995); }
.entity-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: var(--space-sm); }
.entity-title { font-size: 0.92rem; font-weight: 600; line-height: 1.3; flex: 1; min-width: 0; }
.entity-id { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }
.entity-meta { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin-top: var(--space-sm); align-items: center; }

/* --- Badges --- */
.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: var(--radius-full); font-size: 0.7rem; font-weight: 600; line-height: 1.6; letter-spacing: 0.2px; }
.badge-primary { background: var(--primary-bg); color: var(--primary); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-muted { background: var(--bg-muted); color: var(--text-muted); }

/* --- Dots --- */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; flex-shrink: 0; }
.dot-green { background: var(--green); box-shadow: 0 0 8px var(--green-glow); }
.dot-amber { background: var(--amber); box-shadow: 0 0 6px rgba(251,191,36,.3); }
.dot-red { background: var(--red); box-shadow: 0 0 8px var(--red-glow); }
.dot-muted { background: var(--text-muted); }

/* --- Service Health Grid --- */
.service-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-md); margin-bottom: var(--space-xl); }
.service-card {
  background: var(--bg-glass); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--space-lg); display: flex; align-items: center; gap: var(--space-md);
  transition: all var(--duration-normal) var(--ease-out-expo);
}
.service-card:hover { border-color: var(--border-glow); }
.service-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; font-size: 0.9rem;
}
.service-icon.ok { background: var(--green-bg); }
.service-icon.err { background: var(--red-bg); }
.service-icon.unknown { background: var(--bg-muted); }
.service-info { flex: 1; }
.service-name { font-size: 0.82rem; font-weight: 600; display: block; }
.service-port { font-size: 0.7rem; color: var(--text-muted); font-family: var(--font-mono); }

/* --- Quick Actions --- */
.quick-actions { display: flex; gap: var(--space-md); flex-wrap: wrap; margin-bottom: var(--space-xl); }
.action-btn {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: 10px 18px; border-radius: var(--radius-md);
  background: var(--bg-glass); backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 0.85rem; font-weight: 500;
  transition: all var(--duration-normal) var(--ease-out-expo); cursor: pointer;
}
.action-btn:hover { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 16px var(--primary-glow); transform: translateY(-1px); }
.action-btn:active { transform: translateY(0) scale(0.97); }

/* --- Approval Cards --- */
.approval-card {
  background: var(--bg-glass); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--space-xl); margin-bottom: var(--space-md);
  transition: border-color var(--duration-normal);
}
.approval-card.urgent { border-left: 3px solid var(--red); animation: borderGlow 3s ease-in-out infinite; }
.approval-card.info { border-left: 3px solid var(--amber); }
.approval-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-md); }
.approval-type { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.approval-time { font-size: 0.75rem; color: var(--text-muted); }
.approval-body { margin-bottom: var(--space-lg); }
.approval-tool { font-family: var(--font-mono); font-size: 0.85rem; color: var(--primary); margin-bottom: var(--space-sm); }
.approval-args {
  background: var(--bg-elevated); border-radius: var(--radius-sm);
  padding: var(--space-md); font-family: var(--font-mono);
  font-size: 0.78rem; color: var(--text-secondary);
  white-space: pre-wrap; word-break: break-all;
  max-height: 120px; overflow-y: auto; border: 1px solid var(--border-subtle);
}
.approval-actions { display: flex; gap: var(--space-md); }
.approval-actions .btn { flex: 1; }
.approval-reason-input {
  width: 100%; margin-bottom: var(--space-md); padding: 10px 14px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 0.85rem;
  outline: none; resize: vertical; min-height: 56px;
  transition: all var(--duration-fast);
}
.approval-reason-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }

/* --- Section headers --- */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-lg); }
.section-title { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); }

/* --- Filter Chips --- */
.chip-row { display: flex; gap: var(--space-sm); overflow-x: auto; padding-bottom: var(--space-sm); margin-bottom: var(--space-lg); scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 6px 16px; border-radius: var(--radius-full);
  font-size: 0.8rem; font-weight: 500;
  background: var(--bg-muted); color: var(--text-muted);
  border: 1px solid transparent; transition: all var(--duration-fast);
}
.chip.active { background: var(--primary-bg); color: var(--primary); border-color: rgba(99,102,241,.3); box-shadow: 0 0 12px var(--primary-glow); }
.chip:hover:not(.active) { color: var(--text-secondary); background: var(--bg-hover); }
.chip:active { transform: scale(0.95); }

/* --- Empty State --- */
.empty-state { text-align: center; padding: var(--space-3xl) var(--space-lg); color: var(--text-muted); }
.empty-state svg { width: 56px; height: 56px; margin-bottom: var(--space-lg); opacity: 0.3; }
.empty-state p { font-size: 0.9rem; }

/* --- Loading --- */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .6s linear infinite; }
.loading-center { display: flex; align-items: center; justify-content: center; padding: var(--space-3xl); gap: var(--space-md); color: var(--text-muted); font-size: 0.85rem; }
.skeleton { background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-hover) 37%, var(--bg-muted) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }

/* --- Detail Panel --- */
.detail-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); animation: fadeIn var(--duration-fast) ease; }
.detail-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 101;
  max-height: 85vh; overflow-y: auto;
  background: var(--bg-elevated);
  border-top-left-radius: var(--radius-xl); border-top-right-radius: var(--radius-xl);
  padding: var(--space-xl) var(--space-lg);
  padding-bottom: calc(var(--space-xl) + var(--safe-bottom));
  animation: slideUp var(--duration-normal) var(--ease-out-expo);
  box-shadow: 0 -8px 40px rgba(0,0,0,.5);
}
.detail-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--text-muted); margin: 0 auto var(--space-lg); opacity: 0.4; }
.detail-title { font-size: 1.15rem; font-weight: 700; margin-bottom: var(--space-lg); }

/* --- Timeline --- */
.timeline { padding-left: var(--space-lg); border-left: 2px solid var(--border); }
.timeline-item { position: relative; padding-bottom: var(--space-lg); padding-left: var(--space-lg); }
.timeline-item::before {
  content: ''; position: absolute; left: calc(-1 * var(--space-lg) - 5px); top: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--bg-elevated);
  box-shadow: 0 0 6px var(--primary-glow);
}
.timeline-time { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 2px; }
.timeline-text { font-size: 0.85rem; color: var(--text-secondary); }

/* --- Toast --- */
.toast-container {
  position: fixed; top: calc(var(--header-h) + var(--space-lg)); right: var(--space-lg);
  z-index: 200; display: flex; flex-direction: column; gap: var(--space-sm); pointer-events: none;
}
.toast {
  padding: 12px 20px; border-radius: var(--radius-md);
  font-size: 0.85rem; font-weight: 500; box-shadow: var(--shadow-lg);
  animation: fadeInDown var(--duration-normal) var(--ease-out-expo), fadeOut var(--duration-normal) ease 2.7s forwards;
  pointer-events: auto; display: flex; align-items: center; gap: var(--space-sm);
  backdrop-filter: blur(12px);
}
.toast-success { background: rgba(52,211,153,.9); color: #000; }
.toast-error { background: rgba(248,113,113,.9); color: #fff; }
.toast-info { background: rgba(99,102,241,.9); color: #fff; }

/* --- Command Palette --- */
.cmdk-overlay { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.6); backdrop-filter: blur(8px); animation: fadeIn 120ms ease; }
.cmdk-dialog {
  position: fixed; top: 20%; left: 50%; transform: translateX(-50%);
  width: 90%; max-width: 560px; z-index: 301;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 60px rgba(99,102,241,.1);
  animation: scaleIn 180ms var(--ease-out-expo); overflow: hidden;
}
.cmdk-input-wrap {
  display: flex; align-items: center; gap: var(--space-md);
  padding: var(--space-lg) var(--space-xl); border-bottom: 1px solid var(--border);
}
.cmdk-input-wrap svg { color: var(--text-muted); flex-shrink: 0; }
.cmdk-input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 1rem; font-family: var(--font-sans);
}
.cmdk-input::placeholder { color: var(--text-muted); }
.cmdk-results { max-height: 340px; overflow-y: auto; padding: var(--space-sm) 0; }
.cmdk-group-label {
  padding: var(--space-sm) var(--space-xl);
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-muted);
}
.cmdk-item {
  display: flex; align-items: center; gap: var(--space-md);
  padding: 10px var(--space-xl);
  font-size: 0.88rem; color: var(--text-secondary);
  cursor: pointer; transition: all 80ms;
}
.cmdk-item:hover, .cmdk-item.selected { background: var(--primary-bg); color: var(--text); }
.cmdk-item .cmdk-item-icon { width: 20px; text-align: center; opacity: 0.6; }
.cmdk-item .cmdk-item-label { flex: 1; }
.cmdk-item kbd {
  font-family: var(--font-sans); font-size: 0.65rem;
  padding: 2px 6px; border-radius: 4px;
  background: var(--bg-muted); border: 1px solid var(--border); color: var(--text-muted);
}
.cmdk-footer {
  display: flex; align-items: center; gap: var(--space-lg);
  padding: var(--space-md) var(--space-xl); border-top: 1px solid var(--border);
  font-size: 0.7rem; color: var(--text-muted);
}
.cmdk-footer kbd {
  font-family: var(--font-sans); font-size: 0.6rem;
  padding: 1px 4px; border-radius: 3px;
  background: var(--bg-muted); border: 1px solid var(--border);
}

/* --- Activity Feed --- */
.activity-feed { margin-bottom: var(--space-xl); }
.activity-item {
  display: flex; align-items: center; gap: var(--space-md);
  padding: var(--space-md) 0; border-bottom: 1px solid var(--border-subtle);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.activity-dot.green { background: var(--green); box-shadow: 0 0 6px var(--green-glow); }
.activity-dot.amber { background: var(--amber); }
.activity-dot.red { background: var(--red); box-shadow: 0 0 6px var(--red-glow); }
.activity-dot.blue { background: var(--blue); }
.activity-content { flex: 1; min-width: 0; }
.activity-text { font-size: 0.85rem; color: var(--text-secondary); }
.activity-text strong { color: var(--text); font-weight: 600; }
.activity-time { font-size: 0.72rem; color: var(--text-muted); flex-shrink: 0; }

/* --- Health Gauge Ring --- */
.health-gauge { width: 72px; height: 72px; position: relative; }
.health-gauge svg { transform: rotate(-90deg); }
.health-gauge .gauge-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
}

/* --- Responsive --- */
@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .app-body { padding: var(--space-xl) var(--space-2xl); padding-bottom: var(--space-xl); }
  .bottom-nav { display: none; }
  .app-header { padding: 0 var(--space-2xl); }

  .desktop-nav { display: flex !important; gap: 2px; }
  .desktop-nav .nav-link {
    padding: 7px 16px; border-radius: var(--radius-sm);
    font-size: 0.85rem; font-weight: 500;
    color: var(--text-muted); transition: all var(--duration-fast); position: relative;
  }
  .desktop-nav .nav-link.active { color: var(--text); background: var(--bg-hover); }
  .desktop-nav .nav-link.active::after {
    content: ''; position: absolute; bottom: -1px; left: 50%; transform: translateX(-50%);
    width: 16px; height: 2px; border-radius: 1px; background: var(--primary);
  }
  .desktop-nav .nav-link:hover:not(.active) { color: var(--text-secondary); background: var(--bg-muted); }

  .service-grid { grid-template-columns: repeat(5, 1fr); }

  .detail-panel {
    right: 0; left: auto; top: 0; bottom: 0;
    max-height: none; width: 420px;
    border-radius: 0; border-left: 1px solid var(--border);
    animation: slideRight var(--duration-normal) var(--ease-out-expo);
  }
  .detail-handle { display: none; }
}
@media (max-width: 767px) {
  .desktop-nav { display: none !important; }
  .cmdk-trigger { display: none; }
  .service-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1200px) { .app-body { max-width: 1200px; } }

/* ================================================================
   Chat Tab — Split Layout
   ================================================================ */
.chat-tab { display: flex; flex-direction: column; height: calc(100vh - var(--header-h) - 80px); min-height: 400px; }
.chat-layout { display: flex; flex: 1; gap: 0; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-surface); }

/* --- Chat Sidebar --- */
.chat-sidebar {
  width: 280px; min-width: 240px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
}
.chat-sidebar-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem; font-weight: 600; color: var(--text-secondary);
  letter-spacing: 0.3px; text-transform: uppercase;
}
.chat-agent-list { flex: 1; overflow-y: auto; padding: var(--space-xs) 0; }
.chat-agent-item {
  display: flex; align-items: center; gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  cursor: pointer; transition: background var(--duration-fast);
  border-left: 3px solid transparent;
}
.chat-agent-item:hover { background: var(--bg-hover); }
.chat-agent-item.active {
  background: var(--primary-bg);
  border-left-color: var(--primary);
}
.chat-agent-avatar {
  position: relative; width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full);
  background: var(--bg-muted); font-size: 1rem;
}
.chat-agent-avatar .status-dot {
  position: absolute; bottom: 0; right: 0;
  width: 10px; height: 10px; border-radius: var(--radius-full);
  border: 2px solid var(--bg-elevated);
}
.chat-agent-avatar .status-dot.online { background: var(--green); }
.chat-agent-avatar .status-dot.offline { background: var(--text-muted); }
.chat-agent-info { flex: 1; min-width: 0; }
.chat-agent-name {
  font-size: 0.88rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-agent-role {
  font-size: 0.75rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-unread-badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  background: var(--red); color: #fff;
  font-size: 0.7rem; font-weight: 700;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

/* --- Chat Window --- */
.chat-window { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-window-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.chat-window-header .agent-info { display: flex; align-items: center; gap: var(--space-md); }
.chat-window-header .agent-name { font-size: 0.95rem; font-weight: 700; }
.chat-window-header .agent-status {
  font-size: 0.75rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 4px;
}
.chat-window-header .agent-status .dot {
  width: 6px; height: 6px; border-radius: var(--radius-full);
}
.chat-window-header .agent-status .dot.online { background: var(--green); }
.chat-window-header .agent-status .dot.standby { background: var(--amber); }
.chat-window-header .agent-status .dot.offline { background: var(--text-muted); }
.chat-window-actions { display: flex; gap: var(--space-sm); }
.chat-window-actions .btn-sm {
  padding: 5px 12px; font-size: 0.78rem; border-radius: var(--radius-sm);
  font-weight: 600;
}
.chat-window-actions .btn-takeover {
  background: var(--amber-bg); color: var(--amber);
  border: 1px solid rgba(251, 191, 36, 0.2);
}
.chat-window-actions .btn-takeover:hover { background: rgba(251,191,36,.2); }
.chat-window-actions .btn-release {
  background: var(--green-bg); color: var(--green);
  border: 1px solid rgba(52,211,153,.2);
}
.chat-window-actions .btn-release:hover { background: rgba(52,211,153,.2); }

/* --- Chat Messages --- */
.chat-messages {
  flex: 1; overflow-y: auto; padding: var(--space-lg);
  display: flex; flex-direction: column; gap: var(--space-md);
}
.chat-empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-muted); text-align: center; gap: var(--space-md);
}
.chat-empty-state .icon { font-size: 2.5rem; opacity: 0.5; }
.chat-empty-state .hint { font-size: 0.85rem; }

.chat-msg {
  display: flex; flex-direction: column; gap: 2px;
  max-width: 75%; animation: fadeInUp var(--duration-fast) var(--ease-out-expo);
}
.chat-msg.self { align-self: flex-end; align-items: flex-end; }
.chat-msg.other { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: 0.88rem; line-height: 1.6;
  word-break: break-word; white-space: pre-wrap;
}
.chat-bubble.bubble-self {
  background: var(--gradient-primary); color: #fff;
  border-bottom-right-radius: var(--space-xs);
}
.chat-bubble.bubble-other {
  background: var(--bg-muted); color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--space-xs);
}
.chat-time { font-size: 0.7rem; color: var(--text-muted); padding: 0 2px; }

.chat-system-msg {
  align-self: center; max-width: 80%;
  background: var(--bg-muted); border: 1px solid var(--border);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-full);
  font-size: 0.78rem; color: var(--text-muted); text-align: center;
}

/* Confirm / Choice Cards */
.chat-confirm-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--space-lg);
  max-width: 340px;
}
.chat-confirm-card .card-title {
  font-size: 0.82rem; font-weight: 600; margin-bottom: var(--space-sm);
}
.chat-confirm-card .card-desc {
  font-size: 0.8rem; color: var(--text-secondary); margin-bottom: var(--space-md);
  line-height: 1.5;
}
.chat-confirm-card .card-actions { display: flex; gap: var(--space-sm); }
.chat-confirm-card .card-actions .btn-confirm {
  flex: 1; padding: 7px 14px; font-size: 0.78rem; font-weight: 600;
  background: var(--green-bg); color: var(--green);
  border: 1px solid rgba(52,211,153,.2); border-radius: var(--radius-sm);
}
.chat-confirm-card .card-actions .btn-confirm:hover { background: rgba(52,211,153,.2); }
.chat-confirm-card .card-actions .btn-decline {
  flex: 1; padding: 7px 14px; font-size: 0.78rem; font-weight: 600;
  background: var(--red-bg); color: var(--red);
  border: 1px solid rgba(248,113,113,.2); border-radius: var(--radius-sm);
}
.chat-confirm-card .card-actions .btn-decline:hover { background: rgba(248,113,113,.2); }

.chat-choice-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--space-lg);
  max-width: 340px;
}
.chat-choice-card .card-title {
  font-size: 0.82rem; font-weight: 600; margin-bottom: var(--space-md);
}
.chat-choice-option {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-muted); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: var(--space-xs);
  font-size: 0.82rem; cursor: pointer;
  transition: all var(--duration-fast);
}
.chat-choice-option:hover {
  background: var(--primary-bg); border-color: var(--primary);
  color: var(--primary);
}
.chat-choice-option.selected {
  background: var(--primary-bg); border-color: var(--primary);
  color: var(--primary); pointer-events: none;
}

/* --- Chat Input Bar --- */
.chat-input-bar {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}
.chat-input {
  flex: 1; padding: 10px 14px;
  background: var(--bg-muted); border: 1px solid var(--border);
  border-radius: var(--radius-md); color: var(--text);
  font-size: 0.88rem; outline: none;
  transition: border-color var(--duration-fast);
}
.chat-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--ring); }
.chat-input::placeholder { color: var(--text-muted); }
.chat-send-btn {
  padding: 10px 18px;
  background: var(--gradient-primary); color: #fff;
  font-size: 0.85rem; font-weight: 600;
  border-radius: var(--radius-md);
  transition: all var(--duration-fast);
  flex-shrink: 0;
}
.chat-send-btn:hover { filter: brightness(1.1); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Session Cards --- */
.session-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--space-lg);
  display: flex; align-items: center; gap: var(--space-lg);
  transition: all var(--duration-fast);
}
.session-card:hover { border-color: var(--border-glow); }
.session-meta { flex: 1; min-width: 0; }
.session-agent-name { font-size: 0.9rem; font-weight: 600; }
.session-state-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: var(--radius-full);
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  margin-left: var(--space-sm);
}
.session-state-badge.active { background: var(--green-bg); color: var(--green); }
.session-state-badge.paused { background: var(--amber-bg); color: var(--amber); }
.session-state-badge.takeover { background: var(--red-bg); color: var(--red); }
.session-state-badge.standby { background: var(--blue-bg); color: var(--blue); }
.session-detail { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.session-actions { display: flex; gap: var(--space-sm); flex-shrink: 0; }
.session-actions .btn-sm {
  padding: 5px 12px; font-size: 0.76rem; font-weight: 600;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all var(--duration-fast);
}
.session-actions .btn-sm:hover { background: var(--bg-hover); color: var(--text); }

/* --- Nav Badge (unread count) --- */
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--red); color: #fff;
  font-size: 0.65rem; font-weight: 700;
  border-radius: var(--radius-full);
  margin-left: 4px; vertical-align: middle;
}

/* --- Chat Responsive --- */
@media (max-width: 767px) {
  .chat-tab { height: calc(100vh - var(--nav-h) - 40px); }
  .chat-sidebar { display: none; }
  .chat-layout { border-radius: var(--radius-md); }
  .chat-msg { max-width: 88%; }
  .chat-bubble { font-size: 0.85rem; padding: var(--space-sm) var(--space-md); }
}
@media (min-width: 768px) {
  .chat-tab { height: calc(100vh - var(--header-h) - 48px); }
}

/* ================================================================
   Slot Management
   ================================================================ */
.slot-budget-bar {
  width: 100%; height: 6px; border-radius: 3px;
  background: var(--bg-hover); overflow: hidden;
}
.slot-budget-fill {
  height: 100%; border-radius: 3px;
  background: var(--primary);
  transition: width 0.4s ease;
}
.slot-budget-fill.fill-warn {
  background: var(--amber);
}

.dot-blue {
  background: var(--primary);
}

.badge-primary {
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
}
.badge-blue {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}

.loading-center {
  display: flex; align-items: center; justify-content: center;
  gap: var(--space-sm); padding: var(--space-2xl);
  color: var(--text-muted); font-size: 0.85rem;
}

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--space-2xl); color: var(--text-muted);
}
.empty-state svg {
  width: 48px; height: 48px; margin-bottom: var(--space-md);
  opacity: 0.4;
}
.empty-state p {
  font-size: 0.88rem;
}

.btn-success {
  background: var(--green); color: #fff; border: none;
}
.btn-success:hover { opacity: 0.85; }

.btn-danger {
  background: var(--red); color: #fff; border: none;
}
.btn-danger:hover { opacity: 0.85; }

.btn-sm {
  padding: 5px 12px; font-size: 0.78rem; border-radius: var(--radius-sm);
}

.btn-xs {
  padding: 3px 8px; font-size: 0.72rem; border-radius: var(--radius-xs);
}
