/* Dark Mode - Gray palette overrides (matched to marketing site) */
html.dark {
  --color-gray-50:  #0f0d14;
  --color-gray-100: #161422;
  --color-gray-200: #1e1b2a;
  --color-gray-300: #2a2638;
  --color-gray-400: #3a3552;
  --color-gray-500: #6b6580;
  --color-gray-600: #a49eb4;
  --color-gray-700: #d0ccc4;
  --color-gray-800: #ede9e0;
  --color-gray-900: #f5f2ec;
  --color-gray-950: #faf8f4;
  color-scheme: dark;
}

/* bg-white override (can't change --color-white because text-white also uses it) */
html.dark .bg-white,
html.dark .bg-white\/90 {
  background-color: var(--color-gray-100);
}

/* Header backdrop in dark mode */
html.dark header.sticky .before\:bg-white\/90::before,
html.dark header.sticky::before {
  background-color: rgb(22 20 34 / 0.9) !important;
}
html.dark .before\:bg-white\/90::before {
  background-color: rgb(22 20 34 / 0.9) !important;
}
html.dark .lg\:before\:bg-gray-50\/90::before {
  background-color: rgb(15 13 20 / 0.9) !important;
}

/* Overlay/backdrop - must stay dark even with gray palette inversion */
html.dark .bg-gray-900\/30 {
  background-color: rgba(0, 0, 0, 0.4) !important;
}
html.dark .bg-gray-900\/90 {
  background-color: rgba(0, 0, 0, 0.9) !important;
}

/* Borders - bump contrast so they're visible against dark backgrounds */
html.dark .border-gray-100 {
  border-color: var(--color-gray-300) !important;
}
html.dark .border-gray-200 {
  border-color: var(--color-gray-400) !important;
}
html.dark .border-gray-300 {
  border-color: var(--color-gray-400) !important;
}
html.dark .border-t-gray-200 {
  border-top-color: var(--color-gray-400) !important;
}
html.dark .border-b-gray-200 {
  border-bottom-color: var(--color-gray-400) !important;
}
html.dark .border-t-gray-100 {
  border-top-color: var(--color-gray-300) !important;
}
html.dark .border-b-gray-100 {
  border-bottom-color: var(--color-gray-300) !important;
}
html.dark .divide-gray-200 > :not(:last-child) {
  border-color: var(--color-gray-400) !important;
}
html.dark .divide-gray-100 > :not(:last-child) {
  border-color: var(--color-gray-300) !important;
}

/* Shadows - softer on dark backgrounds */
html.dark {
  --shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px rgb(0 0 0 / 0.35);
  --shadow-lg: 0 10px 15px rgb(0 0 0 / 0.4);
  --shadow-xl: 0 20px 25px rgb(0 0 0 / 0.45);
}

/* Selection color in dark mode */
html.dark ::selection {
  background: #e8553a;
  color: #fff;
}

/* Article content tables in dark mode */
html.dark .article-content table th,
html.dark .article-content table td {
  border-color: var(--color-gray-400);
  background-color: var(--color-gray-100);
}

html.dark .article-content thead th,
html.dark .article-content thead td {
  background-color: var(--color-gray-200);
}

/* TipTap editor in dark mode */
html.dark .tiptap-editor {
  border-color: var(--color-gray-400);
  background-color: var(--color-gray-100);
}

html.dark .tiptap table td,
html.dark .tiptap table th {
  border-color: var(--color-gray-400);
}

html.dark .tiptap table th {
  background-color: var(--color-gray-200);
}

html.dark .tiptap blockquote {
  background-color: var(--color-gray-200);
  color: var(--color-gray-600);
}

/* Trix editor in dark mode */
html.dark trix-editor {
  background-color: var(--color-gray-100);
  color: var(--color-gray-800);
}

html.dark .trix-toolbar {
  background-color: var(--color-gray-200) !important;
  border-color: var(--color-gray-400) !important;
}

html.dark .trix-button-group {
  border-color: var(--color-gray-400);
}

html.dark .trix-button.trix-active {
  background-color: var(--color-gray-300) !important;
}

html.dark button.trix-button[data-trix-attribute^="heading"]:hover {
  background-color: var(--color-gray-300) !important;
}

