/* ============================================================
   ScaleUP — components
   Every piece the views compose from. No view defines its own
   look; if something is missing it belongs here first.
   ============================================================ */

/* ---------------- card ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-2) var(--ease),
              transform var(--dur-2) var(--ease),
              border-color var(--dur-2) var(--ease);
}
.card.pad-lg { padding: var(--s-6); }
.card.pad-0  { padding: 0; overflow: hidden; }
.card.lift:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.card.inset { background: var(--surface-2); box-shadow: none; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); margin-bottom: var(--s-4);
}
.card-title { font-size: var(--t-h3); font-weight: 600; letter-spacing: -0.015em; }
.card-sub { font-size: var(--t-xs); color: var(--text-3); margin-top: 2px; }

/* ---------------- buttons ---------------- */
.btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 15px;
  border-radius: var(--r-sm);
  font-size: var(--t-sm); font-weight: 550; letter-spacing: -0.005em;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease),
              color var(--dur-1) var(--ease),
              border-color var(--dur-1) var(--ease),
              box-shadow var(--dur-1) var(--ease),
              transform var(--dur-1) var(--ease);
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: scale(0.975); }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.btn-primary { background: var(--accent); color: var(--text-on-accent); box-shadow: var(--shadow-accent); }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 14px var(--accent-glow); }
.btn-primary:active { background: var(--accent-press); }

.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-3); }

.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-sm { height: 30px; padding: 0 11px; font-size: var(--t-xs); }
.btn-lg { height: 44px; padding: 0 22px; font-size: var(--t-body); border-radius: var(--r-md); }
.btn-block { width: 100%; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: var(--r-sm); }

/* A light sweep on hover — the "alive" cue, once, never looping. */
.btn-primary::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 20%, rgba(255,255,255,0.22) 48%, transparent 76%);
  transform: translateX(-120%);
  transition: transform var(--dur-4) var(--ease);
}
.btn-primary:hover::after { transform: translateX(120%); }

/* ---------------- segmented control ---------------- */
.segmented {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface-2); border-radius: var(--r-sm);
  border: 1px solid var(--line);
}
.segmented button {
  padding: 5px 12px; border-radius: 7px;
  font-size: var(--t-xs); font-weight: 550; color: var(--text-2);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs);
}

/* ---------------- stat tile ---------------- */
.stat { display: flex; flex-direction: column; gap: var(--s-2); }
.stat-k {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--t-xs); font-weight: 500; color: var(--text-3);
}
.stat-k svg { width: 14px; height: 14px; }
.stat-v {
  font-size: 1.75rem; font-weight: 600; letter-spacing: -0.035em; line-height: 1.1;
  color: var(--text);
}
.stat-v.small { font-size: 1.375rem; }
.stat-foot { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-xs); }

.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.delta svg { width: 13px; height: 13px; }
.delta.up   { color: var(--delta-up); }
.delta.down { color: var(--delta-down); }
.delta.flat { color: var(--text-3); }

/* ---------------- badges & pills ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-full);
  font-size: var(--t-micro); font-weight: 650; letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }
.badge-neutral  { background: var(--surface-2); color: var(--text-2); }
.badge-accent   { background: var(--accent-soft); color: var(--accent); }
.badge-good     { background: var(--good-soft); color: var(--delta-up); }
.badge-warning  { background: var(--warning-soft); color: #8A6100; }
.badge-serious  { background: var(--serious-soft); color: #A8471E; }
.badge-critical { background: var(--critical-soft); color: var(--critical); }
:root[data-theme="dark"] .badge-warning { color: var(--warning); }
:root[data-theme="dark"] .badge-serious { color: var(--serious); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .badge-warning { color: var(--warning); }
  :root:where(:not([data-theme="light"])) .badge-serious { color: var(--serious); }
}

/* A dot before the label so state never rides on colour alone. */
.dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.dot.good { background: var(--good); }
.dot.warning { background: var(--warning); }
.dot.critical { background: var(--critical); }
.dot.neutral { background: var(--text-3); }
.dot.live { background: var(--good); box-shadow: 0 0 0 0 var(--good-soft); animation: pulse 2.4s var(--ease) infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(12,163,12,0.34); }
  70%  { box-shadow: 0 0 0 7px rgba(12,163,12,0); }
  100% { box-shadow: 0 0 0 0 rgba(12,163,12,0); }
}

