/* ==========================================================================
   Abhyas Online — Main Website Table Enhancements (main-tables.css)
   Mobile-only Vertical/Horizontal view switcher, Jump to First/Last controls,
   record-count toolbar, and responsive card layout with scroll containment.
   ========================================================================== */

/* ---------- Scrollable Table Wrapper & Overflow Shadow Hint ---------- */
.ac-table-wrap {
  clear: both;
  width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--slate-200, #E2E8F0);
  border-radius: 10px;
  background: var(--white, #FFFFFF);
  margin-bottom: 14px;
  position: relative;
}

.ac-table-wrap table {
  margin-bottom: 0 !important;
  width: 100%;
  border-collapse: collapse;
}

/* Reset Bootstrap 3 .table-responsive when placed directly on <table> inside .ac-table-wrap */
.ac-table-wrap table.table-responsive {
  display: table;
  width: 100%;
  margin-bottom: 0 !important;
  border: none;
}

.ac-table-wrap.is-scrollable {
  box-shadow: inset -12px 0 14px -10px rgba(15, 23, 42, 0.14);
}

.ac-table-wrap.is-scrollable::after {
  content: '';
  position: sticky;
  right: 0;
  top: 0;
  bottom: 0;
  width: 18px;
  float: right;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(15, 23, 42, 0.08));
  transition: opacity 0.2s ease;
}

.ac-table-wrap.scrolled-end,
.ac-table-wrap.scrolled-end::after {
  box-shadow: none;
  opacity: 0;
}

/* Scroll containment for wide non-tabular document tables (papers, e-notes) */
.ac-doc-table-scroll {
  clear: both;
  width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 14px;
}

.ac-doc-table-scroll > table {
  margin-bottom: 0 !important;
}

