/* ==========================================================================
   SchoolERP Enterprise Responsive CSS Framework (RWD-001)
   ========================================================================== */

/* Breakpoint Variables */
:root {
  --rwd-breakpoint-mobile: 767.98px;
  --rwd-breakpoint-tablet: 991.98px;
  --rwd-touch-target: 44px;
}

/* Touch Friendly Targets */
button, 
.btn, 
.nav-link, 
.dropdown-item, 
.form-control, 
.form-select,
.page-link {
  min-height: var(--rwd-touch-target);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn {
  padding: 0.375rem 1rem;
}
.form-control, .form-select {
  padding: 0.375rem 0.75rem;
}

/* Typography Scales for Mobile */
@media (max-width: 767.98px) {
  body {
    font-size: 0.875rem !important;
  }
  h1, .h1 { font-size: 1.5rem !important; }
  h2, .h2 { font-size: 1.25rem !important; }
  h3, .h3 { font-size: 1.15rem !important; }
  h4, .h4 { font-size: 1.05rem !important; }
  h5, .h5 { font-size: 0.95rem !important; }
  h6, .h6 { font-size: 0.85rem !important; }
}

/* ==========================================================================
   Sidebar Drawer for Tablet & Mobile (<=991px)
   ========================================================================== */
@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: -280px !important;
    width: 280px !important;
    z-index: 1040 !important;
    transition: transform 0.3s ease-in-out, left 0.3s ease-in-out !important;
    background-color: var(--erp-sidebar-start, #0f172a) !important;
  }

  body.sidebar-open .app-sidebar,
  body.erp-drawer-open .app-sidebar {
    left: 0 !important;
    transform: none !important;
  }

  .app-main, .app-footer, .app-header {
    margin-left: 0 !important;
    width: 100% !important;
  }

  /* Overlay Background for Drawer */
  .erp-drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 1030;
    backdrop-filter: blur(2px);
  }

  body.erp-drawer-open .erp-drawer-overlay,
  body.sidebar-open .erp-drawer-overlay {
    display: block !important;
  }
}

/* ==========================================================================
   RSC-006 – Desktop Sticky Sidebar Fix (≥992px)
   Two fixes for position:sticky on the sidebar grid item:
   1. align-self:start prevents the sidebar from stretching to full grid
      height (grid default is align-items:stretch), giving sticky room
   2. overflow-x:clip on html/body (below) prevents the browser from
      creating a new scroll container that breaks sticky
   ========================================================================== */
@media (min-width: 992px) {
  .sidebar-expand-lg.layout-fixed .app-sidebar {
    align-self: start;
  }
}

/* ==========================================================================
   Responsive Tables
   ========================================================================== */
.rwd-table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
  border: 1px solid var(--erp-border, #e6edf5);
  border-radius: 8px;
  background-color: var(--erp-surface, #ffffff);
}

.rwd-table-wrapper table {
  margin-bottom: 0 !important;
}

/* Column Priorities */
@media (max-width: 991.98px) {
  .priority-3 {
    display: none !important;
  }
}

@media (max-width: 767.98px) {
  .priority-2 {
    display: none !important;
  }
}

/* ==========================================================================
   Responsive Form Grid & Elements
   ========================================================================== */
.rwd-form-row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -0.75rem;
  margin-left: -0.75rem;
}

.rwd-form-col {
  flex: 0 0 100%;
  max-width: 100%;
  padding-right: 0.75rem;
  padding-left: 0.75rem;
  margin-bottom: 1rem;
}

@media (min-width: 768px) {
  .rwd-form-col-md-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }
  .rwd-form-col-md-4 {
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
  }
}

@media (min-width: 1200px) {
  .rwd-form-col-lg-3 {
    flex: 0 0 25%;
    max-width: 25%;
  }
  .rwd-form-col-lg-4 {
    flex: 0 0 33.333333%;
    max-width: 33.333333%;
  }
  .rwd-form-col-lg-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }
}

.form-label {
  font-weight: 600;
  margin-bottom: 0.35rem !important;
}

/* ==========================================================================
   Sticky Bottom Actions
   ========================================================================== */
.rwd-sticky-actions {
  position: sticky;
  bottom: 0;
  background-color: var(--erp-surface, #ffffff);
  border-top: 1px solid var(--erp-border, #e6edf5);
  padding: 1rem;
  margin-left: -1.25rem;
  margin-right: -1.25rem;
  margin-bottom: -1.25rem;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

@media (max-width: 767.98px) {
  .rwd-sticky-actions {
    flex-direction: column;
    padding: 0.75rem;
  }
  .rwd-sticky-actions .btn {
    width: 100%;
  }
}

/* ==========================================================================
   Responsive Cards
   ========================================================================== */
.rwd-card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 768px) {
  .rwd-card-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  .rwd-card-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1200px) {
  .rwd-card-grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Card Body padding adjust on small mobile */
@media (max-width: 575.98px) {
  .card-body {
    padding: 0.75rem !important;
  }
}

/* ==========================================================================
   Toolbars & Buttons
   ========================================================================== */
.rwd-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

@media (max-width: 767.98px) {
  .rwd-toolbar {
    flex-direction: column;
    width: 100%;
  }
  .rwd-toolbar .btn, 
  .rwd-toolbar .form-control,
  .rwd-toolbar .form-select {
    width: 100% !important;
  }
}

/* ==========================================================================
   Responsive Filter Panels (Accordion on mobile)
   ========================================================================== */
.rwd-filter-panel {
  border: 1px solid var(--erp-border, #e6edf5);
  border-radius: 8px;
  background-color: var(--erp-surface, #ffffff);
  padding: 1rem;
  margin-bottom: 1rem;
}

.rwd-filter-toggle {
  display: none;
}

@media (max-width: 767.98px) {
  .rwd-filter-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--erp-border, #e6edf5);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
  }
  
  .rwd-filter-content {
    display: none;
    padding-top: 1rem;
  }
  
  .rwd-filter-content.show {
    display: block;
  }
}

/* ==========================================================================
   Responsive Modals
   ========================================================================== */
@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem) !important;
  }
  .modal-footer {
    flex-direction: column;
  }
  .modal-footer .btn {
    width: 100%;
    margin: 0.25rem 0 !important;
  }
}

/* Ensure no page-level horizontal overflow.
   Uses clip instead of hidden — hidden creates a new scroll container
   on html/body which breaks position:sticky on descendant elements. */
body, html {
  overflow-x: clip !important;
}

/* Page Header responsiveness */
.erp-page-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

@media (max-width: 767.98px) {
  .erp-page-header__inner {
    flex-direction: column;
    align-items: flex-start;
  }
  .erp-page-header__actions {
    width: 100%;
    margin-left: 0 !important;
  }
  .erp-page-header__actions .btn {
    flex-grow: 1;
  }
}
