/* BLUE STUDIO V7.0 — full-site stability, readability and responsive safety layer */
:root {
  --bs-font-ar: "Cairo", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bs-font-en: "Manrope", "Segoe UI", Arial, sans-serif;
  --bs-bg: #f5f8fc;
  --bs-surface: #ffffff;
  --bs-surface-soft: #f8fbff;
  --bs-text: #10213a;
  --bs-muted: #64748b;
  --bs-border: #dbe5f1;
  --bs-primary: #0b74e5;
  --bs-primary-dark: #075ab3;
  --bs-success: #0a9f6e;
  --bs-warning: #d97706;
  --bs-danger: #dc3545;
  --bs-radius-sm: 10px;
  --bs-radius: 16px;
  --bs-radius-lg: 24px;
  --bs-shadow: 0 12px 34px rgba(18, 53, 91, .08);
  --bs-focus: 0 0 0 3px rgba(11, 116, 229, .18);
  color-scheme: light;
}
html[data-theme="dark"], body[data-theme="dark"], body.theme-dark, .dark-theme {
  --bs-bg: #071425;
  --bs-surface: #0d1d31;
  --bs-surface-soft: #112640;
  --bs-text: #edf5ff;
  --bs-muted: #9db0c7;
  --bs-border: #263d58;
  --bs-primary: #3b9cff;
  --bs-primary-dark: #167ce0;
  --bs-shadow: 0 14px 38px rgba(0, 0, 0, .28);
  color-scheme: dark;
}
html { scroll-behavior: smooth; text-size-adjust: 100%; -webkit-text-size-adjust: 100%; }
html[dir="rtl"] body, body[dir="rtl"], body:lang(ar) { font-family: var(--bs-font-ar); }
html[dir="ltr"] body, body[dir="ltr"], body:lang(en) { font-family: var(--bs-font-en); }
body { overflow-x: hidden; }
body, button, input, select, textarea { font-family: inherit; }
body, body * { cursor: auto !important; }
a, button, [role="button"], input[type="button"], input[type="submit"], input[type="reset"], select, label[for] { cursor: pointer !important; }
input, textarea { cursor: text !important; }
[hidden] { display: none !important; }
.bs-v70-ready body { opacity: 1; }

/* Arabic readability */
html[dir="rtl"] :where(h1,h2,h3,h4,h5,h6,p,li,label,button,a,th,td,small,span) {
  letter-spacing: 0 !important;
  word-spacing: normal;
}
html[dir="rtl"] :where(p,li,.description,.subtitle,.helper-text,.form-hint) { line-height: 1.85; }
:where(h1,h2,h3,h4,h5,h6) { text-wrap: balance; overflow-wrap: anywhere; }
:where(p,li,td,th,label,.card,.panel,.modal) { overflow-wrap: anywhere; }
:where(.amount,.price,.money,.currency,.time,.date,[data-money],[data-time]) {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--bs-font-en);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Focus and interaction */
:where(a,button,input,select,textarea,[tabindex]):focus-visible {
  outline: 2px solid var(--bs-primary) !important;
  outline-offset: 2px;
  box-shadow: var(--bs-focus);
}
:where(button,.btn,[role="button"]) { min-height: 42px; touch-action: manipulation; }
:where(button,.btn,[role="button"]):disabled,
:where(button,.btn,[role="button"])[aria-disabled="true"] { opacity: .58; cursor: not-allowed !important; }

/* Forms */
:where(input,select,textarea) {
  max-width: 100%;
}
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),select,textarea) {
  min-height: 44px;
  border-radius: var(--bs-radius-sm);
}
textarea { min-height: 110px; resize: vertical; }
:where(input,select,textarea)::placeholder { color: var(--bs-muted); opacity: .78; }
.form-error, .field-error, [aria-invalid="true"] + .error-message { color: var(--bs-danger); }

/* Cards, modals, dropdowns */
:where(.modal,.dialog,[role="dialog"],.drawer,.offcanvas) {
  max-width: min(94vw, 900px);
  max-height: min(92vh, 880px);
  overflow: auto;
  overscroll-behavior: contain;
}
:where(.dropdown-menu,.select-menu,.popover) { max-width: min(94vw, 420px); max-height: min(70vh, 560px); overflow: auto; }
:where(.card,.panel,.widget) img { max-width: 100%; }

/* Tables */
.bs-table-scroll { width: 100%; overflow: auto; overscroll-behavior-inline: contain; border-radius: inherit; }
.bs-table-scroll > table { min-width: 720px; margin: 0; }
table { border-collapse: collapse; max-width: 100%; }
th, td { vertical-align: middle; }

