/* ===================================================================
 * Adverships — design system v2 (refined)
 *
 * Loaded AFTER adverships-theme.css on every authenticated page.
 *
 * This file does double duty:
 *   1. Defines the new `.rd-*` components used by rewritten pages.
 *   2. Aliases the legacy `.av-*` classes onto the v2 visual rhythm,
 *      so pages we haven't rewritten yet still pick up the new look
 *      without markup changes.
 *
 * Marketing pages (/, /creators/, /businesses/) have their own
 * gradient-led treatment and should NOT load this file.
 * =================================================================== */

/* ── Tokens ───────────────────────────────────────────────────────── */

:root {
  --av-accent:       #7a3fb5;
  --av-accent-soft:  color-mix(in oklab, var(--av-accent) 14%, white);
  --av-accent-tint:  color-mix(in oklab, var(--av-accent) 6%, white);
  --av-accent-ink:   color-mix(in oklab, var(--av-accent) 88%, black);

  /* Refined neutrals — warm-cool balanced, less saturated than v1 */
  --av-ink:        #15161b;
  --av-ink-2:      #383b46;
  --av-ink-3:      #6a6e7c;
  --av-ink-4:      #9aa0ad;
  --av-line:       #ececef;
  --av-line-2:     #f3f3f5;
  --av-surface:    #ffffff;
  --av-canvas:     #fafaf8;        /* warm paper background */

  /* Status */
  --av-up:    #1f8a5b;
  --av-down:  #c0382b;
  --av-warn:  #b7791f;

  /* Density (cozy default) */
  --d-pad-card: 22px;
  --d-pad-row:  14px;
  --d-gap:      20px;
  --d-radius:   14px;

  /* Type pairings */
  --av-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

  /* Legacy v1 token compatibility — keep these working so unrewritten
   * pages still resolve var(--av-bg), var(--av-text), etc. The values
   * point at the new tokens. */
  --av-bg:         var(--av-canvas);
  --av-text:       var(--av-ink);
  --av-muted:      var(--av-ink-3);
  --av-border:     var(--av-line);
  --av-success:    var(--av-up);
  --av-surface-2: var(--av-line-2);
}

html[data-density="compact"] {
  --d-pad-card: 14px;
  --d-pad-row:  9px;
  --d-gap:      12px;
  --d-radius:   10px;
}

/* Body baseline so pages render correctly even without `.rd-shell`. */
html, body { background: var(--av-canvas); color: var(--av-ink); }
body { font-family: "Urbanist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

/* Tabular numerals for any element opting in. */
.rd-num { font-feature-settings: "tnum","lnum"; font-variant-numeric: tabular-nums; }

/* ──────────────────────────────────────────────────────────────────
 * Shell
 * ────────────────────────────────────────────────────────────────── */

.rd-shell,
.av-shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  background: var(--av-canvas);
  color: var(--av-ink);
  min-height: 100vh;
  font-family: inherit;
}

.rd-side,
.av-sidebar {
  background: var(--av-surface);
  border-right: 1px solid var(--av-line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* Brand block — logo + wordmark. The accent dot is a solid color
 * (gradient is reserved for marketing). */
.rd-brand,
.av-sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 22px;
  font-weight: 600; font-size: 17px; letter-spacing: -0.01em;
  color: var(--av-ink);
}
.rd-brand img,
.av-sidebar-logo img { height: 22px; width: auto; display: block; }

/* When .av-gradient-text appears INSIDE the sidebar, render as a solid
 * accent dot rather than the v1 pink→purple gradient. Marketing pages
 * keep the gradient because they don't load this file. */
.rd-side .av-gradient-text,
.av-sidebar .av-gradient-text,
.rd-brand .av-gradient-text {
  background: none !important;
  -webkit-background-clip: initial;
  background-clip: initial;
  -webkit-text-fill-color: var(--av-accent);
  color: var(--av-accent) !important;
}

.rd-section-label {
  font-size: 11px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--av-ink-4);
  padding: 16px 12px 8px;
}

.rd-nav,
.av-nav { display: flex; flex-direction: column; gap: 2px; }

