/**
 * EMS — global responsive layer (all roles, all modules).
 * Desktop (≥992px) layout is unchanged; rules apply below Bootstrap lg breakpoint.
 */

/* ── Safe viewport & overflow ── */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@media (max-width: 991.98px) {
  body.ems-body {
    overflow-x: hidden;
  }

  .content-area {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
    overflow-x: hidden;
  }

  .main-content {
    max-width: 100vw;
  }
}

/* ── Topbar ── */
@media (max-width: 991.98px) {
  .topbar {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
  }

  .topbar h1.h5 {
    font-size: 0.95rem;
    max-width: min(52vw, 14rem);
  }

  .topbar .btn-sm {
    padding: 0.35rem 0.55rem;
  }
}

@media (max-width: 575.98px) {
  .topbar .notif-dropdown {
    min-width: min(100vw - 1.5rem, 320px) !important;
  }
}

/* ── Touch-friendly controls ── */
@media (max-width: 991.98px) {
  .content-area .btn:not(.btn-link):not(.btn-close),
  .content-area .form-control,
  .content-area .form-select {
    min-height: 2.5rem;
  }

  .content-area .btn-sm {
    min-height: 2.25rem;
  }

  .sidebar-link {
    min-height: 2.75rem;
    display: flex;
    align-items: center;
  }
}

