/**
 * Admin Panel Styles
 * Kingshot Alliance Tools
 *
 * Tab navigation, tables, edit panel, bottom sheet, and mobile responsiveness
 */

/* ========================================
   TAB NAVIGATION
   ======================================== */

.admin-tabs {
  display: flex;
  gap: var(--space-2);
  border-bottom: 2px solid var(--stroke);
  margin-bottom: var(--space-6);
  overflow-x: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  /* Hide scrollbar but keep functionality */
  scrollbar-width: thin;
}

.admin-tabs::-webkit-scrollbar {
  height: 2px;
}

.admin-tabs::-webkit-scrollbar-track {
  background: var(--surface);
}

.admin-tabs::-webkit-scrollbar-thumb {
  background: var(--stroke);
  border-radius: 2px;
}

.admin-tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--muted);
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
  position: relative;
  margin-bottom: -2px; /* Overlap with tab container border */
}

.admin-tab:hover {
  color: var(--text);
  background: var(--surface);
}

.admin-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.admin-tab .icon {
  font-size: 1.125rem;
  opacity: 0.8;
}

.admin-tab.active .icon {
  opacity: 1;
}

/* Mobile: Smaller padding for tabs */
@media (max-width: 599px) {
  .admin-tab {
    padding: var(--space-2) var(--space-3);
    font-size: 0.875rem;
  }
}

/* ========================================
   TOOLBAR (Search/Filter/Actions)
   ======================================== */

.admin-toolbar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  align-items: center;
}

.admin-search {
  flex: 1;
  min-width: 200px;
}

.admin-filters {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.admin-actions {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* Mobile: Stack toolbar elements */
@media (max-width: 599px) {
  .admin-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-search {
    width: 100%;
  }

  .admin-actions {
    margin-left: 0;
    width: 100%;
  }
}

/* ========================================
   TABLE STYLES
   ======================================== */

.admin-table-container {
  overflow-x: auto;
  border-radius: var(--r12);
  border: 1px solid var(--stroke);
  background: var(--panel);
  margin-bottom: var(--space-4);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}

.admin-table thead {
  background: var(--surface);
  border-bottom: 2px solid var(--stroke);
  position: sticky;
  top: 0;
  z-index: 10;
}

.admin-table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  user-select: none;
}

.admin-table th[data-sortable] {
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.admin-table th[data-sortable]:hover {
  background: var(--surface2);
}

.admin-table th[data-sortable]::after {
  content: ' ↕';
  opacity: 0.3;
  font-size: 0.75rem;
  margin-left: var(--space-1);
}

.admin-table th[data-sortable].sorted-asc::after {
  content: ' ↑';
  opacity: 1;
  color: var(--accent);
}

.admin-table th[data-sortable].sorted-desc::after {
  content: ' ↓';
  opacity: 1;
  color: var(--accent);
}

.admin-table tbody tr {
  border-bottom: 1px solid var(--stroke);
  transition: background-color 0.2s ease;
}

.admin-table tbody tr:hover {
  background: var(--surface);
}

.admin-table tbody tr.selected {
  background: rgba(124, 92, 255, 0.1);
}

.admin-table td {
  padding: var(--space-3) var(--space-4);
  font-size: 0.875rem;
  color: var(--text);
}

.admin-table td:first-child {
  width: 40px;
  text-align: center;
}

.admin-table .table-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.admin-table .table-actions .btn {
  padding: var(--space-1) var(--space-2);
  font-size: 0.8125rem;
}

/* Hide table on mobile */
@media (max-width: 859px) {
  .admin-table-container {
    display: none;
  }
}

/* ========================================
   MOBILE CARDS VIEW
   ======================================== */

.admin-cards-mobile {
  display: none;
  flex-direction: column;
  gap: var(--space-3);
}

@media (max-width: 859px) {
  .admin-cards-mobile {
    display: flex;
  }
}

.admin-card {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--r12);
  padding: var(--space-4);
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.1s ease;
}

.admin-card:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.admin-card:active {
  transform: scale(0.99);
}

.admin-card.selected {
  background: rgba(124, 92, 255, 0.1);
  border-color: var(--accent);
}

.admin-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-3);
}

.admin-card-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.admin-card-subtitle {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: var(--space-1);
}

.admin-card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.admin-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
}

.admin-card-label {
  color: var(--muted);
  font-weight: 500;
}

.admin-card-value {
  color: var(--text);
}

.admin-card-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--stroke);
}

/* ========================================
   BULK ACTIONS BAR
   ======================================== */

.bulk-actions-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--panel);
  border-top: 2px solid var(--accent);
  padding: var(--space-4);
  display: none;
  align-items: center;
  gap: var(--space-4);
  z-index: var(--z-modal);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
}

.bulk-actions-bar.show {
  display: flex;
}

.bulk-actions-info {
  font-weight: 600;
  color: var(--accent);
}

.bulk-actions-buttons {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* Desktop: Adjust for sidebar */
@media (min-width: 860px) {
  .bulk-actions-bar {
    left: var(--sidebar-width);
  }
}

/* Mobile: Full width */
@media (max-width: 599px) {
  .bulk-actions-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .bulk-actions-buttons {
    margin-left: 0;
  }
}

/* ========================================
   EDIT PANEL (Desktop - Slides in from right)
   ======================================== */

.edit-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 400px;
  max-width: 100%;
  background: var(--panel);
  border-left: 1px solid var(--stroke);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: calc(var(--z-modal) + 1);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}

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

