/**
 * Dropdowns Component
 * For collapsible content sections using <details> element
 */

/* ============================================
   DROPDOWN BASE
   ============================================ */

details.dropdown {
  position: relative;
  margin: var(--space-6) 0;
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-accent);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-secondary);
  transition: all var(--transition-normal) var(--ease-out);
}

details.dropdown:hover {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

details.dropdown[open] {
  background-color: var(--color-bg-primary);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* ============================================
   DROPDOWN SUMMARY (Trigger)
   ============================================ */

details.dropdown summary {
  cursor: pointer;
  list-style: none;
  font-weight: var(--font-semibold);
  font-size: var(--text-base);
  color: var(--color-text-primary);
  padding-right: var(--space-8);
  position: relative;
  user-select: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: color var(--transition-fast) var(--ease-out);
}

/* Remove default marker */
details.dropdown summary::-webkit-details-marker {
  display: none;
}

details.dropdown summary::marker {
  display: none;
}

/* Custom arrow */
details.dropdown summary::after {
  content: '▶';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  transition: transform var(--transition-fast) var(--ease-out);
}

details.dropdown[open] summary::after {
  transform: translateY(-50%) rotate(90deg);
}

details.dropdown summary:hover {
  color: var(--color-accent);
}

details.dropdown summary:hover::after {
  color: var(--color-accent);
}

/* Focus state for accessibility */
details.dropdown summary:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

details.dropdown summary:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================
   DROPDOWN CONTENT
   ============================================ */

.dropdown-content {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  animation: slideDown 0.2s var(--ease-out);
}

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

.dropdown-content > *:first-child {
  margin-top: 0;
}

.dropdown-content > *:last-child {
  margin-bottom: 0;
}

/* Fix list styling inside dropdowns */
.dropdown-content ul,
.dropdown-content ol {
  padding-left: var(--space-6);
  margin: var(--space-3) 0;
}

.dropdown-content ul {
  list-style-type: disc;
}

.dropdown-content ol {
  list-style-type: decimal;
}

.dropdown-content li {
  margin: var(--space-1) 0;
}

/* Ensure paragraphs don't inherit the left border */
.dropdown-content p {
  border-left: none;
  padding-left: 0;
  background: transparent;
}

/* Remove any unintended styling on strong/bold elements */
.dropdown-content strong,
.dropdown-content b {
  border: none;
  background: transparent;
  padding: 0;
}

/* ============================================
   DROPDOWN VARIANTS
   ============================================ */

/* Minimal variant (no border, subtle background) */
details.dropdown.minimal {
  border: none;
  border-left: 3px solid var(--color-border);
  background-color: transparent;
  padding-left: var(--space-4);
}

details.dropdown.minimal[open] {
  background-color: var(--color-bg-secondary);
}

/* Success variant */
details.dropdown.success {
  border-left-color: #10b981; /* green-500 */
}

details.dropdown.success summary {
  color: #047857; /* green-700 */
}

details.dropdown.success[open] {
  background-color: #ecfdf5; /* green-50 */
}

/* Warning variant */
details.dropdown.warning {
  border-left-color: #f59e0b; /* amber-500 */
}

details.dropdown.warning summary {
  color: #d97706; /* amber-600 */
}

details.dropdown.warning[open] {
  background-color: #fffbeb; /* amber-50 */
}

/* Danger variant */
details.dropdown.danger {
  border-left-color: #ef4444; /* red-500 */
}

details.dropdown.danger summary {
  color: #dc2626; /* red-600 */
}

details.dropdown.danger[open] {
  background-color: #fef2f2; /* red-50 */
}

/* Info variant */
details.dropdown.info {
  border-left-color: #3b82f6; /* blue-500 */
}

details.dropdown.info summary {
  color: #1e40af; /* blue-800 */
}

details.dropdown.info[open] {
  background-color: #eff6ff; /* blue-50 */
}

/* ============================================
   NESTED DROPDOWNS
   ============================================ */

.dropdown-content details.dropdown {
  margin-top: var(--space-3);
  margin-bottom: var(--space-3);
  font-size: var(--text-sm);
}

/* ============================================
   DARK MODE
   ============================================ */

[data-theme="dark"] details.dropdown {
  border-color: var(--color-border-dark);
  background-color: var(--color-bg-secondary-dark);
}

[data-theme="dark"] details.dropdown[open] {
  background-color: var(--color-bg-primary-dark);
}

[data-theme="dark"] .dropdown-content {
  border-top-color: var(--color-border-dark);
}

/* Dark mode variants */
[data-theme="dark"] details.dropdown.success[open] {
  background-color: rgba(16, 185, 129, 0.1);
}

[data-theme="dark"] details.dropdown.success summary {
  color: #6ee7b7; /* green-300 */
}

[data-theme="dark"] details.dropdown.warning[open] {
  background-color: rgba(245, 158, 11, 0.1);
}

[data-theme="dark"] details.dropdown.warning summary {
  color: #fcd34d; /* amber-300 */
}

[data-theme="dark"] details.dropdown.danger[open] {
  background-color: rgba(239, 68, 68, 0.1);
}

[data-theme="dark"] details.dropdown.danger summary {
  color: #fca5a5; /* red-300 */
}

[data-theme="dark"] details.dropdown.info[open] {
  background-color: rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] details.dropdown.info summary {
  color: #93c5fd; /* blue-300 */
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 640px) {
  details.dropdown {
    padding: var(--space-3) var(--space-4);
    margin: var(--space-4) 0;
  }

  details.dropdown summary {
    font-size: var(--text-sm);
    padding-right: var(--space-6);
  }

  .dropdown-content {
    margin-top: var(--space-3);
    padding-top: var(--space-3);
  }
}

/* ============================================
   PRINT
   ============================================ */

@media print {
  details.dropdown {
    border: 1px solid #ccc;
  }

  details.dropdown summary::after {
    display: none;
  }

  /* Force all dropdowns open for printing */
  details.dropdown summary {
    cursor: default;
  }

  details.dropdown:not([open]) {
    display: block;
  }

  details.dropdown:not([open]) .dropdown-content {
    display: block;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .dropdown-content {
    animation: none;
  }

  details.dropdown summary::after {
    transition: none;
  }
}
