/**
 * Dropdowns Component
 * For collapsible content sections using <details> element
 *
 * NOTE: Directive base CSS (bengal/assets/css/directives/dropdowns.css) provides
 * functional styles: marker reset, list-style, cursor, accessibility.
 * Native <details> handles show/hide. This file provides aesthetic styles.
 */

/* ============================================
   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-lg);
  background-color: var(--color-bg-secondary);
  transition: all var(--transition-normal) var(--ease-out), box-shadow 0.2s ease;
  box-shadow: var(--neumorphic-base);
}

details.dropdown.gradient-border {
  border: none;
  border-left: none;
}

details.dropdown:hover {
  box-shadow: var(--neumorphic-hover);
}

details.dropdown[open] {
  background-color: var(--color-bg-primary);
  box-shadow: var(--neumorphic-hover);
}

/* ============================================
   DROPDOWN SUMMARY (Trigger)
   Marker reset is handled by base CSS.
   This adds aesthetic styling on top.
   ============================================ */

details.dropdown summary {
  font-weight: var(--weight-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);
}

/* Custom arrow indicator */
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 summary:hover {
  color: var(--color-accent);
}

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

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

/* Focus state - base CSS provides focus-visible, this adds theme styling */
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 ICON & BADGE
   ============================================ */

.dropdown-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dropdown-icon .bengal-icon {
  width: 18px;
  height: 18px;
  transition: color var(--transition-fast) var(--ease-out);
}

.dropdown-header {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.dropdown-title {
  flex: 1;
}

.dropdown-description {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-normal);
  color: var(--color-text-secondary);
  line-height: 1.4;
}

.dropdown-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125em 0.5em;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.4;
  color: var(--color-text-inverse);
  background-color: var(--color-accent);
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.025em;
  margin-left: auto;
  margin-right: var(--space-6);
}

/* Badge color variants */
details.dropdown.success .dropdown-badge {
  background-color: var(--color-success);
}

details.dropdown.warning .dropdown-badge {
  background-color: var(--color-warning);
  color: var(--color-text-primary);
}

details.dropdown.danger .dropdown-badge {
  background-color: var(--color-error);
}

details.dropdown.info .dropdown-badge {
  background-color: var(--color-info);
}

/* Icon color variants */
details.dropdown.success .dropdown-icon .bengal-icon {
  color: var(--color-success);
}

details.dropdown.warning .dropdown-icon .bengal-icon {
  color: var(--color-warning);
}

details.dropdown.danger .dropdown-icon .bengal-icon {
  color: var(--color-error);
}

details.dropdown.info .dropdown-icon .bengal-icon {
  color: var(--color-info);
}

/* ============================================
   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);
  will-change: transform, opacity;
}

@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;
}

.dropdown-content p {
  border-left: none;
  padding-left: 0;
  background: transparent;
}

.dropdown-content strong,
.dropdown-content b {
  border: none;
  background: transparent;
  padding: 0;
}

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

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);
}

details.dropdown.success {
  border-left-color: var(--color-success);
}

details.dropdown.success summary {
  color: var(--color-success-text);
}

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

details.dropdown.warning {
  border-left-color: var(--color-warning);
}

details.dropdown.warning summary {
  color: var(--color-warning-text);
}

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

details.dropdown.danger {
  border-left-color: var(--color-error);
}

details.dropdown.danger summary {
  color: var(--color-error-text);
}

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

details.dropdown.info {
  border-left-color: var(--color-info);
}

details.dropdown.info summary {
  color: var(--color-info-text);
}

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

/* ============================================
   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);
  box-shadow: var(--neumorphic-base);
}

[data-theme="dark"] details.dropdown:hover {
  box-shadow: var(--neumorphic-hover);
}

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

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

/* ============================================
   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;
  }

  details.dropdown summary {
    cursor: default;
  }

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

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

/* ============================================
   ACCESSIBILITY
   Base CSS handles reduced-motion for functional parts.
   This handles theme-specific animations.
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .dropdown-content {
    animation: none;
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1),
      transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
      visibility 0.2s;
  }

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