/* ==========================================================================
   AIRH Panel — Futuristic Neumorphism
   Desktop: Right-to-left slide (50% width)
   Mobile: Bottom-up sheet (90vh max)
   ========================================================================== */

/* ---------------------------------------------------------------------------
   Overlay / Backdrop with Blur
   --------------------------------------------------------------------------- */
.panel-backdrop {
  position: fixed;
  inset: 0;
  background-color: var(--color-backdrop);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: var(--z-panel);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-panel),
    visibility var(--transition-panel);
}

.panel-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

/* ---------------------------------------------------------------------------
   Panel Container — Raised neumorphic
   --------------------------------------------------------------------------- */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50%;
  max-width: 720px;
  min-width: 380px;
  background: var(--color-bg-primary);
  z-index: calc(var(--z-panel) + 1);
  box-shadow: var(--neu-raised-lg);
  border-left: none;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-panel);
  will-change: transform;
  overflow: hidden;
}

.panel.is-open {
  transform: translateX(0);
}

/* Size Variants */
.panel--sm { width: 35%; max-width: 480px; min-width: 340px; }
.panel--lg { width: 65%; max-width: 960px; }
.panel--xl { width: 80%; max-width: 1200px; }

/* ---------------------------------------------------------------------------
   Panel Header — Neumorphic
   --------------------------------------------------------------------------- */
.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: none;
  flex-shrink: 0;
  gap: var(--space-4);
  background: var(--color-bg-primary);
  position: relative;
  z-index: 1;
}

.panel__header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: var(--space-6);
  right: var(--space-6);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--color-border-light), transparent);
}

.panel__header-content { flex: 1; min-width: 0; }

.panel__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: var(--leading-snug);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel__subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
  line-height: var(--leading-normal);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel__header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Close Button — Neumorphic */
.panel__close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-tertiary);
  background: var(--color-bg-primary);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: var(--neu-flat);
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.panel__close:hover {
  box-shadow: var(--neu-inset-sm);
  color: var(--color-text-primary);
}

.panel__close:active {
  box-shadow: var(--neu-pressed);
}

.panel__close:focus-visible {
  box-shadow: var(--neu-flat), 0 0 0 2px var(--color-accent);
  outline: none;
}

.panel__close-icon { width: 18px; height: 18px; }

/* ---------------------------------------------------------------------------
   Panel Tabs — Neumorphic
   --------------------------------------------------------------------------- */
.panel__tabs {
  display: flex;
  align-items: stretch;
  border-bottom: none;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0 var(--space-6);
  background: var(--color-bg-primary);
  position: relative;
}

.panel__tabs::-webkit-scrollbar { display: none; }

.panel__tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  white-space: nowrap;
  cursor: pointer;
  position: relative;
  transition: color 0.15s ease;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.panel__tab:hover { color: var(--color-text-primary); }

.panel__tab.is-active {
  color: var(--color-text-primary);
  font-weight: 700;
}

.panel__tab.is-active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: var(--space-4);
  right: var(--space-4);
  height: 3px;
  background: linear-gradient(90deg, var(--color-accent), #6366f1);
  border-radius: var(--radius-full) var(--radius-full) 0 0;
}

.panel__tab-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.6; }
.panel__tab.is-active .panel__tab-icon { opacity: 1; color: var(--color-accent); }

.panel__tab-count {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-tertiary);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  line-height: 1.4;
  box-shadow: var(--neu-inset-sm);
}

.panel__tab.is-active .panel__tab-count {
  background: linear-gradient(135deg, var(--color-accent), #6366f1);
  color: #fff;
  box-shadow: none;
}

/* Sliding indicator (JS-driven) */
.panel__tabs-indicator {
  position: absolute;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-accent), #6366f1);
  border-radius: var(--radius-full) var(--radius-full) 0 0;
  transition: left var(--transition-base), width var(--transition-base);
  will-change: left, width;
}

.panel__tabs--animated .panel__tab.is-active::after { display: none; }