/* ---------- Top Toolbar: Showing X records + Mobile Switcher + Jump to Last ---------- */
.ac-table-toolbar {
  clear: both;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.ac-table-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--slate-50, #F8FAFC);
  border: 1px solid var(--slate-200, #E2E8F0);
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--slate-600, #475569);
  line-height: 1.3;
}

.ac-table-count strong {
  color: var(--slate-900, #0F172A);
  font-weight: 700;
}

.ac-table-toolbar-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

/* ---------- Mobile-Only Vertical / Horizontal Switcher ---------- */
.ac-table-view-switch {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--slate-50, #F8FAFC);
  border: 1px solid var(--slate-200, #E2E8F0);
  border-radius: 8px;
  padding: 3px 6px;
}

.ac-view-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--slate-600, #475569);
  margin: 0 2px;
}

.ac-view-radio {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  margin: 0;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-700, #334155);
  cursor: pointer;
  user-select: none;
  transition: background-color 150ms ease, color 150ms ease;
}

.ac-view-radio input[type="radio"] {
  margin: 0;
  width: 14px;
  height: 14px;
  accent-color: var(--blue, #0068B6);
  cursor: pointer;
}

.ac-view-radio.is-active {
  background: var(--blue, #0068B6);
  color: #FFFFFF;
}

.ac-view-radio.is-active input[type="radio"] {
  accent-color: #FFFFFF;
}

.ac-view-radio:focus-within {
  outline: 2px solid var(--blue, #0068B6);
  outline-offset: 1px;
}

/* ---------- Bottom Footer & Jump to First / Jump to Last Buttons ---------- */
.ac-table-footer {
  clear: both;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 16px;
}

.ac-table-footer:empty {
  display: none;
}

.ac-table-toolbar .ac-jump-last-btn,
button.ac-jump-last-btn,
.ac-table-footer .ac-jump-first-btn,
button.ac-jump-first-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 32px;
  padding: 5px 12px !important;
  margin: 0 !important;
  height: auto !important;
  line-height: 1.3 !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  border-radius: 6px !important;
  background: var(--white, #FFFFFF) !important;
  color: var(--slate-700, #334155) !important;
  border: 1px solid #CBD5E1 !important;
  box-shadow: none !important;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, transform 100ms ease;
}

.ac-table-toolbar .ac-jump-last-btn:hover,
button.ac-jump-last-btn:hover,
.ac-table-footer .ac-jump-first-btn:hover,
button.ac-jump-first-btn:hover {
  border-color: var(--blue, #0068B6) !important;
  color: var(--blue, #0068B6) !important;
  background: var(--blue-light, #EFF6FF) !important;
}

.ac-table-toolbar .ac-jump-last-btn:focus-visible,
button.ac-jump-last-btn:focus-visible,
.ac-table-footer .ac-jump-first-btn:focus-visible,
button.ac-jump-first-btn:focus-visible {
  outline: 2px solid var(--blue, #0068B6);
  outline-offset: 2px;
}

.ac-table-toolbar .ac-jump-last-btn:focus:not(:focus-visible),
button.ac-jump-last-btn:focus:not(:focus-visible),
.ac-table-footer .ac-jump-first-btn:focus:not(:focus-visible),
button.ac-jump-first-btn:focus:not(:focus-visible) {
  outline: none !important;
}

.ac-table-toolbar .ac-jump-last-btn:active,
button.ac-jump-last-btn:active,
.ac-table-footer .ac-jump-first-btn:active,
button.ac-jump-first-btn:active {
  transform: scale(0.98);
}

/* ---------- Desktop Table Polish Inside .ac-table-wrap ---------- */
.ac-table-wrap table.ac-card-table > thead th {
  background: var(--slate-50, #F8FAFC);
  color: var(--slate-700, #334155);
  border-bottom: 2px solid var(--slate-200, #E2E8F0);
  vertical-align: middle;
}

.ac-table-wrap table.ac-card-table > tbody td {
  vertical-align: middle;
}

/* ---------- Mobile View Modes (<= 768px) ---------- */
@media (max-width: 768px) {
  .ac-table-view-switch {
    display: inline-flex;
  }

  .ac-table-wrap table.ac-card-table {
    font-size: 14px;
  }

  /* Vertical Card View (default) */
  body:not(.ac-mobile-table-horizontal) .ac-table-wrap,
  body:not(.ac-mobile-table-horizontal) div.table-responsive {
    overflow-x: visible !important;
    border: none;
    background: transparent;
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table,
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    border: none !important;
    background: transparent !important;
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody,
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table > tbody {
    display: block !important;
    width: 100% !important;
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > thead,
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table > thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr,
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table > tbody > tr {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box;
    border: 1px solid var(--slate-200, #E2E8F0);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 4px 0;
    background: var(--white, #FFFFFF);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr:not([style*="background"]):not([bgcolor]):not(.success):not(.danger):not(.warning):not(.info):not(.active),
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table > tbody > tr:not([style*="background"]):not([bgcolor]):not(.success):not(.danger):not(.warning):not(.info):not(.active) {
    background: var(--white, #FFFFFF) !important;
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr > td,
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table > tbody > tr > td {
    display: flex !important;
    align-items: flex-start;
    flex-wrap: wrap;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    padding: 8px 12px !important;
    border: none !important;
    border-bottom: 1px solid var(--slate-100, #F1F5F9) !important;
    font-size: 13.5px;
    line-height: 1.45;
    min-height: 34px;
    gap: 4px 10px;
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: left !important;
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr > td > * {
    max-width: 100%;
    white-space: normal !important;
  }

  /* Prevent Bootstrap grid cols inside table cells (e.g. register.php Total cell) from stacking or misaligning */
  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr > td > [class*="col-xs-"],
  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr > td > [class*="col-sm-"],
  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr > td > [class*="col-md-"] {
    width: auto !important;
    float: none !important;
    display: inline-flex;
    align-items: center;
    padding: 0 4px !important;
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr > td:last-child,
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table > tbody > tr > td:last-child {
    border-bottom: none !important;
  }

  /* Uppercase left-hand field label on light rows (never inherit white text on register.php white rows) */
  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr > td::before,
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table > tbody > tr > td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    min-width: 88px;
    max-width: 38%;
    font-size: 11px;
    font-weight: 700;
    color: var(--slate-500, #64748B);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding-top: 2px;
    white-space: normal;
    overflow-wrap: break-word;
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr > td[data-label=""]::before,
  body:not(.ac-mobile-table-horizontal) .ac-table-wrap table.ac-card-table > tbody > tr > td:not([data-label])::before,
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table > tbody > tr > td[data-label=""]::before,
  body:not(.ac-mobile-table-horizontal) .table-responsive table.ac-card-table > tbody > tr > td:not([data-label])::before {
    display: none;
  }

  body:not(.ac-mobile-table-horizontal) .ac-table-wrap.is-scrollable,
  body:not(.ac-mobile-table-horizontal) .ac-table-wrap.is-scrollable::after {
    box-shadow: none;
    display: none;
  }

  /* Horizontal Table View */
  body.ac-mobile-table-horizontal .ac-table-wrap,
  body.ac-mobile-table-horizontal div.table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  body.ac-mobile-table-horizontal .ac-table-wrap table.ac-card-table,
  body.ac-mobile-table-horizontal .table-responsive table.ac-card-table {
    display: table !important;
    min-width: 560px;
    width: max-content;
    border-collapse: collapse !important;
  }

  body.ac-mobile-table-horizontal .ac-table-wrap table.ac-card-table > thead,
  body.ac-mobile-table-horizontal .table-responsive table.ac-card-table > thead {
    display: table-header-group !important;
    position: static !important;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
  }

  body.ac-mobile-table-horizontal .ac-table-wrap table.ac-card-table > tbody,
  body.ac-mobile-table-horizontal .table-responsive table.ac-card-table > tbody {
    display: table-row-group !important;
  }

  body.ac-mobile-table-horizontal .ac-table-wrap table.ac-card-table > thead > tr,
  body.ac-mobile-table-horizontal .ac-table-wrap table.ac-card-table > tbody > tr,
  body.ac-mobile-table-horizontal .table-responsive table.ac-card-table > thead > tr,
  body.ac-mobile-table-horizontal .table-responsive table.ac-card-table > tbody > tr {
    display: table-row !important;
  }

  body.ac-mobile-table-horizontal .ac-table-wrap table.ac-card-table > thead th,
  body.ac-mobile-table-horizontal .ac-table-wrap table.ac-card-table > tbody td,
  body.ac-mobile-table-horizontal .table-responsive table.ac-card-table > thead th,
  body.ac-mobile-table-horizontal .table-responsive table.ac-card-table > tbody td {
    display: table-cell !important;
    white-space: nowrap;
  }

  body.ac-mobile-table-horizontal .ac-table-wrap table.ac-card-table > tbody td::before,
  body.ac-mobile-table-horizontal .table-responsive table.ac-card-table > tbody td::before {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ac-view-radio,
  .ac-table-toolbar .ac-jump-last-btn,
  button.ac-jump-last-btn,
  .ac-table-footer .ac-jump-first-btn,
  button.ac-jump-first-btn,
  .ac-table-wrap.is-scrollable::after {
    transition: none !important;
  }
  .ac-table-toolbar .ac-jump-last-btn:active,
  button.ac-jump-last-btn:active,
  .ac-table-footer .ac-jump-first-btn:active,
  button.ac-jump-first-btn:active {
    transform: none !important;
  }
}
