:root {
  --festivai-black: #170b1f;
  --festivai-deep-purple: #261b4a;
  --festivai-plum: #5a345b;
  --festivai-mauve: #8a506c;
  --festivai-rose: #c78a8c;
  --festivai-cream: #f6ded5;

  --font-sans: "Plus Jakarta Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --header-height: 3.5rem;
  --page-max: 86rem;
  --radius-pill: 9999px;
  --radius-card: 18px;
  --radius-control: 12px;
  /* App shell: gap around sidebar + main so rounded panels read clearly */
  --layout-shell-gap: 0.75rem;
  --layout-shell-padding: 0.65rem;
  --layout-sidebar-radius: 1.25rem;
  --layout-main-radius: 1.25rem;
  --layout-main-shadow: 0 10px 40px rgba(23, 11, 31, 0.09);
  --layout-sidebar-shadow: 0 14px 44px rgba(23, 11, 31, 0.18);
  --shadow-soft: 0 18px 40px rgba(0, 0, 0, 0.12);
  --shadow-elevated: 0 8px 30px rgba(23, 11, 31, 0.08);
  --focus-ring: 0 0 0 3px var(--accent-primary-soft);
  --surface-glass: rgba(255, 255, 255, 0.72);

  --transition-fast: 150ms ease-out;
  --transition-med: 220ms ease;
  --transition-slow: 360ms cubic-bezier(0.22, 1, 0.36, 1);

  /* Default fallbacks, overridden per theme */
  --bg-body-gradient: linear-gradient(180deg, #ffffff 0%, #fff5ef 40%, var(--festivai-cream) 100%);
  --bg-sidebar-gradient: linear-gradient(180deg, var(--festivai-deep-purple), var(--festivai-plum));
  --widget-inset-sheen: rgba(255, 255, 255, 0.45);
  --chart-tooltip-bg: rgba(23, 11, 31, 0.94);
  --chart-tooltip-border: rgba(255, 255, 255, 0.1);
  --sidebar-tooltip-bg: rgba(23, 11, 31, 0.96);
  --sidebar-tooltip-color: #fdf6f2;
  --sidebar-tooltip-border: rgba(255, 255, 255, 0.14);
  --sidebar-tooltip-shadow: 0 8px 24px rgba(23, 11, 31, 0.28);
  --chart-palette-6: #5c7a99;
  --chart-palette-7: #9d8b7a;
}

html[data-theme="light"] {
  /* Light theme uses white as the true base while keeping the FestivAI palette for accents */
  --bg-body: #ffffff;
  --bg-base: #ffffff;
  --bg-surface: #ffffff;
  --bg-surface-subtle: #f5ece7;
  /* Sidebar: two‑color gradient */
  --bg-sidebar: transparent;
  --bg-sidebar-gradient: linear-gradient(
    180deg,
    var(--festivai-deep-purple) 0%,
    var(--festivai-plum) 100%
  );
  --bg-hover: rgba(90, 52, 91, 0.08);
  /* Legacy aliases still used in page-specific CSS */
  --bg-primary: var(--bg-surface);
  --bg-subtle: var(--bg-surface-subtle);

  --text-main: var(--festivai-black);
  --text-primary: var(--festivai-black);
  --text-secondary: rgba(23, 11, 31, 0.7);
  --text-muted: rgba(23, 11, 31, 0.7);
  --text-on-dark: #fdf6f2;
  --text-on-accent: #fdf6f2;

  --accent-primary: var(--festivai-plum);
  --accent-primary-soft: rgba(90, 52, 91, 0.12);
  --accent-primary-hover: #6a3f6b;
  --accent-primary-dark: #4a2d4f;
  --accent-secondary: var(--festivai-mauve);
  /* Legacy `var(--primary)` in cloud + database admin UIs */
  --primary: var(--accent-primary);
  --primary-alpha: rgba(90, 52, 91, 0.22);
  --border-subtle: rgba(23, 11, 31, 0.08);
  --border-default: rgba(23, 11, 31, 0.14);
  /* Panels / cards (maps to real surfaces; used by file explorer, modals) */
  --surface-raised: var(--bg-surface);
  --surface-sunken: var(--bg-surface-subtle);
  --surface-base: var(--bg-surface-subtle);

  /* Dashboard / inline chart widgets: softer corners and chart chrome */
  --widget-radius: 1.25rem;
  --widget-radius-inner: 0.75rem;
  --chart-grid: rgba(23, 11, 31, 0.07);
  --chart-plot-veil: rgba(23, 11, 31, 0.03);
  --chart-label-color: var(--festivai-black);
  --chart-tooltip-title-color: #fdf6f2;
  --chart-tooltip-body-color: #e8dcd8;
  --widget-inset-sheen: rgba(255, 255, 255, 0.55);
  --chart-tooltip-bg: rgba(23, 11, 31, 0.94);
  --chart-tooltip-border: rgba(255, 255, 255, 0.1);
  --sidebar-tooltip-bg: rgba(23, 11, 31, 0.96);
  --sidebar-tooltip-color: var(--text-on-dark);
  --sidebar-tooltip-border: rgba(255, 255, 255, 0.14);
  --sidebar-tooltip-shadow: 0 8px 24px rgba(23, 11, 31, 0.28);
  --chart-palette-6: #5c7a99;
  --chart-palette-7: #9d8b7a;

  /* Code / JSON blocks */
  --bg-code-block: var(--bg-surface-subtle);
  --text-on-code-block: var(--festivai-black);
  --border-code-block: rgba(23, 11, 31, 0.12);
  --bg-inline-code: rgba(90, 52, 91, 0.1);

  /* Body: mostly white with a diagonal gradient into two brand colors */
  --bg-body-gradient: linear-gradient(
    135deg,
    #ffffff 0%,
    #ffffff 45%,
    var(--festivai-cream) 75%,
    var(--festivai-rose) 100%
  );
}

html[data-theme="dark"] {
  /* Dark theme uses black as the true base while keeping the FestivAI palette for accents */
  --bg-body: #000000;
  --bg-base: #000000;
  --bg-base-dark: #000000;
  --bg-surface: #1b1024;
  --bg-surface-dark: #1b1024;
  --bg-surface-subtle: #241431;
  --bg-surface-subtle-dark: #241431;
  /* Sidebar: two‑color gradient for dark */
  --bg-sidebar: transparent;
  --bg-sidebar-gradient: linear-gradient(
    180deg,
    #12091b 0%,
    #241431 100%
  );
  --bg-hover: rgba(199, 138, 140, 0.12);
  /* Legacy aliases still used in page-specific CSS */
  --bg-primary: var(--bg-surface);
  --bg-subtle: var(--bg-surface-subtle);

  --text-main: #fcefeb;
  --text-primary: #fcefeb;
  --text-secondary: rgba(249, 232, 227, 0.7);
  --text-muted: rgba(249, 232, 227, 0.7);
  --text-on-dark: #fdf6f2;
  --text-on-accent: #fdf6f2;

  --accent-primary: var(--festivai-rose);
  --accent-primary-soft: rgba(199, 138, 140, 0.18);
  --accent-primary-hover: #d99a9c;
  --accent-primary-dark: #a86d70;
  --accent-secondary: var(--festivai-mauve);
  --primary: var(--accent-primary);
  --primary-alpha: rgba(199, 138, 140, 0.28);
  --border-subtle: rgba(248, 230, 224, 0.16);
  --border-subtle-dark: rgba(248, 230, 224, 0.16);
  --border-default: rgba(248, 230, 224, 0.22);
  --surface-glass: rgba(27, 16, 36, 0.75);
  --surface-raised: var(--bg-surface);
  --surface-sunken: var(--bg-surface-subtle);
  --surface-base: var(--bg-surface-subtle);
  --widget-radius: 1.25rem;
  --widget-radius-inner: 0.75rem;
  --chart-grid: rgba(248, 230, 224, 0.1);
  --chart-plot-veil: rgba(0, 0, 0, 0.25);
  --chart-label-color: #fcefeb;
  --chart-tooltip-title-color: #fdf6f2;
  --chart-tooltip-body-color: #e2e8f0;
  --widget-inset-sheen: rgba(255, 255, 255, 0.07);
  --chart-tooltip-bg: rgba(12, 8, 18, 0.96);
  --chart-tooltip-border: rgba(255, 255, 255, 0.12);
  --sidebar-tooltip-bg: rgba(36, 20, 49, 0.98);
  --sidebar-tooltip-color: var(--text-on-dark);
  --sidebar-tooltip-border: rgba(255, 255, 255, 0.16);
  --sidebar-tooltip-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  --chart-palette-6: #7a9ebc;
  --chart-palette-7: #b89a8a;

  /* Code / JSON blocks — lifted purple panel on black base for readable contrast */
  --bg-code-block: #2a1835;
  --text-on-code-block: #f8ebe8;
  --border-code-block: rgba(248, 230, 224, 0.16);
  --bg-inline-code: rgba(199, 138, 140, 0.15);

  --layout-main-shadow: 0 12px 48px rgba(0, 0, 0, 0.55);
  --layout-sidebar-shadow: 0 16px 48px rgba(0, 0, 0, 0.65);

  /* Body: diagonal gradient with black in the middle, blending to two dark brand tones */
  --bg-body-gradient: linear-gradient(
    135deg,
    #0b0710 0%,
    #000000 45%,
    var(--festivai-black) 55%,
    #241431 80%,
    var(--festivai-plum) 100%
  );
}

body,
.festivai-body,
.festivai-auth-body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
  /* The overall page background uses a theme-specific gradient */
  background: var(--bg-body-gradient);
  color: var(--text-main);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.primary-button,
.secondary-button,
.pill-button,
.icon-button {
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.6rem 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition:
    background-color var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.primary-button {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: var(--text-on-dark);
  box-shadow: var(--shadow-soft);
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 22px 46px rgba(0, 0, 0, 0.18);
}

.secondary-button {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
}

.secondary-button:hover {
  background: rgba(0, 0, 0, 0.04);
}

.pill-button {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.pill-button.small {
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
}

.pill-button:hover {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-subtle);
  color: var(--text-main);
}

.icon-button:hover {
  background: var(--accent-primary-soft);
}

.icon-button--menu {
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset;
}

html[data-theme="dark"] .icon-button--menu {
  box-shadow: none;
  background: var(--bg-surface-subtle);
}

.icon-button:focus-visible,
.pill-button:focus-visible,
.primary-button:focus-visible,
.theme-toggle:focus-visible,
.language-select:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* Standard page width + rhythm (use inside <main>) */
.festivai-page {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  animation: page-enter var(--transition-slow) both;
}

/* Opacity only: transform on this ancestor breaks position:fixed overlays
   (e.g. .db-modal) so they no longer cover the sticky header / full viewport. */
@keyframes page-enter {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .festivai-page {
    animation: none;
  }
}

.festivai-page--bleed {
  max-width: none;
  margin: 0;
  min-height: 0;
  flex: 1 1 0%;
  display: flex;
  flex-direction: column;
  align-self: stretch;
  width: 100%;
  animation: none;
}

.page-hero {
  margin-bottom: 1.75rem;
}

.page-hero__eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-primary);
  margin: 0 0 0.35rem;
}

