/*
 * main.css
 *
 * Contains global styles, base element styling, animations,
 * layout rules, and responsive design media queries.
 */

* {
  box-sizing: border-box;
}

body {
  font-family: "Tajawal", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Font styles */
.font-quran {
  font-family: "Noto Naskh Arabic", serif;
}

/* Smooth Scrolling */
html {
  scroll-behavior: smooth;
}

/* Feature Card */
.feature-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.feature-card::before {
  content: "";
  position: absolute;
  top: -50%;
  right: -50%;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, var(--primary-color) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  border-color: var(--primary-color);
}

.feature-card:hover::before {
  opacity: 0.05;
}

/* Verse Number */
.verse-end-number {
  font-family: "Noto Naskh Arabic", serif !important;
  font-size: 0.8em;
  display: inline-block;
  vertical-align: baseline;
  margin: 0 0.2em;
}

/* Arabic Text Punctuation Rules */
#preview-arabic {
  word-break: keep-all;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

/* Prevent line breaks before Arabic punctuation */
#preview-arabic::before {
  content: "";
  white-space: nowrap;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb {
  background: var(--text-tertiary);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Animation Classes */
.fade-in {
  animation: fadeIn 0.5s ease-in-out;
}
.slide-up {
  animation: slideUp 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Expanded Modal Layout */
.modal-content.expanded-preview {
  animation: expandModal 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes expandModal {
  from {
    width: 1400px;
  }
  to {
    width: 95vw;
  }
}

/* Preview Draggable States */
.preview-draggable {
  transition: transform 0.15s ease-out;
}

.preview-draggable.dragging {
  transition: none;
}

/* Hand Tool and Dragging Cursor States */
.draggable-cursor {
  cursor: grab !important;
}

.draggable-cursor:active {
  cursor: grabbing !important;
}

/* Enhanced Preview Panel for Better Visibility */
.preview-panel {
  position: relative;
  background: radial-gradient(
      circle at 20% 20%,
      rgba(30, 64, 175, 0.08) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 80%,
      rgba(14, 165, 233, 0.08) 0%,
      transparent 50%
    ),
    var(--bg-primary);
}

.preview-panel::before {
  content: "";
  position: absolute;
  inset: -20px;
  background: radial-gradient(
    circle at center,
    rgba(59, 130, 246, 0.03) 0%,
    transparent 60%
  );
  pointer-events: none;
  z-index: 0;
}

.preview-container {
  position: relative;
  z-index: 1;
}

/* Enhanced Modal Content for Expanded View */
.modal-content.expanded-preview .collapsible-panel {
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.modal-content.expanded-preview .verse-panel {
  width: 280px;
  min-width: 280px;
  transform: translateX(0);
  opacity: 1;
}

.modal-content.expanded-preview .controls-panel {
  width: 320px;
  min-width: 320px;
  transform: translateX(0);
  opacity: 1;
}

.modal-content.expanded-preview .preview-panel {
  flex: 1;
  max-width: calc(100% - 600px);
  margin: 0 20px;
  border-radius: 16px;
  overflow: hidden;
}

/* Undo/Redo Button States */
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn:disabled:hover {
  transform: none;
  box-shadow: none;
}

/* Tool Button Active States */
.tool-btn.active {
  background: var(--primary-color) !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}

.tool-btn.active:hover {
  background: var(--primary-hover) !important;
}

/* Enhanced Control Panel Visibility */
.controls-panel {
  background: var(--bg-primary);
  border-left: 1px solid var(--border-color);
}

.verse-panel {
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
}

/* Improved Preview Container */
.preview-container {
  background: radial-gradient(
      circle at 20% 20%,
      rgba(30, 64, 175, 0.1) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 80%,
      rgba(14, 165, 233, 0.1) 0%,
      transparent 50%
    ),
    var(--bg-tertiary);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  min-height: 400px;
}

/* Enhanced Live Preview */
#live-preview {
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  transform-origin: center center;
  transition: transform 0.3s ease, background 0.3s ease;
  position: relative;
  overflow: hidden;
}

#live-preview.transparent-preview {
  background: linear-gradient(135deg, #1f2937, #374151) !important;
  position: relative;
}

#live-preview.transparent-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.1) 25%,
      transparent 25%
    ),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.1) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.1) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.1) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  opacity: 0.3;
  z-index: -1;
}

