/*
 * TableGX theme tokens.
 *
 * Import this file from your Tailwind CSS entry file, e.g.:
 *
 *   @import 'tailwindcss';
 *   @source "../node_modules/tablegx/dist";
 *   @import 'tablegx/theme.css';
 *
 * Every token is defined with zero-specificity selectors (`:where(...)`) so any
 * value you declare in your own `:root` / `.dark` blocks wins automatically.
 */

@custom-variant dark (&:is(.dark *));

@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
}

:where(:root) {
  --background: oklch(0.985 0.005 260);
  --foreground: oklch(0.32 0.03 260);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.32 0.03 260);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.32 0.03 260);
  --primary: oklch(0.55 0.18 260);
  --primary-foreground: oklch(0.985 0.005 260);
  --secondary: oklch(0.93 0.015 260);
  --secondary-foreground: oklch(0.32 0.03 260);
  --muted: oklch(0.955 0.01 260);
  --muted-foreground: oklch(0.54 0.02 260);
  --accent: oklch(0.94 0.015 260);
  --accent-foreground: oklch(0.32 0.03 260);
  --destructive: oklch(0.58 0.22 27);
  --destructive-foreground: oklch(0.985 0.005 260);
  --border: oklch(0.82 0.03 260);
  --input: oklch(0.85 0.025 260);
  --ring: oklch(0.55 0.18 260);
  --radius: 0.5rem;
}

/*
 * Derived surfaces. These default to OPAQUE colors: pinned cells paint over
 * scrolled cells, and the sticky header/footer paint over scrolling rows. They
 * resolve against the local --card/--muted/--primary values, so they follow
 * .dark and any consumer overrides automatically.
 *
 * Translucent overrides are supported, but pair them with a backdrop-filter
 * on the [data-tgx-header-block] / [data-tgx-footer-row] / [data-tgx-pinned]
 * hooks so content scrolling behind those surfaces frosts instead of bleeding
 * through (see README "Customization").
 */
:where(:root) {
  --tgx-header-bg: color-mix(in oklch, var(--card), var(--muted) 45%);
  --tgx-row-hover-bg: color-mix(in oklch, var(--card), var(--muted) 60%);
  --tgx-row-selected-bg: color-mix(in oklch, var(--card), var(--primary) 10%);
  --tgx-row-selected-hover-bg: color-mix(in oklch, var(--card), var(--primary) 18%);
}

:where(.dark) {
  --background: oklch(0.26 0.02 260);
  --foreground: oklch(0.94 0.012 260);
  --card: oklch(0.3 0.022 260);
  --card-foreground: oklch(0.94 0.012 260);
  --popover: oklch(0.3 0.022 260);
  --popover-foreground: oklch(0.94 0.012 260);
  --primary: oklch(0.6 0.18 260);
  --primary-foreground: oklch(0.985 0.005 260);
  --secondary: oklch(0.36 0.025 260);
  --secondary-foreground: oklch(0.94 0.012 260);
  --muted: oklch(0.4 0.022 260);
  --muted-foreground: oklch(0.62 0.018 260);
  --accent: oklch(0.42 0.03 260);
  --accent-foreground: oklch(0.94 0.012 260);
  --destructive: oklch(0.65 0.2 27);
  --destructive-foreground: oklch(0.985 0.005 260);
  --border: oklch(0.4 0.035 260);
  --input: oklch(0.45 0.035 260);
  --ring: oklch(0.6 0.18 260);
}

/* --- Overlay enter/exit animations (Radix sets data-state) --- */

@keyframes tgx-pop-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes tgx-pop-out {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

@keyframes tgx-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes tgx-fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

:where([data-tgx-pop]) {
  transform-origin: var(--radix-popper-transform-origin, center);
}

:where([data-tgx-pop][data-state='open']) {
  animation: tgx-pop-in 120ms ease-out;
}

:where([data-tgx-pop][data-state='closed']) {
  animation: tgx-pop-out 100ms ease-in;
}

:where([data-tgx-fade][data-state='open']) {
  animation: tgx-fade-in 120ms ease-out;
}

:where([data-tgx-fade][data-state='closed']) {
  animation: tgx-fade-out 100ms ease-in;
}

/* Centered dialog needs its translate preserved inside the animation. */
@keyframes tgx-dialog-in {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes tgx-dialog-out {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.95);
  }
}

:where([data-tgx-dialog][data-state='open']) {
  animation: tgx-dialog-in 140ms ease-out;
}

:where([data-tgx-dialog][data-state='closed']) {
  animation: tgx-dialog-out 110ms ease-in;
}

/* --- Thin scrollbars for the virtualized scroll containers --- */

:where(.tgx-scrollbar) {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in oklch, var(--muted-foreground) 45%, transparent) transparent;
}

:where(.tgx-scrollbar)::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

:where(.tgx-scrollbar)::-webkit-scrollbar-track {
  background: transparent;
}

:where(.tgx-scrollbar)::-webkit-scrollbar-thumb {
  background: color-mix(in oklch, var(--muted-foreground) 45%, transparent);
  border-radius: 9999px;
}

:where(.tgx-scrollbar)::-webkit-scrollbar-thumb:hover {
  background: color-mix(in oklch, var(--muted-foreground) 65%, transparent);
}

/* Scrollbars are suppressed while a tab-slide animation is in flight so they
   don't visibly sweep across the (counter-translated) frozen pane. The class
   lives on the shared panels container so it covers the exiting panel too,
   whose own props are frozen by AnimatePresence. */
:where(.tgx-sliding) :where(.tgx-scrollbar) {
  scrollbar-width: none;
}

:where(.tgx-sliding) :where(.tgx-scrollbar)::-webkit-scrollbar {
  display: none;
}

/* The TabbedTable strip scrolls horizontally when there are more tabs than
   fit, but per the styling guide it must not show a visible scrollbar. We hide
   it the same way the mid-slide suppression does. The themed thumb/track colors
   below are kept (mirroring `tgx-scrollbar`) so that anywhere a scrollbar could
   still surface — e.g. a consumer override that re-enables it — it inherits the
   library's appearance rather than the browser default. (It does not reuse the
   `tgx-scrollbar` class so the strip isn't mistaken for a virtualized body
   scroll container.) */
:where(.tgx-tab-scroll) {
  scrollbar-width: none;
  scrollbar-color: color-mix(in oklch, var(--muted-foreground) 45%, transparent) transparent;
}

:where(.tgx-tab-scroll)::-webkit-scrollbar {
  display: none;
  height: 8px;
}

:where(.tgx-tab-scroll)::-webkit-scrollbar-track {
  background: transparent;
}

:where(.tgx-tab-scroll)::-webkit-scrollbar-thumb {
  background: color-mix(in oklch, var(--muted-foreground) 45%, transparent);
  border-radius: 9999px;
}
