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

:root {
  --sidebar-w: 220px;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2563eb;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* ── Login ──────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}

.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 48px 40px;
  width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.login-card .logo {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--accent);
  margin-bottom: 4px;
}

.login-card .tagline {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 32px;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: background .15s, border-color .15s;
}

.btn-google:hover { background: #f8fafc; border-color: #94a3b8; }

.login-error {
  margin-top: 16px;
  padding: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  color: var(--danger);
  font-size: 13px;
  display: none;
}

/* ── App shell ──────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  font-size: 20px;
  font-weight: 800;
  color: white;
  letter-spacing: -0.5px;
  border-bottom: 1px solid #1e2d3d;
}

.sidebar-logo span { color: var(--accent); }

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
  border-radius: 0;
  cursor: pointer;
}

.nav-item:hover { background: rgba(255,255,255,.06); color: white; }
.nav-item.active { background: rgba(37,99,235,.25); color: white; border-left: 3px solid var(--accent); }
.nav-item svg { opacity: .7; flex-shrink: 0; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid #1e2d3d;
}

.user-info { color: var(--sidebar-text); font-size: 12px; margin-bottom: 8px; }
.user-email { color: white; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-signout {
  width: 100%;
  padding: 7px;
  background: transparent;
  border: 1px solid #334155;
  border-radius: 6px;
  color: var(--sidebar-text);
  font-size: 12px;
  cursor: pointer;
  margin-top: 8px;
  transition: border-color .15s, color .15s;
}

.btn-signout:hover { border-color: #64748b; color: white; }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: 900px;
}

/* ── Page header ─────────────────────────────────────────── */
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.page-header p  { color: var(--text-muted); margin-top: 4px; font-size: 13.5px; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── Stat grid ───────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); margin-top: 4px; }
.stat-value.green { color: var(--success); }
.stat-value.blue  { color: var(--accent); }
.stat-value.amber { color: var(--warning); }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge.connected { background: #dcfce7; color: #15803d; }
.badge.not-connected { background: #fef9c3; color: #854d0e; }
.badge.error { background: #fee2e2; color: #b91c1c; }

.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Integration card ────────────────────────────────────── */
.integration-card {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  padding: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
}

.integration-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.integration-body { flex: 1; }
.integration-name { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.integration-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }

.integration-meta { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 13.5px;
  font-family: monospace;
  color: var(--text);
  background: white;
  transition: border-color .15s;
}

.form-input:focus { outline: none; border-color: var(--accent); }

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }

.btn-danger { background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fecaca; }

.btn-sm { padding: 5px 12px; font-size: 12.5px; }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 16px;
  display: none;
}

.alert.show { display: block; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-info    { background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; }

/* ── Loading ─────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

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

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

/* ── History table ───────────────────────────────────────── */
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.history-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.history-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.history-table tr:last-child td { border-bottom: none; }

.outcome-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
}

.outcome-vm   { background: #dbeafe; color: #1d4ed8; }
.outcome-live { background: #dcfce7; color: #15803d; }
.outcome-busy { background: #fef9c3; color: #92400e; }
.outcome-err  { background: #fee2e2; color: #b91c1c; }

/* ── AI Context (ICP builder) page ──────────────────────────── */
.page-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  gap: 16px;
}

.page-header-row .page-header { margin-bottom: 0; flex: 1; }

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

.generate-row .form-input {
  width: 240px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.btn-generate {
  background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
  color: white;
  white-space: nowrap;
  border: none;
}

.btn-generate:hover:not(:disabled) {
  background: linear-gradient(135deg, #6d28d9 0%, #4338ca 100%);
  opacity: 1;
}

/* Tabs */
.tab-nav {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
  gap: 0;
}

.tab-btn {
  padding: 10px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ICP section header row */
.icp-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.icp-section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}

/* Card grid */
.icp-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.icp-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}

.icp-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(37,99,235,.12);
}

.icp-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.icp-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.modal-body .form-input {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.modal-body textarea.form-input { resize: vertical; min-height: 72px; }

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

.modal-footer .btn-danger { margin-right: auto; }

/* Section save bar */
.section-save-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Generating overlay */
.generating-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: white;
}

.generating-overlay .gen-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,.25);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.generating-overlay p { font-size: 15px; font-weight: 500; }
.generating-overlay .gen-sub { font-size: 13px; opacity: .7; margin-top: -8px; }

/* ── Vapi Assistant Builder ──────────────────────────────────── */
.assistant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.assistant-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}

.assistant-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(37,99,235,.1);
}

.assistant-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}

.assistant-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.assistant-card-goal {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.assistant-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.type-badge.sap     { background: #dbeafe; color: #1d4ed8; }
.type-badge.workday { background: #dcfce7; color: #15803d; }
.type-badge.si      { background: #ede9fe; color: #6d28d9; }
.type-badge.custom  { background: #f1f5f9; color: #475569; }

.default-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  background: #fef9c3;
  color: #92400e;
}

/* Editor view */
.editor-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 16px;
  border: none;
  background: none;
  padding: 0;
}

.editor-back:hover { color: var(--text); }

.editor-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
}

.var-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.var-chip {
  font-size: 11.5px;
  font-family: monospace;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  color: #475569;
  cursor: pointer;
  user-select: none;
}

.var-chip:hover { background: #e2e8f0; }

.preview-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  margin-top: 8px;
  min-height: 56px;
}

.preview-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-top: 16px;
  margin-bottom: 4px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child { border-bottom: none; }

.toggle-label { font-size: 13.5px; font-weight: 500; }
.toggle-desc  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 11px;
  cursor: pointer;
  transition: background .2s;
}

.toggle-switch input:checked + .toggle-track { background: var(--accent); }

.toggle-track::after {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 16px; height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform .2s;
}

.toggle-switch input:checked + .toggle-track::after { transform: translateX(18px); }
