/* =========================================
   ANIMATED TABLE — Material 3 (Expressive)
   Structure preserved: .animated-table, same ARIA/sorting hooks
   ========================================= */

/* ---- Tokens (fallbacks; your global MD3 tokens can override) ---- */
:root {
  /* Brand seeds */
  --it-purple: #4a154b;
  --it-blue: #64c3eb;
  --it-ink: #0e0f12;

  /* MD3 roles */
  --md-surface: #fafbfc;
  --md-surface-bright: #ffffff;
  --md-surface-container: #edf0f5;
  --md-surface-container-high: #e7ebf2;
  --md-on-surface: #111316;
  --md-on-surface-variant: #3e424a;
  --md-outline: #c3c8d1;
  --md-outline-variant: #dbe0e8;
  --md-primary: var(--it-purple);
  --md-on-primary: #ffffff;
  --md-primary-container: #EADDFF;
  --md-on-primary-container: #21005D;

  /* Elevation & motion */
  --elev-0: none;
  --elev-1: 0 2px 4px rgba(0,0,0,.10), 0 1px 1px rgba(0,0,0,.04);
  --elev-2: 0 6px 16px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.06);
  --ease-out: cubic-bezier(.2,0,.2,1);

  /* Shape & spacing */
  --it-radius: 18px;
  --it-pad-y: 14px;
  --it-pad-x: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --md-surface: #0f1114;
    --md-surface-bright: #14171b;
    --md-surface-container: #181b1f;
    --md-surface-container-high: #1e2227;
    --md-on-surface: #e7eaee;
    --md-on-surface-variant: #c7ccd6;
    --md-outline: #2c3137;
    --md-outline-variant: #3a3f46;
    --md-primary: color-mix(in oklab, var(--it-purple) 72%, var(--it-blue) 28%);
    --md-on-primary: #ffffff;
    --md-primary-container: #3a2a4a;
    --md-on-primary-container: #f0eaf7;

    --elev-1: 0 2px 4px rgba(0,0,0,.55);
    --elev-2: 0 10px 24px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.35);
  }
}

/* Optional page backdrop (kept subtle) */
body {
  background: linear-gradient(180deg, color-mix(in oklab, var(--md-surface) 94%, #fff) 0%, var(--md-surface) 100%)
}

/* ========== Table shell ========== */
table.animated-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  max-width: 760px;
  margin: 3em auto;

  font-family: "Fields Light", -apple-system, system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  color: var(--md-on-surface);

  background: var(--md-surface-bright);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--it-radius);
  box-shadow: var(--elev-1);
  overflow: hidden;
}

/* Cells */
table.animated-table th,
table.animated-table td {
  padding: var(--it-pad-y) var(--it-pad-x);
  text-align: left;
  border-bottom: 1px solid var(--md-outline-variant);
  vertical-align: middle;
  position: relative;
}

