/* =========================================================================
   TABLES - Data Table Styles
   ========================================================================= */

/**
 * Table styles for data display, admin areas, and listing pages.
 * Built on Bootstrap tables with BusOva theming.
 */

/* ---------------------------------------------------------------------
   Base Table Style
   --------------------------------------------------------------------- */

.table {
    width: 100%;
    margin-bottom: 1rem;
    color: var(--text-main);
    vertical-align: middle;
    border-color: var(--border-subtle);
    border-collapse: separate;
    border-spacing: 0 0.75rem;
}

.table > :not(caption) > * > * {
    padding: 0.75rem;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
}

.table thead th {
    padding-bottom: 0.75rem;
}

.table tbody tr {
    margin-bottom: 0.75rem;
}

.table tbody tr td {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}

/* Rounded corners for table rows */
.table tbody tr {
    border-radius: 0.5rem;
    overflow: hidden;
}

.table tbody tr td:first-child {
    border-top-left-radius: 0.5rem;
    border-bottom-left-radius: 0.5rem;
}

.table tbody tr td:last-child {
    border-top-right-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

.table thead tr th:first-child {
    border-top-left-radius: 0.5rem;
}

.table thead tr th:last-child {
    border-top-right-radius: 0.5rem;
}

/* ---------------------------------------------------------------------
   Table Header
   --------------------------------------------------------------------- */

.table thead th {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-main);
    background-color: var(--bg-card-soft);
    border-bottom: 2px solid var(--border-subtle);
    white-space: nowrap;
    border-radius: 0;
}

.table thead th:first-child {
    border-top-left-radius: 0.5rem;
}

.table thead th:last-child {
    border-top-right-radius: 0.5rem;
}

/* Sortable headers */
.table thead th[data-sort],
.table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease;
}

.theme-light .table thead th[data-sort]:hover,
.theme-light .table thead th.sortable:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Active sort column */
.table thead th.sort-active {
    color: var(--accent);
    background-color: rgba(14, 155, 255, 0.08);
}

.table thead th.sort-active i,
.table thead th.sort-active svg {
    color: var(--accent);
}

/* Sort icons */
.table thead th .sort-icon {
    margin-left: 0.35rem;
    opacity: 0.4;
    font-size: 0.75rem;
}

.table thead th:hover .sort-icon {
    opacity: 0.7;
}

.table thead th.sort-active .sort-icon {
    opacity: 1;
}

/* ---------------------------------------------------------------------
   Table Body
   --------------------------------------------------------------------- */

.table tbody tr {
    transition: background-color 0.15s ease, transform 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.theme-light .table tbody tr {
    border: 1px solid var(--border-color-light);
}

.theme-light .table tbody tr td {
    border-right: 1px solid var(--border-color-light);
}

.theme-light .table tbody tr td:last-child {
    border-right: none;
}

.theme-light .table tbody tr:hover {
    background-color: rgba(13, 110, 253, 0.06);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

/* Clickable rows */
.table tbody tr.clickable {
    cursor: pointer;
}

.theme-light .table tbody tr.clickable:hover {
    background-color: rgba(13, 110, 253, 0.1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

body.theme-dark .table tbody tr.clickable:hover {
    background-color: var(--table-hover-bg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), -2px 0 0 var(--accent);
}

/* Selected row */
.theme-light .table tbody tr.selected {
    background-color: rgba(13, 110, 253, 0.12);
}

body.theme-dark .table tbody tr.selected {
    background-color: var(--table-active-bg);
    box-shadow: -3px 0 0 var(--accent);
}

/* ---------------------------------------------------------------------
   Striped Tables
   --------------------------------------------------------------------- */

.theme-light .table-striped tbody tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color-light);
}

.theme-light .table-striped tbody tr:nth-child(even):hover {
    background-color: rgba(13, 110, 253, 0.08);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.theme-light .table-striped tbody tr:nth-child(odd) {
    border: 1px solid var(--border-color-light);
}

/* ---------------------------------------------------------------------
   Bordered Tables
   --------------------------------------------------------------------- */

.table-bordered > :not(caption) > * > * {
    border: 1px solid var(--border-subtle);
}

/* ---------------------------------------------------------------------
   Borderless Tables
   --------------------------------------------------------------------- */

.table-borderless > :not(caption) > * > * {
    border-bottom-width: 0;
}

/* ---------------------------------------------------------------------
   Compact/Dense Tables
   --------------------------------------------------------------------- */

.table-sm > :not(caption) > * > * {
    padding: 0.4rem 0.5rem;
}

/* Admin area table density */
body.admin-area .table th,
body.admin-area .table td {
    padding: 0.45rem 0.65rem;
    vertical-align: middle;
    font-size: 0.85rem;
}

body.admin-area .table thead th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

/* ---------------------------------------------------------------------
   Sticky Header
   --------------------------------------------------------------------- */

.table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background-color: var(--bg-card-soft);
}

/* With offset for fixed navbar */
.table-sticky-offset thead th {
    top: 60px; /* Adjust based on navbar height */
}

/* ---------------------------------------------------------------------
   Responsive Tables
   --------------------------------------------------------------------- */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Hide scrollbars visually; content remains scrollable via wheel/touch/trackpad */
    scrollbar-width: none; /* Firefox */
}

.table-responsive::-webkit-scrollbar {
    height: 0; /* effectively hides the horizontal scrollbar track */
}

/* ---------------------------------------------------------------------
   Table Variants (Row Colors)
   --------------------------------------------------------------------- */

.table-primary {
    --bs-table-bg: rgba(13, 110, 253, 0.1);
    --bs-table-hover-bg: rgba(13, 110, 253, 0.15);
}

.table-success {
    --bs-table-bg: rgba(25, 135, 84, 0.1);
    --bs-table-hover-bg: rgba(25, 135, 84, 0.15);
}

.table-danger {
    --bs-table-bg: rgba(220, 53, 69, 0.1);
    --bs-table-hover-bg: rgba(220, 53, 69, 0.15);
}

.table-warning {
    --bs-table-bg: rgba(255, 193, 7, 0.1);
    --bs-table-hover-bg: rgba(255, 193, 7, 0.15);
}

.table-info {
    --bs-table-bg: rgba(13, 202, 240, 0.1);
    --bs-table-hover-bg: rgba(13, 202, 240, 0.15);
}

/* ---------------------------------------------------------------------
   Table Actions Column
   --------------------------------------------------------------------- */

.table .actions-cell {
    white-space: nowrap;
    text-align: right;
    width: 1%;
}

.table .actions-cell .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.table .actions-cell .btn + .btn {
    margin-left: 0.25rem;
}

/* ---------------------------------------------------------------------
   Empty State
   --------------------------------------------------------------------- */

.table-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}

