/* ============================================================
   family-base.css — shared product-agnostic component styles
   for the planning · marketing · dropshipper family.
   Served at /_family/family-base.css.
   Load order per app:
     1. /_family/family-tokens.css   (tokens — no rules)
     2. /_family/family-menu.css     (cog menu)
     3. /_family/family-base.css     (THIS FILE — components)
     4. <app>/styles.css             (product-local: --accent value,
                                      brand chrome, view internals)

   RULES OF THIS FILE
   - References tokens via var(--token); NEVER redefines token values.
   - Components only — no :root blocks, no [data-palette] token overrides,
     no [data-text-size] overrides, no .high-contrast overrides.
   - Class prefix .mkt-* is retained for parity with existing markup; the
     prefix is product-agnostic in practice (used by both Planning and
     Marketing today).
   ============================================================ */

/* ---------- Reset / base typography ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs-body);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px));
}

a { color: var(--brand); }

/* ---------- Skip link (a11y) ---------- */
.skip-link {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px; height: 1px;
  overflow: hidden;
}
.skip-link:focus {
  position: fixed;
  left: 12px; top: 12px;
  width: auto; height: auto;
  padding: var(--space-sm) var(--space-md);
  background: var(--brand);
  color: var(--brand-ink);
  z-index: 1000;
  border-radius: 6px;
}

/* Global keyboard focus indicator. Per-component :focus-visible rules
   override where the ring needs a tighter offset or a different colour. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 18px;
  background: var(--brand);
  color: var(--brand-ink);
  border-bottom: 1px solid var(--brand-dark);
  box-shadow: inset 0 -3px 0 0 var(--accent);
  flex: 0 0 auto;
}
.header h1 {
  margin: 0;
  font-size: clamp(15px, 1.1vw + 0.6rem, 26px);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: var(--space-md);
  min-width: 0;
}
.header h1 .brand-logo {
  height: clamp(22px, 2.4vw + 0.6rem, 32px);
  width: auto;
  display: block;
  flex-shrink: 0;
}
.header h1 .brand-logo.has-transparency {
  background: #fff;
  padding: 3px 6px;
  border-radius: 4px;
  box-sizing: content-box;
}
.header h1 .brand-suffix {
  white-space: nowrap;
  font-size: 0.78em;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 0.5px;
  position: relative;
  top: 2px;
  margin-left: 18px;
  flex-shrink: 0;
}
.header .badges {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}
.header .adm-launcher {
  background: rgba(255,255,255,0.18);
  color: var(--brand-ink, #fff);
  border: 0;
  width: 38px; height: 38px;
  border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background var(--dur-hover) var(--ease-standard);
}
.header .adm-launcher:hover { background: rgba(255,255,255,0.30); }
.header .adm-launcher:focus-visible { outline: 2px solid var(--brand-ink, #fff); outline-offset: 2px; }
.header .badge {
  padding: var(--space-xs) 10px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
}
.header .badge.error { background: #c02b15; color: var(--brand-ink, #fff); }
.header .time-pill {
  padding: var(--space-xs) 10px;
  background: rgba(var(--brand-rgb), 0.22);
  color: var(--brand-ink);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Subnav ---------- */