/* ========== Header (MD3 primary, expressive sheen & carets) ========== */
table.animated-table thead th {
  background: linear-gradient(110deg, color-mix(in oklab, var(--md-primary) 92%, #000 8%) 0%, color-mix(in oklab, var(--it-blue) 85%, #000 15%) 100%);
  color: var(--md-on-primary);
  font-weight: 400;
  letter-spacing: 0.1px;
  text-transform: uppercase;
  border-bottom: 0;
  cursor: pointer;
  user-select: none;
  outline-offset: 2px;
  transition: filter .18s var(--ease-out), opacity .18s var(--ease-out), background .3s var(--ease-out);
  padding-right: 2.4rem;
  box-shadow: inset 0 -2px 0 color-mix(in oklab, #ffffff 18%, var(--it-blue));
}

/* Rounded header corners */
table.animated-table thead tr th:first-child { border-top-left-radius: var(--it-radius) }
table.animated-table thead tr th:last-child { border-top-right-radius: var(--it-radius) }

/* Hover state layer */
@media (hover:hover) {
  table.animated-table thead th:hover {
    filter: saturate(110%);
  }
}

/* Carets (Font Awesome) */
table.animated-table thead th::before,
table.animated-table thead th::after {
  position: absolute; right: 12px;
  font-family: "Font Awesome 6 Free"; font-weight: 900; font-size: .9rem; line-height: 1;
  color: color-mix(in oklab, currentColor 70%, transparent);
  opacity: .75; pointer-events: none;
  transition: opacity .18s var(--ease-out), transform .18s var(--ease-out), color .18s var(--ease-out);
}
table.animated-table thead th::before { content: "\f0de"; top: calc(50% - .48rem); transform: translateY(-50%) } /* up */
table.animated-table thead th::after { content: "\f0dd"; top: calc(50% + .48rem); transform: translateY(-50%) } /* down */

/* Active sort direction emphasis */
table.animated-table thead th[aria-sort="ascending"]::before { color: var(--md-on-primary); opacity: 1; transform: translateY(-50%) scale(1.06) }
table.animated-table thead th[aria-sort="ascending"]::after { opacity: .35 }
table.animated-table thead th[aria-sort="descending"]::after { color: var(--md-on-primary); opacity: 1; transform: translateY(-50%) scale(1.06) }
table.animated-table thead th[aria-sort="descending"]::before { opacity: .35 }

/* Keyboard focus ring (MD3 container tone) */
table.animated-table thead th:focus-visible {
  outline: 3px solid var(--md-primary-container);
  outline-offset: 2px;
}

/* ========== Body (tonal zebra + hover) ========== */
table.animated-table tbody tr:nth-child(odd) td { background: var(--md-surface-bright) }
table.animated-table tbody tr:nth-child(even) td { background: var(--md-surface-container) }

/* Row hover state layer */
@media (hover:hover) {
  table.animated-table tbody tr:hover td {
    background: color-mix(in oklab, var(--md-primary-container) 22%, transparent);
    transition: background .18s var(--ease-out);
  }
}

/* Sorted column tint (add .sorted-col via JS) */
table.animated-table tbody td.sorted-col {
  background: color-mix(in oklab, var(--md-primary-container) 32%, transparent) !important;
  box-shadow: inset 2px 0 0 color-mix(in oklab, var(--md-primary) 34%, transparent);
  transition: background .24s var(--ease-out), box-shadow .24s var(--ease-out);
}

/* ========== Reveal animation (stagger on first view) ========== */
table.animated-table tbody tr {
  background: transparent;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .38s var(--ease-out), transform .38s var(--ease-out);
  will-change: transform, opacity;
}
table.animated-table tbody tr.visible {
  opacity: 1;
  transform: translateY(0);
  animation: it-row-in .42s var(--ease-out) forwards;
  animation-delay: calc(var(--row-index) * .1s);
}
table.animated-table tbody tr.hidden {
  opacity: 0;
  transform: translateY(-20px);
}
@keyframes it-row-in {
  from { opacity: 0; transform: translateY(20px) }
  to   { opacity: 1; transform: translateY(0) }
}

/* Sorting sheen while reordering (optional) */
table.animated-table.is-sorting tbody td.sorted-col::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent 0%, color-mix(in oklab, var(--it-blue) 26%, transparent) 50%, transparent 100%);
  opacity: 0; animation: it-sort-scan .6s ease;
}
@keyframes it-sort-scan {
  0%  { opacity: 0; transform: translateX(-18%) }
  30% { opacity: .38 }
  100% { opacity: 0; transform: translateX(18%) }
}

/* ========== Footer & last row rounding (optional polish) ========== */
table.animated-table tbody tr:last-child td:first-child { border-bottom-left-radius: calc(var(--it-radius) - 2px) }
table.animated-table tbody tr:last-child td:last-child { border-bottom-right-radius: calc(var(--it-radius) - 2px) }
table.animated-table tbody tr:last-child td { border-bottom: 0 }

/* ========== Reduced motion / High contrast ========== */
@media (prefers-reduced-motion: reduce) {
  table.animated-table tbody tr,
  table.animated-table tbody tr.visible { transition: none !important; animation: none !important; transform: none !important; opacity: 1 !important }
  table.animated-table.is-sorting tbody td.sorted-col::before { animation: none !important }
}
@media (forced-colors: active) {
  table.animated-table { border-color: CanvasText; box-shadow: none }
  table.animated-table thead th { background: CanvasText; color: Canvas; box-shadow: none }
  table.animated-table thead th::before,
  table.animated-table thead th::after { color: Canvas }
  table.animated-table th, table.animated-table td { border-color: CanvasText }
  table.animated-table tbody tr:hover td,
  table.animated-table tbody td.sorted-col { background: Canvas; box-shadow: none }
}

/* ========== Mobile sizing ========== */
@media (max-width: 768px) {
  table.animated-table { font-size: 14px }
  table.animated-table th,
  table.animated-table td { padding: 10px 12px }
  table.animated-table thead th::before,
  table.animated-table thead th::after { right: 10px; font-size: .85rem }
}