/*
 * Bamido FE-03 — RTL / Responsive Layer
 * Depends on public/assets/css/bamido.css
 */

html { overflow-x: hidden; }
body { overflow-x: hidden; }

/* Logical-direction primitives */
.bm-dir-rtl { direction: rtl; }
.bm-dir-ltr { direction: ltr; }
.bm-start { text-align: start !important; }
.bm-end { text-align: end !important; }
.bm-inline-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
.bm-fluid-media { display: block; width: 100%; max-width: 100%; height: auto; }
.bm-safe-area { padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right)); }

/* App shell */
.bm-app-shell { grid-template-columns: 272px minmax(0, 1fr); }
.bm-app-content { min-width: 0; max-width: 100%; }
.bm-app-body { min-width: 0; overflow-x: clip; }
.bm-sidebar { min-width: 0; }
.bm-sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: calc(var(--bm-z-overlay) - 1);
  background: rgba(16, 24, 40, .48);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--bm-transition);
}
.bm-sidebar-overlay.is-visible { opacity: 1; pointer-events: auto; }

/* Wide content */
.bm-container,
.bm-content { max-width: 100%; }
.bm-grid > * { min-width: 0; }
.bm-card { min-width: 0; }
.bm-card-body { overflow-wrap: anywhere; }
.bm-table-wrap { max-width: 100%; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.bm-table { min-width: 640px; }
.bm-table th,
.bm-table td { white-space: normal; overflow-wrap: anywhere; }
.bm-table .bm-table-actions { white-space: nowrap; }

/* <= 1199 */
@media (max-width: 1199px) {
  :root { --bm-container: 1120px; }
  .bm-home-hero-grid { gap: 32px; }
  .bm-home-title { font-size: 44px; }
}

/* <= 991: tablet / drawer */
@media (max-width: 991px) {
  .bm-app-shell { display: block; }
  .bm-sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(310px, 86vw);
    height: 100dvh;
    max-height: 100dvh;
    z-index: var(--bm-z-modal);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--bm-shadow-lg);
  }
  html[dir="rtl"] .bm-sidebar {
    inset-inline-start: auto;
    inset-inline-end: 0;
    transform: translateX(105%);
  }
  .bm-sidebar.is-open,
  html[dir="rtl"] .bm-sidebar.is-open { transform: translateX(0); }
  .bm-mobile-menu-toggle { display: inline-flex; min-width: 44px; min-height: 44px; }
  .bm-app-topbar { position: sticky; top: 0; z-index: var(--bm-z-header); }
  .bm-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bm-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* <= 767: mobile */
