/* ═══════════════════════════════════════════════════════════
   MaaZGSI — Global UI Enhancements
   Applied on top of lite-purple theme. No JS changes.
   ═══════════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --purple-600: #7467ef;
  --purple-700: #5c56c6;
  --purple-800: #3d2fa5;
  --purple-50:  #f0eeff;
  --sidebar-bg: #151929;
  --sidebar-hover: rgba(116,103,239,0.12);
  --sidebar-active: rgba(116,103,239,0.18);
  --sidebar-text: rgba(255,255,255,0.70);
  --sidebar-text-active: #fff;
  --radius: 10px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

/* ── Sidebar background ────────────────────────────────────── */
.sidebar-content.bg-gray-900 {
  background: var(--sidebar-bg) !important;
  border-right: none !important;
  box-shadow: 2px 0 24px rgba(0,0,0,0.18) !important;
}

/* Sidebar header brand */
.sidebar-header {
  padding: 20px 20px 0 !important;
  margin-bottom: 28px !important;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  padding-bottom: 20px !important;
}
.sidebar-brand-text {
  color: #fff !important;
  font-size: 17px !important;
  font-weight: 800 !important;
  letter-spacing: -0.3px;
  line-height: 1;
}
.sidebar-brand-sub {
  color: rgba(255,255,255,0.4);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-top: 2px;
}
.sidebar-brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--purple-600), #9c5fd6);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}

/* ── Sidebar nav items — minimal overrides only ────────────── */
/* Let the original theme (lite-purple.min.css) control nav-item layout.
   We only adjust background and active state colour. */

.sidebar-content .nav-item.active {
  background: rgba(116,103,239,0.20) !important;
  color: #fff !important;
}
.sidebar-content .collapse-button.collapse-active {
  background: rgba(116,103,239,0.15) !important;
  color: #7467ef !important;
}

/* Nav section labels */
.sidebar-section-label {
  font-size: 10px !important;
  font-weight: 800 !important;
  text-transform: uppercase !important;
  letter-spacing: 1.2px !important;
  color: rgba(255,255,255,0.25) !important;
  padding: 20px 22px 6px !important;
  display: block !important;
}

/* ── Header / Topbar ───────────────────────────────────────── */
.layout-header {
  background: #fff !important;
  border-bottom: 1px solid #eeeef5 !important;
  box-shadow: var(--shadow-sm) !important;
  padding: 10px 20px !important;
  border-radius: 0 !important;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  border: 1px solid #ebebf5 !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-sm) !important;
  transition: box-shadow 0.2s !important;
}
.card:hover { box-shadow: var(--shadow-md) !important; }

.card-header {
  background: #fff !important;
  border-bottom: 1px solid #eeeef5 !important;
  border-radius: var(--radius) var(--radius) 0 0 !important;
  padding: 14px 20px !important;
  font-weight: 700 !important;
  font-size: 14px !important;
}
.card-body { padding: 20px !important; }
.card-footer {
  background: #fafafa !important;
  border-top: 1px solid #eeeef5 !important;
  border-radius: 0 0 var(--radius) var(--radius) !important;
  padding: 14px 20px !important;
}

/* KPI cards */
.card-icon-big {
  text-align: center;
  padding: 24px 20px !important;
  position: relative;
  overflow: hidden;
}
.card-icon-big::before {
  content: '';
  position: absolute;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--purple-50);
  top: -20px; right: -20px;
  opacity: 0.6;
}

/* ── Tables ────────────────────────────────────────────────── */
.table {
  font-size: 13px !important;
}
.table thead th {
  background: #f8f8fc !important;
  font-size: 11px !important;
  font-weight: 800 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.6px !important;
  color: #6c6c8a !important;
  border-bottom: 2px solid #eeeef5 !important;
  padding: 12px 16px !important;
  white-space: nowrap;
}
.table td {
  padding: 12px 16px !important;
  vertical-align: middle !important;
  border-bottom: 1px solid #f2f2f8 !important;
  color: #3d3d5c;
}
.table-hover tbody tr:hover td {
  background: #fafaff !important;
}
.table tbody tr:last-child td { border-bottom: none !important; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  font-weight: 600 !important;
  border-radius: 8px !important;
  font-size: 13px !important;
  transition: all 0.15s !important;
}
.btn-primary {
  background: linear-gradient(135deg, var(--purple-600), #9c5fd6) !important;
  border: none !important;
  box-shadow: 0 2px 8px rgba(116,103,239,0.35) !important;
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--purple-700), #8a4fc4) !important;
  box-shadow: 0 4px 12px rgba(116,103,239,0.45) !important;
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0) !important; }

