/* ============================================================
   Campaign Guard tab (dashboard section #abtest).
   Full visual system — matches the dashboard's card/button/table
   language (automation.css tokens). Light + dark aware.
   ============================================================ */

/* ---- Cards -------------------------------------------------- */
.ab-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.ab-card:last-child { margin-bottom: 0; }

.ab-card h3 {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
  color: var(--foreground);
}
.ab-card h3 svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--primary); }

.ab-hint {
  font-size: 0.85rem;
  color: var(--muted-foreground);
  line-height: 1.55;
  margin: 0 0 18px;
}
.ab-hint strong { color: var(--foreground); font-weight: 600; }

/* ---- Create form ------------------------------------------- */
.ab-form { display: flex; flex-direction: column; gap: 16px; }

.ab-form label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--foreground);
}
.ab-form .opt {
  font-weight: 400;
  color: var(--muted-foreground);
  font-size: 0.78rem;
}
.ab-form input,
.ab-form select {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--foreground);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.ab-form select { cursor: pointer; }
.ab-form input:hover,
.ab-form select:hover { border-color: var(--cr-border-strong); }
.ab-form input:focus,
.ab-form select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px var(--cr-accent-bg);
}
.ab-form input::placeholder { color: var(--cr-muted); }

.ab-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 640px) { .ab-2col { grid-template-columns: 1fr; } }

/* ---- Buttons ----------------------------------------------- */
.ab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--cr-border-strong);
  background: var(--card);
  color: var(--foreground);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
  white-space: nowrap;
}
.ab-btn:hover { background: var(--muted); border-color: var(--cr-secondary); }
.ab-btn:disabled { opacity: .55; cursor: default; }
.ab-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.ab-btn.primary {
  align-self: flex-start;
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
}
.ab-btn.primary:hover { background: var(--cr-tertiary-hover); border-color: var(--cr-tertiary-hover); }

.ab-btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--foreground);
}
.ab-btn.ghost:hover { background: var(--muted); border-color: var(--cr-secondary); }

.ab-btn.danger {
  background: transparent;
  border-color: var(--cr-danger-bd);
  color: var(--cr-danger);
}
.ab-btn.danger:hover { background: var(--cr-danger-bg); border-color: var(--cr-danger); }

.ab-btn.sm { padding: 6px 11px; font-size: 0.8rem; }

/* ---- Generated link box ------------------------------------ */
.ab-linkout { display: none; }
.ab-linkout.show {
  display: block;
  margin-top: 4px;
  padding: 16px;
  background: var(--cr-success-bg);
  border: 1px solid var(--cr-success-bd);
  border-radius: var(--radius-md);
}
.ab-linkout code {
  display: block;
  background: var(--card);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin: 8px 0 12px;
  color: var(--foreground);
  word-break: break-all;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---- Campaigns table --------------------------------------- */
.ab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.ab-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ab-table td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--foreground);
}
.ab-table tbody tr:last-child td { border-bottom: none; }
.ab-table tbody tr { transition: background .12s ease; }
.ab-table tbody tr:hover { background: var(--muted); }
.ab-table td:first-child strong { font-weight: 700; font-size: 0.9rem; }
.ab-table .u {
  font-size: 0.76rem;
  color: var(--muted-foreground);
  margin-top: 4px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
/* URLs: single clean line with ellipsis instead of ugly mid-word breaks */
.ab-table .ab-url {
  display: block;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ab-table .nowrap { white-space: nowrap; }

/* ---- Status pills ------------------------------------------ */
.ab-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--muted);
  color: var(--muted-foreground);
  white-space: nowrap;
}
.ab-pill.on  { background: var(--cr-success-bg); color: var(--cr-success-fg); }
.ab-pill.exp { background: var(--cr-danger-bg);  color: var(--cr-danger-fg); }