.subnav-row {
  position: relative;
  display: flex;
  align-items: stretch;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.subnav {
  display: flex;
  gap: 0;
  flex: 1 1 auto;
  padding: 0 var(--space-sm);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.subnav::-webkit-scrollbar { display: none; }

.subnav button {
  position: relative;
  background: none;
  border: none;
  padding: var(--space-md) 18px;
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  font-family: inherit;
  transition: color var(--dur-hover) var(--ease-standard),
              background var(--dur-hover) var(--ease-standard);
  white-space: nowrap;
  flex-shrink: 0;
}
.subnav button::after {
  content: '';
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 0;
  height: 3px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform var(--dur-enter) var(--ease-standard),
              opacity var(--dur-hover) var(--ease-standard);
  opacity: 0;
  pointer-events: none;
}
.subnav button:hover { color: var(--ink); }
.subnav button:hover::after { transform: scaleX(0.4); opacity: 0.4; }
.subnav button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.subnav button.active { color: var(--brand); }
.subnav button.active::after {
  transform: scaleX(1);
  opacity: 1;
}
.subnav button.tab-right {
  margin-left: auto;
  border-left: 1px solid var(--line);
  color: var(--ink-dim);
}
.subnav button.tab-right.active { color: var(--brand); }

/* ---------- Gear button (the cog menu surface itself lives in family-menu.css) ---------- */
.gear-btn {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--ink-dim);
  padding: 0 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--dur-hover) var(--ease-standard);
}
.gear-btn:hover { color: var(--brand); }
.gear-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.gear-menu {
  position: absolute;
  right: 8px;
  top: calc(100% + 4px);
  z-index: 50;
  transform-origin: top right;
  animation: fam-menu-pop var(--dur-enter) var(--ease-emphasis) both;
}
@keyframes fam-menu-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Main view shell ---------- */
main#content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background: var(--bg);
}
.view-root {
  max-width: 1280px;
  margin: 0 auto;
  animation: fam-view-in var(--dur-enter) var(--ease-standard) both;
}
@keyframes fam-view-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.view-loading {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-dim);
}

/* ---------- Placeholder card (stub views) ---------- */
.placeholder-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 28px 26px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.placeholder-card h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  color: var(--brand);
}
.placeholder-card .placeholder-sub {
  color: var(--ink-dim);
  font-size: var(--text-md);
  margin-bottom: 18px;
}
.placeholder-card .placeholder-body {
  color: var(--ink-muted);
  line-height: 1.55;
}
.placeholder-card .placeholder-tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: var(--space-md);
  letter-spacing: 0.3px;
}

/* ---------- Footer ---------- */
.page-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  padding: var(--space-sm) 18px;
  padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
  font-size: var(--text-sm);
  color: var(--ink-muted);
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 6px rgba(0,0,0,0.04);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}
.page-footer .footer-spacer { flex: 1 1 auto; }
.page-footer .label { color: var(--ink-muted); }
.page-footer .count-val { font-weight: 700; color: var(--brand); }
.page-footer .footer-counts { display: inline-flex; align-items: center; gap: var(--space-xs); }
.page-footer .footer-brand {
  color: var(--ink-dim);
  font-size: var(--text-xs);
  letter-spacing: 0.3px;
}

/* ---------- Status pills (operational: loading/ok/error) ---------- */
.status-pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  transition: background-color var(--dur-enter) var(--ease-standard),
              color var(--dur-enter) var(--ease-standard);
}
.status-pill.status-loading { background: var(--status-loading-bg); color: var(--status-loading-ink); }
.status-pill.status-error   { background: var(--status-error-bg);   color: var(--status-error-ink); }
.status-pill.status-ok      { background: var(--status-ok-bg);      color: var(--status-ok-ink); }
.status-pill.status-loading::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 6px;
  vertical-align: 1px;
  animation: fam-pulse-dot 1.4s ease-in-out infinite;
}
@keyframes fam-pulse-dot {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.2); }
}

/* ---------- Card hover lift (transform-only, no layout thrash) ---------- */
.biz-card,
.mkt-card,
.placeholder-card {
  transition: transform var(--dur-hover) var(--ease-standard),
              box-shadow var(--dur-hover) var(--ease-standard);
}
.biz-card:hover,
.mkt-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
}
.biz-card:active,
.mkt-card:active { transform: translateY(0); }

/* ---------- Chip / filter toggle ---------- */
.mkt-chip {
  transition: transform var(--dur-fast) var(--ease-emphasis),
              background var(--dur-hover) var(--ease-standard),
              color var(--dur-hover) var(--ease-standard),
              border-color var(--dur-hover) var(--ease-standard);
  will-change: transform;
}
.mkt-chip.active { transform: scale(1.04); }

