/* ============================================================
   AJ PHARMACY — App Shell Layout
   Sidebar · Header · Content · Responsive
   ============================================================ */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1045;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  -webkit-backdrop-filter: blur(22px) saturate(165%);
  backdrop-filter: blur(22px) saturate(165%);
  border-right: 1px solid var(--edge-soft);
  transition: width var(--t-med), transform var(--t-med);
}
.sidebar-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 14px;
  text-decoration: none;
  flex: none;
}
.brand-mark {
  width: 42px; height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--teal) 120%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 15.5px;
  letter-spacing: -0.02em;
  box-shadow: 0 6px 16px -6px rgba(20, 103, 214, 0.55), inset 0 1px 0 rgba(255,255,255,.3);
  flex: none;
}
.brand-text { min-width: 0; }
.brand-name {
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
}
.brand-tag {
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 12px 18px;
}
.nav-group { margin-top: 14px; }
.nav-group-label {
  padding: 0 10px 6px;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}
.nav-link-aj {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8.5px 11px;
  margin-bottom: 2px;
  border-radius: 11px;
  color: var(--text-2);
  font-size: 13.2px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: all var(--t-fast);
}
.nav-link-aj i.bi {
  font-size: 16.5px;
  width: 21px;
  text-align: center;
  flex: none;
  color: var(--text-3);
  transition: color var(--t-fast);
}
.nav-link-aj:hover { background: var(--hover-tint); color: var(--text); }
.nav-link-aj:hover i.bi { color: var(--brand); }
.nav-link-aj.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
}
.nav-link-aj.active i.bi { color: var(--brand); }
.nav-link-aj.active::before {
  content: "";
  position: absolute;
  left: -12px; top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 22px;
  border-radius: 0 99px 99px 0;
  background: linear-gradient(180deg, var(--brand), var(--teal));
}
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 800;
  min-width: 19px;
  height: 17px;
  padding: 0 5px;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--red-soft);
  color: var(--red);
}

/* Sidebar footer */
.sidebar-foot {
  flex: none;
  padding: 12px;
  border-top: 1px solid var(--edge-soft);
}
.license-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--edge-soft);
}
.license-card i { color: var(--green); font-size: 17px; }
.license-card .lc-title { font-size: 11.5px; font-weight: 700; }
.license-card .lc-sub { font-size: 10.5px; color: var(--text-3); }

/* Collapsed state (desktop) */
@media (min-width: 992px) {
  .app-shell.collapsed .sidebar { width: var(--sidebar-w-collapsed); }
  .app-shell.collapsed .brand-text,
  .app-shell.collapsed .nav-group-label,
  .app-shell.collapsed .nav-link-aj span,
  .app-shell.collapsed .nav-badge,
  .app-shell.collapsed .sidebar-foot { display: none; }
  .app-shell.collapsed .sidebar-brand { justify-content: center; padding: 18px 0 14px; }
  .app-shell.collapsed .nav-link-aj { justify-content: center; padding: 10px 0; }
  .app-shell.collapsed .main-content { margin-left: var(--sidebar-w-collapsed); }
}

/* Mobile offcanvas */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-105%); box-shadow: none; }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(8, 18, 34, 0.45);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: ajFadeIn 0.2s ease both;
  }
}

/* ============ MAIN ============ */
.main-content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  transition: margin-left var(--t-med);
}

/* ============ HEADER ============ */
.top-header {
  position: sticky;
  top: 0;
  z-index: 1030;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid var(--edge-soft);
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-titles { min-width: 0; }
.page-title-h {
  font-size: 16px;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-3);
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
}
.crumbs a { color: var(--text-3); }
.crumbs a:hover { color: var(--brand); }
.crumbs .sep { opacity: 0.6; font-size: 10px; }

.header-search-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 auto;
  width: min(420px, 34vw);
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid var(--edge-soft);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--t-fast);
  font-family: inherit;
}
.header-search-btn:hover { border-color: rgba(20,103,214,.35); color: var(--text-2); }
.header-search-btn i { font-size: 14.5px; }
.header-search-btn .hs-label { flex: 1; text-align: left; }