html.dark button.trix-button[data-trix-attribute^="heading"].trix-active {
  background-color: var(--color-gray-300) !important;
  color: var(--color-gray-900) !important;
}

/* Inline styles that use hardcoded colors */
html.dark [style*="background-color: rgba(120,113,108"] {
  background-color: var(--color-gray-200) !important;
  color: var(--color-gray-600) !important;
}

html.dark [style*="background-color: #f5f2ec"] {
  background-color: var(--color-gray-50) !important;
}

html.dark [style*="background: white"] {
  background: var(--color-gray-100) !important;
}

html.dark [style*="box-shadow: 0 4px 24px rgba(0,0,0,0.06)"] {
  box-shadow: 0 4px 24px rgba(0,0,0,0.3) !important;
}

/* Devise right panel */
html.dark .devise-right-panel {
  background-color: var(--color-gray-50) !important;
}

/* API Keys page green highlights */
html.dark .bg-green-50 {
  background-color: rgba(34, 197, 94, 0.1);
}

/* Status badges and alerts - ensure readability on dark backgrounds */
html.dark .bg-yellow-50 {
  background-color: rgba(234, 179, 8, 0.15);
}

html.dark .bg-yellow-100 {
  background-color: rgba(234, 179, 8, 0.2);
}

html.dark .bg-red-50 {
  background-color: rgba(239, 68, 68, 0.15);
}

html.dark .bg-red-100 {
  background-color: rgba(239, 68, 68, 0.2);
}

html.dark .bg-blue-50 {
  background-color: rgba(59, 130, 246, 0.15);
}

html.dark .bg-blue-100 {
  background-color: rgba(59, 130, 246, 0.2);
}

html.dark .bg-violet-50 {
  background-color: rgba(232, 85, 58, 0.15);
}

html.dark .bg-green-100 {
  background-color: rgba(34, 197, 94, 0.2);
}

/* Scrollbar styling for dark mode */
html.dark ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

html.dark ::-webkit-scrollbar-track {
  background: var(--color-gray-100);
}

html.dark ::-webkit-scrollbar-thumb {
  background: var(--color-gray-300);
  border-radius: 4px;
}

html.dark ::-webkit-scrollbar-thumb:hover {
  background: var(--color-gray-400);
}

/* bg-gray-100 is same as bg-white in dark mode — bump it one step darker */
html.dark .bg-gray-100 {
  background-color: var(--color-gray-200) !important;
}

/* hover states inside bg-white containers need a visible step */
html.dark .bg-white .hover\:bg-gray-100:hover {
  background-color: var(--color-gray-300) !important;
}
html.dark .bg-white .hover\:bg-gray-50:hover {
  background-color: var(--color-gray-200) !important;
}
html.dark .bg-white .hover\:bg-gray-200:hover {
  background-color: var(--color-gray-300) !important;
}

/* Dark SVG icons (icon-quill, icon-black) need to be inverted */
html.dark img[src*="icon-quill"],
html.dark img[src*="icon-black"] {
  filter: invert(1) brightness(0.85);
}

/* Empty state icon containers - gradient is invisible in dark, use solid */
html.dark .from-gray-200 {
  --tw-gradient-from: var(--color-gray-300) !important;
}
html.dark .to-gray-100 {
  --tw-gradient-to: var(--color-gray-200) !important;
}

/* Form inputs - fix dark: variants that assume standard palette */
html.dark .form-input,
html.dark .form-textarea,
html.dark .form-multiselect,
html.dark .form-select {
  color: var(--color-gray-800) !important;
  background-color: var(--color-gray-200) !important;
  border-color: var(--color-gray-400) !important;
}

html.dark .form-input:hover,
html.dark .form-textarea:hover,
html.dark .form-multiselect:hover,
html.dark .form-select:hover {
  border-color: var(--color-gray-500) !important;
}

html.dark .form-input:focus,
html.dark .form-textarea:focus,
html.dark .form-multiselect:focus,
html.dark .form-select:focus {
  border-color: var(--color-gray-500) !important;
}

/* Placeholder text - boost contrast in dark mode */
html.dark ::placeholder {
  color: var(--color-gray-600) !important;
}