.rd-nav a,
.av-nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--av-ink-2); text-decoration: none;
  font-size: 14px; font-weight: 500;
  transition: background 120ms, color 120ms;
}
.rd-nav a:hover,
.av-nav a:hover { background: var(--av-line-2); color: var(--av-ink); }

.rd-nav a.active,
.av-nav a.active {
  background: var(--av-accent-tint);
  color: var(--av-accent-ink);
}

/* Sidebar nav-item badge (e.g. pending count). */
.rd-badge-pill {
  margin-left: auto;
  background: var(--av-accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
  line-height: 1.4;
}

/* FontAwesome icons in the nav — slight desaturation. */
.rd-nav a i,
.av-nav a i { color: inherit; opacity: 0.85; font-size: 14px; }

/* Sidebar footer (avatar + meta + log-out button). */
.rd-side-foot,
.av-sidebar-bottom {
  margin-top: auto;
  border-top: 1px solid var(--av-line);
  padding-top: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.rd-side-foot .who { font-size: 13px; font-weight: 500; color: var(--av-ink); }
.rd-side-foot .who span { display: block; font-size: 11px; color: var(--av-ink-3); font-weight: 400; }

.rd-side-foot .rd-avatar { width: 32px; height: 32px; font-size: 13px; }

/* ──────────────────────────────────────────────────────────────────
 * Main + page head
 * ────────────────────────────────────────────────────────────────── */

.rd-main,
.av-main {
  padding: 28px 36px 48px;
  display: flex; flex-direction: column;
  gap: var(--d-gap);
  min-width: 0;
}

.rd-page-head,
.av-topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.rd-eyebrow {
  font-size: 11px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--av-ink-3);
}

.rd-title {
  font-size: 28px; font-weight: 600; letter-spacing: -0.02em;
  margin: 4px 0 0; color: var(--av-ink);
}

/* Legacy h2/h3 used by un-rewritten pages */
.av-h2 {
  font-size: 28px; font-weight: 600; letter-spacing: -0.02em;
  margin: 0; color: var(--av-ink);
}
.av-h3 {
  font-size: 18px; font-weight: 600; letter-spacing: -0.01em;
  margin: 0; color: var(--av-ink);
}

.rd-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.av-caption {
  font-size: 11px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--av-ink-3);
}
.av-body    { font-size: 14px; color: var(--av-ink-2); line-height: 1.55; }
.av-body-sm { font-size: 13px; color: var(--av-ink-2); line-height: 1.55; }
.av-muted   { color: var(--av-ink-3); }
.av-help    { font-size: 12px; color: var(--av-ink-4); margin-top: 6px; line-height: 1.5; }
.av-label   {
  display: block;
  font-size: 11px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--av-ink-3);
  margin-bottom: 6px;
}

/* ──────────────────────────────────────────────────────────────────
 * Card surface
 * ────────────────────────────────────────────────────────────────── */

.rd-card,
.av-card {
  background: var(--av-surface);
  border: 1px solid var(--av-line);
  border-radius: var(--d-radius);
  padding: var(--d-pad-card);
  box-shadow: none;
}
.rd-card-flush { padding: 0; overflow: hidden; }

.av-card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.av-card-title { font-size: 15px; font-weight: 600; color: var(--av-ink); margin: 0; }

/* ──────────────────────────────────────────────────────────────────
 * Buttons
 * ────────────────────────────────────────────────────────────────── */

.rd-btn,
.av-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13px; font-weight: 500; font-family: inherit;
  background: var(--av-surface);
  color: var(--av-ink);
  border: 1px solid var(--av-line);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 120ms, background 120ms, color 120ms;
  white-space: nowrap;
}
.rd-btn:hover,
.av-btn:hover { border-color: var(--av-ink-3); color: var(--av-ink); }

.rd-btn-primary,
.av-btn-primary {
  background: var(--av-ink); color: var(--av-surface); border-color: var(--av-ink);
}
.rd-btn-primary:hover,
.av-btn-primary:hover { background: var(--av-ink-2); border-color: var(--av-ink-2); color: var(--av-surface); }

