:root {
  --bg: #f5f6f8;
  --bg2: #ffffff;
  --bg3: #edf0f4;
  --bg4: #e4e8ee;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --accent: #f59e0b;
  --accent-dim: rgba(245,158,11,0.1);
  --accent-hover: #d97706;
  --green: #22c55e;
  --green-dim: rgba(34,197,94,0.1);
  --blue: #3b82f6;
  --blue-dim: rgba(59,130,246,0.1);
  --red: #ef4444;
  --red-dim: rgba(239,68,68,0.1);
  --text: #1a1a2e;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --border: #e2e5ea;
  --border-light: #f0f1f3;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.08);
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* ── Nav (Hub-style TitanWorks banner) ── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 2rem;
  background: #1a1d27;
  border-bottom: 1px solid #2a2d3a;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand a {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #e8eaf0;
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
}
.nav-brand a:hover { color: #e8eaf0; text-decoration: none; }
.brand-logo { height: 24px; display: block; }
.brand-name span { color: var(--accent); }
.nav-links { display: flex; align-items: center; gap: 1rem; }
.nav-link { color: #9ca3b4; font-size: 0.9rem; text-decoration: none; }
.nav-link:hover { color: #e8eaf0; text-decoration: none; }
.nav-user { color: #e8eaf0; font-size: 0.85rem; padding-left: 1rem; border-left: 1px solid #2a2d3a; }
.nav-hub { background: rgba(255,255,255,0.1); padding: 5px 14px; border-radius: 6px; font-weight: 500; }
.nav-hub:hover { background: rgba(255,255,255,0.18); color: #fff !important; }
.logout { color: #6b7280 !important; font-size: 0.82rem !important; }

.impersonation-bar {
  background: var(--accent);
  color: #000;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
}
.impersonation-bar a { color: #000; text-decoration: underline; font-weight: 700; }

/* ── Layout ── */
.container { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }

/* ── Mode banner ── */
.mode-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
  font-size: .92rem;
}
.mode-banner.dry { background: var(--accent-dim); border: 1px solid var(--accent); }
.mode-banner.live { background: var(--green-dim); border: 1px solid rgba(34,197,94,.3); color: var(--green); }
.mode-banner strong { font-weight: 700; }

/* ── Connection pills ── */
.conn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  box-shadow: var(--shadow);
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.dot.ok { background: var(--green); animation: pulse 2s infinite; }
.dot.bad { background: var(--red); }
.dot.warn { background: var(--accent); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  70% { box-shadow: 0 0 0 7px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
.conn-pill .meta { color: var(--text-muted); font-weight: 400; }

/* ── Funnel ── */
.funnel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.funnel-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
}
.funnel-card .stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 8px; }
.funnel-card .stat-value { font-size: 2rem; font-weight: 800; color: var(--accent); }
.funnel-card .stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.funnel-card.green .stat-value { color: var(--green); }
.funnel-card.blue .stat-value { color: var(--blue); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; text-align: center; box-shadow: var(--shadow); }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--accent); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; color: #000; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg4); text-decoration: none; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.9; text-decoration: none; color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.9; color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Tables ── */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.admin-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
}
.admin-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--bg3); }
.table-wrap { overflow-x: auto; margin-bottom: 32px; }

/* ── Forms ── */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--accent); }
.form-group textarea { resize: vertical; min-height: 100px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.form-check label { margin-bottom: 0; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.admin-form-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.admin-form-card h3 { font-size: 1.05rem; margin-bottom: 16px; }
.admin-form-card h3 .step { color: var(--accent); margin-right: 6px; }

.pipeline-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--bg);
}
.pipeline-card .pipeline-name { font-weight: 700; font-size: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 10px; }

/* ── Badges + flash ── */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 14px; font-weight: 500; }
.flash-error { background: var(--red-dim); color: var(--red); border: 1px solid rgba(239,68,68,0.2); }
.flash-success { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.2); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-new { background: var(--blue-dim); color: var(--blue); }
.badge-booked { background: var(--accent-dim); color: var(--accent-hover); }
.badge-sold { background: var(--green-dim); color: var(--green); }
.badge-queued { background: var(--blue-dim); color: var(--blue); }
.badge-accepted { background: var(--green-dim); color: var(--green); }
.badge-duplicate { background: rgba(156,163,175,0.15); color: var(--text-muted); }
.badge-error { background: var(--red-dim); color: var(--red); }
.badge-skipped_no_gclid { background: rgba(156,163,175,0.15); color: var(--text-muted); }
.badge-expired { background: rgba(156,163,175,0.15); color: var(--text-muted); }
.badge-dry { background: var(--accent-dim); color: var(--accent-hover); }
.badge-live { background: var(--green-dim); color: var(--green); }
.badge-gclid { background: var(--green-dim); color: var(--green); }

/* ── Event feed ── */
.event-list { display: flex; flex-direction: column; gap: 0; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.event-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border-light); font-size: 13px; align-items: baseline; }
.event-item:last-child { border-bottom: none; }
.event-time { color: var(--text-muted); font-size: 11px; white-space: nowrap; flex-shrink: 0; width: 120px; }
.event-kind { flex-shrink: 0; width: 110px; }
.event-msg { color: var(--text-secondary); }

/* ── Login / connect ── */
.login-wrap { min-height: calc(100vh - 60px); display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px;
  width: 100%;
  max-width: 460px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-brand { font-size: 1.75rem; font-weight: 800; margin-bottom: 8px; letter-spacing: -0.02em; color: var(--text); }
.login-brand span { color: var(--accent); }
.login-sub { color: var(--text-secondary); font-size: 14px; margin-bottom: 32px; line-height: 1.5; }
.login-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 14px; background: var(--accent); color: #000;
  border: none; border-radius: 10px; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: all var(--transition); text-decoration: none;
}
.login-btn:hover { background: var(--accent-hover); text-decoration: none; color: #000; }
.login-features { margin-top: 32px; text-align: left; }
.login-feature { display: flex; align-items: start; gap: 12px; padding: 10px 0; font-size: 13px; color: var(--text-secondary); }
.login-feature-icon { width: 28px; height: 28px; border-radius: 6px; background: var(--accent-dim); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-text { font-size: 16px; margin-bottom: 8px; }
.empty-sub { font-size: 13px; color: var(--text-muted); }

/* ── Flow diagram ── */
.flow-strip { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 32px; font-size: 13px; color: var(--text-secondary); }
.flow-step { background: var(--bg2); border: 1px solid var(--border); border-radius: 30px; padding: 7px 14px; font-weight: 600; box-shadow: var(--shadow); }
.flow-arrow { color: var(--text-muted); }

@media (max-width: 768px) {
  .container { padding: 20px 16px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .event-time { width: 80px; }
}
