/* Anvul polish primitives — used across admin + founder pages.
   Skeletons, status pills with icons, fade-up rows, sticky filter bars,
   inline error blocks, modal polish, and inline-validation states. */

/* ===== Wave 4 motion / shadow tokens ===== */
:root {
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur-med: 240ms;
  --dur-slow: 420ms;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.10);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.25);
}

.btn { transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease); }
.btn:active { transform: scale(0.97); }
.btn:hover:not(:disabled) { box-shadow: var(--shadow-sm); }

.card, .tile, .skin-tile, .row-item { transition: transform var(--dur-med) var(--ease), box-shadow var(--dur-med) var(--ease), border-color var(--dur-fast) var(--ease); }
.card:hover, .tile:hover, .row-item:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

@keyframes toast-slide-in { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.toast { animation: toast-slide-in var(--dur-med) var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ===== Wave 4 tables polish ===== */
.table { width: 100%; border-collapse: collapse; }
.table tbody tr:nth-child(odd) { background: rgba(255,255,255,0.02); }
.table tbody tr:hover { background: rgba(16,185,129,0.04); }
.table td, .table th { padding: 12px 14px; border-bottom: 1px solid var(--border, rgba(255,255,255,0.06)); }
.status-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 500; }
.status-pill.success { background: rgba(16,185,129,0.14); color: #6EE7B7; }
.status-pill.warning { background: rgba(245,158,11,0.14); color: #FBBF24; }
.status-pill.error { background: rgba(248,113,113,0.14); color: #F87171; }
.status-pill.info { background: rgba(59,130,246,0.14); color: #93C5FD; }
.status-pill .ri { font-size: 13px; }

/* ===== Wave 4 empty/error/celebration states ===== */
.empty-state, .error-state, .celebration-state { padding: 32px 16px; text-align: center; }
.empty-state svg, .error-state svg, .celebration-state svg { width: 96px; height: 96px; opacity: 0.85; margin-bottom: 12px; }
.empty-state h3, .error-state h3, .celebration-state h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.empty-state p, .error-state p { margin: 0 0 16px; font-size: 13px; color: var(--text2, #8FB4A8); }

/* ===== Wave 4 required-field markers and form polish ===== */
label .required { color: #F87171; margin-left: 2px; }
input:required + label::after, .form-field.required label::after { content: " *"; color: #F87171; }
input:invalid:not(:placeholder-shown), select:invalid:not(:placeholder-shown) { border-color: #F87171; }
input:valid:not(:placeholder-shown), select:valid:not(:placeholder-shown) { border-color: var(--accent, #10B981); }
.help-link { font-size: 12px; color: var(--text2, #8FB4A8); margin-left: 8px; }
.help-link:hover { color: var(--accent, #10B981); }

/* ===== Wave 4 iPad / tablet landscape layouts ===== */
@media (min-width: 768px) and (orientation: landscape) {
  .admin-layout, .founder-layout { display: grid; grid-template-columns: 240px 1fr; gap: 24px; }
  .admin-layout > .sidebar, .founder-layout > .sidebar { position: sticky; top: 16px; }
}
@media (min-width: 1024px) {
  .container, .container-narrow { max-width: 1200px; }
}
@media (min-width: 768px) {
  .skin-tile-grid { grid-template-columns: repeat(3, 1fr); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ----- Skeleton loaders ----- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 0%, var(--surface) 50%, var(--bg-elevated) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 4px;
  display: inline-block;
}
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-row { height: 14px; margin: 6px 0; }
.skeleton-block { height: 60px; margin: 6px 0; }
.skeleton-table { padding: 16px; }
.skeleton-table .skeleton-row { width: 100%; }
.skeleton-table .skeleton-row:nth-child(2) { width: 88%; }
.skeleton-table .skeleton-row:nth-child(3) { width: 92%; }
.skeleton-table .skeleton-row:nth-child(4) { width: 80%; }
.skeleton-table .skeleton-row:nth-child(5) { width: 76%; }

/* ----- Page-level loading skeleton: auto-hide once page hydrates -----
 * Pages place <div id="loading-skeleton" class="skeleton">…</div> at the top
 * as a hint that the shell is loading. Header.js sets body.is-loaded after
 * DOMContentLoaded so the page-level skeleton vanishes once the shell is up.
 * Per-table skeletons (rendered by skeletonTable()) keep their own lifecycle.
 */
body.is-loaded #loading-skeleton { display: none; }

/* ----- Status pills with inline-icon support ----- */
.pill-icon {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.pill-icon svg { width: 10px; height: 10px; flex: 0 0 10px; }
.pill-icon.ok { background: rgba(74, 222, 128, 0.15); color: var(--success); }
.pill-icon.warn { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.pill-icon.err { background: rgba(248, 113, 113, 0.15); color: var(--error); }
.pill-icon.muted { background: rgba(155, 149, 138, 0.15); color: var(--text-muted); }
.pill-icon.info { background: rgba(229, 115, 83, 0.15); color: var(--accent-strong); }

/* ----- Iconographic backup for status pills (color-blind safe) ------------
   Adds a unicode glyph ::before so any pill marked with a status modifier
   gets an icon even if the markup didn't inline an SVG. The :where() wrapper
   keeps specificity at zero so individual page styles continue to win. */
:where(.pill, .status-pill, .badge):where(
  .s-accepted, .s-approved, .s-active, .s-resolved, .s-paid, .s-signed,
  .s-ok, .s-success, .s-verified, .ok, .success
)::before { content: "\2713\00a0"; }
:where(.pill, .status-pill, .badge):where(
  .s-pending_review, .s-pending, .s-awaiting, .s-awaiting_response,
  .s-trialing, .s-invited, .s-draft, .s-contained, .pending, .awaiting
)::before { content: "\23f1\00a0"; }
:where(.pill, .status-pill, .badge):where(
  .s-declined, .s-rejected, .s-failed, .s-expired, .s-revoked, .s-blocked,
  .s-cancelled, .s-canceled, .err, .error
)::before { content: "\2717\00a0"; }
:where(.pill, .status-pill, .badge):where(
  .s-warn, .s-warning, .s-expiring, .s-stale, .s-open, .s-car_open,
  .s-rejected_max_iterations, .warn
)::before { content: "\26a0\00a0"; }
/* If the markup already includes an inline SVG, hide the duplicated glyph
   to avoid showing both. */
:where(.pill, .status-pill, .badge):where(
  .s-accepted, .s-approved, .s-active, .s-resolved, .s-paid, .s-signed,
  .s-ok, .s-success, .s-verified, .ok, .success,
  .s-pending_review, .s-pending, .s-awaiting, .s-awaiting_response,
  .s-trialing, .s-invited, .s-draft, .s-contained, .pending, .awaiting,
  .s-declined, .s-rejected, .s-failed, .s-expired, .s-revoked, .s-blocked,
  .s-cancelled, .s-canceled, .err, .error,
  .s-warn, .s-warning, .s-expiring, .s-stale, .s-open, .s-car_open,
  .s-rejected_max_iterations, .warn
):has(svg)::before { content: none; }

/* ----- Stagger fade-in for list rows ----- */
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.fade-row { animation: fade-up 0.32s ease-out both; }

/* ----- Inline form validation ----- */
input.invalid, select.invalid, textarea.invalid { border-color: var(--error) !important; }
input:invalid:not(:placeholder-shown), select:invalid, textarea:invalid:not(:placeholder-shown) {
  border-color: var(--error);
}
input:focus:invalid:not(:placeholder-shown), textarea:focus:invalid:not(:placeholder-shown) {
  outline-color: var(--error);
}
.field-error { font-size: 11px; color: var(--error); margin-top: 4px; min-height: 14px; }
.field-hint  { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ----- Friendly error block ----- */
.err-block {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
}
.err-block svg { width: 18px; height: 18px; flex: 0 0 18px; color: var(--error); margin-top: 1px; }
.err-block .err-title { font-weight: 600; margin-bottom: 2px; color: var(--error); }
.err-block .err-msg { color: var(--text-muted); font-size: 12px; }
.err-block button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  margin-left: auto;
  white-space: nowrap;
}
.err-block button:hover { border-color: var(--accent-strong); color: var(--accent-strong); }

/* ----- Empty-state SVG illustrations ----- */
.empty-illust {
  width: 96px;
  height: 96px;
  margin: 0 auto 14px;
  color: var(--text-subtle);
  opacity: 0.7;
}
.empty-illust svg { width: 100%; height: 100%; stroke: currentColor; fill: none; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

/* ----- Sticky filter bar ----- */
.sticky-filter {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 10px 0 12px;
  margin: -10px 0 12px;
  border-bottom: 1px solid var(--border);
}

/* ----- Modal polish (slide / fade depending on viewport) -----
 * W18.E — sibling selectors apply the same fade/slide animation to the
 * .pl-modal-overlay/.pl-modal pair used by the team page. The two
 * dialogs are DOM siblings (not parent → child) so we use ~ for the
 * .pl-modal-overlay ↔ .pl-modal pairing.
 */
@keyframes modal-fade-up { from { opacity: 0; transform: translateY(20px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes modal-slide-right { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes overlay-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-overlay.open,
.pl-modal-overlay.open { backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: overlay-fade 0.2s ease both; }
.modal-overlay.open .modal,
.pl-modal-overlay.open ~ .pl-modal.open { animation: modal-slide-right 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@media (max-width: 720px) {
  .modal-overlay.open .modal,
  .pl-modal-overlay.open ~ .pl-modal.open { animation: modal-fade-up 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
}

/* ----- Generic interactive focus ring ----- */
button:focus-visible, a:focus-visible, [role="button"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ----- KPI sparkline with delta ----- */
.kpi-spark {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 22px;
  margin-top: 6px;
}
.kpi-spark span {
  flex: 1 1 0;
  min-height: 2px;
  background: var(--accent-soft);
  border-radius: 2px 2px 0 0;
  transition: background 0.2s;
}
.kpi-spark span.last { background: var(--accent-strong); }
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
}
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--error); }
.kpi-delta svg { width: 10px; height: 10px; }

/* ----- Animated tab underline ----- */
.tabs-anim { position: relative; }
.tabs-anim .tab-indicator {
  position: absolute;
  bottom: -1px;
  height: 2px;
  background: var(--accent-strong);
  border-radius: 1px;
  transition: left 0.24s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  pointer-events: none;
}

/* ----- Split-hero pattern: form on right, persuasion on left -----
 * Auth pages, marketing landings, anywhere a single form sits in
 * acres of negative space. Collapses to single-column on mobile.
 */
.split-hero {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  min-height: 80vh;
  align-items: center;
  gap: 48px;
  padding: 32px;
  max-width: 1280px;
  margin: 0 auto;
}
.split-aside {
  padding: 32px;
}
.split-aside h1 {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
}
.split-aside p.lead {
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0 0 24px;
}
.split-aside ul.value-props {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.split-aside ul.value-props li {
  display: flex;
  gap: 12px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
}
.split-aside ul.value-props li svg {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  color: var(--accent);
  margin-top: 1px;
}
.split-form {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
@media (max-width: 768px) {
  .split-hero {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 16px;
    gap: 24px;
  }
  .split-aside { padding: 16px; order: 2; }
  .split-aside h1 { font-size: 24px; }
}

/* ===== Tenant-admin permission gates =====
 * Operator-only UI is hidden + replaced with a tooltip when a tenant-admin
 * (operator's deputy) views the same shared admin pages. Saves maintaining
 * a parallel page tree per role — decision 2026-05-12 §3 of the validation
 * doc (research/boss-view-validation-2026-05-12.md). body.role-tenant-admin
 * is set by header.js after /users/me resolves.
 */
body.role-tenant-admin [data-operator-only] {
  position: relative;
  opacity: 0.45;
  pointer-events: none;
  user-select: none;
}
body.role-tenant-admin [data-operator-only]::after {
  content: "Operator only";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, rgba(255,255,255,0.55));
  background: rgba(0,0,0,0.4);
  pointer-events: auto;
  cursor: not-allowed;
  border-radius: inherit;
}
