@import 'tailwindcss';

@import 'tw-animate-css';

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

:root {
  --radius: 0.625rem;
  --background: oklch(1 0 0);
  --foreground: oklch(0.129 0.042 264.695);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.129 0.042 264.695);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.129 0.042 264.695);
  --primary: oklch(0.208 0.042 265.755);
  --primary-foreground: oklch(0.984 0.003 247.858);
  --secondary: oklch(0.968 0.007 247.896);
  --secondary-foreground: oklch(0.208 0.042 265.755);
  --muted: oklch(0.968 0.007 247.896);
  --muted-foreground: oklch(0.554 0.046 257.417);
  --accent: oklch(0.968 0.007 247.896);
  --accent-foreground: oklch(0.208 0.042 265.755);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0.929 0.013 255.508);
  --input: oklch(0.929 0.013 255.508);
  --ring: oklch(0.704 0.04 256.788);
  --chart-1: oklch(0.646 0.222 41.116);
  --chart-2: oklch(0.6 0.118 184.704);
  --chart-3: oklch(0.398 0.07 227.392);
  --chart-4: oklch(0.828 0.189 84.429);
  --chart-5: oklch(0.769 0.188 70.08);
  --sidebar: oklch(0.984 0.003 247.858);
  --sidebar-foreground: oklch(0.129 0.042 264.695);
  --sidebar-primary: oklch(0.208 0.042 265.755);
  --sidebar-primary-foreground: oklch(0.984 0.003 247.858);
  --sidebar-accent: oklch(0.968 0.007 247.896);
  --sidebar-accent-foreground: oklch(0.208 0.042 265.755);
  --sidebar-border: oklch(0.929 0.013 255.508);
  --sidebar-ring: oklch(0.704 0.04 256.788);
  --scrollbar-thumb: rgba(100, 116, 139, 0.38);
  --scrollbar-thumb-hover: rgba(100, 116, 139, 0.58);
  --scrollbar-thumb-active: rgba(100, 116, 139, 0.72);
}

.dark {
  /* Neutral (chroma 0) dark theme — true black/grey rather than blue.
   * Surface/text tokens drop the ~0.04 blue chroma that tinted the whole
   * window. Accent colours that are meant to be coloured are kept: the
   * destructive red, the data-viz chart palette, and the sidebar active
   * highlight (--sidebar-primary). */
  --background: oklch(0.129 0 0);
  --foreground: oklch(0.984 0 0);
  --card: oklch(0.208 0 0);
  --card-foreground: oklch(0.984 0 0);
  --popover: oklch(0.208 0 0);
  --popover-foreground: oklch(0.984 0 0);
  --primary: oklch(0.929 0 0);
  --primary-foreground: oklch(0.208 0 0);
  --secondary: oklch(0.279 0 0);
  --secondary-foreground: oklch(0.984 0 0);
  --muted: oklch(0.279 0 0);
  --muted-foreground: oklch(0.704 0 0);
  --accent: oklch(0.279 0 0);
  --accent-foreground: oklch(0.984 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.551 0 0);
  --chart-1: oklch(0.488 0.243 264.376);
  --chart-2: oklch(0.696 0.17 162.48);
  --chart-3: oklch(0.769 0.188 70.08);
  --chart-4: oklch(0.627 0.265 303.9);
  --chart-5: oklch(0.645 0.246 16.439);
  --sidebar: oklch(0.208 0 0);
  --sidebar-foreground: oklch(0.984 0 0);
  --sidebar-primary: oklch(0.488 0.243 264.376);
  --sidebar-primary-foreground: oklch(0.984 0 0);
  --sidebar-accent: oklch(0.279 0 0);
  --sidebar-accent-foreground: oklch(0.984 0 0);
  --sidebar-border: oklch(1 0 0 / 10%);
  --sidebar-ring: oklch(0.551 0 0);
  --scrollbar-thumb: rgba(163, 163, 163, 0.44);
  --scrollbar-thumb-hover: rgba(189, 189, 189, 0.64);
  --scrollbar-thumb-active: rgba(212, 212, 212, 0.8);
}

@theme inline {
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --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);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);
}

@layer base {
  * {
    @apply border-border outline-ring/50;
  }
  body {
    @apply bg-background text-foreground;
  }
}

/* Theme-aware scrollbars for every native scroll surface. Firefox uses the
 * standardized properties; Chromium/WebView/Safari use the pseudo-elements.
 * A transparent track avoids the bright gutter shown by the platform default,
 * while the inset border keeps the thumb compact without reducing its hitbox. */
