/* ============================================================
   world_class_polish.css — V8.28 site-wide micro-interaction layer
   Class-based only. No element selectors that conflict with page CSS.
   No !important unless absolutely necessary. No body bg rewrite.
   All vars use fallbacks so this file works even when brand_tokens
   isn't loaded. Source-of-truth tokens: templates/_partials/brand_tokens.html
   ============================================================ */


/* ── 1. Hover micro-interactions (subtract, don't add color flood) ── */
/* Hover state on buttons / cards / rows uses a SUBTLE white overlay. */
.btn,
.card,
.row,
.tile,
.pill,
.chip,
.sd-hover {
  transition: background-color 150ms cubic-bezier(0.16, 1, 0.3, 1),
              border-color    150ms cubic-bezier(0.16, 1, 0.3, 1),
              color           150ms cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow      150ms cubic-bezier(0.16, 1, 0.3, 1),
              transform       150ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: background-color, border-color;
}
.btn:hover,
.card:hover,
.row:hover,
.tile:hover,
.pill:hover,
.chip:hover,
.sd-hover:hover {
  background-color: rgba(255, 255, 255, 0.035);
}
.btn:active,
.tile:active,
.pill:active,
.sd-hover:active { transform: translateY(0.5px); }
.sd-hover-lift { transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 200ms cubic-bezier(0.16, 1, 0.3, 1); }
.sd-hover-lift:hover { transform: translateY(-1px); box-shadow: 0 8px 24px -12px rgba(0, 0, 0, 0.6); }