html.dark input.bg-transparent,
html.dark textarea.bg-transparent {
  color: var(--color-gray-900);
}

/* Fix dark: text variants that assume standard Tailwind palette */
html.dark .dark\:text-gray-100 {
  color: var(--color-gray-800) !important;
}
html.dark .dark\:text-gray-300 {
  color: var(--color-gray-600) !important;
}
html.dark .dark\:bg-gray-700\/20 {
  background-color: color-mix(in oklab, var(--color-gray-300) 20%, transparent) !important;
}
html.dark .dark\:bg-gray-800 {
  background-color: var(--color-gray-200) !important;
}
html.dark .dark\:bg-gray-900\/30 {
  background-color: color-mix(in oklab, var(--color-gray-200) 60%, transparent) !important;
}
html.dark .dark\:bg-gray-700 {
  background-color: var(--color-gray-300) !important;
}
html.dark .dark\:border-gray-700\/60 {
  border-color: var(--color-gray-400) !important;
}
html.dark .dark\:border-gray-700 {
  border-color: var(--color-gray-400) !important;
}

/* text-gray-400 is too dark in dark mode for icons and muted text — boost globally */
html.dark .text-gray-400 {
  color: var(--color-gray-600) !important;
}

/* Buttons — give them visible borders and proper hover states */
html.dark .btn,
html.dark .btn-lg,
html.dark .btn-sm,
html.dark .btn-xs {
  border-color: var(--color-gray-400);
}

html.dark .btn.bg-violet-500,
html.dark .btn-sm.bg-violet-500,
html.dark .btn.bg-violet-600,
html.dark .btn-sm.bg-violet-600 {
  border-color: transparent;
}

html.dark .btn.bg-gray-900,
html.dark .btn-sm.bg-gray-900,
html.dark .btn-lg.bg-gray-900 {
  border-color: transparent;
}

/* Fix Simple Form / dark: variant buttons where palette inversion breaks them */
html.dark .dark\:bg-gray-100 {
  background-color: var(--color-gray-800) !important;
}
html.dark .dark\:text-gray-800 {
  color: var(--color-gray-100) !important;
}
html.dark .dark\:hover\:bg-white:hover {
  background-color: var(--color-gray-900) !important;
}

html.dark .btn.bg-red-500,
html.dark .btn-sm.bg-red-500,
html.dark .btn.bg-green-500,
html.dark .btn-sm.bg-green-500 {
  border-color: transparent;
}

html.dark .btn.bg-white,
html.dark .btn-sm.bg-white {
  background-color: var(--color-gray-200) !important;
  border-color: var(--color-gray-400);
}

html.dark .btn.bg-white:hover,
html.dark .btn-sm.bg-white:hover {
  background-color: var(--color-gray-300) !important;
  border-color: var(--color-gray-500);
}

html.dark .hover\:border-gray-300:hover {
  border-color: var(--color-gray-500) !important;
}

html.dark .btn-sm.border-gray-200 {
  border-color: var(--color-gray-400);
}

html.dark .btn-sm.border-gray-200:hover {
  border-color: var(--color-gray-500);
}

/* Article type icons — soften for dark mode */
html.dark [style*="background-color: #78716c"] {
  background-color: var(--color-gray-300) !important;
  border-color: var(--color-gray-400) !important;
}

/* Tooltips — must stay dark even with palette inversion */
html.dark .bg-gray-700.text-white {
  background-color: #2a2638 !important;
  border-color: #3a3552 !important;
}

/* Emoji picker in dark mode */
html.dark .emoji-button:hover {
  background-color: var(--color-gray-200);
}

/* Theme toggle styling */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background-color: var(--color-gray-100);
}

.theme-toggle button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--color-gray-400);
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-toggle button:hover {
  color: var(--color-gray-600);
}

.theme-toggle button.active {
  background-color: var(--color-gray-200);
  color: var(--color-gray-800);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
}

html.dark .theme-toggle {
  background-color: var(--color-gray-200);
}

html.dark .theme-toggle button {
  color: var(--color-gray-600);
}

html.dark .theme-toggle button:hover {
  color: var(--color-gray-800);
}

html.dark .theme-toggle button.active {
  background-color: var(--color-gray-300);
  color: var(--color-gray-900);
}