.edit-panel-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--stroke);
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 60px;
}

.edit-panel-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.edit-panel-body {
  flex: 1;
  padding: var(--space-4);
  overflow-y: auto;
}

.edit-panel-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--stroke);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

/* Mobile: Full-screen edit panel */
@media (max-width: 859px) {
  .edit-panel {
    display: none; /* Hide on mobile, use bottom sheet instead */
  }
}

/* ========================================
   BOTTOM SHEET (Mobile - Slides up from bottom)
   ======================================== */

.bottom-sheet-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.bottom-sheet-backdrop.show {
  opacity: 1;
  pointer-events: all;
}

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90vh;
  background: var(--panel);
  border-top-left-radius: var(--r20);
  border-top-right-radius: var(--r20);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: calc(var(--z-modal) + 1);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.bottom-sheet.open {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--stroke);
  border-radius: 2px;
  margin: var(--space-3) auto;
}

.bottom-sheet-header {
  padding: var(--space-2) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--stroke);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bottom-sheet-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.bottom-sheet-body {
  flex: 1;
  padding: var(--space-4);
  overflow-y: auto;
}

.bottom-sheet-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--stroke);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Desktop: Hide bottom sheet */
@media (min-width: 860px) {
  .bottom-sheet-backdrop,
  .bottom-sheet {
    display: none;
  }
}

/* ========================================
   TABLE FOOTER (Pagination)
   ======================================== */

.admin-table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--stroke);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.table-info {
  font-size: 0.875rem;
  color: var(--muted);
}

.table-pagination {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.table-pagination button {
  padding: var(--space-2) var(--space-3);
  font-size: 0.875rem;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--r8);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.table-pagination button:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--accent);
}

.table-pagination button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.table-pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Mobile: Smaller pagination buttons */
@media (max-width: 599px) {
  .admin-table-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .table-pagination {
    justify-content: center;
  }

  .table-pagination button {
    padding: var(--space-1) var(--space-2);
    font-size: 0.8125rem;
  }
}

/* ========================================
   LOADING, EMPTY, ERROR STATES
   ======================================== */

#contentLoading,
#contentEmpty {
  text-align: center;
}

#contentError {
  margin-bottom: var(--space-4);
}

/* ========================================
   FORM STYLES (Edit Panel & Bottom Sheet)
   ======================================== */

.edit-panel .field,
.bottom-sheet .field {
  margin-bottom: var(--space-4);
}

.edit-panel .field:last-child,
.bottom-sheet .field:last-child {
  margin-bottom: 0;
}

/* Form styling for edit panel and bottom sheet */
.edit-panel .form-group,
.bottom-sheet .form-group {
  margin-bottom: var(--space-4);
}

.edit-panel .form-group label,
.bottom-sheet .form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-2);
}

.edit-panel .form-group input,
.edit-panel .form-group select,
.bottom-sheet .form-group input,
.bottom-sheet .form-group select {
  width: 100%;
  padding: var(--space-3);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--stroke);
  border-radius: var(--r8);
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.edit-panel .form-group input:focus,
.edit-panel .form-group select:focus,
.bottom-sheet .form-group input:focus,
.bottom-sheet .form-group select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel);
}

.edit-panel .form-group input:disabled,
.bottom-sheet .form-group input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--panel);
}

.edit-panel .form-group .form-help,
.bottom-sheet .form-group .form-help {
  display: block;
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: var(--space-1);
}

.edit-panel .form-group input::placeholder,
.bottom-sheet .form-group input::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

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

/* Scrollbar styling for webkit browsers */
.edit-panel-body::-webkit-scrollbar,
.bottom-sheet-body::-webkit-scrollbar {
  width: 8px;
}

.edit-panel-body::-webkit-scrollbar-track,
.bottom-sheet-body::-webkit-scrollbar-track {
  background: var(--surface);
}

.edit-panel-body::-webkit-scrollbar-thumb,
.bottom-sheet-body::-webkit-scrollbar-thumb {
  background: var(--stroke);
  border-radius: 4px;
}

.edit-panel-body::-webkit-scrollbar-thumb:hover,
.bottom-sheet-body::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* Checkbox styling for bulk selection */
.admin-table input[type="checkbox"],
.admin-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* Badge adjustments in table */
.admin-table .badge {
  font-size: 0.75rem;
  padding: 2px 8px;
}

/* Responsive adjustments */
@media (max-width: 599px) {
  .admin-content {
    padding: 0;
  }

  .admin-toolbar {
    padding: 0;
  }
}

/* Animation for table rows */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.admin-table tbody tr,
.admin-card {
  animation: fadeIn 0.2s ease;
}

/* ========================================
   ORPHANED CHARACTER STYLING
   ======================================== */

.orphaned-row {
  background-color: rgba(255, 193, 7, 0.1);
  border-left: 3px solid var(--color-warning, #ffc107);
}

.badge.warning {
  background-color: var(--color-warning, #ffc107);
  color: var(--color-dark, #333);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.text-warning {
  color: var(--color-warning, #ffc107);
}