/* ── 2. Focus rings — 2px accent, 2px offset, inherits radius ── */
/* Class form for explicit opt-in: */
.focus-ring:focus-visible {
  outline: 2px solid var(--accent, #00e676);
  outline-offset: 2px;
  border-radius: inherit;
}
/* Global form: every interactive element gets the same ring on keyboard nav. */
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
[role="tab"]:focus-visible,
[role="link"]:focus-visible,
[role="menuitem"]:focus-visible,
[role="option"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 2px solid var(--accent, #00e676);
  outline-offset: 2px;
}
/* Remove default mouse-click focus ring (keyboard only via :focus-visible). */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}


/* ── 3. Loading skeletons (shimmer + reduced-motion pulse fallback) ── */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bg-surface, #0f0f11);
  border: 1px solid var(--hairline, #27272a);
  border-radius: var(--r-sm, 4px);
  color: transparent;
  user-select: none;
}
.skeleton::after {
  content: "";
  position: absolute; inset: 0;
  background-image: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.05) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  transform: translateX(-100%);
  animation: sd-shimmer 1.5s linear infinite;
}
@keyframes sd-shimmer {
  100% { transform: translateX(100%); }
}
.skeleton-line {
  display: block;
  height: 12px;
  margin: 6px 0;
  border-radius: 4px;
  background: var(--bg-surface, #0f0f11);
}
.skeleton-line--sm { height: 9px; }
.skeleton-line--lg { height: 18px; }
.skeleton-line--title { height: 22px; width: 40%; }
.skeleton-line--meta { height: 10px; width: 70%; opacity: 0.7; }
.skeleton-card {
  padding: 16px;
  border: 1px solid var(--hairline, #27272a);
  border-radius: var(--r-md, 8px);
  background: var(--bg-surface, #0f0f11);
  min-height: 80px;
}
.skeleton-circle {
  display: inline-block;
  width: 32px; height: 32px;
  border-radius: 9999px;
  background: var(--bg-surface, #0f0f11);
}


/* ── 4. Empty states — centered, restrained, serif heading ── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  max-width: 360px;
  margin: 48px auto;
  padding: 24px;
  color: var(--ink-secondary, #a1a1aa);
}
.empty-state__icon {
  display: block;
  width: 40px; height: 40px;
  margin: 0 auto 16px;
  opacity: 0.5;
  color: var(--ink-tertiary, #52525b);
}
.empty-state__title {
  margin: 0 0 8px;
  font-family: var(--ff-serif, 'Instrument Serif', Georgia, serif);
  font-size: var(--type-lg, 19px);
  font-weight: 400;
  color: var(--ink-primary, #e4e4e7);
  letter-spacing: -0.01em;
}
.empty-state__body {
  margin: 0 0 16px;
  font-size: var(--type-sm, 13px);
  line-height: 1.5;
  color: var(--ink-secondary, #a1a1aa);
}
.empty-state__action {
  margin-top: 8px;
}


/* ── 5. Error states — red-tinted, inline banners, retry button ── */
.error-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  max-width: 420px;
  margin: 32px auto;
  padding: 24px;
  border: 1px solid rgba(255, 92, 92, 0.25);
  border-radius: var(--r-md, 8px);
  background: rgba(255, 92, 92, 0.04);
  color: var(--signal-critical, #FF5C5C);
}
.error-state__title {
  margin: 0 0 8px;
  font-family: var(--ff-serif, 'Instrument Serif', Georgia, serif);
  font-size: var(--type-lg, 19px);
  font-weight: 400;
  color: var(--ink-primary, #e4e4e7);
}
.error-state__body {
  margin: 0;
  font-size: var(--type-sm, 13px);
  line-height: 1.5;
  color: var(--ink-secondary, #a1a1aa);
}
.error-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border: 1px solid rgba(255, 92, 92, 0.25);
  border-left: 3px solid var(--signal-critical, #FF5C5C);
  border-radius: var(--r-sm, 4px);
  background: rgba(255, 92, 92, 0.04);
  color: var(--signal-critical, #FF5C5C);
  font-size: var(--type-sm, 13px);
}
.error-banner__icon { flex: 0 0 auto; width: 16px; height: 16px; }
.error-banner__body { flex: 1 1 auto; color: var(--ink-primary, #e4e4e7); }
.error-banner__retry {
  flex: 0 0 auto;
  padding: 4px 10px;
  background: transparent;
  color: var(--signal-critical, #FF5C5C);
  border: 1px solid currentColor;
  border-radius: var(--r-sm, 4px);
  font-family: var(--ff-mono, monospace);
  font-size: var(--type-2xs, 11px);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: background 150ms cubic-bezier(0.16, 1, 0.3, 1);
}
.error-banner__retry:hover { background: rgba(255, 92, 92, 0.1); }


/* ── 6. Toast notifications — bottom-right, auto-dismiss ── */
.toast-stack {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9000;
  max-width: 360px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--bg-overlay, #1c2028);
  border: 1px solid var(--hairline, #27272a);
  border-left: 3px solid var(--ink-tertiary, #52525b);
  border-radius: var(--r-sm, 4px);
  color: var(--ink-primary, #e4e4e7);
  font-size: var(--type-sm, 13px);
  box-shadow: var(--shadow-card, 0 8px 24px -8px rgba(0, 0, 0, 0.7));
  pointer-events: auto;
  transform: translateX(120%);
  opacity: 0;
  animation: sd-toast-in 240ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes sd-toast-in {
  to { transform: translateX(0); opacity: 1; }
}
.toast[data-leaving="true"] {
  animation: sd-toast-out 200ms cubic-bezier(0.65, 0, 0.35, 1) forwards;
}
@keyframes sd-toast-out {
  to { transform: translateX(120%); opacity: 0; }
}
.toast-success { border-left-color: var(--signal-live, #00e676); }
.toast-error   { border-left-color: var(--signal-critical, #FF5C5C); }
.toast-info    { border-left-color: var(--signal-info, #8BB7CC); }
.toast-warning { border-left-color: var(--signal-attention, #FFB454); }
.toast__icon { flex: 0 0 auto; width: 16px; height: 16px; }
.toast__body { flex: 1 1 auto; }
.toast__close {
  flex: 0 0 auto;
  background: transparent; border: none; cursor: pointer;
  color: var(--ink-tertiary, #52525b);
  font-size: 18px; line-height: 1;
  padding: 0; width: 20px; height: 20px;
}
.toast__close:hover { color: var(--ink-primary, #e4e4e7); }


/* ── 7. Tabular numbers everywhere they matter ── */
.num,
.tabular-nums,
.sd-num,
.stat-value,
.metric-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}


/* ── 8. Mobile-responsive utilities ── */
.mobile-hidden  { display: revert; }
.desktop-hidden { display: none; }
@media (max-width: 760px) {
  .mobile-hidden  { display: none !important; }
  .desktop-hidden { display: revert; }
  .mobile-stack {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .mobile-stack > * { width: 100%; }
  .mobile-full { width: 100% !important; }
  .mobile-center { text-align: center; }
}
@media (max-width: 640px) {
  .toast-stack { left: 16px; right: 16px; bottom: 16px; max-width: none; }
  .empty-state, .error-state { margin: 24px 16px; }
}


/* ── 9. Accessibility utilities ── */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  top: -40px; left: 8px;
  padding: 8px 16px;
  background: var(--accent, #00e676);
  color: #0a0a0c;
  font-family: var(--ff-mono, monospace);
  font-size: var(--type-xs, 12px);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-decoration: none;
  border-radius: var(--r-sm, 4px);
  z-index: 10000;
  transition: top 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
.skip-link:focus { top: 8px; outline: 2px solid #0a0a0c; outline-offset: 2px; }
.sd-no-select { user-select: none; -webkit-user-select: none; }
.sd-clickable { cursor: pointer; }
.sd-disabled  { opacity: 0.5; cursor: not-allowed; pointer-events: none; }


/* ── 10. prefers-reduced-motion — disable all animation/transition ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton::after { animation: none; opacity: 0.6; }
  .skeleton { animation: sd-pulse-flat 2s ease-in-out infinite; }
  @keyframes sd-pulse-flat {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.72; }
  }
}


/* ── 11. High-contrast mode (prefers-contrast: more) ── */
@media (prefers-contrast: more) {
  .btn, .card, .row, .tile, .pill, .chip,
  .skeleton, .skeleton-card,
  .error-banner, .error-state, .toast {
    border-width: 2px;
  }
  button:focus-visible,
  a:focus-visible,
  [role="button"]:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline-width: 3px;
    outline-offset: 3px;
  }
  .empty-state__body,
  .toast,
  .error-banner__body {
    color: #ffffff;
  }
}


/* ── 12. Print styles ── */
@media print {
  .no-print,
  .toast-stack,
  .skip-link,
  nav,
  footer,
  .sd-settings-trigger,
  .sd-settings-panel,
  .sd-settings-backdrop,
  button {
    display: none !important;
  }
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-family: Georgia, 'Times New Roman', serif !important;
  }
  .card, .row, .tile {
    background: #ffffff !important;
    color: #000000 !important;
    border: 1px solid #000 !important;
    box-shadow: none !important;
    page-break-inside: avoid;
  }
  a { color: #000000 !important; text-decoration: underline; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 80%; }
  h1, h2, h3, h4 { page-break-after: avoid; }
  .empty-state, .error-state, .skeleton { display: none !important; }
}


/* ── Density variants — set <html data-density="compact"> via settings menu ── */
:root[data-density="compact"] .card,
:root[data-density="compact"] .row,
:root[data-density="compact"] .tile {
  padding: 8px 12px;
}
:root[data-density="compact"] .skeleton-line { margin: 4px 0; }


/* ── Light-mode override stub (experimental) ── */
:root[data-theme="light"] {
  --bg-void:        #fafafa;
  --bg-surface:     #ffffff;
  --bg-raised:      #f4f4f5;
  --bg-overlay:     #e4e4e7;
  --bg-hover:       #ececef;
  --hairline:       #d4d4d8;
  --hairline-strong:#a1a1aa;
  --border:         #d4d4d8;
  --border-glow:    #a1a1aa;
  --ink-primary:    #18181b;
  --ink-secondary:  #52525b;
  --ink-tertiary:   #71717a;
  --text:           #18181b;
  --text2:          #52525b;
  --text3:          #71717a;
}