/* ---------------- form controls ---------------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: var(--t-sm); font-weight: 550; color: var(--text); }
.field .hint { font-size: var(--t-xs); color: var(--text-3); }

.input, .select, .textarea {
  width: 100%;
  padding: 10px 13px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: var(--t-body);
  color: var(--text);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.textarea { min-height: 92px; resize: vertical; line-height: 1.55; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 16px;
  padding-right: 34px;
}

.switch {
  position: relative; width: 40px; height: 24px; flex-shrink: 0;
  border-radius: var(--r-full); background: var(--surface-3);
  border: 1px solid var(--line);
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow-sm);
  transition: transform var(--dur-2) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }

/* ---------------- table ---------------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; padding: 0 var(--s-4) var(--s-3);
  font-size: var(--t-micro); font-weight: 600; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--text-3);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: var(--s-4);
  font-size: var(--t-sm);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tbody tr { transition: background var(--dur-1) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table th.num, .table td.num { text-align: right; }
.table-wrap { overflow-x: auto; }

/* ---------------- empty state ---------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--s-16) var(--s-8);
  animation: cardIn var(--dur-3) var(--ease) both;
}
.empty-art {
  width: 56px; height: 56px; margin-bottom: var(--s-5);
  display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  color: var(--text-3);
}
.empty-art svg { width: 24px; height: 24px; }
.empty h3 { font-size: var(--t-h2); margin-bottom: 6px; }
.empty p { font-size: var(--t-body); color: var(--text-3); max-width: 42ch; line-height: 1.6; }
.empty .btn { margin-top: var(--s-5); }

/* ---------------- skeleton ---------------- */
.skel {
  border-radius: var(--r-xs);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.skel-line { height: 11px; margin-bottom: 9px; }
.skel-line:last-child { margin-bottom: 0; width: 62%; }

/* ---------------- toast ---------------- */
.toasts {
  position: fixed; right: var(--s-6); bottom: var(--s-6);
  display: flex; flex-direction: column; gap: var(--s-2);
  z-index: 400; pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 11px;
  min-width: 280px; max-width: 380px;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn var(--dur-3) var(--ease) both;
}
.toast.out { animation: toastOut var(--dur-2) var(--ease-in) both; }
@keyframes toastIn  { from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translate3d(0, 8px, 0) scale(0.98); } }
.toast-ico { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast-ico svg { width: 18px; height: 18px; }

/* Any icon dropped straight into a flex row, with no component rule of its
   own, sits at text scale rather than its 18px default. */
.row > svg, .row-between > svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast-body b { display: block; font-size: var(--t-sm); font-weight: 600; margin-bottom: 2px; }
.toast-body span { font-size: var(--t-xs); color: var(--text-2); line-height: 1.5; }

/* ---------------- modal ---------------- */
.scrim {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(10, 10, 11, 0.32);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: var(--s-6);
  animation: fadeIn var(--dur-2) var(--ease) both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--s-6);
  animation: modalIn var(--dur-3) var(--ease) both;
  max-height: 86vh; overflow-y: auto;
}
@keyframes modalIn { from { opacity: 0; transform: translate3d(0, 16px, 0) scale(0.97); } to { opacity: 1; transform: none; } }