/* Images and media */
img,video,svg,canvas { max-width: 100%; }
img { height: auto; }
img.bs-image-failed { object-fit: contain !important; background: var(--bs-surface-soft); padding: 12px; }

/* Loading screen fail-safe */
:where(.site-loader,.page-loader,.loading-screen,#siteLoader,#pageLoader,[data-page-loader]) {
  transition: opacity .25s ease, visibility .25s ease;
}
:where(.site-loader,.page-loader,.loading-screen,#siteLoader,#pageLoader,[data-page-loader]).bs-loader-hidden {
  opacity: 0 !important; visibility: hidden !important; pointer-events: none !important;
}

/* Empty and error states */
.bs-empty-state,.bs-friendly-error {
  display: grid; place-items: center; gap: 10px; text-align: center;
  min-height: 150px; padding: 26px; border: 1px dashed var(--bs-border);
  border-radius: var(--bs-radius); background: var(--bs-surface-soft); color: var(--bs-muted);
}
.bs-friendly-error strong { color: var(--bs-text); }
.bs-toast-host { position: fixed; z-index: 2147483000; inset-inline-end: 18px; bottom: 18px; display: grid; gap: 10px; width: min(390px, calc(100vw - 36px)); }
.bs-toast { padding: 13px 15px; border: 1px solid var(--bs-border); border-radius: 13px; background: var(--bs-surface); color: var(--bs-text); box-shadow: var(--bs-shadow); animation: bsToastIn .2s ease both; }
.bs-toast--error { border-inline-start: 4px solid var(--bs-danger); }
.bs-toast--success { border-inline-start: 4px solid var(--bs-success); }
@keyframes bsToastIn { from { opacity: 0; transform: translateY(8px); } }

/* Admin sidebar stability */
:where(.admin-sidebar,.sidebar,[data-admin-sidebar]) { overflow-y: auto; overscroll-behavior: contain; }
:where(.admin-nav-group,.sidebar-group,[data-nav-group]) { position: relative; isolation: isolate; }
:where(.admin-nav-group__items,.sidebar-group-items,[data-nav-panel]) {
  position: static !important;
  overflow: hidden;
  transition: max-height .22s ease, opacity .18s ease, margin .22s ease;
}
:where(.admin-nav-group:not(.is-open) .admin-nav-group__items,
       .sidebar-group:not(.is-open) .sidebar-group-items,
       [data-nav-group]:not(.is-open) [data-nav-panel]) {
  max-height: 0 !important; opacity: 0 !important; margin-block: 0 !important; pointer-events: none;
}
:where(.admin-nav-group.is-open .admin-nav-group__items,
       .sidebar-group.is-open .sidebar-group-items,
       [data-nav-group].is-open [data-nav-panel]) {
  max-height: 1000px !important; opacity: 1 !important; pointer-events: auto;
}

/* Responsive safety */
@media (max-width: 1100px) {
  :where(.dashboard-grid,.admin-grid,.content-grid) { grid-template-columns: minmax(0,1fr) !important; }
}
@media (max-width: 768px) {
  :root { --bs-radius: 14px; --bs-radius-lg: 18px; }
  body { min-width: 0; }
  :where(.container,.page-container,.admin-content,.main-content) { max-width: 100%; padding-inline: 14px; }
  :where(.toolbar,.page-actions,.filter-bar,.filters-row,.form-actions) { flex-wrap: wrap; gap: 8px; }
  :where(.toolbar,.page-actions,.filter-bar) > * { max-width: 100%; }
  :where(.modal,.dialog,[role="dialog"],.drawer,.offcanvas) { width: calc(100vw - 20px) !important; max-height: calc(100vh - 20px); }
  .bs-toast-host { inset-inline: 12px; bottom: 12px; width: auto; }
}

