/* Preview Section */
.preview-section {
  background-color: white;
  border-radius: 1rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  padding: 1.5rem;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.download-button {
  background-color: var(--color-blue-100, #DBEAFE);
  color: var(--color-primary);
  border-radius: 9999px;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.download-button:hover:not(:disabled) {
  background-color: var(--color-blue-200, #BFDBFE);
}

.download-button:disabled {
  background-color: var(--color-gray-100);
  color: var(--color-gray-400);
}

.preview-paper {
  background-color: #ffffff;
  border-radius: 0.75rem;
  padding: 1.5rem;
  height: 28rem; /* Fixed height instead of min-height */
  max-height: 28rem; /* Maximum height */
  overflow-y: auto; /* Enable vertical scrolling */
  background-image: none; /* No default lines - controlled by ruler toggle */
  position: relative; /* For proper layering */
}

/* Custom scrollbar styling */
.preview-paper::-webkit-scrollbar {
  width: 8px;
}

.preview-paper::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.preview-paper::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.preview-paper::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Page type variations */
.preview-paper.white-page {
  background-color: #ffffff;
  background-image: none;
}

.preview-paper.blank-page {
  background-color: #ffffff; /* White background for plain pages */
  background-image: none;
}

.preview-paper.ruled-page {
  background-color: #ffffff; /* White background for ruled pages */
  background-image: repeating-linear-gradient(
    transparent,
    transparent 2rem, /* Line height matches line-height: 2 */
    #000000 2rem,   /* Black line */
    #000000 2.03125rem, /* Line thickness */
    transparent 2.03125rem
  );
  background-position: 0 0.25rem; /* Align with text padding */
}

.preview-paper.graph-page {
  background-color: #ffffff;
  background-image: 
    linear-gradient(#e5e5e5 1px, transparent 1px),
    linear-gradient(90deg, #e5e5e5 1px, transparent 1px);
  background-size: 30px 30px;
}

.preview-paper.dotted-page {
  background-color: var(--color-amber-50);
  background-image: radial-gradient(circle, #e5e5e5 1px, transparent 1px);
  background-size: 40px 40px;
}

.preview-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
}

.empty-icon {
  color: var(--color-gray-300);
  margin-bottom: 1rem;
}

.empty-title {
  font-size: 1.125rem;
  color: var(--color-gray-400);
}

.empty-text {
  font-size: 0.875rem;
  color: var(--color-gray-400);
  margin-top: 0.5rem;
}

.handwriting-content {
  white-space: pre-wrap;
  line-height: 2;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  font-size: 1.5rem; /* Consistent font size */
  position: relative;
  z-index: 1; /* Ensure text appears above background */
}

.preview-footer {
  margin-top: 1.5rem;
  background: linear-gradient(to bottom, rgba(249, 250, 251, 0.5), rgba(249, 250, 251, 1));
  border-radius: 0.75rem;
  border: 1px solid var(--color-gray-200);
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.preview-status {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  background-color: white;
  border-radius: 0.5rem;
  border: 1px solid var(--color-gray-200);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
}

.preview-status:hover {
  border-color: var(--color-gray-300);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.preview-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-gray-100);
}

.control-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.control-row:first-child {
  padding-top: 0;
}

.preview-options {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.preview-actions {
  display: flex;
  gap: 0.75rem;
  margin-left: auto;
}

.action-button {
  padding: 0.625rem 1.25rem;
  background: linear-gradient(135deg, #ffffff 0%, #f9fafb 100%);
  border: 1.5px solid var(--color-gray-200);
  border-radius: 0.625rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-gray-700);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.action-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
  transition: left 0.5s ease;
}

.action-button:hover {
  background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  border-color: var(--color-primary);
  color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.action-button:hover::before {
  left: 100%;
}

.action-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Status Indicator */
.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--color-gray-300);
  position: relative;
  animation: pulse 2s infinite;
  box-shadow: 0 0 0 0 rgba(156, 163, 175, 0.7);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(156, 163, 175, 0.7);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(156, 163, 175, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(156, 163, 175, 0);
  }
}

.status-indicator.active {
  background-color: #10b981;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
}

.status-indicator.active::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 6px;
  height: 6px;
  background-color: white;
  border-radius: 50%;
}

@keyframes pulse-active {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

.status-indicator.active {
  animation: pulse-active 2s infinite;
}

.status-text {
  font-size: 0.875rem;
  color: var(--color-gray-700);
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* Option Group Styles */
.option-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background-color: white;
  border-radius: 0.5rem;
  border: 1px solid var(--color-gray-200);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
}

.option-group:hover {
  border-color: var(--color-gray-300);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.option-label {
  font-size: 0.875rem;
  color: var(--color-gray-700);
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.page-size-select {
  padding: 0.5rem 0.875rem;
  border: 1.5px solid var(--color-gray-200);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-gray-800);
  background-color: white;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 12px;
  padding-right: 2rem;
  cursor: pointer;
  transition: all 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

.page-size-select:hover {
  border-color: var(--color-primary);
  background-color: #fafbff;
}

.page-size-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  background-color: white;
}

.ruler-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1.5px solid var(--color-gray-200);
  border-radius: 0.5rem;
  background: linear-gradient(135deg, #ffffff 0%, #f9fafb 100%);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-gray-700);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  position: relative;
  overflow: hidden;
}

.ruler-toggle::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(59, 130, 246, 0.05) 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ruler-toggle:hover {
  background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  border-color: var(--color-primary);
  color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.ruler-toggle:hover::before {
  opacity: 1;
}

.ruler-toggle.active {
  background: linear-gradient(135deg, var(--color-primary) 0%, #2563eb 100%);
  color: white;
  border-color: var(--color-primary);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  transform: translateY(0);
}

.ruler-toggle.active::before {
  opacity: 0;
}

.ruler-toggle.active:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

.ruler-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 0.3s ease;
}

.ruler-toggle:hover svg {
  transform: scale(1.1);
}

.ruler-toggle.active svg {
  transform: rotate(180deg);
}

/* Modal Styles for Settings Modal (Popup) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.modal-overlay:not(.hidden) {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: linear-gradient(to bottom, #ffffff, #fafbfc);
  border-radius: 1rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  border: 1px solid var(--color-gray-200);
}

.modal-overlay:not(.hidden) .modal-content {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem;
  border-bottom: 1px solid var(--color-gray-200);
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-radius: 1rem 1rem 0 0;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-gray-900);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-title::before {
  content: "⚙️";
  font-size: 1.375rem;
}

.modal-close {
  background: white;
  border: 1.5px solid var(--color-gray-200);
  color: var(--color-gray-500);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.modal-close:hover {
  background-color: var(--color-gray-50);
  border-color: var(--color-gray-300);
  color: var(--color-gray-700);
  transform: rotate(90deg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.modal-body {
  padding: 1.5rem;
  background-color: white;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--color-gray-200);
  background: linear-gradient(to bottom, white, #fafbfc);
  border-radius: 0 0 1rem 1rem;
}

.modal-button {
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.modal-button.primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, #2563eb 100%);
  color: white;
}

.modal-button.primary:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.modal-button.secondary {
  background-color: white;
  color: var(--color-gray-700);
  border: 1.5px solid var(--color-gray-300);
}

.modal-button.secondary:hover {
  background-color: var(--color-gray-50);
  border-color: var(--color-gray-400);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Style Adjustment Modal - Popup (Same as Settings Modal) */
.style-modal-content {
  background: linear-gradient(to bottom, #ffffff, #fafbfc);
  border-radius: 1rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  border: 1px solid var(--color-gray-200);
}

#style-modal:not(.hidden) .style-modal-content {
  transform: scale(1);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-gray-200);
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-radius: 1rem 1rem 0 0;
}

.panel-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-gray-900);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.panel-title::before {
  content: "🎨";
  font-size: 1.375rem;
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

.panel-toggle {
  background: white;
  border: 1.5px solid var(--color-gray-200);
  color: var(--color-gray-500);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.panel-toggle:hover {
  background-color: var(--color-gray-50);
  border-color: var(--color-gray-300);
  color: var(--color-gray-700);
  transform: rotate(90deg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.panel-body {
  padding: 1.5rem 1.5rem 1.25rem;
  max-height: 400px;
  overflow-y: auto;
  background-color: white;
}

/* Custom scrollbar for panel body */
.panel-body::-webkit-scrollbar {
  width: 8px;
}

.panel-body::-webkit-scrollbar-track {
  background: #f8f9fa;
  border-radius: 4px;
}

.panel-body::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #cbd5e1 0%, #94a3b8 100%);
  border-radius: 4px;
}

.panel-body::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #94a3b8 0%, #64748b 100%);
}

.panel-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem 1.25rem;
  border-top: 1px solid var(--color-gray-200);
  background: linear-gradient(to bottom, white, #fafbfc);
  border-radius: 0 0 1rem 1rem;
}

.panel-button {
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.panel-button.primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, #2563eb 100%);
  color: white;
}

.panel-button.primary:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.panel-button.secondary {
  background-color: white;
  color: var(--color-gray-700);
  border: 1.5px solid var(--color-gray-300);
}

.panel-button.secondary:hover {
  background-color: var(--color-gray-50);
  border-color: var(--color-gray-400);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Control Styles - Shared by both panels */
.style-controls, .settings-controls {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-gray-700);
}

.control-input {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.control-input input[type="range"] {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--color-gray-200);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.control-input input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
}

.control-input input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: none;
}

.control-input input[type="color"] {
  width: 50px;
  height: 40px;
  border: 1px solid var(--color-gray-200);
  border-radius: 0.375rem;
  cursor: pointer;
}

.control-value {
  font-size: 0.875rem;
  color: var(--color-gray-600);
  min-width: 60px;
  text-align: right;
}

.control-select {
  padding: 0.5rem;
  border: 1px solid var(--color-gray-200);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: var(--color-gray-600);
  background-color: white;
  cursor: pointer;
}

.control-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Responsive styles for panels */
@media (max-width: 768px) {
  .modal-content,
  .style-modal-content {
    width: 95%;
    max-height: 85vh;
  }

  .modal-header,
  .modal-footer {
    padding: 1.25rem;
  }

  .modal-body {
    padding: 1.25rem;
  }

  .panel-header {
    padding: 1rem 1.25rem;
  }

  .panel-title {
    font-size: 1rem;
  }

  .panel-title::before {
    font-size: 1.25rem;
  }

  .panel-body {
    padding: 1.25rem 1rem;
    max-height: 320px;
  }

  .panel-footer {
    padding: 1rem 1.25rem;
    flex-direction: row;
    gap: 0.625rem;
  }

  .panel-button {
    flex: 1;
    padding: 0.625rem 1rem;
  }

  .control-group {
    gap: 0.5rem;
  }

  .control-label {
    font-size: 0.8125rem;
  }

  /* Preview footer controls for mobile */
  .preview-footer {
    padding: 1rem;
  }

  .control-row {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 0.625rem 0;
  }

  .preview-status {
    justify-content: center;
    padding: 0.75rem 1rem;
  }

  .preview-actions {
    width: 100%;
    flex-direction: column;
    margin-left: 0;
  }

  .action-button {
    width: 100%;
    padding: 0.75rem 1rem;
    justify-content: center;
  }

  .option-group {
    width: 100%;
    justify-content: space-between;
    padding: 0.625rem 0.875rem;
  }

  .page-size-select {
    flex: 1;
    min-width: 0;
  }

  .ruler-toggle {
    width: 100%;
    justify-content: center;
    padding: 0.625rem 1rem;
  }
}

@media (max-width: 480px) {
  .modal-content,
  .style-modal-content {
    width: 95%;
    max-height: 80vh;
    border-radius: 0.75rem;
  }

  .modal-header {
    padding: 1rem;
  }

  .modal-title {
    font-size: 1.125rem;
  }

  .modal-body {
    padding: 1rem;
  }

  .modal-footer {
    padding: 1rem;
    flex-direction: column;
  }

  .modal-button {
    width: 100%;
  }

  .panel-header {
    padding: 0.875rem 1rem;
  }

  .panel-title {
    font-size: 0.9375rem;
  }

  .panel-body {
    padding: 1rem 0.875rem;
    max-height: 280px;
  }

  .panel-footer {
    padding: 0.875rem 1rem;
    flex-direction: column;
  }

  .panel-button {
    width: 100%;
    padding: 0.625rem 1rem;
  }

  .preview-footer {
    padding: 0.75rem;
  }

  .control-row {
    gap: 0.5rem;
  }

  .action-button {
    font-size: 0.8125rem;
    padding: 0.625rem 0.875rem;
  }

  .option-label {
    font-size: 0.8125rem;
  }

  .page-size-select {
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
    padding-right: 1.75rem;
  }

  .ruler-toggle {
    font-size: 0.8125rem;
    padding: 0.5rem 0.875rem;
  }

  .status-text {
    font-size: 0.8125rem;
  }
}