/* ======================================= */
/* 1. IMPORTS & TAILWIND SETUP */
/* ======================================= */

/* ⚠️ DUPLICATE IMPORTS: Merge these two font imports into one. */
/* Commenting out the second, less specific Inter import. */
/* @import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap'); */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&family=DM+Sans:wght@400;600&family=Inter:wght@400;600&display=swap');

@import "tailwindcss";
@plugin "tailwindcss-animate";

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


/* ======================================= */
/* 2. LIGHT MODE (DEFAULT) VARIABLES */
/* ======================================= */
:root {
  /* General */
  --radius: 0.625rem;
  --textDark: #121826;
  --bg: #F8F9FA;

  /* Surface & Text */
  --background: #ffffff;
  --foreground: #252525;
  --card: #ffffff;
  --card-foreground: #252525;
  --popover: #ffffff;
  --popover-foreground: #252525;

  /* Primary & Secondary */
  --primary: #039AE4;
  --primary-foreground: #fafafa;
  --secondary: #0073AD;
  --secondary-foreground: #343434;

  /* Utility */
  --muted: #f2f2f2;
  --muted-foreground: #8a8a8a;
  --accent: #f2f2f2;
  --accent-foreground: #343434;
  --destructive: #df441c;

  /* Border & Input */
  --border: #e8e8e8;
  --input: #e8e8e8;
  --ring: #b4b4b4;

  /* Sidebar */
  --sidebar: #fafafa;
  --sidebar-foreground: #252525;
  --sidebar-primary: #343434;
  --sidebar-primary-foreground: #fafafa;
  --sidebar-accent: #f2f2f2;
  --sidebar-accent-foreground: #343434;
  --sidebar-border: #e8e8e8;
  --sidebar-ring: #b4b4b4;

  /* Chart Colors */
  --chart-1: #c95111;
  --chart-2: #80962d;
  --chart-3: #5880a4;
  --chart-4: #a4d257;
  --chart-5: #ccbe2b;

  /* Fonts */
  --font-poppins: 'Poppins', sans-serif;
  --font-dm-sans: 'DM Sans', sans-serif;
  --font-inter: 'Inter', sans-serif;

  /* Scrollbar Custom Variables */
  --scrollbar-width: 16px;
  --scrollbar-track: transparent;
  --scrollbar-thumb: #cbd5e1;
  --scrollbar-thumb-hover: #94a3b8;
  --scrollbar-radius: 16px;
  --scrollbar-border: 4px;
}


/* ======================================= */
/* 3. DARK MODE VARIABLES */
/* ======================================= */
.dark {
  /* Surface & Text */
  --background: #252525;
  --foreground: #fafafa;
  --card: #343434;
  --card-foreground: #fafafa;
  --popover: #343434;
  --popover-foreground: #fafafa;

  /* Primary & Secondary */
  --primary: #e8e8e8;
  --primary-foreground: #343434;
  --secondary: #454545;
  --secondary-foreground: #fafafa;

  /* Utility */
  --muted: #454545;
  --muted-foreground: #b4b4b4;
  --accent: #454545;
  --accent-foreground: #fafafa;
  --destructive: #d25b52;

  /* Border & Input */
  --border: rgb(255 255 255 / 10%);
  --input: rgb(255 255 255 / 15%);
  --ring: #8a8a8a;

  /* Sidebar */
  --sidebar: #343434;
  --sidebar-foreground: #fafafa;
  --sidebar-primary: #9f49c5;
  --sidebar-primary-foreground: #fafafa;
  --sidebar-accent: #454545;
  --sidebar-accent-foreground: #fafafa;
  --sidebar-border: rgb(255 255 255 / 10%);
  --sidebar-ring: #8a8a8a;

  /* Chart Colors */
  --chart-1: #9f49c5;
  --chart-2: #349454;
  --chart-3: #ccbe2b;
  --chart-4: #48a2dc;
  --chart-5: #8c7ab1;
}


