/**
 * Kroykari Reseller Portal — responsive layout (phones, tablets, small laptops).
 * Loaded via styles.css on all dashboard pages.
 */

/* ── Base: prevent horizontal scroll ── */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.dashboard-page {
  overflow-x: hidden;
}

#main-content-area {
  width: calc(100% - var(--app-sidebar-width));
  max-width: 100%;
  box-sizing: border-box;
}

html.pm-no-sidebar #main-content-area,
body.pm-no-sidebar #main-content-area,
html.pharmacy-no-sidebar #main-content-area,
body.pharmacy-no-sidebar #main-content-area {
  width: 100% !important;
}

/* Mobile sidebar overlay (injected by sidebar-loader.js) */
.reseller-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1095;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.reseller-sidebar-overlay.show {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

body.reseller-sidebar-open {
  overflow: hidden;
}

.reseller-mobile-menu-btn {
  flex-shrink: 0;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0.4rem 0.55rem;
}

/* ── Small laptops (992px–1199px): slightly narrower sidebar ── */
@media (max-width: 1199.98px) {
  :root {
    --app-sidebar-width: 260px;
  }

  #header-container .reseller-header-actions .btn-sm span:not(.badge):not(.visually-hidden) {
    font-size: 0.8rem;
  }

  #main-content-area > .container-fluid {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
}

/* ── Tablets & small laptops (≤991px): drawer sidebar ── */
@media (max-width: 991.98px) {
  :root {
    --app-sidebar-width: min(300px, 88vw);
  }

  #sidebar-container,
  #pm-sidebar-container {
    width: var(--app-sidebar-width) !important;
    max-width: 88vw;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
  }

  #sidebar-container.show,
  #pm-sidebar-container.show {
    transform: translateX(0) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }

  #main-content-area,
  html.pm-module-nav #main-content-area,
  body.pm-module-nav #main-content-area,
  html.pharmacy-split-layout #main-content-area,
  body.pharmacy-split-layout #main-content-area {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  #header-container {
    margin-bottom: 1rem !important;
  }

  #header-container > .reseller-header-toolbar-wrap,
  #header-container > .d-flex {
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    align-items: center !important;
    gap: 0.5rem !important;
  }

  #header-container .reseller-header-actions {
    flex: 1 1 100%;
    justify-content: flex-end;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding: 0.35rem 0.5rem;
  }

  #header-container .reseller-header-actions > .me-3 {
    margin-right: 0.35rem !important;
    flex-shrink: 0;
  }

  /* Hide verbose labels on tablet; keep icons */
  #subscriptionExpiryWrap {
    display: none !important;
  }

  #header-container .reseller-header-actions a.btn span,
  #header-container .reseller-header-actions button.btn span {
    display: none;
  }

  #header-container .reseller-header-actions a.btn .me-1,
  #header-container .reseller-header-actions button.btn .me-1,
  #header-container .reseller-header-actions a.btn .ms-1,
  #header-container .reseller-header-actions button.btn .ms-1 {
    margin: 0 !important;
  }

  #header-container .reseller-header-profile-btn .profile-name {
    max-width: 5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .table-responsive {
    -webkit-overflow-scrolling: touch;
  }

  .row > [class*="col-lg-"],
  .row > [class*="col-xl-"] {
    margin-bottom: 0.75rem;
  }
}

/* ── Phones (≤767px) ── */
@media (max-width: 767.98px) {
  :root {
    --app-sidebar-width: min(280px, 92vw);
  }

  #main-content-area > .container-fluid {
    padding-left: 0.65rem !important;
    padding-right: 0.65rem !important;
    padding-bottom: 0.75rem !important;
  }

  #header-container .reseller-header-actions {
    gap: 0.25rem !important;
    border-radius: 0.5rem;
  }

  #header-container .reseller-header-icon-btn,
  #header-container .reseller-header-actions .btn-sm {
    min-width: 2.35rem;
    min-height: 2.35rem;
    padding: 0.35rem 0.45rem;
  }

  /* Language dropdown: icon only */
  #languageDropdown span#languageCode {
    display: none;
  }

  #languageDropdown .fa-globe {
    margin-right: 0 !important;
  }

  #languageDropdown.dropdown-toggle::after {
    display: none;
  }

  .card-body {
    padding: 0.85rem;
  }

  .card-header {
    padding: 0.65rem 0.85rem;
  }

  h1, .h1 {
    font-size: 1.35rem;
  }

  h2, .h2 {
    font-size: 1.2rem;
  }

  .btn-group {
    flex-wrap: wrap;
  }

  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  .dropdown-menu {
    max-width: min(100vw - 1.5rem, 350px);
  }

  #notificationDropdown {
    width: min(100vw - 1.5rem, 320px) !important;
  }

  /* Stat / dashboard cards stack cleanly */
  .stat-card .stat-value {
    font-size: 1.25rem;
  }

  .d-flex.flex-wrap.gap-2,
  .d-flex.flex-wrap.gap-3 {
    gap: 0.35rem !important;
  }
}

/* ── Small phones (≤575px) ── */
@media (max-width: 575.98px) {
  #header-container .reseller-header-profile-btn .profile-name {
    display: none !important;
  }

  #header-container .reseller-header-profile-btn .me-2 {
    margin-right: 0 !important;
  }

  .form-control,
  .form-select {
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  .table {
    font-size: 0.8125rem;
  }

  .table th,
  .table td {
    padding: 0.4rem 0.35rem;
    white-space: nowrap;
  }

  .pagination {
    flex-wrap: wrap;
    justify-content: center;
  }

  .login-container {
    margin: 0.75rem;
    max-width: calc(100% - 1.5rem);
  }

  .login-header {
    padding: 1.25rem 1rem;
  }

  .login-body {
    padding: 1.25rem 1rem;
  }

  #loginLogoContainer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  #companyNameDisplay {
    font-size: 1.15rem;
    white-space: normal;
  }
}

/* ── Login page (reseller portal entry) ── */
@media (max-width: 767.98px) {
  body:not(.dashboard-page) {
    padding: 0.5rem;
    align-items: flex-start;
    padding-top: max(0.5rem, env(safe-area-inset-top));
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  }
}

/* Safe areas for notched phones */
@supports (padding: max(0px)) {
  body.dashboard-page #main-content-area > .container-fluid {
    padding-left: max(0.65rem, env(safe-area-inset-left)) !important;
    padding-right: max(0.65rem, env(safe-area-inset-right)) !important;
  }

  #sidebar-container.show,
  #pm-sidebar-container.show {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Touch targets in sidebar */
@media (hover: none) and (pointer: coarse) {
  #sidebar-container .nav-link,
  #sidebar-container .submenu-link,
  #pm-sidebar-container .nav-link,
  #pm-sidebar-container .submenu-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}