/* ---------- Form field focus (wrapper-based) ---------- */
.mkt-field {
  position: relative;
}
.mkt-field input,
.mkt-field textarea,
.mkt-field select {
  transition: border-color var(--dur-hover) var(--ease-standard),
              box-shadow var(--dur-hover) var(--ease-standard);
}
.mkt-field input:focus,
.mkt-field textarea:focus,
.mkt-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.mkt-field input:focus-visible,
.mkt-field textarea:focus-visible,
.mkt-field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Toast ---------- */
.mkt-toast {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 100100;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  font-size: var(--text-md);
  font-weight: 500;
  animation: fam-toast-in var(--dur-enter) var(--ease-emphasis) both;
}
.mkt-toast.is-leaving {
  animation: fam-toast-out var(--dur-exit) var(--ease-standard) both;
}
.mkt-toast[data-tone="error"] { border-left-color: #c0392b; }
.mkt-toast[data-tone="ok"]    { border-left-color: #27af00; }
@keyframes fam-toast-in {
  from { opacity: 0; transform: translateY(-8px) translateX(6px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fam-toast-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(-4px); }
}

/* ---------- Modal (backdrop + panel) ---------- */
.mkt-modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--modal-backdrop);
  z-index: 100050;
  animation: fam-fade-in var(--dur-enter) var(--ease-standard) both;
}
.mkt-modal-backdrop.is-leaving {
  animation: fam-fade-out var(--dur-exit) var(--ease-standard) both;
}
.mkt-modal {
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--modal-radius);
  box-shadow: 0 24px 64px rgba(0,0,0,0.28);
  animation: fam-modal-in var(--dur-enter) var(--ease-emphasis) both;
}
.mkt-modal.is-leaving {
  animation: fam-modal-out var(--dur-exit) var(--ease-standard) both;
}
@keyframes fam-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes fam-modal-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: scale(0.98); }
}
@keyframes fam-fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fam-fade-out { from { opacity: 1; } to { opacity: 0; } }

/* ---------- Suggestion card (slide-in side panel) ---------- */
.mkt-suggestion-enter {
  animation: fam-suggestion-in var(--dur-enter) var(--ease-emphasis) both;
}
.mkt-suggestion-leave {
  animation: fam-suggestion-out var(--dur-exit) var(--ease-standard) both;
}
@keyframes fam-suggestion-in {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fam-suggestion-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateX(8px); }
}

/* ---------- Auto-fill sparkle (one-shot tinted wash on populated fields) ---------- */
.mkt-sparkle {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.mkt-sparkle::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg,
    transparent 0%,
    transparent 30%,
    var(--accent-soft) 50%,
    transparent 70%,
    transparent 100%);
  transform: translateX(-100%);
  animation: fam-shimmer 700ms var(--ease-standard) 1 forwards;
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: multiply;
}
@keyframes fam-shimmer {
  to { transform: translateX(100%); }
}

/* ---------- Scan sweep (AI-processing indicator on a row) ---------- */
.mkt-scan {
  position: relative;
  overflow: hidden;
}
.mkt-scan::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 30%;
  height: 100%;
  background: linear-gradient(90deg, transparent,
    color-mix(in srgb, var(--accent) 35%, transparent),
    transparent);
  transform: translateX(-100%);
  animation: fam-scan-sweep 1.8s linear infinite;
  pointer-events: none;
}
@keyframes fam-scan-sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* ---------- Skeleton loader ---------- */
.mkt-skeleton {
  background: linear-gradient(90deg,
    var(--surface-2) 0%,
    var(--line-soft) 50%,
    var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: fam-skeleton-pan 1.4s linear infinite;
  border-radius: 4px;
  color: transparent;
}
@keyframes fam-skeleton-pan {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ---------- Spinner ---------- */
.mkt-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: fam-spin 0.9s linear infinite;
  vertical-align: -2px;
}
@keyframes fam-spin { to { transform: rotate(360deg); } }

/* ---------- Empty-state motion ---------- */
.mkt-empty-illustration {
  animation: fam-float 3.6s ease-in-out infinite;
  transform-origin: center;
  will-change: transform;
}
@keyframes fam-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}
.mkt-empty-pulse {
  animation: fam-empty-breathe 3.2s ease-in-out infinite;
}
@keyframes fam-empty-breathe {
  0%, 100% { opacity: 0.85; }
  50%      { opacity: 1; }
}