@media (max-width: 767px) {
  .bm-container { width: min(calc(100% - 24px), var(--bm-container)); }
  .bm-main { padding-block: 24px; }
  .bm-app-body { padding: 16px 12px; }
  .bm-app-topbar { min-height: 60px; padding: 8px 12px; gap: 10px; }
  .bm-app-topbar > .bm-row { min-width: 0; }
  .bm-app-topbar strong { display: block; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bm-grid-2,
  .bm-grid-3,
  .bm-grid-4,
  .bm-form-grid { grid-template-columns: 1fr; }
  .bm-form-group-full { grid-column: auto; }
  .bm-h1 { font-size: 30px; }
  .bm-h2 { font-size: 24px; }
  .bm-h3 { font-size: 19px; }
  .bm-lead { font-size: 15px; }
  .bm-home-hero { padding: 44px 0; }
  .bm-home-hero-grid { grid-template-columns: 1fr; gap: 28px; }
  .bm-home-title { font-size: clamp(30px, 8vw, 38px); }
  .bm-home-lead { font-size: 15px; }
  .bm-home-actions { flex-direction: column; align-items: stretch; }
  .bm-home-actions .bm-btn { width: 100%; }
  .bm-home-visual { min-height: 220px; }
  .bm-home-section { padding: 48px 0; }
  .bm-section-title { font-size: 24px; }
  .bm-card-header,
  .bm-card-body,
  .bm-card-footer { padding: 16px; }
  .bm-modal { width: min(100%, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
  .bm-modal-header,
  .bm-modal-body,
  .bm-modal-footer { padding: 16px; }
  .bm-modal-footer { flex-wrap: wrap; }
  .bm-modal-footer .bm-btn { flex: 1 1 140px; }
  .bm-toast-container { top: auto; bottom: max(12px, env(safe-area-inset-bottom)); inset-inline: 12px; width: auto; }
  .bm-header-inner { min-height: 60px; }
  .bm-header-actions { gap: 4px; }
  .bm-header-actions .bm-btn-ghost { display: none; }
  .bm-header-actions .bm-btn { min-height: 44px; }
  .bm-btn { min-height: 44px; }
  .bm-btn-sm { min-height: 40px; }
  .bm-btn-icon { width: 44px; }
  .bm-sidebar-link { min-height: 44px; }
}

/* <= 575: narrow phones */
@media (max-width: 575px) {
  body { font-size: 14px; }
  .bm-container { width: calc(100% - 20px); }
  .bm-main { padding-block: 18px; }
  .bm-app-body { padding: 12px 10px; }
  .bm-app-topbar { padding-inline: 10px; }
  .bm-app-topbar .bm-row:last-child .bm-badge { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bm-stat-value { font-size: 24px; }
  .bm-table { min-width: 600px; }
  .bm-table th, .bm-table td { padding: 10px 11px; }
  .bm-form { gap: 16px; }
  .bm-form-group { gap: 5px; }
  .bm-input, .bm-select, .bm-textarea { min-height: 46px; }
  .bm-home-hero { padding: 34px 0; }
  .bm-home-visual { min-height: 180px; border-radius: var(--bm-radius-lg); }
  .bm-cta { padding: 22px 16px; }
}

/* <= 399: very narrow */
@media (max-width: 399px) {
  .bm-home-title { font-size: 28px; }
  .bm-h1 { font-size: 27px; }
  .bm-h2 { font-size: 22px; }
  .bm-header-actions .bm-btn-primary { padding-inline: 11px; }
  .bm-app-topbar .bm-row:last-child .bm-btn { padding-inline: 8px; }
  .bm-sidebar { width: min(300px, 90vw); }
}

@media (orientation: landscape) and (max-height: 520px) {
  .bm-home-hero { padding-block: 24px; }
  .bm-home-visual { min-height: 160px; }
  .bm-modal { max-height: calc(100dvh - 16px); }
}

@media (prefers-reduced-motion: reduce) {
  .bm-sidebar,
  .bm-sidebar-overlay { transition: none; }
}

@media print {
  .bm-sidebar,
  .bm-mobile-menu-toggle,
  .bm-sidebar-overlay,
  .bm-header-actions,
  .bm-app-topbar #bm-logout-button { display: none !important; }
  .bm-app-shell { display: block; }
  .bm-app-body { padding: 0; overflow: visible; }
  .bm-card { box-shadow: none; break-inside: avoid; }
  .bm-table-wrap { overflow: visible; }
  .bm-table { min-width: 0; }
}

/* FE-14 responsive drawer correction: closed by default on mobile. */
@media(max-width:991px){
  .bm-app-shell { grid-template-columns:1fr !important; }
  .bm-sidebar { position:fixed !important; inset:0 0 0 auto !important; width:min(300px,86vw) !important; max-width:86vw; z-index:3000 !important; transform:translateX(105%) !important; transition:transform .18s ease !important; }
  html[dir="ltr"] .bm-sidebar { inset:0 auto 0 0 !important; transform:translateX(-105%) !important; }
  .bm-sidebar.is-open, html[dir="ltr"] .bm-sidebar.is-open { transform:translateX(0) !important; }
  .bm-sidebar-close, [data-shell-sidebar-close] { display:none !important; }
  .bm-sidebar-user .bm-avatar, .bm-sidebar-user .bm-avatar-lg, [data-auth-user-avatar] { display:none !important; }
}
