/**
 * Calibre Design System
 * Based on Claude Visual Style Guide
 * https://github.com/jcmrs/claude-visual-style-guide
 */

/* ============================================
   Light Theme (Default)
   ============================================ */
:root {
  /* Base colors - OKLCH format with RGB fallbacks */
  --color-background: rgb(255, 255, 255);
  --color-background: oklch(100% 0 0);

  --color-foreground: rgb(20, 20, 20);
  --color-foreground: oklch(15% 0 0);

  --color-muted: rgb(245, 245, 245);
  --color-muted: oklch(96% 0 0);

  --color-muted-foreground: rgb(115, 115, 115);
  --color-muted-foreground: oklch(45% 0 0);

  /* Card colors */
  --color-card: rgb(255, 255, 255);
  --color-card: oklch(100% 0 0);

  --color-card-foreground: rgb(20, 20, 20);
  --color-card-foreground: oklch(15% 0 0);

  /* Primary action colors */
  --color-primary: rgb(30, 30, 30);
  --color-primary: oklch(25% 0 0);

  --color-primary-foreground: rgb(255, 255, 255);
  --color-primary-foreground: oklch(100% 0 0);

  /* Secondary colors */
  --color-secondary: rgb(245, 245, 245);
  --color-secondary: oklch(96% 0 0);

  --color-secondary-foreground: rgb(20, 20, 20);
  --color-secondary-foreground: oklch(15% 0 0);

  /* Accent colors (minimal, only for critical states) */
  --color-destructive: rgb(220, 38, 38);
  --color-destructive: oklch(60% 0.2 25);

  --color-destructive-foreground: rgb(255, 255, 255);
  --color-destructive-foreground: oklch(100% 0 0);

  --color-success: rgb(34, 197, 94);
  --color-success: oklch(65% 0.2 145);

  --color-warning: rgb(245, 158, 11);
  --color-warning: oklch(75% 0.15 85);

  /* Border and input colors */
  --color-border: rgb(229, 229, 229);
  --color-border: oklch(90% 0 0);

  --color-input: rgb(229, 229, 229);
  --color-input: oklch(90% 0 0);

  --color-ring: rgb(20, 20, 20);
  --color-ring: oklch(15% 0 0);

  /* Typography scale */
  --font-size-xs: 0.75rem;      /* 12px */
  --font-size-sm: 0.875rem;     /* 14px */
  --font-size-base: 1rem;       /* 16px */
  --font-size-lg: 1.125rem;     /* 18px */
  --font-size-xl: 1.25rem;      /* 20px */
  --font-size-2xl: 1.5rem;      /* 24px */
  --font-size-3xl: 1.875rem;    /* 30px */

  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;

  /* Spacing scale (2-24px) */
  --spacing-1: 0.125rem;  /* 2px */
  --spacing-2: 0.25rem;   /* 4px */
  --spacing-3: 0.5rem;    /* 8px */
  --spacing-4: 0.75rem;   /* 12px */
  --spacing-5: 1rem;      /* 16px */
  --spacing-6: 1.5rem;    /* 24px */

  /* Border radius */
  --radius: 0.625rem;     /* 10px */
  --radius-sm: 0.375rem;  /* 6px */
  --radius-lg: 0.75rem;   /* 12px */
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s ease-in-out;
  --transition-normal: 0.2s ease-in-out;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Dark Theme
   ============================================ */
.dark {
  --color-background: rgb(18, 18, 18);
  --color-background: oklch(15% 0 0);

  --color-foreground: rgb(250, 250, 250);
  --color-foreground: oklch(98% 0 0);

  --color-muted: rgb(38, 38, 38);
  --color-muted: oklch(20% 0 0);

  --color-muted-foreground: rgb(163, 163, 163);
  --color-muted-foreground: oklch(65% 0 0);

  --color-card: rgb(28, 28, 28);
  --color-card: oklch(18% 0 0);

  --color-card-foreground: rgb(250, 250, 250);
  --color-card-foreground: oklch(98% 0 0);

  --color-primary: rgb(250, 250, 250);
  --color-primary: oklch(98% 0 0);

  --color-primary-foreground: rgb(18, 18, 18);
  --color-primary-foreground: oklch(15% 0 0);

  --color-secondary: rgb(38, 38, 38);
  --color-secondary: oklch(20% 0 0);

  --color-secondary-foreground: rgb(250, 250, 250);
  --color-secondary-foreground: oklch(98% 0 0);

  --color-border: rgb(51, 51, 51);
  --color-border: oklch(25% 0 0);

  --color-input: rgb(51, 51, 51);
  --color-input: oklch(25% 0 0);

  --color-ring: rgb(250, 250, 250);
  --color-ring: oklch(98% 0 0);

  /* Adjust accent colors for dark mode (slightly lighter) */
  --color-destructive: rgb(239, 68, 68);
  --color-destructive: oklch(65% 0.22 25);

  --color-success: rgb(52, 211, 153);
  --color-success: oklch(70% 0.18 150);

  --color-warning: rgb(251, 191, 36);
  --color-warning: oklch(80% 0.13 85);

  /* Softer shadows for dark mode */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.6);
}

/* ============================================
   HTMX Loading Indicators
   ============================================ */
.htmx-indicator {
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

.htmx-swapping {
  opacity: 0;
  transition: opacity var(--transition-fast);
}

/* ============================================
   Price Change Indicators
   ============================================ */
.price-up {
  color: var(--color-success);
}

.price-down {
  color: var(--color-destructive);
}

/* ============================================
   Pulse Animation (Loading States)
   ============================================ */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ============================================
   Spin Animation (Loading Spinners)
   ============================================ */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* ============================================
   Tooltip Styles for Column Headers
   ============================================ */
th[title] {
  cursor: help;
  position: relative;
}

th[title]:hover::after {
  content: attr(title);
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-foreground);
  color: var(--color-background);
  padding: var(--spacing-3) var(--spacing-4);
  border-radius: var(--radius);
  font-size: var(--font-size-xs);
  font-weight: normal;
  text-transform: none;
  white-space: normal;
  width: 250px;
  z-index: 50;
  box-shadow: var(--shadow-md);
  margin-top: var(--spacing-2);
  pointer-events: none;
}

/* Arrow for tooltip */
th[title]:hover::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: var(--color-foreground);
  z-index: 51;
  pointer-events: none;
}

/* ============================================
   Focus Styles
   ============================================ */
:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
}

/* ============================================
   Scrollbar Styling (Webkit)
   ============================================ */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--color-muted);
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-muted-foreground);
}

/* For Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) var(--color-muted);
}

/* ============================================
   Smooth Transitions
   ============================================ */
* {
  transition-property: background-color, border-color, color, fill, stroke;
  transition-duration: var(--transition-fast);
  transition-timing-function: ease-in-out;
}

/* Disable transitions for elements that shouldn't animate */
input,
textarea,
select,
button {
  transition-property: background-color, border-color, box-shadow;
}