.rd-btn-accent {
  background: var(--av-accent); color: #fff; border-color: var(--av-accent);
}
.rd-btn-accent:hover { background: var(--av-accent-ink); border-color: var(--av-accent-ink); color: #fff; }

.av-btn-secondary {
  background: var(--av-surface); color: var(--av-ink-2); border-color: var(--av-line);
}
.av-btn-secondary:hover { border-color: var(--av-ink-3); color: var(--av-ink); }

.av-btn-ghost {
  background: transparent; border-color: transparent; color: var(--av-ink-3);
}
.av-btn-ghost:hover { background: var(--av-line-2); color: var(--av-ink); border-color: transparent; }

.av-btn-danger {
  background: var(--av-surface); color: var(--av-down); border-color: var(--av-line);
}
.av-btn-danger:hover { border-color: var(--av-down); }

.av-btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.av-btn-lg { padding: 11px 18px; font-size: 14px; }

/* ──────────────────────────────────────────────────────────────────
 * Chips
 * ────────────────────────────────────────────────────────────────── */

.rd-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  background: var(--av-line-2); color: var(--av-ink-2);
  border: 1px solid transparent; cursor: pointer;
  font-family: inherit;
  transition: background 120ms, border-color 120ms;
}
.rd-chip:hover { background: var(--av-line); }
.rd-chip.is-active { background: var(--av-ink); color: var(--av-surface); }
.rd-chip-outline {
  background: transparent; border-color: var(--av-line); color: var(--av-ink-2);
}
.rd-chip-outline:hover { border-color: var(--av-ink-3); }

/* ──────────────────────────────────────────────────────────────────
 * Status pills (used on badges across the app)
 * ────────────────────────────────────────────────────────────────── */

