/* ============================================
   TABLES.CSS - Tables, Scrolling, Column Utilities
   ============================================
   Contains:
   - Table container & scrolling
   - Table styling
   - Sticky headers
   - Column behavior utilities
   - Expanded/detail rows
   - Work item count badges
   - Dark mode table overrides
   ============================================ */

/* ============================================
   TABLE CONTAINER - Horizontal scroll wrapper
   ============================================ */
.table-responsive-wrapper {
    position: relative;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
    background: var(--surface);
}

/* Custom scrollbar styling */
.table-responsive-wrapper::-webkit-scrollbar {
    height: 8px;
}

.table-responsive-wrapper::-webkit-scrollbar-track {
    background: var(--surface-hover);
    border-radius: 4px;
}

.table-responsive-wrapper::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.table-responsive-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   SHARED DATA GRID SHELL
   ============================================ */
.data-grid-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    overflow: visible;
    box-shadow: var(--shadow-sm);
}

.data-grid-toolbar {
    position: relative;
    z-index: 20;
    background: var(--surface-hover);
    border-bottom: 1px solid var(--border-soft);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.data-grid-toolbar .filter-bar--compact {
    min-width: 0;
    width: 100%;
}

.data-grid-scroll {
    position: relative;
    z-index: 1;
    flex: 1 1 auto;
    width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    min-height: 0;
    max-height: min(70vh, calc(100vh - 20rem));
    -webkit-overflow-scrolling: touch;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.data-grid-scroll::-webkit-scrollbar {
    height: 8px;
}

.data-grid-scroll::-webkit-scrollbar-track {
    background: var(--surface-hover);
    border-radius: 4px;
}

.data-grid-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.data-grid-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.data-grid-scroll .table {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
}

.data-grid-scroll .empty-state {
    background: transparent !important;
}

/* ============================================
   TABLES - Clean, spacious styling
   ============================================ */
.table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    min-width: 700px; /* Ensures table has minimum width before scrolling */
    background: var(--surface);
}

/* Only add shadow/radius when not inside a scroll shell */
.table:not(.table-responsive-wrapper .table):not(.data-grid-scroll .table) {
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table th, .table td {
    padding: 16px 20px;
    vertical-align: top;
    text-align: left;
    background-color: var(--surface);
    border-bottom: 1px solid var(--border-soft);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.table thead th {
    background-color: var(--surface-hover);
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.table tbody tr {
    transition: background-color var(--transition-fast);
}

.table tbody tr:hover {
    background-color: var(--primary-light);
}

.table tbody tr:hover td {
    background-color: transparent;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* ============================================
   COLUMN BEHAVIOR - Natural sizing with limits
   ============================================ */

/* Columns that should NOT wrap (short content) */
.no-wrap,
.table .no-wrap {
    white-space: nowrap !important;
}

/* Long content columns - wrap text nicely */
.cell-content {
    min-width: 150px;
    max-width: 350px;
    line-height: 1.5;
    white-space: normal;
}

/* Timestamp cells - compact but readable */
.cell-timestamp {
    white-space: nowrap;
    font-size: 0.8125rem;
    min-width: 100px;
    max-width: 160px;
}

/* Tags - flex wrap nicely */
.cell-tags-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 100px;
}

.cell-tags-wrap .badge {
    margin: 0;
    white-space: nowrap;
}

/* ============================================
   ACTION BUTTONS - Consistent spacing
   ============================================ */
.action-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    white-space: nowrap;
}

.action-buttons .btn {
    padding: 6px 12px;
}

.action-buttons .btn-sm {
    padding: 5px 10px;
    font-size: 0.8125rem;
}

/* ============================================
   EXPANDED/DETAIL ROWS
   ============================================ */
.release-details-row td,
.prs-details-row td {
    background-color: var(--background) !important;
    padding: 20px 24px !important;
    border-bottom: 2px solid var(--border) !important;
}

.release-details-row .table,
.prs-details-row .table {
    min-width: auto;
    margin: 0;
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--border-soft);
}

.release-details-row .table th,
.release-details-row .table td,
.prs-details-row .table th,
.prs-details-row .table td {
    padding: 12px 16px;
    font-size: 0.875rem;
}

/* Pull Request Specific */
.pr-row {
    cursor: pointer;
}

.pr-row:hover {
    background-color: var(--primary-light);
}

/* Work Item Count Badges - Soft pill style */
.work-item-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    padding: 4px 10px;
    font-size: 0.8125rem;
    font-weight: 700;
    color: #fff;
    background-color: var(--secondary-color);
    border-radius: var(--radius-full);
    text-align: center;
    vertical-align: middle;
}

.work-item-count.bg-success {
    background-color: var(--success) !important;
}

.work-item-count.bg-warning {
    background-color: var(--warning) !important;
    color: var(--warning-text);
}

.work-item-count.bg-secondary {
    background-color: var(--secondary-color) !important;
}

/* Ensure badge placement */
.pull-requests-table .work-item-count {
    position: relative;
    z-index: 10;
}

.work-item-count-cell,
.pull-requests-table th:nth-child(8) {
    text-align: center !important;
    vertical-align: middle !important;
    padding: 8px !important;
    display: table-cell !important;
    visibility: visible !important;
    min-width: 100px !important;
}

/* ============================================
   DARK MODE TABLE OVERRIDES
   ============================================ */

/* Dark mode table structure */
[data-theme="dark"] .table {
  background-color: var(--surface);
  color: var(--text-primary);
  border-color: var(--border);
}

[data-theme="dark"] .table th {
  background-color: var(--surface-elevated) !important;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .table td,
[data-theme="dark"] .table th {
  border-color: var(--border) !important;
}

/* zebra-striping */
[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) {
  background-color: var(--surface-hover) !important;
}

/* Dark mode table cell text */
[data-theme="dark"] .table td,
[data-theme="dark"] .table tbody td {
  color: var(--text-primary) !important;
}

/* Dark mode table inputs */
[data-theme="dark"] .table thead input.form-control {
  background-color: var(--surface-hover) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
}

/* Dark mode table buttons */
[data-theme="dark"] .table a.btn-outline-secondary,
[data-theme="dark"] .table button.btn-outline-secondary {
  border-color: var(--border) !important;
  color: var(--text-secondary) !important;
}

[data-theme="dark"] .table a.btn-outline-secondary .bi,
[data-theme="dark"] .table button.btn-outline-secondary .bi {
  color: var(--text-secondary) !important;
}

[data-theme="dark"] .table a.btn-outline-secondary:hover,
[data-theme="dark"] .table button.btn-outline-secondary:hover {
  background-color: var(--primary-soft) !important;
  border-color: var(--primary) !important;
  color: var(--primary) !important;
}

[data-theme="dark"] .table a.btn-outline-secondary:hover .bi,
[data-theme="dark"] .table button.btn-outline-secondary:hover .bi {
  color: var(--primary) !important;
}
