/* ==========================================================================
   BQIP-SEZ MIS — Responsive Rules
   Breakpoints (Bootstrap 5 aligned)
     xxl : >= 1400px
     xl  : >= 1200px
     lg  : >= 992px
     md  : >= 768px
     sm  : >= 576px
     xs  : <  576px
   ========================================================================== */

/* --------------------------------------------------------------------------
   Large desktop (<= 1600px) — tighten spacing
   -------------------------------------------------------------------------- */
@media (max-width: 1600px) {
  .page-content { padding: 20px 20px 8px; }
  .kpi-value { font-size: 24px; }
  .topbar-search { width: 250px; }
}

/* --------------------------------------------------------------------------
   Desktop / small laptop (<= 1400px)
   -------------------------------------------------------------------------- */
@media (max-width: 1400px) {
  :root { --sidebar-w: 258px; }
  .kpi-value { font-size: 22.5px; }
  .kpi-icon { width: 38px; height: 38px; flex-basis: 38px; font-size: 17px; }
  .auth-visual { padding: 38px 40px; }
  .auth-form-panel { flex-basis: 460px; max-width: 460px; padding: 36px 42px; }
  .auth-hero h2 { font-size: 29px; }
}

/* --------------------------------------------------------------------------
   Tablet landscape (<= 1200px)
   -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .page-content { padding: 18px 18px 8px; }
  .topbar-search { width: 210px; }
  .topbar-search kbd { display: none; }
  .topbar-search input { padding-right: 14px; }

  .kpi-value { font-size: 21px; }
  .kpi-spark { width: 66px; height: 26px; }

  .auth-visual { padding: 32px 32px; }
  .auth-form-panel { flex-basis: 430px; max-width: 430px; padding: 32px 34px; }
  .auth-hero h2 { font-size: 26px; }
  .auth-hero p { font-size: 13.5px; }
  .auth-stats { gap: 24px; }
  .auth-stats .as-item .as-val { font-size: 21px; }
}

/* --------------------------------------------------------------------------
   Tablet portrait / small laptop (<= 991.98px)
   Sidebar becomes an offcanvas drawer.
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
  :root { --topbar-h: 62px; }

  .sidebar {
    width: 282px;
    transform: translateX(-100%);
    box-shadow: none;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 26px rgba(7, 26, 51, .35);
  }
  /* Collapsed mode is a desktop-only concept — ignore it here */
  body.sidebar-collapsed .sidebar { width: 282px; }
  body.sidebar-collapsed .sidebar-nav .nav-label,
  body.sidebar-collapsed .sidebar-nav .nav-caret,
  body.sidebar-collapsed .sidebar-nav .nav-count,
  body.sidebar-collapsed .sidebar-user .su-meta,
  body.sidebar-collapsed .sidebar-user .su-logout-text { display: block; }
  body.sidebar-collapsed .sidebar-nav .submenu { display: block; }
  body.sidebar-collapsed .sidebar-nav .nav-link { justify-content: flex-start; padding: 9px 12px; }
  body.sidebar-collapsed .sidebar-brand .brand-text { display: block; }
  body.sidebar-collapsed .sidebar-brand { padding: 0 18px; }
  body.sidebar-collapsed .sidebar-user .su-inner { justify-content: flex-start; }
  body.sidebar-collapsed .sidebar-user .su-logout { padding: 8px; }
  body.sidebar-collapsed .nav-section-title { opacity: 1; height: auto; padding: 16px 12px 7px; }
  body.sidebar-collapsed .sidebar-nav .nav-item:hover > .nav-link::after { content: none; }

  .app-main,
  body.sidebar-collapsed .app-main { margin-left: 0; }

  .page-content { padding: 16px 16px 8px; }

  /* Offcanvas submenus: keep everything expanded for easy tapping */
  .sidebar-nav .submenu { padding-left: 12px; }

  /* Topbar compaction */
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-search { display: none; }
  .topbar-icon.messages-btn { display: none; }

  .page-heading h1 { font-size: 15.5px; }
  .breadcrumb-mis { display: none; }

  /* Stacked chart heights */
  .chart-holder.h-lg { height: 300px; }

  /* Auth becomes single column */
  .auth-page { flex-direction: column; }
  .auth-visual {
    flex: 0 0 auto;
    padding: 26px 24px 30px;
    min-height: auto;
  }
  .auth-visual::after { height: 120px; }
  .auth-hero { margin: 26px 0 0; padding: 0; }
  .auth-hero h2 { font-size: 24px; margin-bottom: 10px; }
  .auth-hero p { font-size: 13.4px; margin-bottom: 18px; }
  .auth-features { display: none; }
  .auth-visual .auth-security { display: none; }
  .auth-stats { gap: 22px; }
  .auth-stats .as-item .as-val { font-size: 19px; }
  .auth-stats .as-item .as-lbl { font-size: 10.5px; }

  .auth-form-panel {
    flex: 1 1 auto;
    max-width: 100%;
    padding: 30px 24px 26px;
    border-radius: 20px 20px 0 0;
    margin-top: -18px;
    position: relative;
    z-index: 3;
    box-shadow: 0 -8px 24px rgba(7, 26, 51, .12);
  }
  .auth-form-wrap { max-width: 460px; margin-top: 0; }
  .auth-mobile-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
  .auth-mobile-brand .amb-mark {
    width: 42px; height: 42px; border-radius: 12px;
    background: linear-gradient(140deg, var(--mis-blue-500), var(--mis-navy-600));
    color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px;
  }
  .auth-mobile-brand .amb-t1 { font-size: 14.5px; font-weight: 700; color: var(--mis-text); line-height: 1.2; }
  .auth-mobile-brand .amb-t2 { font-size: 10.5px; color: var(--mis-text-faint); text-transform: uppercase; letter-spacing: .7px; font-weight: 600; }
}

