:root {
  --primary-emerald: #059669;
  --primary-emerald-dark: #047857;
  --primary-emerald-light: #10b981;
  --primary-emerald-bg: rgba(5, 150, 105, 0.12);
  --primary-emerald-border: rgba(16, 185, 129, 0.28);

  --accent-gold: #f59e0b;
  --accent-gold-dark: #d97706;
  --accent-gold-light: #fbbf24;
  --accent-gold-bg: rgba(245, 158, 11, 0.12);

  --accent-cyan: #06b6d4;
  --accent-indigo: #6366f1;
  --accent-rose: #f43f5e;

  --bg-dark-base: #0a0e17;
  --bg-dark-card: #111827;
  --bg-dark-card-hover: #182234;
  --bg-dark-input: #1e293b;
  --bg-dark-subtle: #0f172a;

  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-strong: rgba(255, 255, 255, 0.16);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --wa-user-bg: #005c4b;
  --wa-agent-bg: #202c33;
  --wa-chat-bg: #0b141a;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
  --shadow-glow-emerald: 0 0 20px rgba(16, 185, 129, 0.25);
  --shadow-glow-gold: 0 0 20px rgba(245, 158, 11, 0.25);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
}

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

body {
  background-color: var(--bg-dark-base);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(5, 150, 105, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(245, 158, 11, 0.05) 0%, transparent 40%);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark-base);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color-strong);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

.app-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
}

/* =========================================================================
   TOP NAVIGATION HEADER
   ========================================================================= */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.nav-left .brand-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary-emerald-dark), var(--primary-emerald));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow-glow-emerald);
}

.brand-title {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-sharia {
  background: var(--primary-emerald-bg);
  color: var(--primary-emerald-light);
  border: 1px solid var(--primary-emerald-border);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.nav-center .agent-identity-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(30, 41, 59, 0.7);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color-strong);
}

.avatar-ring {
  font-size: 18px;
  background: rgba(16, 185, 129, 0.2);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.agent-id-info {
  display: flex;
  flex-direction: column;
}

.agent-name {
  font-weight: 700;
  font-size: 13px;
  color: #fff;
}

.agent-status-tag {
  font-size: 11px;
  color: var(--primary-emerald-light);
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: #10b981;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 8px #10b981;
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  outline: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-emerald), var(--primary-emerald-dark));
  color: #fff;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.4);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-emerald-light), var(--primary-emerald));
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.9);
  color: var(--text-main);
  border: 1px solid var(--border-color-strong);
}
.btn-secondary:hover {
  background: rgba(51, 65, 85, 0.9);
  border-color: rgba(255, 255, 255, 0.3);
}

.btn-danger-outline {
  background: rgba(244, 63, 94, 0.1);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.3);
}
.btn-danger-outline:hover {
  background: rgba(244, 63, 94, 0.2);
  border-color: #f43f5e;
}

/* =========================================================================
   KPI METRIC SUMMARY BAR
   ========================================================================= */
.kpi-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.kpi-card {
  background: var(--bg-dark-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-color-strong);
}

.kpi-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.kpi-icon-wrap.emerald { background: var(--primary-emerald-bg); color: var(--primary-emerald-light); }
.kpi-icon-wrap.teal { background: rgba(20, 184, 166, 0.15); color: #2dd4bf; }
.kpi-icon-wrap.gold { background: var(--accent-gold-bg); color: var(--accent-gold-light); }
.kpi-icon-wrap.indigo { background: rgba(99, 102, 241, 0.15); color: #818cf8; }

.kpi-content {
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.kpi-target {
  font-size: 10px;
  color: var(--text-dim);
}

/* =========================================================================
   MAIN WORKSPACE GRID
   ========================================================================= */
.main-workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  flex: 1;
}

/* Left Panel */
.left-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-card {
  background: var(--bg-dark-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-md);
}

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

.card-title {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.card-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.35);
  text-transform: uppercase;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.form-group label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.custom-select {
  background: var(--bg-dark-input);
  color: var(--text-main);
  border: 1px solid var(--border-color-strong);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s ease;
  cursor: pointer;
}
.custom-select:focus {
  border-color: var(--primary-emerald-light);
}

.lead-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(15, 23, 42, 0.6);
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.detail-item.full-width {
  grid-column: span 2;
  border-top: 1px dashed var(--border-color);
  padding-top: 6px;
  margin-top: 2px;
}

.detail-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 600;
}

.detail-val {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  word-break: break-all;
}
.detail-val.highlight-gold {
  color: var(--accent-gold-light);
  font-family: var(--font-heading);
  font-size: 14px;
}

.lead-notes-box {
  margin-top: 8px;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
}

.notes-header {
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.notes-content {
  color: var(--text-main);
  line-height: 1.4;
  max-height: 60px;
  overflow-y: auto;
}

/* Preset Quick Test Buttons */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset-btn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-dark-input);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}
.preset-btn:hover {
  background: var(--bg-dark-card-hover);
  border-color: var(--primary-emerald-border);
  transform: translateX(3px);
}

