@import "tailwindcss";

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

@layer base {
  /* Import Inter font from Google Fonts */
  @import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap");

  body {
    font-family: "Inter", system-ui, -apple-system, sans-serif;
  }
}

@layer components {
  /* Meilisearch highlight styling */
  em {
    font-style: normal;
    font-weight: 600;
    color: rgb(194 65 12); /* orange-700 */
    background-color: rgb(255 237 213); /* orange-100 */
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
  }

  .dark em {
    color: rgb(255 237 213); /* orange-100 */
    background-color: rgb(124 45 18); /* orange-900 */
  }

  /* Radio button and checkbox custom styles */
  input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
  }

  input[type="radio"]:checked {
    background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e") !important;
    border-color: transparent !important;
    background-color: currentColor !important;
    background-size: 100% 100% !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
  }

  input[type="radio"]:checked:hover,
  input[type="radio"]:checked:focus {
    border-color: transparent !important;
    background-color: currentColor !important;
  }

  input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
  }

  input[type="checkbox"]:checked {
    background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e") !important;
    border-color: transparent !important;
    background-color: currentColor !important;
    background-size: 100% 100% !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
  }

  input[type="checkbox"]:checked:hover,
  input[type="checkbox"]:checked:focus {
    border-color: transparent !important;
    background-color: currentColor !important;
  }

  /* Custom button styles */
  .btn-primary {
    @apply inline-flex items-center px-6 py-3 bg-gradient-to-r from-orange-500 to-red-600 text-white font-semibold rounded-lg hover:from-orange-600 hover:to-red-700 transition-all shadow-sm hover:shadow-md;
  }

  .btn-secondary {
    @apply inline-flex items-center px-6 py-3 bg-white border-2 border-gray-300 text-gray-700 font-semibold rounded-lg hover:border-gray-400 hover:bg-gray-50 transition-all;
  }

  /* Custom input styles */
  .input-field {
    @apply w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500 transition-colors;
  }

  /* Card styles */
  .card {
    @apply bg-white rounded-xl shadow-sm border border-gray-200 p-6 hover:shadow-md transition-shadow;
  }

  /* Gradient text */
  .gradient-text {
    @apply text-transparent bg-clip-text bg-gradient-to-r from-orange-500 to-red-600;
  }

  /* Keyboard shortcut badge */
  kbd {
    font-family: "SF Mono", "Monaco", "Inconsolata", "Roboto Mono",
      "Courier New", monospace;
    transition: all 0.2s ease-in-out;
    font-weight: 600;
  }

  [data-keyboard-shortcuts-target="badge"] {
    animation: fadeIn 0.15s ease-in-out;
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(-2px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Editor.js styles */
  .codex-editor {
    @apply text-gray-900 dark:text-gray-100;
  }

  /* Better text selection visibility in dark mode */
  .codex-editor ::selection {
    background-color: rgba(59, 130, 246, 0.5) !important;
    color: #ffffff !important;
  }

  .codex-editor ::-moz-selection {
    background-color: rgba(59, 130, 246, 0.5) !important;
    color: #ffffff !important;
  }

  .dark .codex-editor ::selection {
    background-color: rgba(96, 165, 250, 0.6) !important;
    color: #ffffff !important;
  }

  .dark .codex-editor ::-moz-selection {
    background-color: rgba(96, 165, 250, 0.6) !important;
    color: #ffffff !important;
  }

  .codex-editor__redactor {
    padding-bottom: 2rem !important;
  }

  .ce-block__content {
    max-width: 100% !important;
  }

  .ce-toolbar__content {
    max-width: 100% !important;
  }

  .ce-toolbar {
    margin-left: 2rem !important;
  }

  .ce-block {
    padding: 0 !important;
  }

  /* Disable pointer events on empty blocks so menu can be clicked */
  .ce-block:has([data-empty="true"]) {
    pointer-events: none !important;
  }

  /* Re-enable for the actual editor content */
  .ce-block:has([data-empty="true"]) .ce-block__content > * {
    pointer-events: auto !important;
  }

  .ce-paragraph {
    @apply text-gray-900 dark:text-gray-100;
  }

  /* Header styles */
  .ce-header {
    @apply text-gray-900 dark:text-gray-100;
    font-weight: bold;
    line-height: 1.25;
  }

  h1.ce-header {
    font-size: 2.25rem; /* 36px */
  }

  h2.ce-header {
    font-size: 1.875rem; /* 30px */
  }

  h3.ce-header {
    font-size: 1.5rem; /* 24px */
  }

  h4.ce-header {
    font-size: 1.25rem; /* 20px */
  }

  h5.ce-header {
    font-size: 1.125rem; /* 18px */
  }

  h6.ce-header {
    font-size: 1rem; /* 16px */
  }

  /* Header alignment */
  .ce-header.text-left {
    text-align: left;
  }

  .ce-header.text-center {
    text-align: center;
  }

  .ce-header.text-right {
    text-align: right;
  }

  .ce-paragraph[data-placeholder]:empty {
    pointer-events: none !important;
  }

  .ce-paragraph[data-placeholder]:empty::before {
    @apply text-gray-400 dark:text-gray-500;
    pointer-events: none !important;
    opacity: 0;
  }

  /* Only show placeholder when editor is focused */
  .codex-editor:focus-within .ce-paragraph[data-placeholder]:empty::before {
    opacity: 1;
  }

  .cdx-alert [contentEditable="true"][data-placeholder] {
    pointer-events: none !important;
  }

  .cdx-alert [contentEditable="true"][data-placeholder]::before {
    position: absolute;
    pointer-events: none !important;
    opacity: 0;
  }

  /* Only show alert placeholder when editor is focused */
  .codex-editor:focus-within
    .cdx-alert
    [contentEditable="true"][data-placeholder]::before {
    opacity: 1;
  }

  /* Ensure WYSIWYG wrapper doesn't create stacking context */
  [data-controller="wysiwyg"] > div > div {
    isolation: auto;
    transform: none;
  }

  /* Allow popover to escape parent containers */
  .ce-toolbar,
  .ce-toolbar__content,
  .ce-toolbar__actions,
  .ce-toolbox {
    overflow: visible !important;
    clip-path: none !important;
  }

  .ce-toolbar__plus,
  .ce-toolbar__settings-btn {
    @apply text-gray-600 dark:text-gray-100 hover:text-gray-900 dark:hover:text-white;
    background-color: transparent !important;
  }

  .ce-toolbar__plus svg,
  .ce-toolbar__settings-btn svg {
    @apply dark:text-gray-100;
  }

  .ce-toolbar__plus:hover,
  .ce-toolbar__settings-btn:hover {
    @apply dark:bg-gray-700;
  }

  .ce-inline-tool,
  .ce-conversion-tool {
    @apply text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100;
    color: currentColor !important;
  }

  /* Inline toolbar icon visibility */
  .ce-inline-tool svg,
  .ce-inline-toolbar__dropdown svg,
  .ce-inline-tool svg path,
  .ce-inline-toolbar__dropdown svg path {
    fill: currentColor !important;
    stroke: none !important;
  }

  .dark .ce-inline-tool svg,
  .dark .ce-inline-toolbar__dropdown svg,
  .dark .ce-inline-tool svg path,
  .dark .ce-inline-toolbar__dropdown svg path {
    fill: #d1d5db !important;
  }

  .dark .ce-inline-tool:hover svg,
  .dark .ce-inline-toolbar__dropdown:hover svg,
  .dark .ce-inline-tool:hover svg path,
  .dark .ce-inline-toolbar__dropdown:hover svg path {
    fill: #f3f4f6 !important;
  }

  .ce-popover__container {
    z-index: 100000 !important;
  }

  .ce-popover {
    @apply bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600;
    z-index: 100000 !important;
  }

  .ce-popover__items {
    z-index: 100000 !important;
    background: inherit;
  }

  .ce-popover-item {
    z-index: 100000 !important;
    background: inherit;
  }

  .ce-popover__item {
    @apply text-gray-900 dark:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-700;
  }

  .ce-popover__item-icon {
    @apply dark:text-gray-300;
  }

  .ce-inline-toolbar {
    @apply bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600;
    z-index: 100000 !important;
  }

  /* Inline toolbar buttons - force visibility */
  .ce-inline-toolbar .ce-popover-item-html button.ce-inline-tool,
  .ce-popover__items .ce-popover-item-html button.ce-inline-tool {
    color: #1f2937 !important;
  }

  .dark .ce-inline-toolbar .ce-popover-item-html button.ce-inline-tool,
  .dark .ce-popover__items .ce-popover-item-html button.ce-inline-tool {
    color: #e5e7eb !important;
  }

  .ce-inline-toolbar .ce-popover-item-html button.ce-inline-tool svg,
  .ce-popover__items .ce-popover-item-html button.ce-inline-tool svg {
    stroke: currentColor !important;
    fill: none !important;
  }

  .ce-inline-toolbar .ce-popover-item-html button.ce-inline-tool svg path,
  .ce-popover__items .ce-popover-item-html button.ce-inline-tool svg path {
    stroke: inherit !important;
  }

  .ce-inline-tool-input {
    @apply dark:bg-gray-700 dark:text-gray-100 dark:border-gray-600;
  }

  /* Image tool styling */
  .image-tool {
    @apply dark:bg-gray-800;
  }

  .image-tool__image {
    @apply dark:border-gray-600;
  }

  .image-tool__caption {
    @apply dark:bg-gray-700 dark:text-gray-100 dark:border-gray-600 dark:placeholder-gray-400;
  }

  .cdx-input {
    @apply dark:bg-gray-700 dark:text-gray-100 dark:border-gray-600;
  }

  .image-tool__image-preloader {
    @apply dark:bg-gray-700;
  }

  .cdx-loader {
    @apply dark:border-gray-600;
  }

  .image-tool__caption[contentEditable="true"][data-placeholder]:empty::before {
    @apply dark:text-gray-400;
  }

  /* Attaches tool styling */
  .cdx-attaches {
    @apply dark:bg-gray-800 dark:border-gray-600;
  }

  .cdx-attaches__file-icon {
    @apply dark:bg-gray-700 dark:border-gray-600;
  }

  .cdx-attaches__file-icon svg {
    @apply dark:text-gray-300;
  }

  .cdx-attaches__file-info {
    @apply dark:text-gray-100;
  }

  .cdx-attaches__title {
    @apply dark:bg-gray-700 dark:text-gray-100 dark:border-gray-600;
  }

  .cdx-attaches__size {
    @apply dark:text-gray-400;
  }

  .cdx-attaches__download-button {
    @apply dark:bg-gray-700 dark:text-gray-100 dark:border-gray-600;
  }

  .cdx-attaches__download-button:hover {
    @apply dark:bg-gray-600;
  }

  .cdx-attaches--with-file {
    @apply dark:bg-gray-800;
  }

  /* Alert plugin icon colors - fixed selectors */
  .ce-popover-item[data-item-name="alert-primary"] svg #background {
    fill: #ebf8ff !important;
    stroke: #4299e1 !important;
  }

  .ce-popover-item[data-item-name="alert-primary"] svg #content {
    fill: #2b6cb0 !important;
  }

  .ce-popover-item[data-item-name="alert-secondary"] svg #background {
    fill: #f7fafc !important;
    stroke: #cbd5e0 !important;
  }

  .ce-popover-item[data-item-name="alert-secondary"] svg #content {
    fill: #222731 !important;
  }

  .ce-popover-item[data-item-name="alert-info"] svg #background {
    fill: #e6fdff !important;
    stroke: #4cd4ce !important;
  }

  .ce-popover-item[data-item-name="alert-info"] svg #content {
    fill: #00727c !important;
  }

  .ce-popover-item[data-item-name="alert-success"] svg #background {
    fill: #f0fff4 !important;
    stroke: #68d391 !important;
  }

  .ce-popover-item[data-item-name="alert-success"] svg #content {
    fill: #2f855a !important;
  }

  .ce-popover-item[data-item-name="alert-warning"] svg #background {
    fill: #fffaf0 !important;
    stroke: #ed8936 !important;
  }

  .ce-popover-item[data-item-name="alert-warning"] svg #content {
    fill: #c05621 !important;
  }

  .ce-popover-item[data-item-name="alert-danger"] svg #background {
    fill: #fff5f5 !important;
    stroke: #fc8181 !important;
  }

  .ce-popover-item[data-item-name="alert-danger"] svg #content {
    fill: #c53030 !important;
  }

  .ce-popover-item[data-item-name="alert-light"] svg #background {
    fill: #fff !important;
    stroke: #edf2f7 !important;
  }

  .ce-popover-item[data-item-name="alert-light"] svg #content {
    fill: #1a202c !important;
  }

  .ce-popover-item[data-item-name="alert-dark"] svg #background {
    fill: #2d3748 !important;
    stroke: #1a202c !important;
  }

  .ce-popover-item[data-item-name="alert-dark"] svg #content {
    fill: #d3d3d3 !important;
  }
}

@layer utilities {
  /* Smooth scroll behavior */
  html {
    scroll-behavior: smooth;
  }

  /* Custom animations */
  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .animate-fade-in {
    animation: fadeIn 0.5s ease-out;
  }

  /* Hide scrollbar but keep functionality */
  .scrollbar-hide::-webkit-scrollbar {
    display: none;
  }

  .scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  /* Ace Editor fixes */
  .ace_gutter {
    z-index: unset !important;
  }
}