/* Tab panels */
.panel__tab-content { display: none; }

.panel__tab-content.is-active {
  display: block;
  animation: panelTabFadeIn 200ms ease;
}

@keyframes panelTabFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------------------
   Panel Body
   --------------------------------------------------------------------------- */
.panel__body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-6);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.panel__body--flush { padding: 0; }
.panel__body--compact { padding: var(--space-4); }

.panel__body::-webkit-scrollbar { width: 6px; }
.panel__body::-webkit-scrollbar-track { background: transparent; }
.panel__body::-webkit-scrollbar-thumb { background: var(--color-scrollbar-thumb); border-radius: var(--radius-full); }
.panel__body::-webkit-scrollbar-thumb:hover { background: var(--color-scrollbar-thumb-hover); }

.panel__section { margin-bottom: var(--space-8); }
.panel__section:last-child { margin-bottom: 0; }

.panel__section-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-bottom: var(--space-4);
}

.panel__divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--color-border-light), transparent);
  margin: var(--space-6) 0;
}

/* ---------------------------------------------------------------------------
   Panel Footer — Neumorphic
   --------------------------------------------------------------------------- */
.panel__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: none;
  flex-shrink: 0;
  background: var(--color-bg-primary);
  position: relative;
  z-index: 1;
}

.panel__footer::before {
  content: '';
  position: absolute;
  top: 0;
  left: var(--space-6);
  right: var(--space-6);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--color-border-light), transparent);
}

.panel__footer--between { justify-content: space-between; }
.panel__footer--start { justify-content: flex-start; }

/* Loading & Empty */
.panel__loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: var(--space-12);
}

.panel__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  flex: 1;
}

.panel__empty-icon {
  width: 48px;
  height: 48px;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.panel__empty-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.panel__empty-description {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  line-height: var(--leading-normal);
}

/* ---------------------------------------------------------------------------
   Mobile — Bottom-up sheet behavior
   --------------------------------------------------------------------------- */
@media (max-width: 639px) {
  .panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    max-height: 90vh;
    max-height: 90dvh;
    border-left: none;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    transform: translateY(100%);
    transition: transform var(--transition-sheet);
  }

  .panel.is-open { transform: translateY(0); }

  .panel__drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-3) 0 var(--space-1);
    cursor: grab;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }

  .panel__drag-handle:active { cursor: grabbing; }

  .panel__drag-handle-pill {
    width: 36px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--color-text-tertiary);
    opacity: 0.4;
    transition: opacity var(--transition-fast), width var(--transition-fast);
  }

  .panel__drag-handle:hover .panel__drag-handle-pill { opacity: 0.7; width: 48px; }

  .panel__header {
    padding: var(--space-3) var(--space-5);
    background: var(--color-bg-primary);
  }

  .panel__title { font-size: var(--text-md); }
  .panel__tabs { padding: 0 var(--space-4); }
  .panel__tab { padding: var(--space-3) var(--space-3); }
  .panel__body { padding: var(--space-4); }

  .panel__footer {
    padding: var(--space-4) var(--space-5);
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0));
    flex-wrap: wrap;
  }

  .panel__footer--stacked { flex-direction: column-reverse; }
  .panel__footer--stacked > * { width: 100%; }

  .panel--sm, .panel--lg, .panel--xl {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
}

@media (min-width: 640px) {
  .panel__drag-handle { display: none; }
}

/* ---------------------------------------------------------------------------
   States
   --------------------------------------------------------------------------- */
.panel.is-dragging { transition: none; }

@media (prefers-reduced-motion: reduce) {
  .panel, .panel-backdrop, .panel__tab-content { transition-duration: 0ms; }
  .panel__tab-content.is-active { animation: none; }
}

@media print {
  .panel-backdrop { display: none; }
  .panel {
    position: static;
    width: 100%;
    max-width: 100%;
    transform: none;
    box-shadow: none;
  }
}