/* ---------------- insight card (the proactive layer) ---------------- */
.insight {
  display: flex; gap: var(--s-3);
  padding: var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color var(--dur-2) var(--ease), transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
.insight:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); border-color: var(--line-strong); }
.insight-ico {
  width: 32px; height: 32px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
}
.insight-ico svg { width: 16px; height: 16px; }
.insight-ico.good     { background: var(--good-soft); color: var(--delta-up); }
.insight-ico.warning  { background: var(--warning-soft); color: #8A6100; }
.insight-ico.serious  { background: var(--serious-soft); color: #A8471E; }
.insight-ico.critical { background: var(--critical-soft); color: var(--critical); }
.insight-ico.info     { background: var(--accent-soft); color: var(--accent); }
.insight-body { flex: 1; min-width: 0; }
.insight-body b { display: block; font-size: var(--t-sm); font-weight: 600; margin-bottom: 3px; }
.insight-body p { font-size: var(--t-xs); color: var(--text-2); line-height: 1.55; }
.insight-actions { display: flex; gap: var(--s-2); margin-top: var(--s-3); }

/* ---------------- chart ---------------- */
.chart { position: relative; width: 100%; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: var(--s-4);
  margin-top: var(--s-4); padding-top: var(--s-3);
  border-top: 1px solid var(--line);
}
.legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: var(--t-xs); color: var(--text-2); }
.legend-swatch { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }

.axis-tick { font-size: 10.5px; fill: var(--axis-ink); }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.baseline  { stroke: var(--axis); stroke-width: 1; }

/* Series lines draw themselves in on first paint. */
.series-line {
  fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: var(--len); stroke-dashoffset: var(--len);
  animation: drawLine var(--dur-4) var(--ease) forwards;
}
@keyframes drawLine { to { stroke-dashoffset: 0; } }
.series-area { animation: fadeIn var(--dur-4) var(--ease) both; animation-delay: 160ms; }

.bar-mark {
  transition: opacity var(--dur-1) var(--ease);
  animation: barIn var(--dur-3) var(--ease) both;
  animation-delay: calc(var(--i, 0) * 40ms);
  transform-origin: bottom;
}
@keyframes barIn { from { transform: scaleY(0); opacity: 0; } to { transform: scaleY(1); opacity: 1; } }
.chart:hover .bar-mark:not(:hover) { opacity: 0.55; }

.chart-crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.chart-dot { stroke: var(--surface); stroke-width: 2; pointer-events: none; }

.tooltip {
  position: absolute; z-index: 30; pointer-events: none;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
  font-size: var(--t-xs);
  white-space: nowrap;
  transition: opacity var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
  opacity: 0; transform: translateY(3px);
}
.tooltip.show { opacity: 1; transform: none; }
.tooltip .tt-label { color: var(--text-3); font-size: var(--t-micro); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; margin-top: 3px; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; }

/* Horizontal ranked bars (top / worst campaigns). */
.rank-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px var(--s-3); align-items: center; padding: 9px 0; }
.rank-row + .rank-row { border-top: 1px solid var(--line); }
.rank-name { font-size: var(--t-sm); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-val { font-size: var(--t-sm); font-weight: 600; font-variant-numeric: tabular-nums; }
.rank-track { grid-column: 1 / -1; height: 6px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; }
.rank-fill {
  height: 100%; border-radius: var(--r-full);
  transform-origin: left; animation: growX var(--dur-4) var(--ease) both;
  animation-delay: calc(var(--i, 0) * 55ms);
}
@keyframes growX { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------------- connected accounts ---------------- */
.avatars { display: flex; }
.avatars .av { margin-left: -8px; }
.avatars .av:first-child { margin-left: 0; }
.av {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-2);
  border: 2px solid var(--surface);
  font-size: var(--t-xs); font-weight: 650;
  transition: transform var(--dur-1) var(--ease);
}
.av svg { width: 15px; height: 15px; }
.av.add { border-style: dashed; border-color: var(--line-strong); background: transparent; color: var(--text-3); }
.av.add:hover { color: var(--accent); border-color: var(--accent); transform: scale(1.08); }

/* ---------------- plan card ---------------- */
.plan-card {
  padding: var(--s-4);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.plan-card .quota-track { height: 5px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; margin: var(--s-3) 0 var(--s-2); }
.plan-card .quota-fill { height: 100%; background: var(--accent); border-radius: var(--r-full); transition: width var(--dur-4) var(--ease); }

.user-chip {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px; border-radius: var(--r-md);
  transition: background var(--dur-1) var(--ease);
}
.user-chip:hover { background: var(--surface-2); }
.user-chip .av { width: 30px; height: 30px; background: var(--accent-soft); color: var(--accent); border: none; }
.user-chip .who { flex: 1; min-width: 0; text-align: left; }
.user-chip .who b { display: block; font-size: var(--t-sm); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who span { font-size: var(--t-micro); color: var(--text-3); }
/* The sign-out glyph is a hint, not a button — keep it quiet until hover. */
.user-chip svg {
  width: 15px; height: 15px; flex-shrink: 0;
  color: var(--text-3);
  opacity: 0.65;
  transition: opacity var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.user-chip:hover svg { opacity: 1; color: var(--text-2); }

/* ---------------- theme toggle ---------------- */
.theme-toggle {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2); border-radius: var(--r-md);
}
.theme-toggle .tt-btn {
  flex: 1; display: grid; place-items: center; height: 28px;
  border-radius: var(--r-xs); color: var(--text-3);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.theme-toggle .tt-btn svg { width: 15px; height: 15px; }
.theme-toggle .tt-btn:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle .tt-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }

/* ---------------- quick actions ---------------- */
.qa-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
.qa {
  display: flex; flex-direction: column; gap: var(--s-2);
  padding: var(--s-4) var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  text-align: left;
  transition: transform var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
.qa:hover { transform: translateY(-2px); border-color: var(--accent-line); box-shadow: var(--shadow-sm); }
.qa-ico { width: 28px; height: 28px; display: grid; place-items: center; border-radius: var(--r-xs); background: var(--accent-soft); color: var(--accent); }
.qa-ico svg { width: 15px; height: 15px; }
.qa b { font-size: var(--t-xs); font-weight: 600; }

/* ---------------- activity feed ---------------- */
.activity { display: flex; gap: 11px; padding: 11px 0; }
.activity + .activity { border-top: 1px solid var(--line); }
.activity .a-ico { width: 26px; height: 26px; flex-shrink: 0; display: grid; place-items: center; border-radius: var(--r-xs); background: var(--surface-2); color: var(--text-2); }
.activity .a-ico svg { width: 13px; height: 13px; }
.activity .a-body { flex: 1; min-width: 0; }
.activity .a-body p { font-size: var(--t-xs); line-height: 1.5; }
.activity .a-body time { font-size: var(--t-micro); color: var(--text-3); }
