/* ============================================
   SIDE-PANEL.CSS - Side Panel & Tab System
   KlassKit Hub
   ============================================ */

/* ============================================
   1. SIDE PANEL CONTAINER
   ============================================ */

#side-panel {
  box-shadow: 4px 0 0 var(--border-primary);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark #side-panel {
  box-shadow: 4px 0 0 rgba(0, 0, 0, 0.5);
}

/* Hide side panel when modal is hidden or in focus mode */
#game-modal.hidden #side-panel,
body.focus-mode #side-panel {
  transform: translateX(-100%);
}

/* ============================================
   2. SIDE PANEL BUTTONS (Common Styles)
   ============================================ */

.side-panel-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;

  width: 3.5rem;
  height: 3.5rem;

  background: var(--bg-tertiary);
  color: var(--text-secondary);

  border: 3px solid transparent;
  border-radius: 1rem;

  cursor: pointer;
  user-select: none;

  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  /* Prevent text selection */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.side-panel-btn:hover {
  background: var(--bg-secondary);
  border-color: var(--border-secondary);
  transform: translateX(4px) scale(1.05);
  box-shadow: 2px 2px 0 var(--border-primary);
}

.dark .side-panel-btn:hover {
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

.side-panel-btn:active {
  transform: translateX(2px) scale(1);
  box-shadow: none;
}

.side-panel-btn:focus-visible {
  outline: 3px solid var(--color-blue);
  outline-offset: 2px;
}

/* ============================================
   3. HOME BUTTON
   ============================================ */

.side-panel-home {
  background: var(--color-pink);
  color: white;
  border-color: var(--border-primary);
  box-shadow: 2px 2px 0 var(--border-primary);
}

.side-panel-home:hover {
  background: var(--color-orange);
  transform: translateX(4px) scale(1.1);
}

.dark .side-panel-home {
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

/* ============================================
   4. TAB ICON BUTTONS
   ============================================ */

.side-panel-tab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;

  width: 3.5rem;
  height: 3.5rem;

  background: var(--bg-tertiary);

  border: 3px solid var(--border-secondary);
  border-radius: 1rem;

  cursor: pointer;
  user-select: none;

  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  /* Animation on creation */
  animation: slide-in-left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.side-panel-tab:hover {
  transform: translateX(4px) scale(1.05);
  border-color: var(--border-primary);
  box-shadow: 2px 2px 0 var(--border-primary);
}

.dark .side-panel-tab:hover {
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

.dark .side-panel-tab {
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
}

/* Active tab */
.side-panel-tab.active {
  border-color: var(--border-primary);
  border-width: 4px;
  box-shadow: 4px 4px 0 var(--border-primary);
  transform: translateX(8px) scale(1.1);
}

.dark .side-panel-tab.active {
  margin-top: 5px;
  margin-right: 15px;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.8);
}

/* Pinned tab */
.side-panel-tab.pinned {
  border-color: var(--color-orange);
  border-width: 3px;
  border-style: dashed;
}

.side-panel-tab.pinned.active {
  border-style: solid;
}

.side-panel-tab.pinned::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  width: 12px;
  height: 12px;
  background-color: var(--color-orange);
  border: 2px solid var(--border-primary);
  border-radius: 50%;
  z-index: 10;
}

/* Tab icon */
.side-panel-tab-icon {
  width: 1.75rem;
  height: 1.75rem;
  flex-shrink: 0;
  color: white;
}

/* Tab color backgrounds */
.side-panel-tab[data-color="text-pink"] {
  background: var(--color-pink);
}

.side-panel-tab[data-color="text-orange"] {
  background: var(--color-orange);
}

.side-panel-tab[data-color="text-green"] {
  background: var(--color-green);
}

.side-panel-tab[data-color="text-blue"] {
  background: var(--color-blue);
}

.side-panel-tab[data-color="text-red-500"] {
  background: #ef4444;
}

.side-panel-tab[data-color="text-slate-500"] {
  background: #64748b;
}

/* ============================================
   5. TAB CLOSE BUTTON
   ============================================ */

.side-panel-tab-close {
  position: absolute;
  top: -6px;
  right: -6px;

  display: none;
  align-items: center;
  justify-content: center;

  width: 1.25rem;
  height: 1.25rem;

  background: var(--color-pink);
  color: white;

  border: 2px solid var(--border-primary);
  border-radius: 50%;

  cursor: pointer;
  z-index: 20;
  pointer-events: auto;

  transition: all 0.15s;
}

.side-panel-tab:not(.pinned):hover .side-panel-tab-close {
  display: flex;
  pointer-events: auto;
}

.side-panel-tab-close:hover {
  background: #ef4444;
  transform: scale(1.2) rotate(90deg);
}

.side-panel-tab-close i {
  width: 0.75rem;
  height: 0.75rem;
}

/* ============================================
   6. LOADING STATE
   ============================================ */

.side-panel-tab.loading .side-panel-tab-icon {
  animation: spin 1s linear infinite;
}

/* ============================================
   7. TAB ICONS SCROLLBAR
   ============================================ */

#side-panel-tabs {
  scrollbar-width: thin;
  scrollbar-color: var(--border-secondary) transparent;
}

#side-panel-tabs::-webkit-scrollbar {
  width: 4px;
}

#side-panel-tabs::-webkit-scrollbar-track {
  background: transparent;
}

#side-panel-tabs::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: 2px;
}

#side-panel-tabs::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ============================================
   8. TRASH BUTTON (Danger Style)
   ============================================ */

