/* Backend Table Styles - 通用表格樣式系統 */

/* === 基礎表格容器 === */
.table-container {
  width: 100%;
  overflow-x: auto;
  margin: 1.5rem 0;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* === 表格工具列 === */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.table-search {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 400px;
}

.table-search input {
  width: 100%;
  padding: 0.6rem 1rem 0.6rem 2.5rem;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.table-search input:focus {
  outline: none;
  border-color: var(--primary-color, #4f46e5);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.table-search i {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted, #64748b);
}

.table-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* === 基礎表格樣式 === */
.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  font-size: 0.9rem;
}

.table thead {
  background: #f8fafc;
  border-bottom: 2px solid var(--border-color, #e2e8f0);
}

.table thead th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-main, #1e293b);
  white-space: nowrap;
  user-select: none;
}

.table tbody tr {
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  transition: background-color 0.2s;
}

.table tbody tr:hover {
  background-color: #f8fafc;
}

.table tbody td {
  padding: 1rem;
  color: var(--text-main, #1e293b);
}

/* === 可排序表頭 === */
.table thead th.sortable {
  cursor: pointer;
  position: relative;
  padding-right: 2rem;
}

.table thead th.sortable:hover {
  background: #f1f5f9;
}

.table thead th.sortable::after {
  content: "⇅";
  position: absolute;
  right: 0.8rem;
  opacity: 0.3;
  font-size: 0.8rem;
}

.table thead th.sortable.asc::after {
  content: "↑";
  opacity: 1;
  color: var(--primary-color, #4f46e5);
}

.table thead th.sortable.desc::after {
  content: "↓";
  opacity: 1;
  color: var(--primary-color, #4f46e5);
}

/* === 斑馬紋樣式 === */
.table-striped tbody tr:nth-child(odd) {
  background-color: #fafbfc;
}

.table-striped tbody tr:nth-child(odd):hover {
  background-color: #f1f5f9;
}

/* === 邊框樣式 === */
.table-bordered {
  border: 1px solid var(--border-color, #e2e8f0);
}

.table-bordered th,
.table-bordered td {
  border: 1px solid var(--border-color, #e2e8f0);
}

/* === 緊湊樣式 === */
.table-compact thead th,
.table-compact tbody td {
  padding: 0.5rem 0.75rem;
}

/* === 表格內的狀態標籤 === */
.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 12px;
  white-space: nowrap;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.badge-info {
  background: #dbeafe;
  color: #1e40af;
}

.badge-secondary {
  background: #f1f5f9;
  color: #475569;
}

/* === 表格內的按鈕 === */
.btn-table {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.btn-table-primary {
  background: var(--primary-color, #4f46e5);
  color: white;
}

.btn-table-primary:hover {
  background: #4338ca;
}

.btn-table-secondary {
  background: #f1f5f9;
  color: var(--text-main, #1e293b);
}

.btn-table-secondary:hover {
  background: #e2e8f0;
}

.btn-table-danger {
  background: #fee2e2;
  color: #991b1b;
}

.btn-table-danger:hover {
  background: #fecaca;
}

.btn-table-icon {
  padding: 0.4rem;
  background: transparent;
  color: var(--text-muted, #64748b);
  border: none;
  cursor: pointer;
  border-radius: 4px;
  font-size: 1rem;
  transition: all 0.2s;
}

.btn-table-icon:hover {
  background: #f1f5f9;
  color: var(--text-main, #1e293b);
}

/* === 表格動作欄 === */
.table-actions-cell {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* === 表格分頁 === */
.table-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color, #e2e8f0);
  flex-wrap: wrap;
  gap: 1rem;
}

.table-pagination-info {
  color: var(--text-muted, #64748b);
  font-size: 0.9rem;
}

.table-pagination-buttons {
  display: flex;
  gap: 0.5rem;
}

.pagination-btn {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color, #e2e8f0);
  background: white;
  color: var(--text-main, #1e293b);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.85rem;
}

.pagination-btn:hover:not(:disabled) {
  background: #f8fafc;
  border-color: var(--primary-color, #4f46e5);
}

.pagination-btn.active {
  background: var(--primary-color, #4f46e5);
  color: white;
  border-color: var(--primary-color, #4f46e5);
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === 空狀態 === */
.table-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted, #64748b);
}

.table-empty i {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.table-empty p {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

/* === 載入中狀態 === */
.table-loading {
  position: relative;
  min-height: 200px;
}

.table-loading::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === RWD 響應式設計 === */

/* 平板尺寸 */
@media (max-width: 1024px) {
  .table {
    font-size: 0.85rem;
  }

  .table thead th,
  .table tbody td {
    padding: 0.75rem;
  }
}

/* 手機尺寸 - 卡片式佈局 */
@media (max-width: 768px) {
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .table-search {
    max-width: 100%;
  }

  .table-actions {
    justify-content: flex-end;
  }

  /* 隱藏原始表格，改用卡片式 */
  .table-responsive {
    border: none;
    box-shadow: none;
  }

  .table-responsive table {
    display: none;
  }

  /* 卡片式表格 */
  .table-responsive .table-mobile-cards {
    display: block;
  }

  .table-mobile-card {
    background: white;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
  }

  .table-mobile-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .table-mobile-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f1f5f9;
  }

  .table-mobile-row:last-child {
    border-bottom: none;
  }

  .table-mobile-label {
    font-weight: 600;
    color: var(--text-muted, #64748b);
    font-size: 0.85rem;
  }

  .table-mobile-value {
    color: var(--text-main, #1e293b);
    text-align: right;
  }

  .table-pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .table-pagination-info {
    text-align: center;
  }

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

/* 桌面尺寸 - 隱藏卡片式 */
@media (min-width: 769px) {
  .table-mobile-cards {
    display: none;
  }
}

/* === 數字對齊 === */
.table td.text-right,
.table th.text-right {
  text-align: right;
}

.table td.text-center,
.table th.text-center {
  text-align: center;
}

/* === 可選擇的行 === */
.table tbody tr.selectable {
  cursor: pointer;
}

.table tbody tr.selectable.selected {
  background-color: #ede9fe;
}

.table tbody tr.selectable.selected:hover {
  background-color: #ddd6fe;
}

/* === Checkbox 樣式 === */
.table-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary-color, #4f46e5);
}

/* === 固定列 === */
.table-fixed-column {
  position: sticky;
  left: 0;
  background: white;
  z-index: 1;
}

.table thead th.table-fixed-column {
  background: #f8fafc;
  z-index: 2;
}

/* === 導出按鈕 === */
.btn-export {
  padding: 0.6rem 1rem;
  background: white;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-main, #1e293b);
  transition: all 0.2s;
}

.btn-export:hover {
  background: #f8fafc;
  border-color: var(--primary-color, #4f46e5);
  color: var(--primary-color, #4f46e5);
}