.rd-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.rd-pill::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.rd-pill-live, .rd-pill-active     { background: #e6f5ec; color: var(--av-up); }
.rd-pill-negotiating               { background: #eef0fb; color: #3730a3; }
.rd-pill-pending, .rd-pill-invited, .rd-pill-paused { background: #fff3da; color: #92400e; }
.rd-pill-archived, .rd-pill-draft  { background: var(--av-line-2); color: var(--av-ink-3); }
.rd-pill-declined, .rd-pill-ended  { background: #fae9e9; color: #991b1b; }

/* Legacy badges → reuse the pill look. Existing pages set bg/color
 * inline, which still wins; this is just the baseline. */
.av-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  background: var(--av-line-2); color: var(--av-ink-2);
}
.av-badge-soft-green { background: #e6f5ec; color: var(--av-up); }
.av-badge-soft-red   { background: #fae9e9; color: #991b1b; }

/* ──────────────────────────────────────────────────────────────────
 * Alerts (top-of-dashboard stripes)
 * ────────────────────────────────────────────────────────────────── */

.rd-alert {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--av-line);
  background: var(--av-surface);
  color: var(--av-ink-2);
  font-size: 13.5px;
}
.rd-alert-amber  { background: #fff7ea; color: #b7791f; border-color: #f4dca5; }
.rd-alert-purple { background: var(--av-accent-tint); color: var(--av-accent-ink);
                   border-color: color-mix(in oklab, var(--av-accent) 18%, white); }
.rd-alert-success { background: #e6f5ec; color: var(--av-up); border-color: #c5e6d3; }
.rd-alert .rd-alert-action { margin-left: auto; font-weight: 600; text-decoration: underline; cursor: pointer; }

/* Legacy alert classes — alias to the same shape. */
.av-alert {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--av-line);
  background: var(--av-surface);
  color: var(--av-ink-2);
  font-size: 13.5px;
}
.av-alert-warning { background: #fff7ea; color: #b7791f; border-color: #f4dca5; }
.av-alert-success { background: #e6f5ec; color: var(--av-up); border-color: #c5e6d3; }

/* ──────────────────────────────────────────────────────────────────
 * Form controls
 * ────────────────────────────────────────────────────────────────── */

.rd-input, .av-input, .av-select, .av-textarea {
  display: block; width: 100%;
  padding: 10px 12px;
  font-size: 14px; font-family: inherit;
  background: var(--av-surface);
  color: var(--av-ink);
  border: 1px solid var(--av-line);
  border-radius: 10px;
  transition: border-color 120ms, box-shadow 120ms;
}
.rd-input:focus, .av-input:focus, .av-select:focus, .av-textarea:focus {
  outline: none;
  border-color: var(--av-accent);
  box-shadow: 0 0 0 2px var(--av-accent-tint) inset;
}
.av-textarea { line-height: 1.5; min-height: 80px; resize: vertical; font-family: inherit; }
.av-select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='none' stroke='%236a6e7c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ──────────────────────────────────────────────────────────────────
 * Stats / KPI tiles
 * ────────────────────────────────────────────────────────────────── */

.rd-stat,
.av-stat {
  background: var(--av-surface);
  border: 1px solid var(--av-line);
  border-radius: var(--d-radius);
  padding: var(--d-pad-card);
}
.rd-stat-label,
.av-stat-label {
  display: block;
  font-size: 12px; font-weight: 500; color: var(--av-ink-3);
}
.rd-stat-value,
.av-stat-value {
  display: block;
  margin-top: 6px;
  font-size: 32px; font-weight: 500; letter-spacing: -0.02em;
  font-feature-settings: "tnum","lnum"; font-variant-numeric: tabular-nums;
  color: var(--av-ink);
}
.rd-delta { font-size: 12px; font-weight: 600; margin-top: 6px; display: block; }
.rd-delta.up   { color: var(--av-up); }
.rd-delta.down { color: var(--av-down); }
.rd-delta.flat { color: var(--av-ink-3); }

/* ──────────────────────────────────────────────────────────────────
 * Partner avatars
 *
 * v2 spec: circular, neutral hashed bg, single or double initial.
 * v1 markup uses `.av-conn-avatar` with a hard-coded pink→purple
 * gradient; we override to a neutral surface so the legacy markup
 * picks up the new look without code changes. Pages we rewrite can
 * still set inline backgroundColor for the hashed variant.
 * ────────────────────────────────────────────────────────────────── */

.rd-avatar,
.av-conn-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--av-line-2);
  color: var(--av-ink);
  display: inline-grid; place-items: center;
  font-weight: 600; font-size: 13px;
  flex-shrink: 0;
  text-transform: uppercase;
}

/* The marketing/landing gradient — keep for callsites NOT inside the
 * authenticated shell. Inside the shell, the dot becomes solid. */
.av-gradient-text {
  background: linear-gradient(135deg, #bf86f7, #f5acc4);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ──────────────────────────────────────────────────────────────────
 * Connection row cards (status-bordered)
 * ────────────────────────────────────────────────────────────────── */

.av-conn-list { display: flex; flex-direction: column; gap: 10px; }

.av-conn-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px; align-items: center;
  padding: 14px 16px;
  background: var(--av-surface);
  border: 1px solid var(--av-line);
  border-left: 3px solid var(--av-line);
  border-radius: 12px;
  text-decoration: none;
  color: var(--av-ink);
  transition: border-color 120ms, background 120ms;
}
.av-conn-card:hover {
  border-color: var(--av-ink-3);
  background: var(--av-line-2);
  color: var(--av-ink);
}
.av-conn-card.status-active   { border-left-color: var(--av-up); }
.av-conn-card.status-pending  { border-left-color: #d99a26; }
.av-conn-card.status-archived { border-left-color: var(--av-line); opacity: 0.7; }

.av-conn-meta { min-width: 0; }
.av-conn-name {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 500; color: var(--av-ink);
  margin-bottom: 3px;
}
.av-conn-last {
  font-size: 12.5px; color: var(--av-ink-3);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.av-conn-right {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  flex-shrink: 0;
}
.av-conn-time   { font-size: 11px; color: var(--av-ink-4); font-family: var(--av-mono); }
.av-conn-clicks { font-size: 11px; color: var(--av-ink-4); font-family: var(--av-mono); font-weight: 500; }

.av-status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.av-status-dot.active   { background: var(--av-up); }
.av-status-dot.pending  { background: #d99a26; }
.av-status-dot.archived { background: var(--av-ink-4); }

/* ──────────────────────────────────────────────────────────────────
 * Tab pills (Connections page)
 * ────────────────────────────────────────────────────────────────── */

.av-conn-tabs { display: flex; gap: 6px; margin-bottom: 4px; }

.av-conn-tab {
  position: relative;
  padding: 8px 18px;
  font-size: 13px; font-weight: 600;
  border-radius: 999px;
  background: var(--av-surface);
  color: var(--av-ink-2);
  border: 1px solid var(--av-line);
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.av-conn-tab:hover { background: var(--av-line-2); color: var(--av-ink); }
.av-conn-tab.active {
  background: var(--av-ink); color: var(--av-surface); border-color: var(--av-ink);
}
.av-conn-tab-dot {
  position: absolute; top: 5px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--av-accent);
}

/* ──────────────────────────────────────────────────────────────────
 * Chat thread
 * ────────────────────────────────────────────────────────────────── */

.av-messages {
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px 20px;
  background: var(--av-canvas);
  max-height: 460px; min-height: 320px;
  overflow-y: auto;
  border-radius: 0;
}

.av-msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px; line-height: 1.5;
}

.av-msg.mine {
  align-self: flex-end;
  background: var(--av-ink);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.av-msg.theirs {
  align-self: flex-start;
  background: var(--av-surface);
  border: 1px solid var(--av-line);
  color: var(--av-ink);
  border-bottom-left-radius: 4px;
}
.av-msg.system {
  align-self: center;
  background: transparent;
  border: none;
  color: var(--av-ink-4);
  font-size: 11.5px;
  font-style: italic;
  padding: 4px 0;
  max-width: none;
}
.av-msg .ts {
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 4px;
  font-family: var(--av-mono);
}
.av-msg.theirs .ts { color: var(--av-ink-4); }

/* ──────────────────────────────────────────────────────────────────
 * Bootstrap modal compatibility
 * ────────────────────────────────────────────────────────────────── */

.modal-content {
  background: var(--av-surface);
  border: 1px solid var(--av-line);
  border-radius: var(--d-radius);
  color: var(--av-ink);
}
.modal-header, .modal-footer { border-color: var(--av-line) !important; }
.modal-header .av-h3 { font-size: 17px; font-weight: 600; }

/* ──────────────────────────────────────────────────────────────────
 * Code blocks (install page)
 * ────────────────────────────────────────────────────────────────── */

.code-block {
  background: #1b1c20;
  color: #e8e8ec;
  border-radius: var(--d-radius);
  padding: 18px;
  font-family: var(--av-mono);
  font-size: 12.5px;
  line-height: 1.6;
  overflow-x: auto;
  position: relative;
}

/* ──────────────────────────────────────────────────────────────────
 * Responsive — collapse at ≤ 900px
 *
 * Sidebar becomes a top bar; main reflows.
 * ────────────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .rd-shell, .av-shell { grid-template-columns: 1fr; }
  .rd-side, .av-sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--av-line);
    padding: 14px 18px;
  }
  .rd-brand, .av-sidebar-logo { padding: 0 0 12px; }
  .rd-section-label { display: none; }
  .rd-nav, .av-nav { flex-direction: row; gap: 4px; flex-wrap: wrap; }
  .rd-nav a, .av-nav a { padding: 8px 10px; font-size: 13px; }
  .rd-side-foot, .av-sidebar-bottom {
    flex-direction: row; align-items: center; gap: 10px;
    border-top: 1px solid var(--av-line); padding-top: 10px; margin-top: 10px;
  }
  .rd-side-foot .who { display: none; }

  .rd-main, .av-main { padding: 20px 18px 32px; }
  .rd-title, .av-h2 { font-size: 22px; }
  .rd-page-head, .av-topbar { flex-direction: column; align-items: stretch; }
  .rd-toolbar { justify-content: flex-end; }
}

/* ──────────────────────────────────────────────────────────────────
 * Bootstrap utility carve-outs
 *
 * The pages use Bootstrap's `.row` + `.col-*` grid in places. Leave
 * that alone — it works fine alongside the new tokens.
 * ────────────────────────────────────────────────────────────────── */