.table-empty i,
.table-empty svg {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.table-empty p {
    margin: 0;
}

body.theme-dark .table-empty {
    color: var(--text-muted);
}

body.theme-dark .table-empty i,
body.theme-dark .table-empty svg {
    opacity: 0.4;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------------
   Dark Theme - Bootstrap Variable Overrides
   --------------------------------------------------------------------- */

body.theme-dark .table {
    --bs-table-bg: var(--bg-card);
    --bs-table-striped-bg: var(--bg-card-soft);
    --bs-table-hover-bg: rgba(14, 155, 255, 0.14);
    --bs-table-active-bg: rgba(14, 155, 255, 0.18);
    --bs-table-color: var(--text-main);
    --bs-table-striped-color: var(--text-main);
    --bs-table-hover-color: var(--text-main);
    --bs-table-active-color: var(--text-main);
    --bs-table-border-color: var(--border-subtle);

    color: var(--text-main);
    border-collapse: separate;
    border-spacing: 0 0.75rem;
}

body.theme-dark .table thead th {
    padding-bottom: 0.75rem;
}

body.theme-dark .table tbody tr {
    margin-bottom: 0.75rem;
}

body.theme-dark .table tbody tr td {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}

body.theme-dark .table tbody tr {
    border-radius: 0.5rem;
    overflow: hidden;
}

body.theme-dark .table tbody tr td:first-child {
    border-top-left-radius: 0.5rem;
    border-bottom-left-radius: 0.5rem;
}

body.theme-dark .table tbody tr td:last-child {
    border-top-right-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

body.theme-dark .table thead tr th:first-child {
    border-top-left-radius: 0.5rem;
}

body.theme-dark .table thead tr th:last-child {
    border-top-right-radius: 0.5rem;
}

body.theme-dark .table > :not(caption) > * > * {
    background-color: var(--bs-table-bg);
    color: var(--bs-table-color);
    border-color: var(--bs-table-border-color);
}

body.theme-dark .table thead th {
    background-color: var(--bg-card-soft);
    color: var(--text-inverse);
    border-bottom-color: var(--border-subtle);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

body.theme-dark .table tbody tr {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 0.5rem;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

body.theme-dark .table tbody tr:last-child {
    border-bottom: 1px solid var(--border-subtle);
}

body.theme-dark .table tbody tr td {
    border: none;
    border-right: 1px solid var(--border-subtle);
}

body.theme-dark .table tbody tr td:last-child {
    border-right: none;
}

body.theme-dark .table tbody tr:nth-child(even) {
    background-color: var(--bg-card-soft);
}

body.theme-dark .table tbody tr:hover {
    background-color: var(--table-hover-bg);
    transform: translateX(2px) translateY(-1px);
    box-shadow: -2px 0 0 var(--accent), 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.theme-dark .table tbody tr.clickable:hover {
    background-color: var(--table-hover-bg);
    cursor: pointer;
}

body.theme-dark .table tbody tr.selected {
    background-color: var(--table-active-bg);
    box-shadow: -3px 0 0 var(--accent);
}

body.theme-dark .table tbody td {
    color: var(--text-main);
    border-color: var(--border-subtle);
    padding: 0.75rem;
}

body.theme-dark .table tbody td strong,
body.theme-dark .table tbody td b {
    color: var(--text-inverse);
    font-weight: 600;
}

body.theme-dark .table a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s ease;
}

body.theme-dark .table a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Dark theme sortable headers */
body.theme-dark .table thead th[data-sort]:hover,
body.theme-dark .table thead th.sortable:hover {
    background-color: var(--accent-soft);
    color: var(--accent);
}

body.theme-dark .table thead th.sort-active {
    background-color: var(--accent-soft);
    color: var(--accent);
    border-bottom-color: var(--accent);
}

body.theme-dark .table thead th.sort-active i,
body.theme-dark .table thead th.sort-active svg {
    color: var(--accent);
}

/* Dark theme sticky header */
body.theme-dark .table-sticky thead th {
    background-color: var(--bg-card-soft);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    border-bottom: 2px solid var(--accent);
}

body.theme-dark .table-bordered {
    border: none;
    border-spacing: 0 0.5rem;
}

body.theme-dark .table-bordered tbody tr {
    border: 1px solid var(--border-subtle);
    border-radius: 0.5rem;
}

body.theme-dark .table-bordered tbody tr td {
    border-right: 1px solid var(--border-subtle);
}

body.theme-dark .table-bordered tbody tr td:last-child {
    border-right: none;
}

.theme-light .table-bordered {
    border: none;
    border-spacing: 0 0.5rem;
}

.theme-light .table-bordered tbody tr {
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
}

.theme-light .table-bordered tbody tr td {
    border-right: 1px solid var(--border-color);
}

.theme-light .table-bordered tbody tr td:last-child {
    border-right: none;
}

/* Dark theme striped */
body.theme-dark .table-striped tbody tr:nth-child(even) {
    background-color: var(--table-stripe-bg);
    border: 1px solid var(--border-subtle);
}

body.theme-dark .table-striped tbody tr:nth-child(even):hover {
    background-color: var(--table-hover-bg);
}

body.theme-dark .table-striped tbody tr:nth-child(odd) {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
}

body.theme-dark .table-striped tbody tr:nth-child(odd):hover {
    background-color: var(--table-hover-bg);
}

/* ---------------------------------------------------------------------
   Dark Theme - Inline Forms Inside Tables
   --------------------------------------------------------------------- */

body.theme-dark .table .form-control,
body.theme-dark .table .form-select,
body.theme-dark .table .form-control-sm,
body.theme-dark .table .form-select-sm,
body.theme-dark .table .form-control-plaintext,
body.theme-dark .table input,
body.theme-dark .table select,
body.theme-dark .table textarea {
    background-color: var(--bg-card-soft);
    color: var(--text-main);
    border-color: var(--border-subtle);
}

body.theme-dark .table .form-control-plaintext {
    background-color: transparent;
    color: var(--text-main);
}

body.theme-dark .table input::placeholder,
body.theme-dark .table textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

body.theme-dark .table .form-control:focus,
body.theme-dark .table .form-select:focus,
body.theme-dark .table input:focus,
body.theme-dark .table select:focus,
body.theme-dark .table textarea:focus {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-color: var(--accent);
    box-shadow: 0 0 0 0.2rem var(--accent-soft);
}

/* ---------------------------------------------------------------------
   Dark Theme - Table Variants
   --------------------------------------------------------------------- */

body.theme-dark .table-primary {
    --bs-table-bg: rgba(13, 110, 253, 0.15);
    --bs-table-hover-bg: rgba(13, 110, 253, 0.2);
}

body.theme-dark .table-success {
    --bs-table-bg: rgba(25, 135, 84, 0.15);
    --bs-table-hover-bg: rgba(25, 135, 84, 0.2);
}

body.theme-dark .table-danger {
    --bs-table-bg: rgba(220, 53, 69, 0.15);
    --bs-table-hover-bg: rgba(220, 53, 69, 0.2);
}

body.theme-dark .table-warning {
    --bs-table-bg: rgba(255, 193, 7, 0.15);
    --bs-table-hover-bg: rgba(255, 193, 7, 0.2);
}

body.theme-dark .table-info {
    --bs-table-bg: rgba(13, 202, 240, 0.15);
    --bs-table-hover-bg: rgba(13, 202, 240, 0.2);
}

/* ---------------------------------------------------------------------
   Responsive Adjustments
   --------------------------------------------------------------------- */

@media (max-width: 768px) {
    .table > :not(caption) > * > * {
        padding: 0.5rem;
    }

    .table thead th {
        font-size: 0.8rem;
    }

    /* Hide less important columns on mobile */
    .table .d-mobile-none {
        display: none;
    }
}
