/**
 * Safe Clicks — global responsive + RTL helpers.
 * Breakpoints: mobile <480px, tablet 481–1024px, desktop >1024px (see media queries below).
 */
html {
  font-size: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  -webkit-text-size-adjust: 100%;
  font-family: var(--font-ui, var(--font-ku));
}

body {
  font-family: inherit;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Drawer open: lock background scroll */
body.sc-global-drawer-open,
body.sidebar-active {
  overflow: hidden;
  touch-action: none;
}

/* --- Horizontal scroll tables (all viewports; critical on mobile) --- */
.sc-table-scroll {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

[dir="rtl"] .sc-table-scroll {
  direction: ltr;
}

[dir="rtl"] .sc-table-scroll > table {
  direction: rtl;
}

.sc-table-scroll > table {
  width: max-content;
  min-width: 100%;
}

/* --- Card-style tables below 768px (requires td[data-sc-label]) --- */
@media (max-width: 767.98px) {
  .sc-mobile-cards-768 > table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .sc-mobile-cards-768 > table tbody tr {
    display: block;
    margin-bottom: 0.85rem;
    padding: 0.5rem 0.65rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.85rem;
    background: #fff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  }

  .sc-mobile-cards-768 > table tbody td {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
    width: 100% !important;
    padding: 0.5rem 0.15rem !important;
    border: none !important;
    border-bottom: 1px solid #f1f5f9 !important;
    text-align: start !important;
    vertical-align: top !important;
  }

  .sc-mobile-cards-768 > table tbody td:last-child {
    border-bottom: none !important;
  }

  .sc-mobile-cards-768 > table tbody td[colspan] {
    display: block !important;
    text-align: center !important;
    justify-content: center !important;
  }

  .sc-mobile-cards-768 > table tbody td[colspan]::before {
    display: none !important;
    content: none !important;
  }

  .sc-mobile-cards-768 > table tbody td[data-sc-label]::before {
    content: attr(data-sc-label);
    font-weight: 800;
    font-size: 0.68rem;
    color: #64748b;
    flex: 0 0 auto;
    max-width: 46%;
    line-height: 1.35;
  }
}

/* --- Mobile: single-column density (<480px) --- */
@media (max-width: 479.98px) {
  .sc-stack-xs {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .sc-full-xs {
    width: 100% !important;
  }
}

/* --- Tablet: slightly tighter chrome (481–1024px) --- */
@media (min-width: 481px) and (max-width: 1024px) {
  .sc-tablet-condense {
    padding-inline: clamp(0.75rem, 2vw, 1.25rem) !important;
  }
}

/* --- Settings / invoice preview frame --- */
.sc-invoice-preview-frame {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

.sc-invoice-preview-frame iframe,
.sc-invoice-preview-frame > * {
  max-width: 100%;
}

/* --- Touch targets: minimum 44px where class applied --- */
.sc-touch-target {
  min-height: 2.75rem;
  min-width: 2.75rem;
  touch-action: manipulation;
}

@media (pointer: coarse) {
  .sc-touch-target-lg {
    min-height: 3rem;
    min-width: 3rem;
  }
}

/* --- <1024px: main content uses full viewport width (sidebar = off-canvas drawer only) --- */
@media (max-width: 1023.98px) {
  .sc-page-main-pad {
    padding-inline: max(0.5rem, env(safe-area-inset-left, 0px)) max(0.5rem, env(safe-area-inset-right, 0px));
  }

  .sc-main-max-none {
    width: 100%;
    max-width: none !important;
  }

  [data-sc-nav-toggle-host] {
    align-items: center;
  }

  /* Dashboard: full width — hidden drawer must not reserve horizontal space (RTL/LTR) */
  .dashboard-shell {
    width: 100% !important;
    max-width: 100% !important;
    margin-right: 0 !important;
    margin-left: 0 !important;
    margin-inline: 0 !important;
    box-sizing: border-box;
  }

  .dashboard-shell > main {
    width: 100%;
    max-width: 100%;
    margin-inline: auto;
  }
}
