/* ===== HISTORY TABLE ===== */
/* Drop-in replacement for assets/css/tables.css
   Same IDs and class names as index.html's history tab. */

:root {
  --tb-ink: #1a0f33;
  --tb-head: #241443;
  --tb-body: #374151;
  --tb-muted: #6b7280;
  --tb-line: #e8e9ee;
  --tb-line-soft: #f1f2f6;
  --tb-surface: #ffffff !important;
  --tb-hover: #faf9ff;
  --tb-accent: #8b7ff5;
  --tb-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Shell --------------------------------------------------------------- */
#historyResultBox {
  display: none;
  position: relative;
  border: 1px solid var(--tb-line);
  border-radius: 14px;
  overflow: hidden;
  background: #ffffff !important;
}

#historyResultBox.show {
  display: block;
}

#historyTableContainer {
  display: block;
  width: 100%;
  max-height: 700px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #ffffff !important;
  border-radius: 14px;
  box-shadow: none;
}

#historyTableContainer::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
#historyTableContainer::-webkit-scrollbar-thumb {
  background: #d3d6de;
  border-radius: 8px;
}
#historyTableContainer::-webkit-scrollbar-track {
  background: var(--tb-line-soft);
}

/* Section header ------------------------------------------------------ */
.history-header {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--tb-line);
}

.history-header h5 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--tb-head);
}

.history-header h5 i {
  font-size: 1.15rem;
  color: var(--tb-accent);
}

/* Table --------------------------------------------------------------- */
#historyTable {
  width: 100%;
  margin: 0;
  background: #ffffff !important;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
  font-size: 0.83rem;
  font-variant-numeric: tabular-nums;
}

#historyTable thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #ffffff !important;
}

#historyTable thead th {
  padding: 0.75rem 1rem;
  background: #fbfbfd;
  color: var(--tb-muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
  border: none;
  border-bottom: 1px solid var(--tb-line);
  min-width: 110px;
}

#historyTable tbody tr {
  background: #ffffff !important;
  transition: background 0.15s var(--tb-ease);
}

#historyTable tbody tr:hover {
  background: #faf9ff !important;
  cursor: pointer;
  transform: none;
  box-shadow: none;
}

#historyTable tbody td {
  padding: 0.8rem 1rem;
  color: var(--tb-body);
  font-size: 0.82rem;
  line-height: 1.45;
  vertical-align: middle;
  word-break: break-word;
  border: none;
  border-bottom: 1px solid var(--tb-line-soft);
  background: #ffffff !important;
}

#historyTable tbody tr:last-child td {
  border-bottom: none;
}

#historyTable tbody i {
  margin-right: 0.25rem;
  font-size: 0.9rem;
  color: var(--tb-muted);
}

#historyTable strong {
  color: var(--tb-head);
  font-weight: 600;
}

#historyTable small {
  display: block;
  max-width: 100%;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--tb-muted);
  white-space: normal;
  word-break: break-word;
}

#historyTable small[title] {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

/* Column widths ------------------------------------------------------- */
#historyTable th:nth-child(1),
#historyTable td:nth-child(1) { width: 11%; min-width: 90px; }
#historyTable th:nth-child(2),
#historyTable td:nth-child(2) { width: 9%;  min-width: 80px; }
#historyTable th:nth-child(3),
#historyTable td:nth-child(3) { width: 9%;  min-width: 80px; }
#historyTable th:nth-child(4),
#historyTable td:nth-child(4) { width: 10%; min-width: 85px; }
#historyTable th:nth-child(5),
#historyTable td:nth-child(5) { width: 9%;  min-width: 80px; }
#historyTable th:nth-child(6),
#historyTable td:nth-child(6) { width: 7%;  min-width: 70px; }
#historyTable th:nth-child(7),
#historyTable td:nth-child(7) { width: 7%;  min-width: 70px; }
#historyTable th:nth-child(8),
#historyTable td:nth-child(8) { width: 18%; min-width: 140px; }
#historyTable th:nth-child(9),
#historyTable td:nth-child(9) { width: 7%;  min-width: 70px; }
#historyTable th:nth-child(12),
#historyTable td:nth-child(12) { width: 4%; min-width: 48px; }

/* Badges -------------------------------------------------------------- */
#historyTable .badge {
  display: inline-block;
  min-width: 0;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 550;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  box-shadow: none;
}

#historyTable .badge.bg-info {
  background: rgba(139, 127, 245, 0.12) !important;
  color: #5b4fd1 !important;
}

#historyTable .badge.bg-success {
  background: rgba(16, 185, 129, 0.12) !important;
  color: #047857 !important;
}

#historyTable .badge.bg-danger {
  background: rgba(239, 68, 68, 0.12) !important;
  color: #b91c1c !important;
}

#historyTable .badge.bg-warning {
  background: rgba(245, 158, 11, 0.14) !important;
  color: #b45309 !important;
}

#historyTable .badge.bg-secondary {
  background: var(--tb-line-soft) !important;
  color: var(--tb-muted) !important;
}

