/* MISWIMS Responsive Fixes */

/* ========================================
   DTR TABLE (Daily Time Record / Hours Tracking)
   Mobile-first responsive design
   ======================================== */

/* Wrapper: clean overflow handling on all screen sizes */
.dtr-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0.35rem;
}

/* Base DTR table */
.dtr-table {
  width: 100%;
  margin-bottom: 0;
  border-collapse: separate;
  border-spacing: 0;
}

.dtr-table thead th {
  background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  text-align: center;
  vertical-align: middle;
  padding: 0.65rem 0.5rem;
  border: 1px solid #224abe;
  white-space: nowrap;
}

.dtr-table tbody td {
  vertical-align: middle;
  padding: 0.55rem 0.5rem;
  font-size: 0.85rem;
  border: 1px solid #e3e6f0;
}

.dtr-table tbody tr:nth-of-type(even) td { background-color: #fbfcfe; }
.dtr-table tbody tr:hover td { background-color: #eef2ff; transition: background 0.15s ease; }

.dtr-table tbody tr.weekend-row td { background-color: #fff5f5; }
.dtr-table tbody tr.weekend-row:hover td { background-color: #ffe9e9; }

.dtr-table tr.table-success-soft td { background-color: #e8f8f0 !important; }

/* Totals footer styling */
.dtr-table tfoot.dtr-totals td {
  background: linear-gradient(135deg, #f8f9fc 0%, #eaecf4 100%);
  font-size: 0.85rem;
  padding: 0.65rem 0.75rem;
  border-top: 2px solid #4e73df;
}

/* ========================================
   TABLET (≤ 992px): compact horizontal layout
   ======================================== */
@media (max-width: 992px) {
  .dtr-table thead th { font-size: 0.72rem; padding: 0.5rem 0.35rem; }
  .dtr-table tbody td { font-size: 0.78rem; padding: 0.45rem 0.4rem; }
  .dtr-table tfoot.dtr-totals td { font-size: 0.78rem; padding: 0.55rem 0.5rem; }
}

/* ========================================
   MOBILE (≤ 768px): stacked card layout
   Each row becomes a vertical card with labels
   ======================================== */
@media (max-width: 768px) {
  .dtr-table-wrap { overflow-x: visible; }

  .dtr-table { border: none; background: transparent; }
  .dtr-table thead { display: none; }

  .dtr-table tbody tr {
    display: block;
    margin: 0 0 12px 0;
    border: 1px solid #e3e6f0;
    border-left: 4px solid #4e73df;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    overflow: hidden;
  }
  .dtr-table tbody tr.weekend-row { border-left-color: #e74a3b; }
  .dtr-table tbody tr.table-success-soft { border-left-color: #1cc88a; }

  .dtr-table tbody tr:nth-of-type(even) td,
  .dtr-table tbody tr:hover td,
  .dtr-table tbody tr.weekend-row td { background-color: transparent; }

  .dtr-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
    padding: 0.55rem 0.85rem;
    border: none;
    border-bottom: 1px solid #f1f2f7;
    font-size: 0.85rem;
    min-height: 38px;
  }
  .dtr-table tbody td:last-child { border-bottom: none; }

  .dtr-table tbody td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 40%;
    text-align: left;
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #6e707e;
    padding-right: 8px;
  }

  /* Empty state row */
  .dtr-table tbody tr:has(td[colspan]) {
    border-left: none;
    background: transparent;
    box-shadow: none;
  }
  .dtr-table tbody td[colspan] {
    display: table-cell;
    text-align: center;
    border: 1px dashed #d1d3e2;
    border-radius: 6px;
  }
  .dtr-table tbody td[colspan]::before { display: none; }

  /* Totals footer: full-width banner */
  .dtr-table tfoot { display: block; margin-top: 12px; }
  .dtr-table tfoot tr {
    display: block;
    border-radius: 8px;
    margin-bottom: 8px;
    overflow: hidden;
    border: 1px solid #4e73df;
  }
  .dtr-table tfoot td {
    display: block;
    padding: 0.55rem 0.85rem;
    text-align: left;
    border: none;
    font-size: 0.8rem;
  }
  .dtr-table tfoot td:first-child {
    background: #4e73df;
    color: #fff;
    text-align: center;
    font-weight: 700;
  }

  /* Hours summary cards on mobile */
  .hours-summary .card-body { padding: 0.85rem; }
  .hours-summary .h4 { font-size: 1.1rem; }
}

/* ========================================
   SMALL MOBILE (≤ 480px): even more compact
   ======================================== */
@media (max-width: 480px) {
  .dtr-table tbody td { padding: 0.45rem 0.7rem; font-size: 0.8rem; min-height: 34px; }
  .dtr-table tbody td[data-label]::before { font-size: 0.65rem; flex-basis: 42%; }
  .hours-summary .col-md-6 { flex: 0 0 100%; max-width: 100%; }
}

/* ========================================
   GENERIC TABLES & LAYOUT
   ======================================== */
@media (max-width: 768px) {
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table:not(.dtr-table) { min-width: 500px; }
  .table-sm th, .table-sm td { font-size: 0.8rem; padding: 0.35rem; }

  .container-fluid { padding-left: 12px; padding-right: 12px; }

  /* Stack summary cards vertically */
  .col-xl-3.col-md-6 { flex: 0 0 50%; max-width: 50%; }

  /* Full-width buttons on mobile */
  .btn-sm { font-size: 0.75rem; padding: 0.25rem 0.5rem; }
  .d-sm-flex { flex-direction: column; }
  .d-sm-flex .btn { margin-top: 8px; }

  /* SweetAlert modal width */
  .swal2-popup { width: 95% !important; max-width: 95% !important; }
  .swal2-popup .table { min-width: auto; font-size: 0.75rem; }

  /* Card header text */
  .card-header h6 { font-size: 0.85rem; }

  /* Topbar adjustments */
  .topbar .d-none.d-lg-inline { display: none !important; }

  /* Profile page avatars */
  .img-profile { width: 32px !important; height: 32px !important; }
}

@media (max-width: 576px) {
  .col-xl-3.col-md-6 { flex: 0 0 100%; max-width: 100%; }

  .h3 { font-size: 1.2rem; }

  /* Reduce card padding */
  .card-body { padding: 0.8rem; }
  .py-2 { padding-top: 0.35rem !important; padding-bottom: 0.35rem !important; }

  /* Attendance quick action stacking */
  .card-body.d-flex { flex-wrap: wrap; }
  .card-body.d-flex .btn { margin-bottom: 4px; }
  .card-body.d-flex .mr-3 { margin-right: 0.5rem !important; }

  /* Sidebar brand text */
  .sidebar-brand-text { font-size: 0.85rem; }
}

/* Print-friendly: hide sidebar and topbar */
@media print {
  .sidebar, .topbar, .sticky-footer, .btn, #darkModeToggle { display: none !important; }
  #content-wrapper { margin-left: 0 !important; }
  #content { padding: 0 !important; }
  .card { border: none !important; box-shadow: none !important; }
  .card-header { background: none !important; }

  /* Force DTR table back to tabular layout for print, even on small screens */
  .dtr-table { display: table !important; }
  .dtr-table thead { display: table-header-group !important; }
  .dtr-table tbody { display: table-row-group !important; }
  .dtr-table tfoot { display: table-footer-group !important; }
  .dtr-table tr { display: table-row !important; border: none !important; box-shadow: none !important; }
  .dtr-table td, .dtr-table th {
    display: table-cell !important;
    border: 1px solid #888 !important;
    padding: 4px 6px !important;
    font-size: 9pt !important;
    text-align: left !important;
  }
  .dtr-table td[data-label]::before { display: none !important; }
}