.preset-icon {
  font-size: 16px;
  margin-top: 1px;
}

.preset-text strong {
  display: block;
  font-size: 12px;
  color: #fff;
}

.preset-text small {
  font-size: 10px;
  color: var(--text-muted);
}

/* Right Panel (Chat & Telemetry) */
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-container {
  background: var(--wa-chat-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  height: 540px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  position: relative;
  background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 20px 20px;
}

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

.chat-header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-box {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #111b21;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.online-indicator {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #25d366;
  border: 2px solid #202c33;
  border-radius: 50%;
}

.user-meta .user-display-name {
  font-weight: 700;
  font-size: 13px;
  color: #e9edef;
}

.user-subtext {
  font-size: 11px;
  color: #8696a0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.subtext-sep {
  opacity: 0.5;
}

.grounding-badge {
  font-size: 11px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

/* Chat Stream */
.chat-stream {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-empty-state {
  margin: auto;
  text-align: center;
  max-width: 320px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.chat-empty-state .empty-icon {
  font-size: 36px;
  opacity: 0.8;
}

.chat-msg {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
  position: relative;
  word-wrap: break-word;
  animation: fadeInMsg 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.chat-msg.user {
  align-self: flex-end;
  background: var(--wa-user-bg);
  color: #e9edef;
  border-bottom-right-radius: 2px;
}

.chat-msg.agent {
  align-self: flex-start;
  background: var(--wa-agent-bg);
  color: #e9edef;
  border-bottom-left-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-msg .msg-sender-name {
  font-size: 11px;
  font-weight: 700;
  color: #53bdeb;
  margin-bottom: 2px;
}

.chat-msg.user .msg-sender-name {
  color: #a7f3d0;
}

.chat-msg .msg-text {
  white-space: pre-wrap;
}

.chat-msg .msg-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
}

.msg-status-ticks {
  color: #53bdeb;
}

/* Typing Indicator */
.typing-indicator {
  padding: 6px 20px;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--wa-agent-bg);
  color: #8696a0;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 11px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.typing-bubble .dot {
  width: 4px;
  height: 4px;
  background: #8696a0;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-bubble .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Chat Input Area */
.chat-input-wrapper {
  background: #202c33;
  padding: 10px 14px;
  border-top: 1px solid var(--border-color);
}

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

.chat-input {
  flex: 1;
  background: #2a3942;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #d1d7db;
  padding: 10px 16px;
  border-radius: var(--radius-full);
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.chat-input:focus {
  border-color: #00a884;
  background: #32444f;
}
.chat-input::placeholder {
  color: #8696a0;
}

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #00a884;
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 16px;
}
.btn-send:hover {
  background: #06cf9c;
  transform: scale(1.05);
}
.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* =========================================================================
   TELEMETRY & REASONING PANEL
   ========================================================================= */
.telemetry-card {
  padding: 12px 16px;
  background: rgba(17, 24, 39, 0.9);
}

.telemetry-header {
  border-bottom: none;
  padding-bottom: 0;
}

.telemetry-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.telemetry-title h3 {
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}
.pulse-icon {
  font-size: 14px;
}

.telemetry-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.meta-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}
.meta-tag.subagent-tag {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

.telemetry-box {
  background: rgba(15, 23, 42, 0.5);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.box-title {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 700;
  display: block;
  margin-bottom: 6px;
}

.stage-flow {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}
.badge-subagent {
  background: rgba(6, 182, 212, 0.15);
  color: #22d3ee;
  border: 1px solid rgba(6, 182, 212, 0.3);
}
.badge-stage {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.flow-arrow {
  color: var(--text-dim);
  font-size: 10px;
}

.tools-list {
  font-size: 11px;
  color: #cbd5e1;
}

.tool-chip {
  display: inline-block;
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 4px;
  font-family: monospace;
}

/* =========================================================================
   MODAL DIALOG
   ========================================================================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-dark-card);
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalScale 0.2s ease-out;
}

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

.modal-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}
.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 15px;
  color: #fff;
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}
.btn-close-modal:hover {
  color: #fff;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-input {
  background: var(--bg-dark-input);
  border: 1px solid var(--border-color-strong);
  color: #fff;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.modal-input:focus {
  border-color: var(--primary-emerald-light);
}

.required {
  color: var(--accent-rose);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