/* ---- Row actions ------------------------------------------- */
.ab-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---- Empty / loading states -------------------------------- */
.ab-empty, .ab-loading {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted-foreground);
  font-size: 0.875rem;
}
.ab-loading { animation: ab-pulse 1.3s ease-in-out infinite; }
@keyframes ab-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ---- Summary KPIs ------------------------------------------ */
.ab-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.ab-kpi {
  padding: 16px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--muted);
  text-align: center;
}
.ab-kpi .n {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  color: var(--foreground);
}
.ab-kpi .l {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.ab-kpi .l svg { width: 13px; height: 13px; flex-shrink: 0; }

/* ---- Traffic split bar ------------------------------------- */
.ab-bar {
  display: flex;
  height: 12px;
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--muted);
  margin-bottom: 12px;
}
.ab-bar .a,
.ab-bar .b { height: 100%; transition: width .35s ease; }
.ab-bar .a { background: #10b981; } /* REAL traffic */
.ab-bar .b { background: #ef4444; } /* DECOY traffic */

.ab-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  font-size: 0.8rem;
  color: var(--muted-foreground);
}
.ab-legend > span { display: inline-flex; align-items: center; gap: 7px; }
.ab-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.ab-dot.a { background: #10b981; }
.ab-dot.b { background: #ef4444; }

/* ---- How it works note ------------------------------------- */
.ab-note { font-size: 0.875rem; color: var(--foreground); }
.ab-note ol {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  color: var(--muted-foreground);
}
.ab-note li { line-height: 1.5; }
.ab-note li::marker { color: var(--primary); font-weight: 700; }

.warn {
  display: block;
  margin-top: 14px;
  padding: 12px 14px;
  border-left: 3px solid var(--cr-warning);
  background: var(--cr-warning-bg);
  border-radius: var(--radius-sm);
  color: var(--foreground);
  font-size: 0.85rem;
  line-height: 1.55;
}

/* ============================================================
   Summary modal (opens when a campaign row is clicked)
   ============================================================ */
.ab-row { cursor: pointer; }

.ab-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  padding: 40px 16px;
  overflow-y: auto;
}
.ab-modal-overlay.open { display: flex; }

.ab-modal {
  position: relative;
  width: 100%;
  max-width: 820px;
  margin: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 26px 28px;
}
.ab-modal-x {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--muted-foreground);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.ab-modal-x:hover { background: var(--muted); color: var(--foreground); }

.ab-modal-head { margin-bottom: 18px; padding-right: 40px; }
.ab-modal-head h3 {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
  color: var(--foreground);
}
.ab-modal-head h3 svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--primary); }
.ab-modal-link { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ab-modal-link code {
  flex: 1;
  min-width: 0;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--foreground);
  word-break: break-all;
}
.ab-modal-meta { font-size: 0.78rem; color: var(--muted-foreground); }

.ab-modal .ab-bar { margin-top: 14px; }
.ab-modal .ab-legend { margin-bottom: 6px; }

/* Section grid */
.ab-sec-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px 26px;
  margin-top: 20px;
}
.ab-sec-wide { grid-column: 1 / -1; }
.ab-sec h4 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  margin: 0 0 12px;
}
.ab-sec-note { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: 0.75; }
.ab-recent-more-row { margin-top: 12px; text-align: center; }

