/* ==========================================================================
   LAYOUT STYLES
   Application structure, panels, and deck list layouts
   ========================================================================== */

/* ==========================================================================
   RESET & BASE
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  color: var(--text-primary);
  background: var(--bg-base);
  line-height: 1.5;
}

/* ==========================================================================
   APP LAYOUT
   ========================================================================== */

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   TOP BAR
   ========================================================================== */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border-subtle);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--font-size-lg);
  font-weight: bold;
  color: var(--text-primary);
}

.logo-icon {
  width: 32px;
  height: 32px;
  fill: var(--accent);
}

.search-container {
  position: relative;
  flex: 1;
  max-width: 500px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.social-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.social-link:hover {
  color: var(--accent);
  background: var(--accent-subtle);
}

.social-link svg {
  width: 20px;
  height: 20px;
}

/* ==========================================================================
   MAIN CONTENT AREA
   ========================================================================== */

.main-content {
  display: grid;
  grid-template-columns: 280px 1fr;
  overflow: hidden;
}

/* ==========================================================================
   LEFT PANEL
   ========================================================================== */

.left-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-inset);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
}

.card-preview {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.card-preview-image-container {
  width: 100%;
  aspect-ratio: 488 / 680;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-mid);
  background: var(--bg-raised);
}

.card-preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-lg);
}

.card-preview-placeholder {
  width: 100%;
  aspect-ratio: 488 / 680;
  background: var(--bg-raised);
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.card-preview-info {
  padding: var(--space-sm);
}

.card-preview-name {
  font-size: var(--font-size-md);
  font-weight: bold;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.card-preview-type {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.card-preview-price {
  margin-top: var(--space-sm);
}

/* ==========================================================================
   MAIN PANEL
   ========================================================================== */

.main-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border-subtle);
}

.main-panel-title {
  font-size: var(--font-size-lg);
  font-weight: bold;
}

.loading-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--font-size-sm);
  color: var(--accent);
}

.loading-indicator::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.deck-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: var(--space-xs);
  align-content: start;
}

.deck-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: var(--space-xl);
}

.deck-empty-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-md);
  opacity: 0.5;
}

/* ==========================================================================
   DECK CARD ROW
   ========================================================================== */

.deck-card {
  display: grid;
  grid-template-columns: 60px 1fr auto auto auto auto;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md) var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast);
}

.deck-card:hover {
  background: var(--bg-raised);
}

.deck-card.removing {
  animation: card-remove 0.3s ease-out forwards;
  pointer-events: none;
}

@keyframes card-remove {
  0% {
    background: rgba(239, 68, 68, 0.3);
    opacity: 1;
    transform: scale(1);
  }
  50% {
    background: rgba(239, 68, 68, 0.4);
  }
  100% {
    background: rgba(239, 68, 68, 0);
    opacity: 0;
    transform: scale(0.95);
  }
}