.side-panel-danger {
  background: #fee2e2;
  color: #ef4444;
  border-color: #ef4444;
}

.dark .side-panel-danger {
  background: #7f1d1d;
  color: #fca5a5;
  border-color: #991b1b;
}

.side-panel-danger:hover {
  background: #ef4444;
  color: white;
  border-color: #dc2626;
  transform: translateX(4px) scale(1.1);
}

.side-panel-danger:active {
  background: #dc2626;
}

/* ============================================
   9. MAIN CONTENT AREA
   ============================================ */

#tab-content-area {
  position: relative;
  width: calc(100% - 5rem);
  height: 100vh;
  overflow: hidden;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.focus-mode #tab-content-area {
  width: 100%;
  margin-left: 0;
}

/* Split-Screen Mode Layout */
#tab-content-area.split-mode {
  display: flex;
  flex-direction: row;
}

/* ============================================
   10. TAB PANELS
   ============================================ */

.tab-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  opacity: 0;
  pointer-events: none;

  transition: opacity 0.3s ease, width 0.3s ease, transform 0.3s ease;
}

.tab-panel.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 1;
}

/* Split-Screen Active Panes */
#tab-content-area.split-mode .tab-panel.split-left {
  position: relative;
  width: 50%;
  opacity: 1;
  pointer-events: auto;
  z-index: 1;
  border-right: 4px solid var(--border-primary);
}

#tab-content-area.split-mode .tab-panel.split-right {
  position: relative;
  width: 50%;
  opacity: 1;
  pointer-events: auto;
  z-index: 1;
}

/* Focus indicator for split panes (which one receives the next navigation) */
#tab-content-area.split-mode .tab-panel.split-left.split-focused,
#tab-content-area.split-mode .tab-panel.split-right.split-focused {
  border: 4px solid var(--color-blue);
  box-sizing: border-box;
}

.tab-panel iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

/* Loading spinner for each tab */
.tab-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;

  color: white;
  font-family: 'Fredoka', sans-serif;
  z-index: 10;
}

.dark .tab-loading {
  color: var(--text-primary);
}

.tab-loading .spinner {
  width: 5rem;
  height: 5rem;
  border: 5px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--color-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.tab-loading .loading-text {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.tab-panel.loaded .tab-loading {
  display: none;
}

/* ============================================
   11. HOME VIEW
   ============================================ */

#home-view-panel {
  background: var(--bg-primary);
}

#home-view-panel iframe {
  background: var(--bg-primary);
}

#home-view-panel:not(.active) {
  display: none;
}

/* ============================================
   12. EMPTY STATE
   ============================================ */

.side-panel-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;

  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  font-family: 'Fredoka', sans-serif;

  animation: fade-in 0.3s ease;
}

.dark .side-panel-empty {
  color: rgba(248, 250, 252, 0.5);
}

.side-panel-empty i {
  width: 6rem;
  height: 6rem;
  opacity: 0.3;
}

.side-panel-empty .empty-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.side-panel-empty .empty-text {
  font-size: 1rem;
  opacity: 0.8;
}

/* ============================================
   13. FOCUS MODE BUTTONS
   ============================================ */

.exit-focus-btn {
  position: absolute;
  top: 1.5rem;
  left: 1.5rem;
  z-index: 100;

  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;

  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-xl);
  color: var(--text-primary);

  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark .exit-focus-btn {
  background: rgba(15, 23, 42, 0.4);
  border-color: rgba(255, 255, 255, 0.1);
  color: white;
}

body.focus-mode .exit-focus-btn {
  opacity: 0.5;
  pointer-events: auto;
  transform: translateY(0);
}

body.focus-mode .exit-focus-btn:hover {
  opacity: 1;
  background: white;
  color: var(--color-blue);
  border-color: var(--color-blue);
  box-shadow: 4px 4px 0 var(--color-blue);
  transform: translateY(-2px);
}

.dark body.focus-mode .exit-focus-btn:hover {
  background: var(--bg-secondary);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.8);
}

/* ============================================
   14. TOOLTIP FOR TABS & BUTTONS
   ============================================ */

.side-panel-tab[data-title]:hover::before,
.side-panel-btn[data-title]:hover::before {
  content: attr(data-title);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);

  margin-left: 0.75rem;
  padding: 0.5rem 0.75rem;

  background: var(--text-primary);
  color: var(--bg-primary);

  border: 2px solid var(--border-primary);
  border-radius: 0.5rem;

  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;

  z-index: 100;
  pointer-events: none;

  animation: fade-in 0.2s ease;
}

/* ============================================
   14. RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
  #side-panel {
    width: 4rem;
  }

  .side-panel-btn,
  .side-panel-tab {
    width: 2.75rem;
    height: 2.75rem;
  }

  .side-panel-tab-icon {
    width: 1.5rem;
    height: 1.5rem;
  }

  #tab-content-area {
    width: calc(100% - 4rem);
    margin-left: 4rem;
  }
}

/* ============================================
   16. PRINT STYLES
   ============================================ */

@media print {
  #side-panel {
    display: none;
  }

  #tab-content-area {
    margin-left: 0;
    width: 100%;
  }

  .tab-panel:not(.active) {
    display: none;
  }
}

/* ============================================
   17. ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {

  .side-panel-tab,
  .side-panel-btn,
  .tab-panel {
    animation: none;
    transition: none;
  }
}

/* ============================================
   18. DRAG AND DROP
   ============================================ */

.side-panel-tab.dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

.side-panel-tab.drag-over {
  border-top: 3px solid var(--color-blue);
  margin-top: 3px;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
}