/* --------------------------------------------------------------------------
   Mobile landscape (<= 767.98px)
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
  .page-content { padding: 14px 12px 6px; }
  .topbar { padding: 0 10px; gap: 6px; height: 58px; }
  :root { --topbar-h: 58px; }

  .topbar-icon { width: 36px; height: 36px; font-size: 16px; }
  .topbar-toggle { width: 36px; height: 36px; flex-basis: 36px; font-size: 16px; }
  .topbar-divider { display: none; }
  .profile-chip .pc-meta { display: none; }
  .profile-chip { padding: 3px; border-radius: 50%; }

  .page-heading h1 { font-size: 14.5px; }

  /* KPI cards: 2-up then 1-up */
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 20px; letter-spacing: -.5px; }
  .kpi-icon { width: 36px; height: 36px; flex-basis: 36px; font-size: 16px; border-radius: 9px; }
  .kpi-spark { width: 58px; height: 24px; }
  .kpi-label { font-size: 10.5px; }
  .kpi-desc { font-size: 11px; }

  .card-body { padding: 15px; }
  .card-header { padding: 13px 15px; }
  .card-header .card-title { font-size: 13.5px; }
  .card { border-radius: var(--radius); margin-bottom: 16px; }

  .section-head { margin-bottom: 12px; }
  .section-head h2 { font-size: 14.5px; }

  .page-hero { padding: 18px; border-radius: var(--radius); }
  .page-hero h2 { font-size: 17.5px; }

  /* Tables scroll horizontally with comfortable minimum widths */
  .table-responsive-mis { border-radius: 0; }
  .table-mis { min-width: 720px; }
  .table-mis.table-narrow { min-width: 520px; }
  .table-mis thead th { padding: 9px 11px; font-size: 10.3px; }
  .table-mis tbody td { padding: 10px 11px; font-size: 12.5px; }
  .table-mis thead th:first-child, .table-mis tbody td:first-child { padding-left: 14px; }
  .table-mis thead th:last-child, .table-mis tbody td:last-child { padding-right: 14px; }
  .table-mis thead th { position: static; } /* sticky headers are janky on small screens */

  .table-pagination { padding: 11px 14px; flex-direction: column; align-items: stretch; gap: 10px; }
  .table-pagination .tp-info { text-align: center; }
  .table-pagination .pagination { justify-content: center; }

  /* Filter bar stacks */
  .filter-bar { padding: 12px; border-radius: var(--radius); }
  .filter-bar .fb-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .filter-bar .fb-field,
  .filter-bar .fb-field.fb-grow { min-width: 100%; flex: 1 1 auto; }
  .filter-bar .fb-actions { flex-direction: column; align-items: stretch; }
  .filter-bar .fb-actions .btn { width: 100%; }

  .chart-holder.h-lg { height: 260px; }
  .chart-holder.h-md { height: 240px; }
  .chart-holder.h-sm { height: 200px; }
  .chart-legend { gap: 10px; }

  .plot-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 7px; }
  .plot-map .pm-legend { position: static; margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 12px; }
  .plot-map .pm-legend .lgl { margin-bottom: 0; }

  .detail-list { grid-template-columns: 1fr; }

  .timeline { padding-left: 26px; }
  .timeline-item .tl-dot { left: -26px; width: 18px; height: 18px; }

  .workflow-steps { padding-bottom: 6px; }
  .wf-step { min-width: 106px; }
  .wf-step .wf-label { font-size: 10.8px; }

  .toast-stack { top: auto; bottom: 14px; right: 12px; left: 12px; width: auto; }

  .modal-body { padding: 16px; }
  .modal-header, .modal-footer { padding: 13px 16px; }
  .modal-dialog { margin: 8px; }

  .app-footer { padding: 14px; flex-direction: column; text-align: center; gap: 9px; }
  .app-footer .af-links { justify-content: center; }

  .report-card { padding: 15px; }
  .report-card .rc-actions { gap: 6px; }
  .report-card .rc-actions .btn { flex: 1 1 auto; }
}