* {
  scrollbar-color: var(--scrollbar-thumb) transparent;
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track,
*::-webkit-scrollbar-corner {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  min-width: 36px;
  min-height: 36px;
  border: 2px solid transparent;
  border-radius: 999px;
  background-color: var(--scrollbar-thumb);
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-thumb:active {
  background-color: var(--scrollbar-thumb-active);
}

/* Android WebView fallback: hex border colors when oklch() is unsupported.
 * Without this, --input/--border resolve to invalid → no visible border on
 * Checkbox (and other thin-bordered surfaces). Light values match the
 * oklch tokens at L=0.929 / L=1@10%. */
@supports not (color: oklch(0% 0 0)) {
  :root {
    --border: #e5e7eb;
    --input: #e5e7eb;
  }
  .dark {
    --border: rgba(255, 255, 255, 0.1);
    --input: rgba(255, 255, 255, 0.15);
  }
}

/* Touch devices: make checkbox borders thicker AND high-contrast so they're
 * reliably visible on Android WebView. The default --input token resolves to
 * oklch(0.929), which can render at near-zero contrast against a white card on
 * Android even when oklch() itself is supported. Hex values bypass that.
 * !important is required to beat the Tailwind utility specificity from
 * data-[state=checked]:bg-primary in checkbox.svelte. */
@media (pointer: coarse) {
  [data-slot='checkbox'] {
    border-width: 2px !important;
    border-color: #525252 !important;
    /* Unchecked fill: bg-background resolves to pure white in light mode, so
     * the box was white-on-white against a white row on Android. A light-gray
     * fill makes the box itself visible even where the thin border reads faint
     * at phone density. The checked selector below overrides this. */
    background-color: #f0f0f0 !important;
  }
  .dark [data-slot='checkbox'] {
    border-color: rgba(255, 255, 255, 0.55) !important;
    background-color: rgba(255, 255, 255, 0.1) !important;
  }
  [data-slot='checkbox'][data-state='checked'] {
    background-color: #171717 !important;
    border-color: #171717 !important;
    color: #fafafa !important;
  }
  .dark [data-slot='checkbox'][data-state='checked'] {
    background-color: #e5e5e5 !important;
    border-color: #e5e5e5 !important;
    color: #171717 !important;
  }
}

/* Tooltip styling for data-tooltip attributes */
[data-tooltip] {
  position: relative;
  overflow: visible !important;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 9999;
  background: rgb(30 30 30 / 0.95);
  color: #fff;
  box-shadow:
    0 4px 6px -1px rgb(0 0 0 / 0.1),
    0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.dark [data-tooltip]::after {
  background: rgb(250 250 250 / 0.95);
  color: #1a1a1a;
}

[data-tooltip]:hover::after {
  opacity: 1;
  transition-delay: 0.3s;
}

/* Tooltip arrow */
[data-tooltip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgb(30 30 30 / 0.95);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 9999;
}

.dark [data-tooltip]::before {
  border-top-color: rgb(250 250 250 / 0.95);
}

[data-tooltip]:hover::before {
  opacity: 1;
  transition-delay: 0.3s;
}

/* Bottom-positioned tooltips (for elements near top of viewport) */
[data-tooltip-position='bottom']::after {
  bottom: auto;
  top: calc(100% + 8px);
}

[data-tooltip-position='bottom']::before {
  bottom: auto;
  top: calc(100% + 2px);
  border-top-color: transparent;
  border-bottom-color: rgb(30 30 30 / 0.95);
}

.dark [data-tooltip-position='bottom']::before {
  border-top-color: transparent;
  border-bottom-color: rgb(250 250 250 / 0.95);
}

/* Suppress data-attribute tooltips on touch-only devices.
   On touch they stick after tap and clash with the minimal mobile UI.
   bits-ui tooltips are guarded separately in tooltip-content.svelte. */
@media (hover: none) {
  [data-tooltip]::after,
  [data-tooltip]::before {
    display: none !important;
  }
}

/* ============================================
   FORM INPUT DARK MODE FIX
   Native radio buttons, checkboxes, and other form controls use the
   CSS accent-color property. In dark mode, --primary resolves to a
   very light gray (oklch 0.929) which makes checked/unchecked states
   indistinguishable. Override with a vivid blue so the selected state
   is clearly visible against the dark background.
   ============================================ */
.dark input[type='radio'],
.dark input[type='checkbox'],
.dark input[type='range'] {
  accent-color: oklch(0.488 0.243 264.376);
}

/* Ensure native date/time/color pickers render legibly in dark mode */
.dark input[type='date'],
.dark input[type='time'],
.dark input[type='datetime-local'] {
  color-scheme: dark;
}

/* Light mode: use the standard primary color for accent */
:root:not(.dark) input[type='radio'],
:root:not(.dark) input[type='checkbox'],
:root:not(.dark) input[type='range'] {
  accent-color: oklch(0.208 0.042 265.755);
}

:root:not(.dark) input[type='date'],
:root:not(.dark) input[type='time'],
:root:not(.dark) input[type='datetime-local'] {
  color-scheme: light;
}