/* Search -------------------------------------------------------------- */
.search-box-container {
  margin-bottom: 0;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 0;
}

.search-input-wrapper i {
  position: absolute;
  left: 0.85rem;
  font-size: 0.95rem;
  color: var(--tb-muted);
  pointer-events: none;
}

#historySearchInput {
  width: 100%;
  padding: 0.6rem 0.9rem 0.6rem 2.35rem;
  font-size: 0.88rem;
  color: var(--tb-body);
  background: var(--tb-surface);
  border: 1px solid var(--tb-line);
  border-radius: 10px;
  box-shadow: none;
  transition: border-color 0.18s var(--tb-ease), box-shadow 0.18s var(--tb-ease);
}

#historySearchInput:focus {
  outline: none;
  background: var(--tb-surface);
  border-color: var(--tb-accent);
  box-shadow: 0 0 0 3px rgba(139, 127, 245, 0.15);
}

#historySearchInput::placeholder {
  color: #a3a8b3;
  font-weight: 400;
}

/* Empty search result -------------------------------------------------- */
#noSearchResults {
  padding: 2.5rem 1.25rem;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--tb-muted);
  background: #fbfbfd;
  border: 1px dashed var(--tb-line);
  border-radius: 12px;
}

/* Action buttons ------------------------------------------------------- */
.history-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.btn-export,
.btn-delete {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font-size: 0.86rem;
  font-weight: 550;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.18s var(--tb-ease), border-color 0.18s var(--tb-ease);
}

.btn-export {
  color: var(--tb-surface) !important;
  background: var(--tb-ink) !important;
  border: 1px solid var(--tb-ink) !important;
  box-shadow: none;
}

.btn-export:hover {
  background: #2a1a4d !important;
  transform: none;
  box-shadow: none;
}

.btn-delete {
  color: #b91c1c !important;
  background: var(--tb-surface) !important;
  border: 1px solid #f3c9c9 !important;
  box-shadow: none;
}

.btn-delete:hover {
  background: #fef4f4 !important;
  border-color: #e9a8a8 !important;
  transform: none;
  box-shadow: none;
}

.btn-export:focus-visible,
.btn-delete:focus-visible {
  outline: 2px solid var(--tb-accent);
  outline-offset: 2px;
}

/* Pagination ----------------------------------------------------------- */
.history-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.pagination {
  display: flex;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.pagination .page-link {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--tb-body);
  background: var(--tb-surface);
  border: 1px solid var(--tb-line);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s var(--tb-ease), border-color 0.15s var(--tb-ease);
}

.pagination .page-link:hover {
  background: var(--tb-hover);
  border-color: #cfd2da;
  color: var(--tb-head);
  transform: none;
}

.pagination .page-item.active .page-link {
  color: var(--tb-surface);
  background: var(--tb-ink);
  border-color: var(--tb-ink);
  box-shadow: none;
}

/* Responsive ----------------------------------------------------------- */
@media (max-width: 768px) {
  #historyTable {
    font-size: 0.78rem;
  }

  #historyTable thead th {
    padding: 0.6rem 0.6rem;
    font-size: 0.66rem;
    min-width: 90px;
  }

  #historyTable tbody td {
    padding: 0.6rem 0.6rem;
    font-size: 0.75rem;
  }

  #historyTable small {
    font-size: 0.72rem;
  }

  #historyTable .badge {
    font-size: 0.68rem;
    padding: 0.15rem 0.4rem;
  }

  .btn-export,
  .btn-delete {
    padding: 0.5rem 0.85rem;
    font-size: 0.82rem;
  }
}

@media (max-width: 576px) {
  #historyTable thead th,
  #historyTable tbody td {
    padding: 0.5rem;
    white-space: nowrap;
  }

  #historyTable tbody td {
    font-size: 0.72rem;
  }

  /* Let columns size to content and scroll sideways instead of cramming */
  #historyTable th[class],
  #historyTable td[class],
  #historyTable th:nth-child(n),
  #historyTable td:nth-child(n) {
    width: auto;
    min-width: 88px;
  }

  .history-header h5 {
    font-size: 1.05rem;
  }

  .history-actions {
    flex-direction: column;
  }

  .btn-export,
  .btn-delete {
    width: 100%;
    justify-content: center;
  }

  #historySearchInput {
    font-size: 0.85rem;
    padding-left: 2.1rem;
  }

  .pagination .page-link {
    padding: 0.3rem 0.55rem;
    font-size: 0.78rem;
  }

  #noSearchResults {
    padding: 1.5rem 0.75rem;
    font-size: 0.88rem;
  }
}

@media (max-width: 480px) {
  #historyTable thead th {
    font-size: 0.62rem;
  }

  #historyTable tbody td {
    font-size: 0.7rem;
  }

  .history-header {
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  #historyTable tbody tr,
  #historySearchInput,
  .btn-export,
  .btn-delete,
  .pagination .page-link {
    transition: none;
  }
}