/**
 * Qahera UI Kit — Dropdown Menu Component Styles
 * 100% Logical CSS, Zero Physical Slop, WCAG 2.1 AA Contrast
 * Supports placements, variants, split buttons, user headers, shortcuts, and submenus
 */

/* ==========================================================================
   1. Dropdown Container (.qhr-dropdown)
   ========================================================================== */
.qhr-dropdown, .dropup {
  position: relative;
  display: inline-flex;
}

/* ==========================================================================
   2. Dropdown Menu Container (.qhr-dropdown-menu)
   ========================================================================== */
.qhr-dropdown-menu {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: calc(100% + var(--qhr-space-1-5, 6px));
  z-index: var(--qhr-z-dropdown, 1000);
  min-width: 220px;
  background-color: var(--qhr-surface-elevated, #ffffff);
  border: 1px solid var(--qhr-border-subtle, #e2e8f0);
  border-radius: var(--qhr-radius-lg, 12px);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  padding: var(--qhr-space-1-5, 6px);
  display: flex;
  flex-direction: column;
  gap: var(--qhr-space-0-5, 2px);
  transition: opacity var(--qhr-duration-fast, 150ms) ease,
              transform var(--qhr-duration-fast, 150ms) ease;
}

[data-theme="dark"] .qhr-dropdown-menu {
  background-color: var(--qhr-surface-elevated, #0f172a);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 12px 30px -5px rgba(0, 0, 0, 0.6);
}

/* 2.1 Alignment: End Aligned (.dropdown-menu-end / .qhr-dropdown-menu--end) */
.qhr-dropdown-menu--end,
.dropdown-menu-end {
  inset-inline-start: auto;
  inset-inline-end: 0;
}

/* 2.2 Dropup (.dropup / .qhr-dropdown--dropup) */
.dropup .qhr-dropdown-menu,
.qhr-dropdown--dropup .qhr-dropdown-menu {
  inset-block-start: auto;
  inset-block-end: calc(100% + var(--qhr-space-1-5, 6px));
}

.dropup .qhr-dropdown-caret,
.qhr-dropdown--dropup .qhr-dropdown-caret {
  transform: rotate(180deg);
}

/* 2.3 Luxury Menu Variant (.qhr-dropdown-menu--luxury) */
.qhr-dropdown-menu--luxury {
  background: linear-gradient(145deg, #0f172a 0%, #07090e 100%) !important;
  border: 1px solid rgba(212, 175, 55, 0.3) !important;
  box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.7), 0 0 15px rgba(212, 175, 55, 0.08) !important;
}

.qhr-dropdown-menu--luxury .qhr-dropdown-item:hover {
  background-color: rgba(212, 175, 55, 0.1) !important;
  color: #f5d77f !important;
}

/* ==========================================================================
   3. Caret Icon (.qhr-dropdown-caret)
   ========================================================================== */
.qhr-dropdown-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-inline-start: var(--qhr-space-2, 8px);
  transition: transform var(--qhr-duration-fast, 150ms) ease;
}

.no-caret .qhr-dropdown-caret,
.qhr-dropdown-toggle--no-caret .qhr-dropdown-caret {
  display: none !important;
}

/* ==========================================================================
   4. Dropdown Item (.qhr-dropdown-item)
   ========================================================================== */
.qhr-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--qhr-space-2-5, 10px);
  padding-block: var(--qhr-space-2, 8px);
  padding-inline: var(--qhr-space-3, 12px);
  font-family: var(--qhr-font-body, "Cairo", sans-serif);
  font-size: var(--qhr-text-sm, 0.875rem);
  font-weight: 500;
  color: var(--qhr-content-primary, #0f172a);
  border-radius: var(--qhr-radius-sm, 6px);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: start;
  outline: none;
  transition: background-color var(--qhr-duration-fast, 150ms) ease,
              color var(--qhr-duration-fast, 150ms) ease;
}

[data-theme="dark"] .qhr-dropdown-item {
  color: var(--qhr-content-primary, #f8fafc);
}

.qhr-dropdown-item:hover,
.qhr-dropdown-item:focus-visible {
  background-color: var(--qhr-surface-muted, #f1f5f9);
}

[data-theme="dark"] .qhr-dropdown-item:hover,
[data-theme="dark"] .qhr-dropdown-item:focus-visible {
  background-color: rgba(255, 255, 255, 0.08);
}

/* 4.1 Item Active State */
.qhr-dropdown-item.active,
.qhr-dropdown-item.is-active {
  background-color: var(--qhr-color-primary-bg, #0b6bcb) !important;
  color: #ffffff !important;
  font-weight: 600;
}

/* 4.2 Item Destructive State */
.qhr-dropdown-item--destructive {
  color: var(--qhr-color-danger-bg, #e11d48) !important;
}

.qhr-dropdown-item--destructive:hover {
  background-color: #fff1f2 !important;
}

[data-theme="dark"] .qhr-dropdown-item--destructive:hover {
  background-color: rgba(225, 29, 72, 0.15) !important;
}

/* 4.3 Item Disabled State */
.qhr-dropdown-item.disabled,
.qhr-dropdown-item.is-disabled,
.qhr-dropdown-item:disabled,
.qhr-dropdown-item[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
  cursor: not-allowed;
}

/* ==========================================================================
   5. Item Anatomy: Icons, Badges & Keyboard Shortcuts
   ========================================================================== */
.qhr-dropdown-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: currentColor;
}

.qhr-dropdown-item-badge {
  margin-inline-start: auto;
  font-size: 0.72rem;
  padding-inline: 6px;
  padding-block: 1px;
}

.qhr-dropdown-shortcut {
  margin-inline-start: auto;
  font-family: var(--qhr-font-mono, monospace);
  font-size: var(--qhr-text-xs, 0.75rem);
  letter-spacing: 0.05em;
  opacity: 0.65;
  color: var(--qhr-text-muted, #94a3b8);
}

/* ==========================================================================
   6. Header, Separator & User Profile Card
   ========================================================================== */
.qhr-dropdown-header {
  font-size: var(--qhr-text-xs, 11px);
  font-weight: 700;
  color: var(--qhr-text-muted, #94a3b8);
  padding-block: var(--qhr-space-1, 4px);
  padding-inline: var(--qhr-space-3, 12px);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.qhr-dropdown-separator,
.qhr-dropdown-divider {
  height: 1px;
  background-color: var(--qhr-border-subtle, #e2e8f0);
  margin-block: var(--qhr-space-1-5, 6px);
  margin-inline: 0;
  border: none;
}

[data-theme="dark"] .qhr-dropdown-separator,
[data-theme="dark"] .qhr-dropdown-divider {
  background-color: rgba(255, 255, 255, 0.08);
}

/* 6.1 User Profile Header */
.qhr-dropdown-user-header {
  display: flex;
  align-items: center;
  gap: var(--qhr-space-3, 12px);
  padding-block: var(--qhr-space-2, 8px);
  padding-inline: var(--qhr-space-3, 12px);
  border-block-end: 1px solid var(--qhr-border-subtle, #e2e8f0);
  margin-block-end: var(--qhr-space-1, 4px);
}

[data-theme="dark"] .qhr-dropdown-user-header {
  border-block-end-color: rgba(255, 255, 255, 0.08);
}

.qhr-dropdown-user-meta {
  display: flex;
  flex-direction: column;
  text-align: start;
}

.qhr-dropdown-user-name {
  font-size: var(--qhr-text-sm, 0.875rem);
  font-weight: 700;
  color: var(--qhr-content-primary, #0f172a);
}

[data-theme="dark"] .qhr-dropdown-user-name {
  color: #f8fafc;
}

.qhr-dropdown-user-email {
  font-size: var(--qhr-text-xs, 0.75rem);
  color: var(--qhr-text-muted, #64748b);
}

/* ==========================================================================
   7. Split Button Dropdown (.qhr-dropdown--split)
   ========================================================================== */
.qhr-dropdown--split {
  display: inline-flex;
  border-radius: var(--qhr-radius-md, 8px);
  overflow: visible;
}

.qhr-dropdown--split .qhr-btn:first-child {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}

.qhr-dropdown--split .qhr-dropdown-toggle {
  border-start-start-radius: 0;
  border-end-start-radius: 0;
  padding-inline: var(--qhr-space-2, 8px);
  border-inline-start: 1px solid rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   8. Submenu / Nested Menus (.qhr-dropdown-sub)
   ========================================================================== */
.qhr-dropdown-sub {
  position: relative;
}

.qhr-dropdown-sub-menu {
  position: absolute;
  inset-inline-start: calc(100% + var(--qhr-space-1, 4px));
  inset-block-start: 0;
  z-index: calc(var(--qhr-z-dropdown, 1000) + 1);
}

.qhr-dropdown-sub-caret {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
}

/* ==========================================================================
   9. Dropdown Sizes
   ========================================================================== */
.qhr-dropdown-menu--sm {
  min-width: 180px;
  padding: var(--qhr-space-1, 4px);
}
.qhr-dropdown-menu--sm .qhr-dropdown-item {
  font-size: var(--qhr-text-xs, 0.78rem);
  padding-block: var(--qhr-space-1-5, 6px);
  padding-inline: var(--qhr-space-2-5, 10px);
}

.qhr-dropdown-menu--lg {
  min-width: 260px;
  padding: var(--qhr-space-2, 8px);
}
.qhr-dropdown-menu--lg .qhr-dropdown-item {
  font-size: var(--qhr-text-base, 1rem);
  padding-block: var(--qhr-space-2-5, 10px);
  padding-inline: var(--qhr-space-3-5, 14px);
}

/* ==========================================================================
   10. Dropdown Grid Layouts (.dropdown-grid, .cols-2, .cols-4)
   ========================================================================== */
.qhr-dropdown-grid,
.dropdown-grid,
.qhr-dropdown-menu.dropdown-grid,
.qhr-dropdown-menu.qhr-dropdown-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--qhr-space-2, 8px);
  padding: var(--qhr-space-3, 12px);
  min-width: 290px;
}

/* 10.1 Columns Modifiers */
.dropdown-grid.cols-2,
.dropdown-grid.qhr-dropdown-grid--cols-2,
.qhr-dropdown-grid--cols-2 {
  grid-template-columns: repeat(2, 1fr);
  min-width: 210px;
}

.dropdown-grid.cols-4,
.dropdown-grid.qhr-dropdown-grid--cols-4,
.qhr-dropdown-grid--cols-4 {
  grid-template-columns: repeat(4, 1fr);
  min-width: 370px;
}

/* 10.2 Grid Item Formatting */
/* Pre-emit critique: P5 H5 E5 S5 R5 V5 D5 */
.dropdown-grid .dropdown-item,
.dropdown-grid .qhr-dropdown-item,
.qhr-dropdown-grid .dropdown-item,
.qhr-dropdown-grid .qhr-dropdown-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding-block: var(--qhr-space-3, 12px);
  padding-inline: var(--qhr-space-2, 8px);
  gap: var(--qhr-space-1-5, 6px);
  border-radius: var(--qhr-radius-md, 12px);
  cursor: pointer;
  text-decoration: none;
  background: transparent;
  border: 2px solid transparent;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: background-color var(--qhr-duration-fast, 150ms) ease,
              transform var(--qhr-duration-fast, 150ms) ease,
              border-color var(--qhr-duration-fast, 150ms) ease;
}

.dropdown-grid .dropdown-item:hover,
.dropdown-grid .qhr-dropdown-item:hover,
.qhr-dropdown-grid .dropdown-item:hover,
.qhr-dropdown-grid .qhr-dropdown-item:hover {
  background-color: var(--qhr-surface-muted, #f8fafc);
  transform: translateY(-1px);
}

[data-theme="dark"] .dropdown-grid .dropdown-item:hover,
[data-theme="dark"] .dropdown-grid .qhr-dropdown-item:hover,
[data-theme="dark"] .qhr-dropdown-grid .dropdown-item:hover,
[data-theme="dark"] .qhr-dropdown-grid .qhr-dropdown-item:hover {
  background-color: rgba(255, 255, 255, 0.07);
}

/* 10.3 Grid Item Active & Focus State (Crisp Architectural 2px Border) */
.dropdown-grid .dropdown-item:focus,
.dropdown-grid .dropdown-item:focus-visible,
.dropdown-grid .dropdown-item.active,
.dropdown-grid .qhr-dropdown-item:focus,
.dropdown-grid .qhr-dropdown-item:focus-visible,
.dropdown-grid .qhr-dropdown-item.active,
.qhr-dropdown-grid .dropdown-item:focus,
.qhr-dropdown-grid .dropdown-item:focus-visible,
.qhr-dropdown-grid .dropdown-item.active,
.qhr-dropdown-grid .qhr-dropdown-item:focus,
.qhr-dropdown-grid .qhr-dropdown-item:focus-visible,
.qhr-dropdown-grid .qhr-dropdown-item.active {
  border-color: var(--qhr-content-primary, #0f172a) !important;
  border-width: 2px !important;
  border-style: solid !important;
  border-radius: var(--qhr-radius-md, 12px) !important;
  background-color: transparent !important;
  color: var(--qhr-content-primary, #0f172a) !important;
  font-weight: 600;
  outline: none !important;
}

[data-theme="dark"] .dropdown-grid .dropdown-item:focus,
[data-theme="dark"] .dropdown-grid .dropdown-item:focus-visible,
[data-theme="dark"] .dropdown-grid .dropdown-item.active,
[data-theme="dark"] .dropdown-grid .qhr-dropdown-item:focus,
[data-theme="dark"] .dropdown-grid .qhr-dropdown-item:focus-visible,
[data-theme="dark"] .dropdown-grid .qhr-dropdown-item.active,
[data-theme="dark"] .qhr-dropdown-grid .dropdown-item:focus,
[data-theme="dark"] .qhr-dropdown-grid .dropdown-item:focus-visible,
[data-theme="dark"] .qhr-dropdown-grid .dropdown-item.active,
[data-theme="dark"] .qhr-dropdown-grid .qhr-dropdown-item:focus,
[data-theme="dark"] .qhr-dropdown-grid .qhr-dropdown-item:focus-visible,
[data-theme="dark"] .qhr-dropdown-grid .qhr-dropdown-item.active {
  border-color: #f8fafc !important;
  color: #ffffff !important;
  background-color: rgba(255, 255, 255, 0.06) !important;
  outline: none !important;
}

/* 10.4 Grid Item Disabled State */
.dropdown-grid .dropdown-item.disabled,
.dropdown-grid .qhr-dropdown-item.disabled,
.dropdown-item.disabled,
.qhr-dropdown-item.disabled,
.dropdown-item[aria-disabled="true"],
.qhr-dropdown-item[aria-disabled="true"] {
  opacity: 0.38 !important;
  pointer-events: none !important;
  cursor: not-allowed !important;
}

/* 10.5 Grid Icon & Title Anatomy */
.dropdown-grid-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  color: var(--qhr-content-primary, #1e293b);
}

[data-theme="dark"] .dropdown-grid-icon {
  color: var(--qhr-content-primary, #f8fafc);
}

.dropdown-grid-icon svg {
  width: 32px;
  height: 32px;
  display: block;
}

.dropdown-grid-title {
  font-family: var(--qhr-font-body, "Cairo", sans-serif);
  font-size: var(--qhr-text-xs, 0.8125rem);
  font-weight: 500;
  color: var(--qhr-text-secondary, #475569);
  line-height: 1.25;
  text-align: center;
}

[data-theme="dark"] .dropdown-grid-title {
  color: var(--qhr-text-secondary, #94a3b8);
}

.dropdown-grid .dropdown-item:hover .dropdown-grid-title,
.dropdown-grid .dropdown-item.active .dropdown-grid-title,
.dropdown-grid .qhr-dropdown-item:hover .dropdown-grid-title,
.dropdown-grid .qhr-dropdown-item.active .dropdown-grid-title {
  color: var(--qhr-content-primary, #0f172a);
}

[data-theme="dark"] .dropdown-grid .dropdown-item:hover .dropdown-grid-title,
[data-theme="dark"] .dropdown-grid .dropdown-item.active .dropdown-grid-title,
[data-theme="dark"] .dropdown-grid .qhr-dropdown-item:hover .dropdown-grid-title,
[data-theme="dark"] .dropdown-grid .qhr-dropdown-item.active .dropdown-grid-title {
  color: #ffffff;
}