/* Print/PDF: content only */
@media print {
  @page { margin: 10mm; }
  html, body { background: #fff !important; color: #111 !important; }
  :where(.admin-sidebar,.sidebar,.admin-header,.topbar,.page-actions,.no-print,[data-no-print],.bs-toast-host) { display: none !important; }
  :where(.admin-main,.main-content,.page-content,.statement-page,.invoice-page) { margin: 0 !important; padding: 0 !important; width: 100% !important; max-width: none !important; }
  .bs-table-scroll { overflow: visible !important; }
  .bs-table-scroll > table { min-width: 0 !important; }
  a { color: inherit !important; text-decoration: none !important; }
  .card,.panel,.widget { box-shadow: none !important; break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Public navigation and header stability */
:where(.site-header,.main-header,.navbar) { z-index: 1000; }
:where(.nav-menu,.main-nav,.navbar-menu) a { text-decoration: none; }
@media (max-width: 900px) {
  :where(.nav-menu,.main-nav,.navbar-menu).is-open { display: flex !important; visibility: visible !important; opacity: 1 !important; pointer-events: auto !important; }
  body.bs-menu-open { overflow: hidden; }
}

/* Consistent friendly data states */
:where(.status,.badge,.chip,[data-status]) { font-weight: 700; line-height: 1.2; }
:where(.status-pending,[data-status="pending"]) { color: #9a5b00; background: #fff3d6; }
:where(.status-confirmed,[data-status="confirmed"]) { color: #075ab3; background: #e7f2ff; }
:where(.status-active,[data-status="active"],.status-running,[data-status="running"]) { color: #6840bd; background: #f0eaff; }
:where(.status-completed,[data-status="completed"],.status-paid,[data-status="paid"]) { color: #087b55; background: #def8ed; }
:where(.status-cancelled,[data-status="cancelled"]) { color: #5f6b7a; background: #edf1f5; }
:where(.status-overdue,[data-status="overdue"],.status-error,[data-status="error"]) { color: #b42335; background: #ffe8eb; }

/* Full public-site visual consistency */
:where(.site-section,section.section,.section) { scroll-margin-top: 92px; }
:where(.section-header,.section-heading) { max-width: 780px; }
:where(.section-header p,.section-heading p) { color: var(--bs-muted); }
:where(.services-grid,.portfolio-grid,.studios-grid,.pricing-grid,.cards-grid,.equipment-grid) {
  align-items: stretch;
}
:where(.service-card,.portfolio-card,.studio-card,.pricing-card,.equipment-card,.client-card) {
  min-width: 0;
  overflow: hidden;
}
:where(.service-card,.studio-card,.pricing-card,.equipment-card) :where(h2,h3,h4) { line-height: 1.45; }
:where(.service-card,.studio-card,.pricing-card,.equipment-card) :where(.description,p) { color: var(--bs-muted); }
:where(.hero,.hero-section,.page-hero) { isolation: isolate; }
:where(.hero-content,.page-hero-content) { min-width: 0; }
:where(.hero h1,.hero-section h1,.page-hero h1) { line-height: 1.2; max-width: 18ch; }
:where(.hero-actions,.cta-actions) { display: flex; flex-wrap: wrap; gap: 10px; }
:where(.clients-carousel,.logo-carousel,.carousel-track) { touch-action: pan-y; }
:where(.site-footer,.footer) a { text-underline-offset: 4px; }

/* Booking and checkout clarity */
:where(.booking-layout,.booking-shell,.checkout-layout,.rental-checkout-layout) { min-width: 0; }
:where(.booking-summary,.order-summary,.checkout-summary) { align-self: start; }
:where(.booking-step,.form-step,.wizard-step) { min-width: 0; }
:where(.stepper,.booking-steps,.wizard-nav) { overflow-x: auto; scrollbar-width: thin; }
:where(.slot,.time-slot,.booking-slot) { min-height: 44px; }
:where(.slot[aria-disabled="true"],.time-slot.disabled,.booking-slot.disabled) { opacity: .55; pointer-events: none; }

/* Friendly admin workspace */
:where(.admin-topbar,.topbar,.admin-header) { backdrop-filter: saturate(1.25) blur(12px); }
:where(.metric-card,.stat-card,.kpi-card) :where(.value,.number,.metric-value) {
  font-family: var(--bs-font-en); font-variant-numeric: tabular-nums; line-height: 1.1;
}
:where(.admin-card,.metric-card,.stat-card,.kpi-card,.workspace-card) { min-width: 0; }
:where(.admin-card-header,.card-header,.panel-header) { gap: 10px; }
:where(.page-title,.admin-page-title) { line-height: 1.3; }
:where(.page-subtitle,.admin-page-subtitle) { color: var(--bs-muted); line-height: 1.7; }
:where(.quick-actions,.action-grid) > * { min-width: 0; }

@media (max-width: 900px) {
  :where(.hero,.hero-section,.page-hero) { min-height: auto !important; }
  :where(.hero h1,.hero-section h1,.page-hero h1) { max-width: none; }
  :where(.hero-actions,.cta-actions) > * { flex: 1 1 180px; }
  :where(.services-grid,.portfolio-grid,.studios-grid,.pricing-grid,.cards-grid,.equipment-grid) { grid-template-columns: minmax(0,1fr) !important; }
  :where(.booking-layout,.booking-shell,.checkout-layout,.rental-checkout-layout) { grid-template-columns: minmax(0,1fr) !important; }
  :where(.booking-summary,.order-summary,.checkout-summary) { position: static !important; }
}
