/* Responsive navigation drawer. Loaded after the legacy stylesheet on purpose. */
.btn-sidebar-toggle,
.sidebar-close-btn,
.sidebar-backdrop {
  display: none;
}

/* Keep the complete backoffice menu in the drawer while the login wall is
   checking an existing session. Merchant and staff sessions are hidden after
   their verified role is applied. */
#sidebarAdminGroup { display: block !important; }
body[data-user-role="merchant"] #sidebarAdminGroup,
body[data-user-role="staff"] #sidebarAdminGroup { display: none !important; }
body[data-user-role="owner"] #sidebarAdminGroup .sidebar-menu-item,
body[data-user-role="manager"] #sidebarAdminGroup .sidebar-menu-item,
body.has-admin-access #sidebarAdminGroup .sidebar-menu-item,
body.admin-view-active #sidebarAdminGroup .sidebar-menu-item { display: flex; }
body[data-user-role="manager"] #sidebarAdminGroup .owner-only-nav { display: none; }
body[data-user-role="owner"] #sidebarAdminGroup .owner-only-nav { display: flex; }
body[data-user-role="staff"] .sidebar-priority-finance,
body[data-user-role="merchant"] .sidebar-priority-finance { display: none !important; }

.desktop-sidebar .sidebar-priority-nav {
  flex: 0 0 auto;
  display: grid;
  gap: 7px;
  padding: 13px 12px 11px;
  background: linear-gradient(180deg, #071a3b 0%, #04142e 100%);
  border-top: 1px solid rgba(255, 201, 49, .35);
}
.desktop-sidebar .sidebar-priority-item {
  min-height: 49px;
  margin: 0;
  color: #fff;
  font-weight: 800;
  background: rgba(255, 201, 49, .10);
  border: 1px solid rgba(255, 201, 49, .45);
  box-shadow: 0 3px 12px rgba(0, 0, 0, .13);
}
.desktop-sidebar .sidebar-priority-item:hover,
.desktop-sidebar .sidebar-priority-item.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(255, 201, 49, .23), rgba(18, 53, 104, .85));
  border-color: #ffca36;
}
.desktop-sidebar .sidebar-priority-item .sidebar-item-icon {
  color: #ffca36;
  background: rgba(255, 201, 49, .13);
  border-color: rgba(255, 201, 49, .28);
}
.desktop-sidebar .sidebar-priority-item.active .sidebar-item-icon {
  color: #061735;
  background: #ffca36;
}

.desktop-sidebar .sidebar-alert-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 21px;
  height: 21px;
  margin-left: auto;
  padding: 0 6px;
  border-radius: 999px;
  background: #ffca36;
  color: #06204d;
  font-size: .68rem;
  font-weight: 800;
}
.desktop-sidebar .sidebar-alert-count[hidden] { display: none !important; }

/* Keep navigation symbols consistent across desktop and mobile drawers. */
.desktop-sidebar .sidebar-item-icon {
  box-sizing: border-box;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  line-height: 1;
}

