:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-soft: rgba(79, 70, 229, 0.09);
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #0F172A;
  --muted: #64748B;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --radius: 12px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 20;
  font-size: 20px;
  vertical-align: middle;
  user-select: none;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.22);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: #F1F5F9; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover { background: #F1F5F9; color: var(--text); }
.btn-danger {
  background: #FEF2F2;
  color: var(--danger);
  border-color: #FECACA;
}
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #334155;
  margin-bottom: 5px;
}

/* Auth / Magic Link Screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, rgba(79, 70, 229, 0.12), transparent 45%),
              radial-gradient(circle at bottom left, rgba(14, 165, 233, 0.1), transparent 45%),
              #F8FAFC;
}
.auth-card {
  width: 100%;
  max-width: 450px;
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--border);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.02em;
  margin-bottom: 20px;
}
.auth-logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4F46E5, #7C3AED);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Top Navigation Bar */
.topbar {
  height: 62px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 60;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
}
.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4F46E5, #6366F1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ws-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  background: #F8FAFC;
  border: 1px solid var(--border);
}
.ws-switcher select {
  border: none;
  background: transparent;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.ws-switcher select:focus { outline: none; }

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}
.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-tab:hover { color: var(--text); background: #F1F5F9; }
.nav-tab.active {
  color: var(--primary);
  background: var(--primary-soft);
}

/* Main Page Container */
.page-wrap {
  max-width: 1360px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}
.page-title {
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}
.page-subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 13.5px;
}

/* Cards & Grids */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
}
.card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card:hover { box-shadow: var(--shadow-md); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
.badge-green { background: #ECFDF5; color: #059669; }
.badge-indigo { background: #EEF2FF; color: #4F46E5; }
.badge-amber { background: #FFFBEB; color: #D97706; }
.badge-slate { background: #F1F5F9; color: #475569; }

/* Funnel Card Metrics Row */
.fn-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
  background: #F8FAFC;
  border-radius: 9px;
  margin: 14px 0;
  border: 1px solid #F1F5F9;
}
.fn-stat-label { font-size: 11px; color: var(--muted); font-weight: 600; }
.fn-stat-val { font-size: 16px; font-weight: 800; margin-top: 2px; }

/* ============================================================================
   VISUAL FUNNEL STUDIO (3-COLUMN BUILDER)
   ============================================================================ */
.studio-shell {
  position: fixed;
  inset: 0;
  background: #F1F5F9;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.studio-topbar {
  height: 58px;
  background: #0F172A;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  flex-shrink: 0;
}
.studio-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.08);
  padding: 4px;
  border-radius: 9px;
}
.studio-tab {
  padding: 6px 13px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #94A3B8;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.studio-tab.active {
  background: #4F46E5;
  color: #fff;
}

.studio-body {
  flex: 1;
  display: grid;
  grid-template-columns: 270px 1fr 360px;
  overflow: hidden;
}

/* Studio Left Sidebar: Pages/Steps */
.studio-left {
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
}
.step-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
  background: #fff;
  transition: all 0.15s ease;
}
.step-item:hover { border-color: #CBD5E1; background: #F8FAFC; }
.step-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.step-num {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: #E2E8F0;
  color: #334155;
  font-size: 11.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.step-item.active .step-num {
  background: var(--primary);
  color: #fff;
}

/* Studio Center: Mobile Device Frame */
.studio-center {
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.phone-frame {
  width: 412px;
  min-height: 740px;
  background: #F6F7FB;
  border-radius: 34px;
  border: 10px solid #1E293B;
  box-shadow: 0 24px 50px rgba(15, 23, 42, 0.16);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease;
}
.phone-frame.desktop-mode {
  width: 100%;
  max-width: 780px;
  border-radius: 16px;
  border-width: 4px;
}
.phone-canvas {
  padding: 20px 18px 40px;
  flex: 1;
}

.canvas-block {
  position: relative;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
  background: rgba(255,255,255,0.65);
  cursor: pointer;
  transition: all 0.15s ease;
}
.canvas-block:hover {
  border-color: #94A3B8;
  background: #fff;
}
.canvas-block.selected {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.12);
}
.block-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
}
.block-actions {
  display: flex;
  gap: 3px;
}
.icon-btn {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: #94A3B8; }

/* Studio Right Inspector */
.studio-right {
  background: #fff;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 18px;
}
.inspector-section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 16px;
}

/* ============================================================================
   CRM KANBAN PIPELINE & CONTACTS
   ============================================================================ */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(250px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 16px;
}
.kanban-col {
  background: #F1F5F9;
  border-radius: 12px;
  padding: 12px;
  min-height: 520px;
  display: flex;
  flex-direction: column;
}
.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 4px;
}
.kanban-card {
  background: #fff;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}
.kanban-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.data-table th {
  text-align: left;
  padding: 12px 16px;
  background: #F8FAFC;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid #F1F5F9;
  font-size: 13.5px;
}
.data-table tr:hover td { background: #F8FAFC; }

/* Drawer / Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px;
  box-shadow: var(--shadow-lg);
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px 20px;
}
.kpi-val {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 6px 0 2px;
}