.header-right { display: flex; align-items: center; gap: 9px; margin-left: auto; }

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--edge-soft);
  background: var(--surface-2);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--t-fast);
  font-family: inherit;
}
.conn-pill:hover { border-color: var(--edge); }
.conn-pill .dot { width: 7.5px; height: 7.5px; }
.conn-pill.online .dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.conn-pill.syncing .dot { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); animation: ajPulse 1.6s infinite; --pulse-color: rgba(217,138,6,.4); }
.conn-pill.offline .dot { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px 5px 5px;
  border-radius: 13px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: all var(--t-fast);
  font-family: inherit;
}
.user-chip:hover { background: var(--hover-tint); border-color: var(--edge-soft); }
.user-chip .uc-name { font-size: 12.5px; font-weight: 700; line-height: 1.2; color: var(--text); text-align: left; }
.user-chip .uc-role { font-size: 10.5px; color: var(--text-3); font-weight: 600; text-align: left; }

/* ============ CONTENT REGION ============ */
.page-content {
  flex: 1;
  padding: 24px 26px 40px;
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
}
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}
.page-head .ph-title { font-size: 22px; font-weight: 800; letter-spacing: -0.03em; }
.page-head .ph-sub { font-size: 13px; color: var(--text-3); margin-top: 3px; font-weight: 500; }
.page-head .ph-actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main-side { grid-template-columns: minmax(0, 2.05fr) minmax(300px, 1fr); align-items: start; }
@media (max-width: 1199.98px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main-side { grid-template-columns: 1fr; }
}
@media (max-width: 767.98px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ============ RESPONSIVE HEADER ============ */
@media (max-width: 1199.98px) {
  .header-search-btn { width: min(320px, 30vw); }
}
@media (max-width: 991.98px) {
  .header-search-btn .hs-label, .header-search-btn .palette-kbd { display: none; }
  .header-search-btn { width: auto; padding: 8px 11px; }
  .user-chip .uc-meta { display: none; }
}
@media (max-width: 767.98px) {
  .top-header { padding: 0 14px; gap: 9px; }
  .page-content { padding: 16px 14px 96px; }
  .crumbs { display: none; }
  .conn-pill .conn-label { display: none; }
  .conn-pill { padding: 6px 9px; }
  .page-head .ph-title { font-size: 19px; }
}

/* Hamburger — always visible */
.hamburger-btn { flex: none; }

/* ============ MOBILE STICKY POS BAR ============ */
.mobile-pos-bar {
  position: fixed;
  left: 12px; right: 12px; bottom: 12px;
  z-index: 1020;
  display: none;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 17px;
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  backdrop-filter: blur(24px) saturate(170%);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-lg);
}
.mobile-pos-bar.visible { display: flex; }
@media (min-width: 768px) { .mobile-pos-bar { display: none !important; } }
.mpb-total .mpb-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-3); }
.mpb-total .mpb-value { font-size: 16.5px; font-weight: 800; letter-spacing: -0.02em; }

/* Floating action button (mobile) */
.fab-aj {
  position: fixed;
  right: 16px; bottom: 84px;
  z-index: 1015;
  width: 54px; height: 54px;
  border-radius: 17px;
  border: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  font-size: 22px;
  box-shadow: 0 12px 26px -8px rgba(20, 103, 214, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.fab-aj:active { transform: scale(0.94); }
@media (max-width: 767.98px) { .fab-aj.show-mobile { display: flex; } }

/* Tooltip for collapsed sidebar */
.tt-wrap { position: relative; }
.tt-tip {
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) scale(0.94);
  padding: 6px 11px;
  border-radius: 9px;
  background: var(--surface-strong);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-md);
  font-size: 12px;
  font-weight: 650;
  color: var(--text);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all var(--t-fast);
  z-index: 1060;
}
@media (min-width: 992px) {
  .app-shell.collapsed .tt-wrap:hover .tt-tip { opacity: 1; transform: translateY(-50%) scale(1); }
}


/* ============================================================
   AJ PHARMACY — RESPONSIVE FIX PATCH
   Fixes mobile horizontal overflow and desktop sidebar spacing.
   Keep this block at the VERY END of the stylesheet.
   ============================================================ */

/* Prevent every flex/grid child from forcing the page wider */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.app-shell,
.main-content,
.page-content,
.top-header,
.header-left,
.header-right,
.page-head,
.grid {
  min-width: 0;
  max-width: 100%;
}

/* IMPORTANT:
   The sidebar becomes an off-canvas element below 992px.
   Therefore the desktop sidebar margin MUST be removed from
   the main content on tablets and phones. */
@media (max-width: 991.98px) {
  .main-content {
    width: 100%;
    max-width: 100%;
    margin-left: 0 !important;
  }

  .page-content {
    width: 100%;
    max-width: 100%;
  }

  .sidebar {
    width: min(var(--sidebar-w), 88vw);
    max-width: 88vw;
  }
}