.desktop-sidebar .sidebar-item-icon svg {
  display: block;
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 1023px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .top-nav {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .btn-sidebar-toggle {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid rgba(255, 201, 49, 0.42);
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.09);
    cursor: pointer;
  }

  .btn-sidebar-toggle span {
    display: block;
    width: 17px;
    height: 2px;
    border-radius: 999px;
    background: #ffffff;
  }

  .desktop-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 220;
    display: flex;
    flex-direction: column;
    width: min(84vw, 300px);
    color: #ffffff;
    background: #061735;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 18px 0 55px rgba(0, 10, 30, 0.38);
    transform: translateX(-105%);
    transition: transform 220ms ease;
  }

  .desktop-sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 210;
    display: block;
    padding: 0;
    visibility: hidden;
    background: rgba(2, 8, 23, 0.58);
    border: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease, visibility 180ms ease;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
  }

  .sidebar-backdrop.is-open {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-brand {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 36px;
    align-items: center;
    gap: 11px;
    min-height: 72px;
    padding: 13px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  }

  .sidebar-brand-emblem {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(255, 201, 49, 0.15) 0%, rgba(14, 165, 233, 0.12) 50%, rgba(2, 6, 23, 0.6) 100%);
    border: 1px solid rgba(255, 201, 49, 0.45);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
    overflow: hidden;
  }

  .sidebar-brand-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  }

  .sidebar-brand-name {
    font-size: 0.94rem;
    font-weight: 800;
    color: #ffffff;
  }

  .sidebar-brand-sub {
    margin-top: 2px;
    color: #8fa5c6;
    font-size: 0.63rem;
    font-weight: 600;
  }

  .sidebar-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0 0 2px;
    color: #dbe7f7;
    font-size: 1.6rem;
    line-height: 1;
    background: rgba(255, 255, 255, 0.07);
    border: 0;
    border-radius: 10px;
    cursor: pointer;
  }

  .sidebar-scroll-area {
    flex: 1;
    min-height: 0;
    padding: 14px 11px;
    overflow-y: auto;
  }

  .sidebar-menu-group {
    margin-bottom: 17px;
  }

  .sidebar-menu-label {
    padding: 0 10px 6px;
    color: #7185a4;
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.7px;
  }

  .sidebar-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 9px 10px;
    color: #b9c7da;
    font-family: var(--font-thai);
    font-size: 0.84rem;
    font-weight: 600;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
  }

  .sidebar-menu-item.active {
    color: #ffffff;
    background: #123568;
    box-shadow: inset 3px 0 0 var(--brand-gold);
  }

  .sidebar-item-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 27px;
    height: 27px;
    flex: 0 0 27px;
    color: #a9bad2;
    font-family: Arial, sans-serif;
    background: rgba(255, 255, 255, 0.07);
    border-radius: 7px;
  }

  .sidebar-menu-item.active .sidebar-item-icon {
    color: var(--brand-navy-950);
    background: var(--brand-gold);
  }

  .sidebar-system-group {
    padding-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
  }

  .desktop-sidebar .sidebar-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: #041228;
    color: #dbe7f7;
    font-size: 0.76rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }

  .desktop-sidebar .sidebar-footer div {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .desktop-sidebar .sidebar-footer strong {
    color: #ffffff;
    font-weight: 700;
    font-size: 0.84rem;
  }

  .desktop-sidebar .sidebar-footer small {
    color: #7dd3fc;
    font-size: 0.70rem;
    margin-top: 1px;
  }

  .sidebar-live-dot {
    width: 9px;
    height: 9px;
    flex: 0 0 9px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.25);
  }
}

@media (min-width: 1024px) {
  .sidebar-backdrop {
    display: none !important;
  }
}

/* Account identity and the branch used by each operation are separate. */
.working-branch-context { display:flex; align-items:center; gap:7px; padding:9px 13px; border:1px solid #cddfec; border-radius:9px; background:#f1f7fd; color:#244c73; font-size:.78rem; font-weight:700; line-height:1.5; }
.working-branch-context[hidden] { display:none!important; }
#viewShippingStation > .working-branch-context { grid-column:1 / -1; }
#modalCheckoutPayment > .modal-card > .working-branch-context { margin:8px 16px 0; }
#suppliesViewInventory > .working-branch-context { margin:10px 0; }
.dash-scope-control { display:flex; align-items:center; gap:8px; padding:7px 10px; border:1px solid #d6e2ed; border-radius:9px; background:#f6f9fd; color:#244b72; font-size:.78rem; }
.dash-scope-control label { white-space:nowrap; font-weight:700; }
.dash-scope-control select { min-width:155px; max-width:290px; border:0; background:transparent; color:#11345c; font:inherit; font-weight:700; }
.dashboard-scope-notice { margin:0 0 14px; padding:10px 14px; border-radius:9px; background:#edf5fe; border:1px solid #d6e5f7; color:#315b83; font-size:.8rem; line-height:1.6; }
#viewDashboard.dashboard-loading > :not(.dash-top-bar):not(.dashboard-scope-notice) { opacity:.4; pointer-events:none; }
@media(max-width:750px) { .dash-scope-control{width:100%;flex-wrap:wrap}.dash-scope-control select{flex:1;min-width:0;max-width:100%}.working-branch-context{font-size:.74rem}.dashboard-scope-notice{font-size:.75rem} }