.page-hero h1,
.page-hero__title {
  font-size: clamp(1.5rem, 2.2vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.4rem;
  color: var(--text-primary);
  line-height: 1.2;
}

.page-hero__lede,
.page-hero p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-muted);
  max-width: 42rem;
}

.card {
  background: var(--bg-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-elevated);
  padding: 1.4rem 1.6rem;
  border: 1px solid var(--border-subtle);
  transition:
    box-shadow var(--transition-med),
    border-color var(--transition-med),
    transform var(--transition-fast);
}

.card h2,
.card h3 {
  margin-top: 0;
  letter-spacing: -0.01em;
}

.card--interactive {
  cursor: pointer;
}

.card--interactive:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
  border-color: var(--accent-primary-soft);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.4rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 1rem;
}

.full-width {
  width: 100%;
}

.language-select {
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  padding: 0.25rem 0.9rem;
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.85rem;
}

/* Global dropdown readability across pages/tabs (native <select>/<option>) */
select,
option,
optgroup {
  color: var(--text-primary);
  background-color: var(--bg-surface);
}

select:disabled,
option:disabled {
  color: var(--text-muted);
}

html[data-theme="dark"] select {
  border-color: var(--border-default);
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

html[data-theme="dark"] select:focus {
  border-color: var(--accent-primary);
}

/* Toast / notification system */
.festivai-toast-root {
  position: fixed;
  top: 1.2rem;
  right: 1.4rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.festivai-toast {
  min-width: 220px;
  max-width: 360px;
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  animation: festivai-toast-in var(--transition-med);
}

.festivai-toast-icon {
  font-size: 1rem;
}

.festivai-toast-message {
  flex: 1;
}

.festivai-toast-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  font-size: 0.9rem;
}

.festivai-toast-success {
  border-color: var(--accent-primary);
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
}

.festivai-toast-error {
  border-color: var(--festivai-rose);
  background: rgba(199, 138, 140, 0.15);
  color: var(--festivai-rose);
}

.festivai-toast-info {
  border-color: var(--accent-secondary);
  background: rgba(138, 80, 108, 0.12);
  color: var(--accent-secondary);
}

@keyframes festivai-toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px) translateX(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) translateX(0);
  }
}