.btn-outline-primary {
  border-color: var(--purple-600) !important;
  color: var(--purple-600) !important;
}
.btn-outline-primary:hover {
  background: var(--purple-600) !important;
  color: #fff !important;
}

.btn-success {
  background: linear-gradient(135deg, #28a745, #20c997) !important;
  border: none !important;
  box-shadow: 0 2px 8px rgba(40,167,69,0.3) !important;
}
.btn-danger {
  background: linear-gradient(135deg, #dc3545, #e74c6e) !important;
  border: none !important;
  box-shadow: 0 2px 8px rgba(220,53,69,0.3) !important;
}
.btn-warning {
  background: linear-gradient(135deg, #ffc107, #fd9a27) !important;
  border: none !important;
}

.btn-xs {
  padding: 4px 10px !important;
  font-size: 11px !important;
  border-radius: 6px !important;
}

/* ── Form controls ─────────────────────────────────────────── */
.form-control, .form-select {
  border-radius: 8px !important;
  border: 1.5px solid #e4e4f0 !important;
  font-size: 13px !important;
  padding: 9px 14px !important;
  transition: border-color 0.2s, box-shadow 0.2s !important;
  background: #fafafa !important;
}
.form-control:focus, .form-select:focus {
  border-color: var(--purple-600) !important;
  background: #fff !important;
  box-shadow: 0 0 0 3px rgba(116,103,239,0.12) !important;
}
.form-label, label.fw-semibold, label.col-form-label {
  font-size: 12.5px !important;
  font-weight: 700 !important;
  color: #3d3d5c !important;
  margin-bottom: 6px !important;
}

/* ── Badges ────────────────────────────────────────────────── */
.badge-pill, .badge {
  border-radius: 20px !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  padding: 3px 10px !important;
}
.badge-success  { background: #e8f8ed !important; color: #1d7a3d !important; }
.badge-danger   { background: #fff0f2 !important; color: #b91c1c !important; }
.badge-warning  { background: #fffbea !important; color: #92610a !important; }
.badge-info     { background: #e8fbff !important; color: #0c7a99 !important; }
.badge-primary  { background: var(--purple-50) !important; color: var(--purple-700) !important; }
.badge-secondary{ background: #f3f3f8 !important; color: #6c6c8a !important; }

/* ── Breadcrumb ────────────────────────────────────────────── */
.breadcrumb {
  margin-bottom: 8px !important;
}
.breadcrumb h1 {
  font-size: 20px !important;
  font-weight: 800 !important;
  color: #1a1a2e !important;
  margin-bottom: 4px !important;
}
.breadcrumb ul li {
  font-size: 12px !important;
  color: #9090a8 !important;
}
.breadcrumb ul li a { color: var(--purple-600) !important; }

.separator-breadcrumb {
  border-top: 1px solid #eeeef5 !important;
  margin-bottom: 24px !important;
}

/* ── Pagination ────────────────────────────────────────────── */
.pagination .page-link {
  border-radius: 6px !important;
  margin: 0 2px !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  border: 1px solid #e4e4f0 !important;
  color: var(--purple-700) !important;
}
.pagination .page-item.active .page-link {
  background: var(--purple-600) !important;
  border-color: var(--purple-600) !important;
  color: #fff !important;
}

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  border-radius: var(--radius) !important;
  border: none !important;
  font-size: 13px !important;
  font-weight: 600 !important;
}
.alert-info    { background: #e8fbff !important; color: #0c7a99 !important; }
.alert-warning { background: #fffbea !important; color: #92610a !important; }
.alert-danger  { background: #fff0f2 !important; color: #b91c1c !important; }
.alert-success { background: #e8f8ed !important; color: #1d7a3d !important; }

/* ── Dropdown menus ────────────────────────────────────────── */
.dropdown-menu {
  border: 1px solid #eeeef5 !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 6px !important;
  font-size: 13px !important;
}
.dropdown-item {
  border-radius: 6px !important;
  padding: 8px 14px !important;
  font-weight: 600 !important;
  color: #3d3d5c !important;
  transition: background 0.12s !important;
}
.dropdown-item:hover {
  background: var(--purple-50) !important;
  color: var(--purple-700) !important;
}

/* ── Modals ────────────────────────────────────────────────── */
.modal-content {
  border-radius: 14px !important;
  border: none !important;
  box-shadow: var(--shadow-lg) !important;
}
.modal-header {
  border-bottom: 1px solid #eeeef5 !important;
  padding: 18px 24px !important;
}
.modal-title { font-weight: 800 !important; font-size: 16px !important; }
.modal-footer {
  border-top: 1px solid #eeeef5 !important;
  padding: 14px 24px !important;
}

/* ── Progress bars ─────────────────────────────────────────── */
.progress {
  border-radius: 10px !important;
  background: #f0f0f8 !important;
}
.progress-bar {
  border-radius: 10px !important;
}

/* ── Footer ────────────────────────────────────────────────── */
.app-footer {
  background: #fafafa !important;
  border-top: 1px solid #eeeef5 !important;
  padding: 16px 24px !important;
  font-size: 12px !important;
  color: #9090a8 !important;
}

/* ── List groups ───────────────────────────────────────────── */
.list-group-item {
  border-color: #f0f0f8 !important;
  font-size: 13px !important;
  padding: 12px 16px !important;
}

/* ── Input groups ──────────────────────────────────────────── */
.input-group-text {
  border-radius: 8px !important;
  border: 1.5px solid #e4e4f0 !important;
  background: #f5f5fc !important;
  font-size: 13px !important;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
.scroll-nav::-webkit-scrollbar { width: 3px; }
.scroll-nav::-webkit-scrollbar-track { background: transparent; }
.scroll-nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}

/* ── Alert badge on bell icon ──────────────────────────────── */
.alert-badge-wrap { position: relative; display: inline-flex; }
.alert-badge {
  position: absolute; top: -4px; right: -6px;
  background: #dc3545; color: #fff;
  font-size: 9px; font-weight: 800;
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}

/* ── Compact sidebar icon color ────────────────────────────── */
.compact .sidebar-brand-text,
.compact .sidebar-brand-sub { display: none; }


/* ── Toastr tweaks ─────────────────────────────────────────── */
#toast-container .toast {
  border-radius: var(--radius) !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  opacity: 0.97 !important;
}

/* ═══════════════════════════════════════════════════════════
   OVERFLOW PREVENTION — applies at all screen sizes
   ═══════════════════════════════════════════════════════════ */

/* Prevent any element from breaking the page width */
body, .layout-content, .content-section {
  overflow-x: hidden;
}

/* Truncate long text in table cells that hold names/addresses */
.table td .text-truncate,
.table td p.mb-0,
.table td strong {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

/* KPI card numbers — shrink to fit, never overflow */
.card-icon-big h4 {
  font-size: clamp(14px, 2.2vw, 22px) !important;
  word-break: break-all;
  overflow-wrap: break-word;
  line-height: 1.2;
}
.card-icon-big p {
  font-size: clamp(10px, 1.4vw, 13px) !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Retailer name + email cell in retailers table */
.retailer-cell-name {
  max-width: 160px;
  overflow: hidden;
}
.retailer-cell-name p,
.retailer-cell-name small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  max-width: 100%;
}

/* Dashboard list items (Inactive Retailers, Pending Orders) */
.list-group-item .fw-semibold.small {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Ensure nav-tabs wrap instead of overflow on narrow screens */
.nav-tabs { flex-wrap: wrap !important; }
.nav-tabs .nav-link { white-space: nowrap; }

/* Card header titles — truncate if too long */
.card-header .fw-semibold,
.card-header span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 0;
}

/* Breadcrumb title — clamp on all sizes */
.breadcrumb h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Alert badges (product names, retailer names inside alert list) */
.list-group-item .badge {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Mobile & Tablet
   ═══════════════════════════════════════════════════════════ */

/* ── Tablet (≤ 991px) ────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .layout-content .content-section {
    padding: 1rem 1rem 0 !important;
  }
  .layout-header { padding: 8px 14px !important; }
  .card-body     { padding: 16px !important; }
  .card-header   { padding: 12px 16px !important; }
  .breadcrumb h1 { font-size: 18px !important; }
  .separator-breadcrumb { margin-bottom: 16px !important; }
  .layout-content { min-width: 0; flex: 1 1 auto; }
  .compact-layout { overflow-x: hidden; }

  /* KPI cards — 2 per row on tablet */
  .card-icon-big { padding: 18px 14px !important; }
  .card-icon-big h4 { font-size: 18px !important; }

  /* Table cells — allow wrapping on tablet */
  .table td { white-space: normal !important; }
  .table thead th { white-space: nowrap !important; }

  /* Dashboard split panels stack */
  .col-lg-8, .col-lg-4, .col-lg-5, .col-lg-3 {
    margin-bottom: 1rem;
  }
}

/* ── Mobile (≤ 767px) ────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .layout-content .content-section {
    padding: 0.75rem 0.75rem 0 !important;
  }
  .layout-header { padding: 8px 10px !important; }
  .card-body     { padding: 12px !important; }
  .card-header   { padding: 10px 12px !important; }
  .card-footer   { padding: 10px 12px !important; }
  .card-icon-big { padding: 14px 10px !important; }

  /* KPI card — compact */
  .card-icon-big i[style*="font-size:40px"] { font-size: 28px !important; }
  .card-icon-big i[style*="font-size:32px"] { font-size: 24px !important; }
  .card-icon-big i[style*="font-size:30px"] { font-size: 22px !important; }
  .card-icon-big h4 { font-size: 15px !important; margin-top: 6px !important; }
  .card-icon-big p  { font-size: 10px !important; }

  /* Breadcrumb */
  .breadcrumb h1 { font-size: 15px !important; }
  .breadcrumb    { margin-bottom: 4px !important; }
  .separator-breadcrumb { margin-bottom: 10px !important; }

  /* Tables — scroll horizontally, compact padding */
  .table-responsive { -webkit-overflow-scrolling: touch; }
  .table thead th {
    padding: 8px 10px !important;
    font-size: 10px !important;
  }
  .table td {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }

  /* Truncate product names, retailer names in tables */
  .table td strong,
  .table td p.mb-0 {
    max-width: 120px !important;
    font-size: 12px !important;
  }
  .table td small { font-size: 10px !important; }

  /* Hide less-critical columns on mobile via utility class */
  .col-hide-mobile { display: none !important; }

  /* Modals go full-width on mobile */
  .modal-dialog {
    margin: 0.5rem auto !important;
    max-width: calc(100vw - 1rem) !important;
  }
  .modal-content { border-radius: 10px !important; }

  /* Pagination */
  .pagination .page-link {
    padding: 4px 8px !important;
    font-size: 11px !important;
  }

  /* No hover-lift on touchscreens */
  .btn:hover { transform: none !important; }
  .btn-primary:hover { box-shadow: 0 2px 8px rgba(116,103,239,0.35) !important; }

  /* Hide fullscreen button */
  [data-fullscreen] { display: none !important; }

  /* Charts */
  #echart_sales_purchase,
  #echart_Top_products,
  #echart_Top_Clients,
  canvas[id*="Chart"] { height: 180px !important; max-height: 180px; }

  /* Alert/Inactive Retailers list — stack content vertically */
  .list-group-item .d-flex.justify-content-between {
    flex-wrap: wrap;
    gap: 4px;
  }
  .list-group-item .btn-xs { align-self: flex-start; margin-top: 2px; }

  /* Switch Org alert banner */
  .alert.d-flex.align-items-center.justify-content-between {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px;
  }

  /* Card header with button — wrap */
  .card-header.d-flex {
    flex-wrap: wrap !important;
    gap: 6px;
  }
  .card-header .btn { flex-shrink: 0; }

  /* Retailer index — action buttons stack */
  .table td .d-inline { display: block !important; margin-top: 3px; }

  /* Nav tabs — scrollable row */
  .nav-tabs {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap !important;
    border-bottom: 1px solid #dee2e6;
  }
  .nav-tabs .nav-link {
    white-space: nowrap;
    padding: 6px 10px !important;
    font-size: 12px !important;
  }
}

/* ── Small mobile (≤ 479px) ─────────────────────────────────── */
@media (max-width: 479.98px) {
  .layout-content .content-section {
    padding: 0.5rem 0.5rem 0 !important;
  }
  .layout-header { padding: 6px 8px !important; }
  .card-body     { padding: 10px !important; }
  .card-header   { padding: 8px 10px !important; }

  /* Language dropdown — hides to reclaim header space */
  .lang-dropdown { display: none !important; }

  /* Tables ultra-compact */
  .table thead th, .table td {
    padding: 6px 8px !important;
    font-size: 11px !important;
  }
  .table td strong,
  .table td p.mb-0 { max-width: 90px !important; }

  /* Badge */
  .badge { padding: 2px 7px !important; font-size: 10px !important; }

  /* Breadcrumb trail — hide trail, keep title */
  .breadcrumb h1  { font-size: 14px !important; }
  .breadcrumb > ul { display: none !important; }

  /* KPI cards — 2 per row on xs */
  .card-icon-big h4 { font-size: 13px !important; }

  /* Credit & Payments KPI numbers */
  .card-icon-big h4.fw-semibold {
    font-size: 12px !important;
    word-break: break-all;
  }

  /* Buttons full-width stacking on very small */
  .d-flex.gap-2.flex-wrap-xs > .btn { flex: 1 1 auto; }

  /* Plans page pricing cards */
  .plan-card-price { font-size: 22px !important; }
}

/* ── Mobile sidebar (drawer over content) ───────────────────── */
#mobile-sidebar .modal-dialog { display: none !important; }
#mobile-sidebar {
  z-index: 1050 !important;
  background: rgba(0,0,0,0.45) !important;
}

.layout-sidebar-mobile {
  position: fixed !important;
  top: 0; left: 0;
  height: 100vh !important;
  max-width: 0;
  z-index: 1060 !important;
  overflow: hidden;
  transition: max-width 300ms ease !important;
  box-shadow: 4px 0 32px rgba(0,0,0,0.3);
}
.layout-sidebar-mobile .sidebar-content {
  width: 270px !important;
  min-height: 100vh;
  height: 100% !important;
  overflow-y: auto;
}

/* ── Forms — single column on mobile ───────────────────────── */
@media (max-width: 575.98px) {
  .row.g-3 > [class*="col-"]:not([class*="col-12"]),
  .row.mb-3 > [class*="col-"]:not([class*="col-12"]) {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* ── Table action buttons on mobile ─────────────────────────── */
@media (max-width: 767.98px) {
  .table .btn-xs { padding: 3px 7px !important; font-size: 10px !important; }
  .table .d-flex.gap-1 { gap: 3px !important; }
}

/* ── Supplier select-org radio cards ────────────────────────── */
@media (max-width: 575.98px) {
  .supplier-org-cards .col-md-6 { flex: 0 0 100%; max-width: 100%; }
}

/* ── Supplier dashboard — inactive retailers list ───────────── */
.list-group-item .fw-semibold.small {
  max-width: 140px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Dashboard: pending orders widget reference text ─────────── */
.list-group-item small.text-muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  max-width: 150px;
}

/* ── Credit page — progress bar column min-width ─────────────── */
.progress[style*="height:6px"] { min-width: 60px !important; max-width: 120px; }

/* ── Analytics table — warehouse & product name columns ──────── */
.table td:first-child { max-width: 180px; }

/* ── Warehouse name in any table ─────────────────────────────── */
.warehouse-name-cell {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Select-org cards on mobile ──────────────────────────────── */
@media (max-width: 575.98px) {
  .supplier-org-cards .col-md-6 { flex: 0 0 100%; max-width: 100%; }
}