/* ── Cards & spacing ── */
@media (max-width: 991.98px) {
  .content-area .card {
    border-radius: 0.65rem;
  }

  .content-area .card-header,
  .content-area .card-body {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .content-area .d-flex.justify-content-between.align-items-center.mb-3,
  .content-area .d-flex.flex-wrap.justify-content-between.mb-3 {
    gap: 0.65rem;
  }
}

/* ── Tables (all modules) ── */
@media (max-width: 991.98px) {
  .content-area .table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .content-area .card:has(> .table),
  .content-area .card:has(> .table-responsive),
  .content-area .card-body:has(> .table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .content-area table.table {
    font-size: 0.8125rem;
  }

  .content-area table.table th,
  .content-area table.table td {
    white-space: nowrap;
    vertical-align: middle;
  }

  .content-area table.table .text-break,
  .content-area table.table td.allow-wrap {
    white-space: normal;
  }

  .table-attendance thead th {
    position: static;
  }
}

@media (max-width: 575.98px) {
  .content-area table.table th,
  .content-area table.table td {
    padding: 0.4rem 0.45rem !important;
  }
}

/* ── Forms & filters ── */
@media (max-width: 991.98px) {
  .content-area form.row > [class*="col-"],
  .content-area .row.g-2 > [class*="col-md-"],
  .content-area .row.g-3 > [class*="col-md-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .content-area .row.g-2 > .col-6,
  .content-area .row.g-2 > .col-sm-4,
  .content-area .row.g-2 > .col-sm-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .content-area .input-group {
    flex-wrap: wrap;
  }

  .content-area .btn-group {
    flex-wrap: wrap;
    width: 100%;
  }

  .content-area .btn-group .btn {
    flex: 1 1 auto;
  }
}

@media (max-width: 575.98px) {
  .content-area .row.g-2 > .col-6,
  .content-area .row.g-2 > .col-sm-4,
  .content-area .row.g-2 > .col-sm-6 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* ── Stat cards (employees, reports, attendance) ── */
@media (max-width: 991.98px) {
  .stat-card-grid {
    gap: 0.55rem;
  }

  .stat-card .stat-value {
    font-size: 1.45rem;
  }
}

/* Override inline grid on attendance summary */
@media (max-width: 767.98px) {
  .ems-attendance .stat-grid-att {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 479.98px) {
  .ems-attendance .stat-grid-att {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* ── Attendance calendar ── */
@media (max-width: 575.98px) {
  .ems-attendance .cal-day {
    min-height: 2.35rem;
    font-size: 0.65rem;
  }

  .ems-attendance .cal-day-tag {
    font-size: 0.5rem;
  }

  .ems-attendance .cal-legbar {
    font-size: 0.58rem;
    gap: 0.25rem 0.5rem;
  }
}

/* ── Modals ── */
@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  .modal-dialog.modal-sm {
    max-width: calc(100% - 1rem);
  }

  .modal-body {
    padding: 0.85rem;
  }
}

/* ── Charts (dashboard & reports) ── */
@media (max-width: 991.98px) {
  .content-area canvas {
    max-width: 100% !important;
    height: auto !important;
  }

  .att-chart-card {
    min-height: 200px;
  }

  .att-chart-card canvas {
    max-height: 180px !important;
  }
}

/* ── Admin / HR dashboard (mgmt) ── */
@media (max-width: 991.98px) {
  .hrms-dash--mgmt {
    max-width: 100%;
    overflow-x: hidden;
  }

  .hrms-dash--mgmt .hrms-top-row {
    grid-template-columns: 1fr;
  }

  .hrms-dash--mgmt .hrms-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hrms-dash--mgmt .hrms-chart-grid {
    grid-template-columns: 1fr;
  }

  .hrms-dash--mgmt .hrms-dark-feed-scroll {
    max-height: min(300px, 45vh);
  }

  .hrms-dash--mgmt .hrms-mini-tools {
    width: 100%;
    justify-content: flex-start;
  }

  .hrms-dash--mgmt .card .table-responsive {
    max-height: min(360px, 50vh);
    overflow-y: auto;
  }
}

@media (max-width: 575.98px) {
  .hrms-dash--mgmt .hrms-kpi-grid {
    grid-template-columns: 1fr;
  }

  .hrms-dash--mgmt .hrms-kpi .v {
    font-size: 1.15rem;
  }
}

/* ── Employee dashboard (shared with dashboard-mobile.css) ── */
@media (max-width: 991.98px) {
  .hrms-dash.hrms-dash--employee {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-width: 100%;
    overflow-x: hidden;
  }

  .hrms-dash--employee .hrms-mob-order-header {
    order: 1;
  }

  .hrms-dash--employee .hrms-mob-order-clock {
    order: 2;
  }

  .hrms-dash--employee .hrms-mob-order-news {
    order: 3;
  }

  .hrms-dash--employee .hrms-mob-order-my-attendance {
    order: 1;
  }

  .hrms-dash--employee .hrms-mob-order-profile {
    order: 2;
  }

  .hrms-dash--employee .hrms-mob-order-section1 {
    display: contents;
  }

  .hrms-dash--employee .hrms-section1-title {
    display: none;
  }

  .hrms-dash--employee .hrms-top-row {
    display: contents;
  }

  .hrms-dash--employee .hrms-mob-order-section2 {
    order: 4;
    width: 100%;
  }

  .hrms-dash--employee .hrms-mob-order-rest {
    order: 6;
    width: 100%;
  }

  .hrms-dash--employee .hrms-mob-clock-wrap,
  .hrms-dash--employee .hrms-mob-news-wrap {
    width: 100%;
    min-width: 0;
  }

  .hrms-dash--employee .hrms-dark-feed-scroll {
    max-height: min(280px, 42vh);
  }

  .hrms-dash--employee .dash-att-card .hrms-mini-cal {
    display: none;
  }

  .hrms-dash--employee .dash-week-strip {
    display: none;
  }

  .hrms-emp-profile-att-row {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .hrms-emp-profile-att-row > [class*="col-"] {
    width: 100%;
    max-width: 100%;
  }

  .dash-my-attendance-scroll {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    max-height: min(300px, 48vh);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    border-radius: 0.45rem;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.6);
  }

  .dash-my-attendance-scroll .hrms-mini-table {
    margin-bottom: 0;
    min-width: 320px;
  }

  .main-content:has(.hrms-dash--employee) {
    overflow-x: hidden;
  }
}

@media (max-width: 575.98px) {
  .hrms-dash--employee .hrms-dash-page-title {
    font-size: 1rem;
  }

  .hrms-dash--employee .hrms-att-live-clock {
    font-size: 1.1rem;
  }

  .hrms-dash--employee .hrms-dash-actions .btn {
    flex: 1 1 auto;
    min-width: calc(50% - 0.35rem);
  }

  .hrms-dash--employee .hrms-dash-actions .btn.ms-sm-auto {
    margin-left: 0 !important;
    width: 100%;
  }
}

/* ── Login page ── */
@media (max-width: 991.98px) {
  .lpr-page .lpr-shell {
    flex-direction: column;
  }

  .lpr-brand {
    min-height: auto;
    padding: 1.5rem 1rem;
  }

  .lpr-form-col {
    padding: 1.25rem 1rem 2rem;
  }
}

@media (max-width: 575.98px) {
  .lpr-card {
    padding: 1.25rem 1rem;
  }

  .lpr-submit {
    min-height: 2.75rem;
  }
}

/* ── Company footer strip ── */
@media (max-width: 991.98px) {
  .company-footer-strip .col-lg-4 {
    text-align: start !important;
    margin-top: 0.5rem;
  }
}

/* ── Access / permission tables ── */
@media (max-width: 991.98px) {
  .content-area .table-responsive .form-check {
    min-height: 1.5rem;
  }
}

/* ── Utilities ── */
.ems-scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

@media (max-width: 991.98px) {
  .ems-mob-stack {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .ems-mob-full {
    width: 100% !important;
    max-width: 100% !important;
  }

  .ems-mob-hide {
    display: none !important;
  }
}

@media (min-width: 992px) {
  .ems-desk-only {
    display: block;
  }
}

@media (max-width: 991.98px) {
  .ems-desk-only {
    display: none !important;
  }
}