/* Tablet header */
@media (max-width: 991.98px) {
  .top-header {
    width: 100%;
    min-width: 0;
    padding-left: 14px;
    padding-right: 14px;
  }

  .header-left {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
  }

  .header-titles {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }

  .page-title-h {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-search-btn {
    flex: 0 0 auto;
  }

  .header-right {
    flex: 0 0 auto;
    min-width: 0;
  }
}

/* Phone header — stop controls from pushing the viewport sideways */
@media (max-width: 767.98px) {
  .top-header {
    height: var(--header-h);
    padding-left: 10px;
    padding-right: 10px;
    gap: 7px;
  }

  .header-left {
    flex: 1 1 auto;
    gap: 8px;
  }

  .header-right {
    gap: 5px;
    margin-left: 0;
  }

  .page-title-h {
    font-size: 14px;
  }

  .header-search-btn {
    flex: 0 0 auto;
  }

  .page-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .page-head {
    width: 100%;
  }

  .page-head .ph-actions {
    width: 100%;
  }

  .page-head .ph-actions > * {
    max-width: 100%;
  }

  /* Prevent long buttons/cards/inputs from creating horizontal scroll */
  button,
  input,
  select,
  textarea,
  .btn,
  .form-control,
  .form-select {
    max-width: 100%;
  }

  .grid,
  .grid-2,
  .grid-3,
  .grid-4,
  .grid-main-side {
    width: 100%;
    min-width: 0;
  }
}

/* Very small phones */
@media (max-width: 575.98px) {
  .top-header {
    gap: 5px;
  }

  .header-left {
    flex: 1 1 0;
    min-width: 0;
  }

  .header-right {
    flex-shrink: 0;
  }

  .header-search-btn {
    padding: 7px 9px;
  }

  .page-title-h {
    font-size: 13.5px;
  }

  .page-content {
    padding: 14px 10px 94px;
  }

  .page-head {
    gap: 10px;
    margin-bottom: 15px;
  }

  .page-head .ph-title {
    font-size: 18px;
  }

  .page-head .ph-sub {
    font-size: 12px;
  }

  .mobile-pos-bar {
    left: 8px;
    right: 8px;
    bottom: 8px;
    gap: 8px;
    padding: 10px 11px;
  }

  .fab-aj {
    right: 12px;
    bottom: 78px;
  }
}

/* Extra-small phones such as 320px–400px */
@media (max-width: 400px) {
  .top-header {
    padding-left: 8px;
    padding-right: 8px;
    gap: 4px;
  }

  .header-left {
    gap: 6px;
  }

  .header-right {
    gap: 3px;
  }

  /* Search becomes icon-only at this width */
  .header-search-btn {
    padding: 7px 8px;
  }

  .conn-pill {
    padding-left: 7px;
    padding-right: 7px;
  }

  .user-chip {
    padding-left: 2px;
    padding-right: 2px;
  }

  .page-content {
    padding-left: 8px;
    padding-right: 8px;
  }

  .page-head .ph-title {
    font-size: 17px;
  }

  /* Never allow action rows to overflow */
  .page-head .ph-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .page-head .ph-actions > * {
    width: 100%;
  }
}

/* Tiny 320px screens */
@media (max-width: 340px) {
  .header-search-btn {
    display: none;
  }

  .top-header {
    gap: 3px;
  }

  .page-title-h {
    font-size: 13px;
  }
}

/* Long text must wrap instead of expanding the layout */
.page-content,
.page-head,
.card,
.card-body,
.table-responsive,
.modal-content,
.dropdown-menu {
  overflow-wrap: anywhere;
}

/* Tables should scroll INSIDE their container, never expand the page */
.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Images/media can never exceed their parent */
.page-content img,
.page-content video,
.page-content iframe,
.page-content canvas,
.page-content svg {
  max-width: 100%;
}

/* Bootstrap rows commonly create negative horizontal margins.
   Keep them inside the page on narrow screens. */
@media (max-width: 767.98px) {
  .page-content > .row,
  .page-content .row {
    --bs-gutter-x: 1rem;
  }

  .page-content .row > * {
    min-width: 0;
  }
}

/* If a desktop collapsed state is accidentally left on a mobile
   shell, mobile must still win. */
@media (max-width: 991.98px) {
  .app-shell.collapsed .main-content {
    margin-left: 0 !important;
  }
}