/* --------------------------------------------------------------------------
   Small mobile (<= 575.98px)
   -------------------------------------------------------------------------- */
@media (max-width: 575.98px) {
  .kpi-value { font-size: 18.5px; }
  .kpi-spark { display: none; }
  .kpi-foot { margin-top: 8px; }

  .stat-strip { padding: 11px 13px; gap: 11px; }
  .stat-strip .ss-icon { width: 34px; height: 34px; flex-basis: 34px; font-size: 15px; }
  .stat-strip .ss-value { font-size: 16.5px; }

  .summary-tile { padding: 12px; gap: 10px; }
  .summary-tile .st-icon { width: 32px; height: 32px; flex-basis: 32px; font-size: 15px; }
  .summary-tile .st-value { font-size: 17px; }

  .avatar-lg { width: 42px; height: 42px; font-size: 15px; }
  .avatar-xl { width: 62px; height: 62px; font-size: 21px; }

  .btn { padding: 7px 13px; font-size: 12.5px; }
  .btn-sm { padding: 5px 9px; font-size: 11.8px; }
  .btn-icon { width: 28px; height: 28px; font-size: 12.5px; }

  .nav-tabs-mis .nav-link { padding: 10px 12px; font-size: 12.2px; }

  .donut-center .dc-value { font-size: 19px; }
  .donut-center .dc-label { font-size: 9.5px; }

  .auth-visual { padding: 22px 18px 26px; }
  .auth-hero h2 { font-size: 21px; }
  .auth-stats { gap: 18px; }
  .auth-stats .as-item .as-val { font-size: 17px; }
  .auth-form-panel { padding: 24px 18px 22px; }
  .auth-form-head h1 { font-size: 20px; }
  .auth-input-group .form-control { height: 44px; font-size: 13.2px; }
}

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */
@media print {
  .sidebar, .topbar, .app-footer, .toast-stack, .filter-bar,
  .table-pagination, .btn, .chip-group { display: none !important; }
  .app-main, body.sidebar-collapsed .app-main { margin-left: 0 !important; }
  .page-content { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  body { background: #fff; font-size: 11pt; }
  .table-mis { min-width: 0 !important; }
  a[href]::after { content: none !important; }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .kpi-card:hover, .report-card:hover, .plot-tile:hover, .hover-lift:hover { transform: none !important; }
}

/* --------------------------------------------------------------------------
   High-contrast / forced colours fallback
   -------------------------------------------------------------------------- */
@media (forced-colors: active) {
  .sidebar { border-right: 1px solid CanvasText; }
  .kpi-card, .card, .report-card { border: 1px solid CanvasText; }
}