/* Distribution rows (bars) */
.ab-dist-row {
  display: grid;
  grid-template-columns: 118px 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 0.82rem;
}
.ab-dist-label {
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ab-dist-track {
  height: 8px;
  background: var(--muted);
  border-radius: var(--radius-pill);
  overflow: hidden;
  display: flex;
}
.ab-dist-fill { height: 100%; background: var(--primary); }
.ab-dist-fill.real { background: #10b981; }
.ab-dist-fill.decoy { background: #ef4444; }
.ab-dist-val { color: var(--foreground); font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.ab-dist-extra { font-size: 0.72rem; font-weight: 400; color: var(--muted-foreground); margin-left: 4px; }

/* Opens-over-time bars */
.ab-timeline {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 120px;
}
.ab-tl-col { flex: 1 1 0; height: 100%; display: flex; align-items: flex-end; min-width: 3px; }
.ab-tl-bar {
  width: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 3px 3px 0 0;
  overflow: hidden;
  min-height: 2px;
}
.ab-tl-decoy { width: 100%; background: #ef4444; }
.ab-tl-real { width: 100%; background: #10b981; }
.ab-tl-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--muted-foreground);
  margin-top: 7px;
}

/* Recent-activity table (compact) */
.ab-recent th, .ab-recent td { padding: 8px 10px; }
.ab-recent td { font-size: 0.8rem; }

@media (max-width: 620px) {
  .ab-modal { padding: 22px 18px; }
  .ab-sec-grid { grid-template-columns: 1fr; }
  .ab-dist-row { grid-template-columns: 92px 1fr auto; }
}

/* ============================================================
   Targeting rules modal
   ============================================================ */
#ab-rules-modal .ab-modal { max-width: 640px; }

.ab-rule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.ab-rule-row:last-child { border-bottom: none; }
.ab-rule-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--foreground);
}
.ab-rule-hint { font-size: 0.74rem; font-weight: 400; color: var(--muted-foreground); }

/* Real / Decoy segmented control */
.ab-seg {
  display: inline-flex;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.ab-seg-btn {
  border: none;
  background: var(--card);
  color: var(--muted-foreground);
  padding: 6px 15px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background .12s ease, color .12s ease;
}
.ab-seg-btn + .ab-seg-btn { border-left: 1px solid var(--border); }
.ab-seg-btn:hover { background: var(--muted); }
.ab-seg-btn.on[data-v="real"]  { background: #10b981; color: #fff; }
.ab-seg-btn.on[data-v="decoy"] { background: #ef4444; color: #fff; }

/* Advanced filters */
.ab-adv-block { margin-bottom: 16px; }
.ab-adv-block:last-child { margin-bottom: 0; }
.ab-adv-title { font-size: 0.82rem; font-weight: 600; margin-bottom: 8px; color: var(--foreground); }
.ab-chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.83rem;
  color: var(--foreground);
  cursor: pointer;
}
.ab-chk input { accent-color: var(--primary); width: 15px; height: 15px; }
.ab-chk-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 16px;
  margin-top: 8px;
  padding-left: 22px;
}
.ab-chk-grid.ab-disabled { opacity: 0.4; pointer-events: none; }
.ab-input {
  width: 100%;
  padding: 8px 10px;
  margin-top: 8px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--foreground);
  font-family: var(--font-sans);
}
select.ab-input { cursor: pointer; }
.ab-input:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px var(--cr-accent-bg); }

.ab-rules-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Country picker (pick from list -> chips) */
.ab-country-picker { margin-top: 10px; }
.ab-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.ab-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px 5px 3px 12px;
  font-size: 0.78rem;
  color: var(--foreground);
}
.ab-chip-x {
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  padding: 0 4px;
  border-radius: 50%;
}
.ab-chip-x:hover { color: var(--cr-danger); }

/* ---- Hardening settings: per-check rows, number fields, inline groups ------
   Each check gets its own row so the name, the switch, what it costs, and its
   own settings all stay on one line at desk width and stack on a phone. Nothing
   is ever truncated — long check names wrap. */
.ab-sig-list {
  border: 1px solid var(--cr-border);
  border-radius: 10px;
  overflow: hidden;
}
.ab-sig-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 16px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--cr-border);
}
.ab-sig-row:last-child { border-bottom: none; }
.ab-sig-row:nth-child(even) { background: var(--cr-surface-2, rgba(128, 128, 128, 0.04)); }
.ab-sig-name { margin: 0; min-width: 0; }
.ab-sig-name span { overflow-wrap: anywhere; }
.ab-sig-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  justify-self: end;
  font-size: 0.86rem;
  color: var(--muted-foreground);
}
.ab-sig-hint {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted-foreground);
  opacity: 0.85;
}
.ab-sig-row.ab-sig-off { opacity: 0.5; }
.ab-sig-extra { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.ab-num {
  width: 74px;
  padding: 5px 8px;
  border: 1px solid var(--cr-border);
  border-radius: 7px;
  background: var(--cr-surface);
  color: var(--foreground);
  font: inherit;
  font-size: 0.86rem;
  text-align: right;
}
.ab-num:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px var(--cr-accent-bg); }
.ab-num:disabled { opacity: 0.55; cursor: not-allowed; }

.ab-input.sm { width: auto; padding: 5px 8px; font-size: 0.86rem; }

.ab-inline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.ab-inline .ab-hint { margin: 0; }

@media (max-width: 640px) {
  .ab-sig-row { grid-template-columns: 1fr; }
  .ab-sig-controls { justify-self: start; }
}
