/* AAA Indie Admin - Reusable Components */

/* Tables */
.data-table-wrapper {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

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

.data-table thead {
  background: var(--panel2);
  position: sticky;
  top: 0;
  z-index: 10;
}

.data-table th {
  padding: 14px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 120ms ease;
}

.data-table th.sortable:hover {
  color: var(--text);
}

.data-table th.sorted {
  color: var(--accent);
}

.sort-indicator {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  opacity: 0.5;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 120ms ease;
}

.data-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.01);
}

.data-table tbody tr:hover {
  background: var(--panel2);
}

.data-table td {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.data-table td.actions {
  white-space: nowrap;
}

.table-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 120ms ease;
  background: var(--panel2);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.action-btn:hover {
  background: var(--border);
  transform: translateY(-1px);
}

.action-btn.danger:hover {
  background: var(--danger);
  color: white;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 24px;
  padding: 16px 0;
}

.pagination-info {
  font-size: 14px;
  color: var(--muted);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: all 120ms ease;
  font-size: 14px;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.page-btn:hover:not(:disabled):not(.active) {
  background: var(--panel2);
  border-color: var(--accent);
}

.page-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}

.page-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-btn.ellipsis {
  cursor: default;
  border: none;
  background: transparent;
}

.page-btn.ellipsis:hover {
  background: transparent;
  border: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-width: 1250px;
  width: 90%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.9);
  transition: transform 180ms ease;
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 24px;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 120ms ease;
}

.modal-close:hover {
  background: var(--panel2);
  color: var(--text);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal.danger .modal-header {
  background: rgba(214, 48, 49, 0.1);
  border-bottom-color: rgba(214, 48, 49, 0.3);
}

.modal.danger .modal-title {
  color: var(--danger);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
}

.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: slideIn 180ms ease;
  cursor: pointer;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.removing {
  animation: slideOut 180ms ease forwards;
}

@keyframes slideOut {
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

.toast-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 14px;
}

.toast-message {
  font-size: 13px;
  color: var(--muted);
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.success .toast-icon {
  color: var(--success);
}

.toast.error {
  border-left: 3px solid var(--danger);
}

.toast.error .toast-icon {
  color: var(--danger);
}

.toast.info {
  border-left: 3px solid var(--accent);
}

.toast.info .toast-icon {
  color: var(--accent);
}

.toast.warning {
  border-left: 3px solid var(--warning);
}

.toast.warning .toast-icon {
  color: var(--warning);
}

/* Form Components */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.select-wrapper {
  position: relative;
}

.select-wrapper::after {
  content: "▼";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted);
  font-size: 10px;
}

.searchable-select {
  position: relative;
}

.searchable-select-input {
  width: 100%;
}

.searchable-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.searchable-select-dropdown.active {
  display: block;
}

.searchable-select-option {
  padding: 10px 12px;
  cursor: pointer;
  transition: background 120ms ease;
  font-size: 14px;
}

.searchable-select-option:hover {
  background: var(--panel2);
}

.searchable-select-option.selected {
  background: var(--accent);
  color: white;
}

.searchable-select-option.no-results {
  color: var(--muted);
  cursor: default;
  font-style: italic;
}

.searchable-select-option.no-results:hover {
  background: transparent;
}

/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

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

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

/* Utility Classes */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-2 {
  gap: 8px;
}

.gap-4 {
  gap: 16px;
}

.mt-4 {
  margin-top: 16px;
}

.mb-4 {
  margin-bottom: 16px;
}

.hidden {
  display: none !important;
}

/* Modal Large */
.modal-large {
  max-width: 1400px;
  width: 95%;
  max-height: 95vh;
}

/* Table Browser Modal */
.table-browser-modal .modal-toolbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--panel2);
}

.table-browser-modal .search-box {
  flex: 1;
  max-width: 400px;
}

.table-browser-modal .toolbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.table-browser-modal .row-count {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

.table-browser-modal .modal-body {
  padding: 0;
}

.table-browser-content {
  min-height: 400px;
  position: relative;
}

.table-browser-modal .data-table-wrapper {
  border: none;
  border-radius: 0;
  max-height: calc(95vh - 280px);
  overflow-y: auto;
}

.table-browser-modal .modal-footer {
  padding: 16px 24px;
  background: var(--panel2);
}

/* Loading Skeleton */
.loading-skeleton {
  padding: 24px;
}

.skeleton-row {
  height: 48px;
  background: linear-gradient(
    90deg,
    var(--panel2) 0%,
    var(--border) 50%,
    var(--panel2) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 8px;
  margin-bottom: 12px;
}

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

/* Table Row Clickable */
.table-row-clickable {
  cursor: pointer;
}

.table-row-clickable:hover {
  background: var(--panel2) !important;
}

/* No Data */
.no-data {
  text-align: center;
  padding: 48px 24px !important;
  color: var(--muted);
  font-style: italic;
}

/* Null Value */
.null-value {
  color: var(--muted);
  font-style: italic;
  opacity: 0.6;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.badge-success {
  background: rgba(46, 213, 115, 0.15);
  color: var(--success);
}

.badge-secondary {
  background: var(--panel2);
  color: var(--muted);
}

.badge-danger {
  background: rgba(214, 48, 49, 0.15);
  color: var(--danger);
}

.badge-warning {
  background: rgba(255, 159, 67, 0.15);
  color: var(--warning);
}

/* Form Modal */
.form-modal .modal {
  max-width: 800px;
}

.form-modal .form-group {
  margin-bottom: 20px;
}

.form-modal .form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
}

.form-modal .required {
  color: var(--danger);
}

.form-modal .json-input {
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

.form-modal .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.form-modal .checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Responsive Tables */
@media (max-width: 1200px) {
  .modal-large {
    width: 98%;
  }
  
  .data-table {
    font-size: 13px;
  }
  
  .data-table th,
  .data-table td {
    padding: 10px 12px;
  }
}

@media (max-width: 768px) {
  .table-browser-modal .modal-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .table-browser-modal .search-box {
    max-width: none;
  }
  
  .table-browser-modal .toolbar-actions {
    justify-content: space-between;
  }
  
  .modal {
    max-width: 95%;
    width: 95%;
  }
  
  .toast-container {
    left: 12px;
    right: 12px;
    max-width: none;
  }
}
