/* ===== CSS Variables for Theme ===== */
:root {
  /* Light Theme (default) */
  --bg-app: #fdfbf7;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-input: #f5f5f4;
  --primary-color: #ea580c;
  --primary-hover: #c2410c;
  --text-on-primary: #ffffff;
  --accent-color: #f97316;
  --text-main: #1c1917;
  --text-muted: #78716c;
  --text-placeholder: #a8a29e;
  --border-color: #e7e5e4;
  --border-highlight: #fdba74;
  
  /* Modal/Overlay backgrounds */
  --overlay-bg: rgba(41, 37, 36, 0.5);
  --overlay-blur: 8px;
}

/* ===== Base Styles ===== */
html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg-app);
  color: var(--text-main);
  font-family: 'Heebo', sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===== Enhanced Modal/Overlay Backgrounds ===== */
.modal-overlay {
  background: linear-gradient(
    135deg,
    rgba(120, 113, 108, 0.4) 0%,
    rgba(87, 83, 78, 0.5) 50%,
    rgba(68, 64, 60, 0.4) 100%
  );
  backdrop-filter: blur(var(--overlay-blur));
  -webkit-backdrop-filter: blur(var(--overlay-blur));
}

/* Premium glass effect for overlays */
.glass-overlay {
  background: linear-gradient(
    145deg,
    rgba(253, 251, 247, 0.85) 0%,
    rgba(255, 255, 255, 0.75) 100%
  );
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(255, 255, 255, 0.5) inset;
}

/* ===== Improved Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #fed7aa 0%, #fdba74 100%);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #fdba74 0%, #fb923c 100%);
  background-clip: padding-box;
}

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

/* ===== Animation Utilities ===== */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes slide-up {
  from { 
    opacity: 0; 
    transform: translateY(20px); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0); 
  }
}

@keyframes slide-down {
  from { 
    opacity: 0; 
    transform: translateY(-20px); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0); 
  }
}

@keyframes scale-in {
  from { 
    opacity: 0; 
    transform: scale(0.95); 
  }
  to { 
    opacity: 1; 
    transform: scale(1); 
  }
}

@keyframes pulse-glow {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.4);
  }
  50% {
    box-shadow: 0 0 20px 10px rgba(249, 115, 22, 0);
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Animation classes */
.animate-fade-in { animation: fade-in 0.3s ease-out forwards; }
.animate-fade-out { animation: fade-out 0.3s ease-out forwards; }
.animate-slide-up { animation: slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.animate-slide-down { animation: slide-down 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.animate-scale-in { animation: scale-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.animate-pulse-glow { animation: pulse-glow 2s ease-in-out infinite; }

/* ===== Button Press Animation ===== */
.btn-press {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-press:active {
  transform: scale(0.96);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ===== Loading Skeleton ===== */
.skeleton {
  background: linear-gradient(
    90deg,
    #f5f5f4 25%,
    #e7e5e4 50%,
    #f5f5f4 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

/* ===== Card Hover Effects ===== */
.card-hover {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card-hover:hover {
  transform: translateY(-4px);
  box-shadow: 
    0 20px 40px -15px rgba(234, 88, 12, 0.15),
    0 8px 16px -8px rgba(0, 0, 0, 0.1);
}

/* ===== Focus States ===== */
*:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

/* ===== Selection Styles ===== */
::selection {
  background: rgba(251, 146, 60, 0.4);
  color: inherit;
}

::-moz-selection {
  background: rgba(251, 146, 60, 0.4);
  color: inherit;
}

/* Keep selection visible even when not focused */
.selection\:bg-orange-200::selection,
.selection\:bg-orange-200::-moz-selection {
  background: rgba(251, 146, 60, 0.5) !important;
}

/* Make text selectable with better cursor */
[data-source] p {
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

/* ===== Safe Area Padding for Mobile ===== */
@supports (padding-top: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* ===== No Scrollbar Utility ===== */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}

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

/* ===== Rich Text Content ===== */
.rich-content h1, .rich-content h2, .rich-content h3 {
  font-family: 'Frank Ruhl Libre', serif;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.rich-content p {
  margin-bottom: 1em;
  line-height: 1.8;
}

.rich-content ul, .rich-content ol {
  padding-right: 1.5em;
  margin-bottom: 1em;
}

.rich-content li {
  margin-bottom: 0.5em;
}

/* ===== RTL Specific Fixes ===== */
[dir="rtl"] input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

/* ===== Print Styles ===== */
@media print {
  .no-print {
    display: none !important;
  }
  
  body {
    background: white;
  }
}

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

/* ===== Accessibility Styles ===== */

/* High Contrast Mode */
body.high-contrast {
  --bg-app: #ffffff !important;
  --bg-surface: #ffffff !important;
  --text-main: #000000 !important;
  --text-muted: #333333 !important;
  --primary-color: #0066cc !important;
}

body.high-contrast * {
  border-color: #333333 !important;
}

body.high-contrast button,
body.high-contrast a {
  border-width: 2px !important;
}

body.high-contrast img {
  filter: contrast(1.1);
}

/* Reduce Motion (programmatic) */
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* Highlight Links */
body.highlight-links a {
  text-decoration: underline !important;
  text-decoration-thickness: 2px !important;
  text-underline-offset: 3px !important;
}

body.highlight-links a:not([class*="bg-"]) {
  color: #0000EE !important;
}

body.highlight-links a:visited:not([class*="bg-"]) {
  color: #551A8B !important;
}

/* Highlight Focus */
body.highlight-focus *:focus,
body.highlight-focus *:focus-visible {
  outline: 4px solid #0066FF !important;
  outline-offset: 4px !important;
  border-radius: 4px;
}

/* Dynamic Line Spacing */
body p,
body li,
body span:not(.icon),
body div:not(.flex):not(.grid) {
  line-height: calc(1.6 * var(--a11y-line-height, 1));
}

/* Accessibility Dark Mode */
body.a11y-dark {
  --bg-app: #1a1a1a !important;
  --bg-surface: #2a2a2a !important;
  --bg-elevated: #333333 !important;
  --text-main: #f0f0f0 !important;
  --text-muted: #cccccc !important;
  --border-color: #444444 !important;
}

body.a11y-dark {
  background-color: #1a1a1a !important;
  color: #f0f0f0 !important;
}

body.a11y-dark .bg-white {
  background-color: #2a2a2a !important;
}

body.a11y-dark .text-stone-800,
body.a11y-dark .text-stone-700,
body.a11y-dark .text-stone-600 {
  color: #e0e0e0 !important;
}

/* Selection Toolbar Animation */
@keyframes selection-appear {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(5px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.selection-actions-toolbar {
  animation: selection-appear 0.15s ease-out forwards;
}