/* Navbar Enhancements */
nav {
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Improved Surah Card with Gradient Border */
.surah-card {
  background: var(--bg-secondary);
  border: 2px solid transparent;
  border-radius: 20px;
  padding: 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  background-image: linear-gradient(var(--bg-secondary), var(--bg-secondary)),
    linear-gradient(135deg, var(--primary-color), var(--accent-color));
  background-origin: border-box;
  background-clip: padding-box, border-box;
}

.surah-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    transparent 40%,
    rgba(59, 130, 246, 0.1) 100%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.surah-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.surah-card:hover::after {
  opacity: 1;
}

/* Enhanced Button Animations */
.btn {
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
  z-index: 0;
}

.btn:active::before {
  width: 300px;
  height: 300px;
}

.btn > * {
  position: relative;
  z-index: 1;
}

/* Focus Styles for Accessibility */
.btn:focus-visible,
.input:focus-visible,
.select:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Smooth Panel Transitions */
.collapsible-panel {
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

/* Enhanced Zoom Controls Layout */
.modal-content .preview-panel .preview-container {
  position: relative;
}

.modal-content .preview-panel .preview-container > .absolute {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 10;
}

/* Better Separation Between Buttons */
.btn-group {
  display: flex;
  gap: 4px;
  align-items: center;
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Improved Divider */
.divider-vertical {
  width: 1px;
  height: 24px;
  background: var(--border-color);
  margin: 0 4px;
  opacity: 0.6;
}

/* Enhanced Toast Positioning */
#toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 1000;
  pointer-events: none;
}

/* Responsive Design */
@media (max-width: 1400px) {
  .modal-content.expanded-preview .verse-panel {
    width: 260px;
    min-width: 260px;
  }
  .modal-content.expanded-preview .controls-panel {
    width: 300px;
    min-width: 300px;
  }
  .modal-content.expanded-preview .preview-panel {
    max-width: calc(100% - 560px);
  }
}

@media (max-width: 1200px) {
  .modal-content.expanded-preview .verse-panel {
    width: 240px;
    min-width: 240px;
  }
  .modal-content.expanded-preview .controls-panel {
    width: 280px;
    min-width: 280px;
  }
  .modal-content.expanded-preview .preview-panel {
    max-width: calc(100% - 520px);
    margin: 0 10px;
  }
}

@media (max-width: 1024px) {
  .modal-content {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    flex-direction: column;
  }

  .modal-content.expanded-preview {
    width: 100%;
  }

  .panel {
    width: 100% !important;
    min-width: 100% !important;
  }

  .verse-panel {
    height: 45vh;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .preview-panel {
    min-height: 200px;
    height: auto;
    flex: 1;
  }

  .controls-panel {
    height: 45vh;
    max-height: 45vh;
    border-left: none;
    border-top: 1px solid var(--border-color);
  }

  .modal-content.expanded-preview .preview-panel {
    max-width: 100%;
    margin: 0;
  }

  /* Adjust button layout for mobile */
  .btn-group {
    gap: 2px;
    padding: 2px;
  }

  .btn-icon {
    width: 36px;
    height: 36px;
    padding: 6px;
  }
}

@media (max-width: 767px) {
  .btn {
    padding: 10px 16px;
    font-size: 13px;
  }

  .btn-icon {
    width: 40px;
    height: 40px;
    padding: 8px;
  }

  .input,
  .select {
    padding: 12px 14px;
    font-size: 14px;
  }

  .card,
  .surah-card,
  .verse-item {
    border-radius: 12px;
    padding: 16px;
  }

  .control-section {
    border-radius: 12px;
  }

  .modal-content {
    border-radius: 0;
  }

  .toast {
    right: 10px;
    left: 10px;
    width: auto;
    min-width: auto;
  }

  nav .container {
    padding: 0 16px;
  }

  .feature-card {
    padding: 20px;
  }

  .divider-vertical {
    display: none;
  }

  /* Mobile-specific preview adjustments */
  .preview-container {
    min-height: 250px;
  }

  #toast-container {
    top: 70px;
    right: 10px;
    left: 10px;
  }

  /* Simplified button layout for mobile */
  .modal-content .preview-panel .preview-container > .absolute {
    bottom: 10px;
    right: 10px;
  }

  .verse-panel,
  .controls-panel {
    height: auto;
    max-height: none;
    flex: 1;
  }

  .modal-content {
    display: block;
    overflow-y: auto;
  }
}

@media (max-width: 480px) {
  .btn-group {
    flex-wrap: wrap;
    gap: 4px;
  }

  .btn-icon {
    width: 32px;
    height: 32px;
    padding: 4px;
  }

  .preview-container {
    min-height: 200px;
  }

  .modal-content .preview-panel .preview-container > .absolute {
    bottom: 5px;
    right: 5px;
    flex-wrap: wrap;
  }
}

/* Utility Classes */
/* MODIFICATION: Removed !important to allow responsive classes to override it. */
.hidden {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Enhanced Transitions */
.transition-all {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.transition-transform {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark theme enhancements */
[data-theme="dark"] {
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3),
    0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3),
    0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3),
    0 10px 10px -5px rgba(0, 0, 0, 0.2);
}

/* Performance optimizations */
.modal-content,
.preview-draggable,
.btn,
.surah-card {
  will-change: transform;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }

  .surah-card,
  .verse-item {
    border-width: 3px;
  }
}

/* Collapsible Control Sections */
.control-header.collapsible {
  cursor: pointer;
  user-select: none; /* Prevent text selection on click */
}

.control-header.collapsible .collapse-icon {
  transition: transform 0.3s ease-in-out;
}

.control-section.collapsed .control-header.collapsible .collapse-icon {
  transform: rotate(180deg);
}

.control-section.collapsed .control-body {
  max-height: 0;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-in-out, padding-top 0.4s ease-in-out,
    padding-bottom 0.4s ease-in-out, opacity 0.2s ease-in-out;
}

/* Collapsible Verse List Panel */
.verse-panel .collapsible-header .collapse-icon {
  transition: transform 0.3s ease-in-out;
}

.verse-panel.collapsed .collapsible-header .collapse-icon {
  transform: rotate(-180deg);
}

.verse-panel .panel-body {
  max-height: 2000px; /* A large enough value to not clip content */
  transition: max-height 0.5s ease-in-out, opacity 0.3s ease-in-out,
    padding 0.5s ease-in-out;
  overflow: auto;
}

.verse-panel.collapsed .panel-body {
  max-height: 0 !important;
  opacity: 0;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  overflow: hidden;
  border-top: 1px solid var(--border-color);
}