/* Top bar: theme control */
.theme-toggle {
  position: relative;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

.theme-toggle:hover {
  background: var(--accent-primary-soft);
}

.theme-toggle__icon {
  position: absolute;
  font-size: 1.05rem;
  line-height: 1;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

html[data-theme="light"] .theme-toggle__icon--moon {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

html[data-theme="light"] .theme-toggle__icon--sun {
  opacity: 1;
}

html[data-theme="dark"] .theme-toggle__icon--sun {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

html[data-theme="dark"] .theme-toggle__icon--moon {
  opacity: 1;
  color: var(--text-main);
}

.theme-toggle--auth {
  width: 2.4rem;
  height: 2.4rem;
}

/* Product / brand logos (SVG, e.g. Simple Icons — use with <img alt="">) */
.brand-icon {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  object-fit: contain;
  object-position: center;
  flex-shrink: 0;
  vertical-align: middle;
}

.brand-icon--sm {
  width: 1.1rem;
  height: 1.1rem;
}

.brand-icon--md {
  width: 1.35rem;
  height: 1.35rem;
}

.brand-icon--lg {
  width: 1.5rem;
  height: 1.5rem;
}

/*
 * Monochrome brand SVGs (e.g. Simple Icons) are black on transparent — invert in dark
 * mode so they stay visible on --bg-surface / sidebars / tabs. Scope to empty alt
 * (decorative) <img> only.
 */
html[data-theme="dark"] img.brand-icon[alt=""],
html[data-theme="dark"] img.db-brand-icon[alt=""],
html[data-theme="dark"] img.fe-tab-brand[alt=""],
html[data-theme="dark"] img.fe-name-icon[alt=""],
html[data-theme="dark"] img.archive-btn-icon[alt=""],
html[data-theme="dark"] img.db-summary-type-icon[alt=""] {
  filter: brightness(0) invert(1);
  opacity: 0.92;
}

/* File Explorer: “soon” tabs — keep glyph readable but slightly muted */
html[data-theme="dark"] .fe-tab:disabled img.fe-tab-brand[alt=""],
html[data-theme="dark"] .fe-tab.is-disabled img.fe-tab-brand[alt=""] {
  filter: brightness(0) invert(1) grayscale(0.2);
  opacity: 0.7;
}

/* Faint lift on main nav if brand images are added later */
.festivai-sidebar img.brand-icon[alt=""] {
  vertical-align: middle;
}

/* --------------------------------------------------------------------------
   Global responsive utilities (phones + tablets)
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .page-hero {
    margin-bottom: 1.25rem;
  }

  .page-hero h1,
  .page-hero__title {
    font-size: clamp(1.35rem, 5vw, 1.75rem);
  }

  .card {
    padding: 1.15rem 1.2rem;
  }

  .pill-row {
    gap: 0.55rem;
  }

  .primary-button,
  .secondary-button,
  .pill-button {
    min-height: 2.5rem;
  }
}

@media (max-width: 768px) {
  .cards-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .festivai-toast-root {
    left: 0.75rem;
    right: 0.75rem;
    top: max(0.75rem, env(safe-area-inset-top));
  }

  .festivai-toast {
    max-width: none;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .page-hero__lede,
  .page-hero p {
    font-size: 0.9rem;
  }

  .card {
    padding: 1rem;
    border-radius: var(--radius-control);
  }
}

@media (max-width: 900px) {
  body:not(.festivai-body--chatbot) .festivai-page--bleed {
    flex: none;
    min-height: auto;
    overflow: visible;
  }

  /* Tables: horizontal swipe + taller scroll regions on small screens */
  .table-container,
  .dashboard-manage-table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
}