/* ---------- Bot status pill (pulsing dot) ---------- */
.mkt-bot-pill {
  position: relative;
}
.mkt-bot-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  margin-right: 6px;
  vertical-align: 1px;
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
  animation: fam-bot-pulse 1.6s ease-in-out infinite;
}
.mkt-bot-dot[data-state="idle"]   { background: #94a3b8; animation: none; box-shadow: none; }
.mkt-bot-dot[data-state="failed"] { background: #f87171; animation: none; box-shadow: none; }
@keyframes fam-bot-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(52, 211, 153, 0.7); }
  70%  { box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0   rgba(52, 211, 153, 0); }
}

/* ============================================================
   Responsive breakpoints
   ≤1280px — single-column shell
   ≤768px  — mobile: stacks, full-viewport modals, ≥44px touch
   ≤479px  — phone: header brand-suffix shrinks
   ============================================================ */
@media (max-width: 1280px) {
  .view-root { max-width: 100%; }
}

@media (max-width: 768px) {
  main#content { padding: var(--space-md); }
  .placeholder-card { padding: 20px 18px; }

  .header { flex-wrap: wrap; row-gap: var(--space-xs); padding: var(--space-sm) var(--space-md); }
  .header h1 { gap: var(--space-sm); flex: 1 1 auto; min-width: 0; }
  .header .badges { gap: var(--space-xs); flex-wrap: wrap; }
  .header .adm-launcher { width: 44px; height: 44px; }

  .page-footer { gap: var(--space-sm); padding-left: 10px; padding-right: 10px; }
  .page-footer .footer-counts .label { display: none; }

  .gear-menu { right: var(--space-sm); max-width: calc(100vw - 16px); }

  .subnav button { min-height: 44px; padding: var(--space-md) 14px; font-size: var(--text-md); }
  .gear-btn { min-width: 44px; min-height: 44px; }

  /* Trial / upgrade banner — JS-injected anchor needs touch target */
  #mkt-trial-banner a {
    display: inline-block;
    min-height: 44px;
    line-height: 44px;
    padding: 0 6px;
    vertical-align: middle;
  }

  /* Modal — full-viewport sheet on phones */
  .mkt-modal-backdrop { padding: 0; align-items: stretch; }
  .mkt-modal {
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
}

@media (max-width: 600px) {
  /* Right-edge fade hint that subnav scrolls horizontally */
  .subnav-row::after {
    content: '';
    position: absolute;
    right: 50px;
    top: 0; bottom: 1px;
    width: 28px;
    background: linear-gradient(to right, transparent, var(--surface-2));
    pointer-events: none;
  }
}

@media (max-width: 479px) {
  .header h1 .brand-suffix { margin-left: 10px; font-size: 0.72em; }
  .header h1 { margin-right: auto; }
}

/* ============================================================
   Reduced motion
   Kill loops and transform-based enter/exit; keep colour fades
   short and visible — they communicate state without triggering
   vestibular issues.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .status-pill,
  .subnav button {
    transition-duration: 120ms !important;
  }
  .biz-card:hover,
  .mkt-card:hover { transform: none !important; }
  .mkt-bot-dot,
  .rbu-pill-dot-running { box-shadow: none !important; }
  .mkt-skeleton { background: var(--surface-2) !important; }
}
