/**
 * Qudra Charge ERP — Responsive polish overlay (v14.3.210)
 * Loaded after qc-erp-modern. Preserves theme; fixes overlap / mobile / tables / modals.
 */
:root {
  --qc-space-1: 4px;
  --qc-space-2: 8px;
  --qc-space-3: 12px;
  --qc-space-4: 16px;
  --qc-space-5: 24px;
  --qc-space-6: 32px;
  --qc-touch-min: 44px;
  --qc-safe-top: env(safe-area-inset-top, 0px);
  --qc-safe-bottom: env(safe-area-inset-bottom, 0px);
  --qc-safe-left: env(safe-area-inset-left, 0px);
  --qc-safe-right: env(safe-area-inset-right, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  overflow-x: hidden;
  max-width: 100vw;
  padding-left: var(--qc-safe-left);
  padding-right: var(--qc-safe-right);
}
#root {
  min-height: 100dvh;
  max-width: 100vw;
  overflow-x: hidden;
}

/* Prevent page-level horizontal scroll; allow inner table scroll */
.qc-erp-main,
main,
[class*="flex-1"] {
  min-width: 0;
  max-width: 100%;
}

/* Long text */
.qc-erp-main h1,
.qc-erp-main h2,
.qc-erp-main h3,
.qc-erp-main td,
.qc-erp-main th,
.qc-erp-main label {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.qc-erp-main td,
.qc-erp-main [class*="truncate"] {
  max-width: 100%;
}

/* Touch targets */
@media (max-width: 1023px) {
  .qc-erp-main button:not([role="switch"]):not([role="checkbox"]),
  .qc-erp-main a.inline-flex,
  header button,
  [aria-label="Notifications"],
  [aria-label="Open navigation menu"] {
    min-height: var(--qc-touch-min);
  }
  .qc-erp-main button.h-7,
  .qc-erp-main button.h-8,
  .qc-erp-main button.h-9 {
    min-height: 40px;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* Tables: contain scroll */
.qc-erp-main .overflow-x-auto,
.qc-erp-main [class*="overflow-x-auto"],
.qc-erp-main [class*="shadow-card"]:has(table) {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.qc-erp-main table {
  min-width: 0;
}
@media (max-width: 767px) {
  .qc-erp-main table {
    font-size: 0.72rem !important;
  }
  .qc-erp-main table thead th {
    font-size: 0.58rem !important;
    padding: 0.45rem 0.4rem !important;
  }
  .qc-erp-main table tbody td {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    padding-left: 0.4rem !important;
    padding-right: 0.4rem !important;
  }
}

/* Forms: single column on phone */
@media (max-width: 639px) {
  .qc-erp-main form .grid,
  .qc-erp-main [role="dialog"] .grid,
  .qc-erp-main .grid.grid-cols-2,
  .qc-erp-main .grid.md\:grid-cols-2,
  .qc-erp-main .grid.md\:grid-cols-3,
  .qc-erp-main .grid.md\:grid-cols-4,
  .qc-erp-main .grid.lg\:grid-cols-3,
  .qc-erp-main .grid.lg\:grid-cols-4,
  .qc-erp-main .grid.xl\:grid-cols-6,
  .qc-erp-main .grid.xl\:grid-cols-8 {
    grid-template-columns: 1fr !important;
  }
  .qc-erp-main input,
  .qc-erp-main textarea,
  .qc-erp-main select,
  .qc-erp-main [role="combobox"] {
    width: 100% !important;
    max-width: 100% !important;
  }
  .qc-erp-main .flex.flex-wrap.items-center.gap-2,
  .qc-erp-main .flex.flex-wrap.gap-2 {
    gap: var(--qc-space-2) !important;
  }
}

/* Header / company selector */
@media (max-width: 1023px) {
  header.lg\:hidden,
  .lg\:hidden.sticky {
    padding-top: max(0.5rem, var(--qc-safe-top));
  }
}
@media (max-width: 639px) {
  /* Shrink wallet search on very small phones */
  input[placeholder*="Search wallets"],
  input[placeholder*="wallets"] {
    max-width: 42vw;
    font-size: 0.75rem;
  }
}

/* Modals */
[role="dialog"] {
  max-width: min(96vw, 100%) !important;
  max-height: min(92dvh, 100%) !important;
}
@media (max-width: 767px) {
  [role="dialog"] {
    width: min(100vw - 1rem, 100%) !important;
    max-height: calc(100dvh - var(--qc-safe-top) - var(--qc-safe-bottom) - 1rem) !important;
    margin: 0.5rem !important;
    border-radius: 16px !important;
  }
  [role="dialog"] [class*="overflow-y-auto"],
  [role="dialog"].overflow-y-auto,
  [role="dialog"] .max-h-\[90vh\] {
    max-height: calc(100dvh - 8rem - var(--qc-safe-bottom)) !important;
  }
}

/* Sidebar sheet */
[data-radix-dialog-content][class*="w-\[min(20rem"] {
  padding-top: max(1rem, var(--qc-safe-top));
  padding-bottom: max(1rem, var(--qc-safe-bottom));
}

/* KPI / card grids on stock & dashboard */
@media (max-width: 767px) {
  .qc-erp-main .grid.grid-cols-2.md\:grid-cols-4,
  .qc-erp-main .grid.grid-cols-2.md\:grid-cols-5 {
    grid-template-columns: 1fr 1fr !important;
  }
  .qc-erp-main .space-y-3.mb-4 > div > .grid {
    gap: 0.5rem !important;
  }
}

/* Action button groups: stack on mobile */
@media (max-width: 639px) {
  .qc-erp-main > div > .flex.flex-wrap.items-center.gap-2,
  .qc-erp-main [class*="PageHeader"] + *,
  .qc-erp-main h1 ~ .flex.flex-wrap {
    width: 100%;
  }
  .qc-erp-main .bg-brand-gradient,
  .qc-erp-main button.bg-brand-gradient {
    width: 100%;
    justify-content: center;
  }
}

/* Notification popover on mobile */
@media (max-width: 639px) {
  [data-radix-popper-content-wrapper] {
    max-width: min(94vw, 380px) !important;
  }
}

/* Sonner toaster: safe area + mobile */
[data-sonner-toaster] {
  --width: min(380px, calc(100vw - 1.5rem)) !important;
  z-index: 10050 !important;
}
[data-sonner-toaster][data-y-position="top"] {
  top: max(1rem, calc(var(--qc-safe-top) + 0.5rem)) !important;
}
@media (max-width: 639px) {
  [data-sonner-toaster] {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: calc(100vw - 1rem) !important;
    --width: calc(100vw - 1rem) !important;
  }
}

/* Custom QCC notify banner (fallback) */
.qc-notify-stack {
  position: fixed;
  top: max(0.75rem, calc(var(--qc-safe-top) + 0.5rem));
  right: max(0.75rem, var(--qc-safe-right));
  z-index: 10060;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(380px, calc(100vw - 1.5rem));
  pointer-events: none;
}
@media (max-width: 639px) {
  .qc-notify-stack {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: calc(100vw - 1rem);
  }
}
.qc-notify-toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: start;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  background: var(--card, #F7F6F4);
  color: var(--foreground, #202020);
  border: 1px solid var(--border, #DDD2C8);
  box-shadow: 0 18px 40px rgba(60, 40, 20, 0.14);
  animation: qcNotifyIn 0.28s ease;
}
.qc-notify-toast.is-success { border-left: 4px solid var(--success, #087D62); }
.qc-notify-toast.is-warning { border-left: 4px solid var(--warning, #EA9C42); }
.qc-notify-toast.is-urgent,
.qc-notify-toast.is-error { border-left: 4px solid var(--danger, #C13A42); }
.qc-notify-toast.is-info { border-left: 4px solid var(--info, #178D73); }
.qc-notify-toast strong {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.25;
}
.qc-notify-toast p {
  margin: 0.15rem 0 0;
  font-size: 0.72rem;
  color: var(--muted-foreground, #6B6B6B);
  line-height: 1.35;
}
.qc-notify-toast time {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.62rem;
  color: var(--muted-foreground, #9A9A9A);
}
.qc-notify-toast .qc-notify-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}
.qc-notify-toast .qc-notify-actions button {
  min-height: 32px;
  padding: 0 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--background, #fff);
  font-size: 0.68rem;
  font-weight: 650;
  cursor: pointer;
}
.qc-notify-toast .qc-notify-actions button.primary {
  background: var(--primary, #087D62);
  color: #fff;
  border-color: transparent;
}
.qc-notify-dismiss {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--muted-foreground);
  min-width: 28px;
  min-height: 28px;
}
.qc-notify-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  font-size: 0.95rem;
}
@keyframes qcNotifyIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Permission banner */
.qc-notify-perm {
  position: fixed;
  bottom: max(1rem, calc(var(--qc-safe-bottom) + 0.75rem));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10070;
  width: min(420px, calc(100vw - 1.5rem));
  padding: 0.9rem 1rem;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
}
.qc-notify-perm p {
  font-size: 0.78rem;
  margin: 0 0 0.65rem;
  line-height: 1.4;
}
.qc-notify-perm .row {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}
.qc-notify-perm button {
  min-height: 40px;
  padding: 0 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 650;
  cursor: pointer;
}
.qc-notify-perm button.primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

/* Charts */
.qc-erp-main canvas,
.qc-erp-main svg.recharts-surface {
  max-width: 100% !important;
}
.qc-chart-wrap {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* Images */
.qc-erp-main img {
  max-width: 100%;
  height: auto;
  object-fit: contain;
}

/* Filter bars */
@media (max-width: 767px) {
  .qc-erp-main .grid.grid-cols-2.md\:grid-cols-4.xl\:grid-cols-8,
  .qc-erp-main .p-4.mb-4 .grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.55rem !important;
  }
}
@media (max-width: 430px) {
  .qc-erp-main .p-4.mb-4 .grid {
    grid-template-columns: 1fr !important;
  }
}

/* Landscape phones */
@media (max-height: 480px) and (orientation: landscape) {
  [role="dialog"] {
    max-height: 96dvh !important;
  }
  .qc-notify-stack {
    top: 0.35rem;
  }
}

/* WhatsApp module */
.qc-whatsapp-module .qc-wa-layout { min-height: 0; }
@media (max-width: 767px) {
  .qc-whatsapp-module .qc-wa-layout { grid-template-columns: 1fr !important; }
  .qc-whatsapp-module textarea { font-size: 16px !important; }
}