/* ======================================= */
/* 4. TAILWIND THEME EXTENSION */
/* ======================================= */
@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-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);
}


/* ======================================= */
/* 5. BASE & FONT STYLES */
/* ======================================= */
@layer base {
  * {
    @apply border-border outline-ring/50;
  }
  body {
    @apply bg-background text-foreground;
  }
}

body {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.font-poppins {
  font-family: var(--font-poppins);
}

.font-dm-sans {
  font-family: var(--font-dm-sans);
}

.font-inter {
  font-family: var(--font-inter);
}

/* Webkit (Chrome/Safari) - Using variables (KEEP) */
::-webkit-scrollbar,
div::-webkit-scrollbar {
  width: var(--scrollbar-width);
}

::-webkit-scrollbar-track,
div::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: var(--scrollbar-radius);
}

::-webkit-scrollbar-thumb,
div::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--scrollbar-radius);
  border: var(--scrollbar-border) solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover,
div::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  border: var(--scrollbar-border) solid transparent;
  background-clip: content-box;
}

/* Firefox Support */
* {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

[data-theme="dark"] * {
  scrollbar-color: #475569 transparent;
}


/* ======================================= */
/* 7. ANIMATIONS */
/* ======================================= */
.slide-in-left {
  -webkit-animation: slide-in-left 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
  animation: slide-in-left 0.5s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
}

@-webkit-keyframes slide-in-left {
  0% {
    -webkit-transform: translateX(-1000px);
    transform: translateX(-1000px);
    opacity: 0;
  }
  100% {
    -webkit-transform: translateX(0);
    transform: translateX(0);
    opacity: 1;
  }
}


/* ======================================= */
/* 8. TIP TAP / PROSEMIRROR STYLES */
/* ======================================= */

.tiptap-wrapper {
  width: 100%;
}

/* ProseMirror Base */
.ProseMirror {
  min-height: 200px;
  padding: 1rem;
  background: transparent;
  border-radius: 0 0 5px 5px;
  outline: none;
}

/* ⚠️ DUPLICATE: min-height was previously 100px. The 200px above is kept. */
/* .ProseMirror { min-height: 200px; padding: 1rem; outline: none; } */


.ProseMirror > * + * {
  margin-top: 0.9rem;
}

/* ProseMirror Content */
.ProseMirror ul {
  padding: 0 1rem;
  list-style: disc !important;
}
.ProseMirror ol {
  padding: 0 2rem;
  list-style: decimal !important;
}

.ProseMirror ul strong,
.ProseMirror ol strong {
  @apply text-black dark:text-white;
}

.ProseMirror code {
  background-color: rgba(#616161, 0.1);
  color: #616161;
  padding: 0;
  /* ⚠️ DUPLICATE: background: none; was already included later */
  background: none; 
  font-size: 0.8rem;
}
/* ⚠️ DUPLICATE: This section duplicates the code styling above (except background: none) */
/*
.ProseMirror code {
  background-color: rgba(#616161, 0.1);
  color: #616161;
}
*/

.ProseMirror pre {
  background: #0d0d0d;
  color: #fff;
  font-family: 'JetBrainsMono', monospace;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
}

.ProseMirror blockquote {
  @apply p-2 md:p-3 lg:p-6 bg-[#d4d4d4] rounded-md;
}

.ProseMirror blockquote strong {
  margin-top: 1rem;
  display: flex;
  justify-self: end;
  width: 100%;
  align-items: end;
}

.ProseMirror hr {
  border: none;
  border-top: 3px solid #999999;
  margin: 2rem 0;
}

.ProseMirror p {
  @apply md:text-base text-[14.8px] dark:text-white;
}

.ProseMirror h2 {
  @apply md:text-xl text-base;
}

.ProseMirror h3 {
  @apply md:text-base text-sm;
}

.ProseMirror-focused {
  outline: none;
}
/* Fix for any potential parent overflow */
.ProseMirror > * {
  max-width: 100%;
}


/* Tiptap Editor Base */
.tiptap-editor * {
  max-width: 100%;
}

.dark .tiptap-editor {
  background-color: #1f2937;
  color: #f9fafb;
}


/* Image Overlap/Fixes */
/* ⚠️ DUPLICATE: overflow: visible !important; is repeated for different selectors. */
.tiptap-editor *,
[data-tiptap-editor] *,
.editor-container * {
  overflow: visible !important;
}


/* ⚠️ DUPLICATE IMAGE STYLES: There are multiple, overlapping rules for images. 
   General, redundant blocks are commented out below. */

/* Image Container (Tiptap-specific) */
.tiptap-editor .image-container {
  margin: 1.5rem 0;
  max-width: 100%;
  overflow: hidden;
  border-radius: 0.5rem;
  position: relative;
}

/* Image Wrapper (ProseMirror-specific for handling delete/hover) */
.ProseMirror .image-wrapper {
  position: relative;
  margin: 1.5rem 0;
  border-radius: 0.5rem;
  overflow: hidden;
  transition: all 0.2s ease;
  z-index: 1;
  cursor: pointer;
}

.ProseMirror .image-wrapper:hover {
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Main Image Styling (Max-Width/Centering) */
.tiptap-editor .tip-tap-image {
  /* ⚠️ DUPLICATE: Properties like display, max-width, height, margin, border-radius */
  display: block !important;
  max-width: 100% !important;
  height: auto !important;
  margin: 0 auto !important;
  border-radius: 0.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.tiptap-editor img[class*="tip-tap-image"] {
  display: block !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* Centralized Max-Width Rules (Keep these for size control) */
.tiptap-editor img.tip-tap-image {
  /* ⚠️ DUPLICATE: This section re-applies centering/max-width */
  max-width: min(100%, 800px) !important;
  width: auto !important;
  height: auto !important;
  display: block !important;
  margin: 1rem auto !important;
}

@media (min-width: 1024px) {
  .tiptap-editor img.tip-tap-image {
    max-width: min(100%, 900px) !important;
  }
}

@media (min-width: 1536px) {
  .tiptap-editor img.tip-tap-image {
    max-width: min(100%, 1000px) !important;
  }
}

/* Image Caption */
.tiptap-editor .image-caption {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: #6b7280;
  text-align: center;
  font-style: italic;
}

.dark .tiptap-editor .image-caption {
  color: #9ca3af;
}

/* Image Hover/Delete Button */
.tiptap-editor .image-container:hover .tip-tap-image {
  transform: scale(1.01);
  transition: transform 0.2s ease;
}

.ProseMirror .image-delete-btn {
  /* ⚠️ DUPLICATES: Consolidation applied here. */
  opacity: 0;
  transition: opacity 0.2s ease;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  /* ⚠️ DUPLICATES: These properties are repeated across multiple rules. */
  font-size: 18px;
  font-weight: bold;
  line-height: 1;
}

.ProseMirror .image-wrapper:hover .image-delete-btn {
  opacity: 1;
}

.ProseMirror .image-delete-btn:hover {
  transform: scale(1.1);
}

.ProseMirror .image-delete-btn:active {
  transform: scale(0.95);
}

.dark .ProseMirror .image-delete-btn {
  background-color: #dc2626;
}

.dark .ProseMirror .image-delete-btn:hover {
  background-color: #b91c1c;
}

/* Delete Button Hint Overlay */
.ProseMirror .image-wrapper::after {
  content: "Click to remove";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s ease;
  border-radius: 0.5rem;
}

.ProseMirror .image-wrapper:hover::after {
  opacity: 1;
}

/* Responsive Delete Button */
@media (max-width: 640px) {
  .ProseMirror .image-delete-btn {
    width: 28px;
    height: 28px;
    top: 6px;
    right: 6px;
    /* ⚠️ DUPLICATE: This font-size is also set above. */
    font-size: 16px;
  }
  
  .ProseMirror .image-delete-btn svg {
    width: 14px;
    height: 14px;
  }
}

.ProseMirror .image-delete-btn:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}