.deck-card-thumb {
  width: 60px;
  height: 44px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.deck-card-info {
  min-width: clamp(0px, 30%, 140px);  /* Responsive: shrinks when needed, expands when available */
  overflow: hidden;
}

.deck-card-name {
  font-size: var(--font-size-sm);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.deck-card-type {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

.deck-card-mana {
  display: flex;
  gap: 2px;
  align-items: center;
}

.mana-symbol {
  width: 18px;
  height: 18px;
}

.deck-card-quantity {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.deck-card-qty-value {
  min-width: 24px;
  text-align: center;
  font-weight: 500;
}

.deck-card-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}

.deck-card-price {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  width: 48px;
  text-align: right;
}

.deck-card-actions {
  display: flex;
  gap: var(--space-xs);
}

/* ==========================================================================
   DECK CARD LOADING STATE
   ========================================================================== */

.deck-card.loading {
  position: relative;
}

.deck-card.loading::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--commander-gradient, var(--accent));
  background-size: 200% 100%;
  animation: commander-progress 1.5s linear infinite;
}

@keyframes commander-progress {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* Skeleton placeholder for loading cards */
.deck-card-thumb-placeholder {
  width: 60px;
  height: 44px;
  background: linear-gradient(
    90deg,
    var(--bg-inset) 25%,
    var(--bg-hover) 50%,
    var(--bg-inset) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.deck-card-type-placeholder {
  width: 80px;
  height: 12px;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ==========================================================================
   BOTTOM BAR
   ========================================================================== */

.bottombar {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-sm) var(--space-lg);
  background: var(--bg-inset);
  border-top: 1px solid var(--border-subtle);
}

.stat {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-size-sm);
}

.stat-label {
  color: var(--text-secondary);
}

.stat-value {
  font-weight: bold;
  color: var(--text-primary);
}

.stat-value-accent {
  color: var(--accent);
}

/* ==========================================================================
   UTILITIES
   ========================================================================== */

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   SPLIT VIEW (Type Filter Active)
   ========================================================================== */

.split-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  height: 100%;
}

.split-column {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.split-column-main {
  border-right: 1px solid var(--border-subtle);
  padding-right: var(--space-md);
}

.split-column-side {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  overflow-y: auto;
}

.split-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.split-section-fit {
  flex: 0 0 auto;
}

.split-header {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-xs);
}

.split-cards {
  flex: 1;
  overflow-y: auto;
}

.split-empty {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  padding: var(--space-md);
  text-align: center;
}

/* Hide mobile-only elements on desktop */
.filter-toggle,
.deck-card-menu-btn,
.card-action-menu {
  display: none;
}

/* ==========================================================================
   MOBILE RESPONSIVE (≤768px)
   ========================================================================== */

@media (max-width: 768px) {
  /* Hide desktop-only elements */
  .left-panel {
    display: none;
  }

  .bottombar {
    display: none;
  }

  /* Single column layout */
  .main-content {
    grid-template-columns: 1fr;
  }

  /* Full height main panel */
  .main-panel {
    height: 100%;
    overflow-y: auto;
  }

  /* Make room for bottom tabs */
  .app {
    padding-bottom: 56px;
  }

  /* Deck list mobile grid */
  .deck-list {
    grid-template-columns: 1fr;
    padding: var(--space-sm);
  }

  /* Mobile Filter Bar - stack vertically */
  .filter-bar {
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-sm);
  }

  .filter-group {
    flex: 1 1 100%;
  }

  .filter-divider {
    display: none;
  }

  .color-filters,
  .type-filters,
  .board-filters {
    flex-wrap: wrap;
  }

  /* Collapsible filter bar */
  .filter-bar {
    transition: transform 0.2s ease, opacity 0.2s ease, max-height 0.2s ease;
    max-height: 200px;
    overflow: hidden;
  }

  .filter-bar.collapsed {
    max-height: 0;
    opacity: 0;
    padding: 0;
    margin: 0;
    pointer-events: none;
  }

  /* Filter toggle button */
  .filter-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: var(--space-xs);
    background: var(--bg-inset);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    margin-bottom: var(--space-xs);
    transition: color var(--transition-fast);
  }

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

  /* Mobile Topbar */
  .topbar {
    padding: var(--space-sm) var(--space-md);
    gap: var(--space-sm);
  }

  .logo span {
    display: none;
  }

  .logo-icon {
    width: 28px;
    height: 28px;
  }

  .search-container {
    display: none;
  }

  .topbar-actions {
    gap: var(--space-xs);
    flex-shrink: 0;
  }

  .topbar-actions .btn {
    display: none;
  }

  .topbar-actions .social-link {
    width: 20px;
    height: 20px;
  }

  .topbar-actions .social-link svg {
    width: 16px;
    height: 16px;
  }

  .deck-selector {
    flex: 1;
    min-width: 0;
    max-width: 180px;
  }

  .deck-selector-button {
    max-width: 100%;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
    gap: var(--space-xs);
  }

  .deck-selector-selected {
    min-width: 0;
    flex: 1;
  }

  .deck-selector-selected-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100px;
    display: inline-block;
  }

  .deck-selector-selected-art {
    width: 24px;
    height: 18px;
  }

  .deck-completion {
    font-size: 10px;
    padding: 2px 6px;
    flex-shrink: 0;
  }

  /* Mobile dropdown */
  .deck-selector-dropdown {
    max-width: 280px;
    left: 0;
    right: auto;
  }

  /* Mobile Bottom Tabs */
  .mobile-tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    display: flex;
    background: var(--bg-raised);
    border-top: 1px solid var(--border-subtle);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
  }

  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    transition: color var(--transition-fast);
  }

  .mobile-tab svg {
    width: 24px;
    height: 24px;
  }

  .mobile-tab.active {
    color: var(--accent);
  }

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

  /* Mobile Card Row - compact single row */
  .deck-card {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    min-height: auto;
  }

  .deck-card-thumb {
    width: 40px;
    height: 30px;
    flex-shrink: 0;
  }

  .deck-card-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .deck-card-name {
    font-size: var(--font-size-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
  }

  .deck-card-type {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
  }

  .deck-card-mana {
    display: flex;
    flex-shrink: 0;
    font-size: 12px;
  }

  .deck-card-price {
    display: block;
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-muted);
    width: 48px;
    text-align: right;
    margin-left: -10px;
  }

  /* Hide inline controls and menu button on mobile */
  .deck-card-controls,
  .deck-card-actions,
  .deck-card-menu-btn {
    display: none !important;
  }

  /* Card action popup menu */
  .card-action-menu {
    position: fixed;
    background: var(--bg-raised);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-xs);
    z-index: 300;
    box-shadow: var(--shadow-high);
    min-width: 160px;
  }

  .card-action-menu.hidden {
    display: none;
  }

  .card-action-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    cursor: pointer;
    border-radius: var(--radius-sm);
    text-align: left;
  }

  .card-action-menu-item:hover {
    background: var(--bg-hover);
  }

  .card-action-menu-item.danger {
    color: var(--error);
  }

  .card-action-menu-qty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-xs);
  }

  .card-action-menu-qty .btn {
    min-width: 36px;
    min-height: 36px;
  }

  .card-action-menu-qty-value {
    min-width: 24px;
    text-align: center;
    font-weight: 600;
  }

  /* Mobile Search Tab */
  .search-container.mobile-visible {
    display: block;
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    bottom: 56px;
    padding: var(--space-md);
    background: var(--bg-base);
    z-index: 50;
    overflow-y: auto;
  }

  .search-container.mobile-visible .search-input-wrapper {
    margin-bottom: var(--space-md);
  }

  .search-container.mobile-visible .dropdown {
    position: static;
    max-height: none;
    box-shadow: none;
    border: 1px solid var(--border-subtle);
  }

  /* Mobile Stats Tab */
  .left-panel.mobile-visible {
    display: flex;
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    bottom: 56px;
    border-right: none;
    z-index: 50;
  }

  .left-panel.mobile-visible .stats-panel {
    flex: 1;
    overflow-y: auto;
  }

  .left-panel.mobile-visible .card-preview {
    display: none;
  }
}

/* ==========================================================================
   HIDE MOBILE ELEMENTS ON DESKTOP
   ========================================================================== */

/* Hide mobile elements on desktop */
.mobile-tabs,
.card-modal,
.card-modal-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .mobile-tabs {
    display: flex;
  }

  .card-modal.visible,
  .card-modal-backdrop.visible {
    display: block;
  }
}
