/* ============================================
   Layout Mobile CSS - Enterprise V9
   שכבת CSS ייעודית למובייל
   ============================================
   
   קובץ זה מכיל כללים גלובליים למובייל בלבד
   כל הכללים בתוך @media (max-width: 768px)
   
   מטרה: להבטיח שכל 800+ הטמפלטים יוצגו נכון במובייל
   בלי לגעת בתבניות HTML ובלי לשנות CSS קיים
   
   תאריך יצירה: 2025-01-27
   גרסה: 1.0.0
   ============================================ */

@layer utilities {
  /* ========= בסיס רספונסיבי לכל האתר ========= */
  @media (max-width: 768px) {

  /* מבנה כללי */
  /* ⚠️ הוסר overflow-x: hidden מ-html/body - פתרון קסם גלובלי אסור לפי חוקי זהב #9 */
  /* טיפול בגלישות נעשה ברמת הרכיב/מודול הספציפי */
  html, body {
    max-width: 100%;
    /* overflow-x: hidden; - הוסר - אסור גלובלי */
    width: 100%;
  }

  .app-layout,
  .content-wrapper,
  .container,
  .container-fluid,
  main,
  [role="main"],
  #main,
  #main-content {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    padding-inline: 12px;
    margin-inline: 0;
    /* ⚠️ הוסר overflow-x: hidden - פתרון קסם גלובלי אסור לפי חוקי זהב #9 */
    /* overflow-x: hidden; - הוסר - אסור גלובלי */
  }

  /* כותרות דפים */
  .page-header,
  .module-header,
  .projects-header,
  .page-header-complex {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .page-title,
  .module-title,
  .projects-title {
    margin-bottom: 0.5rem;
    width: 100%;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  .page-description,
  .page-intro,
  .projects-intro-card,
  .module-intro-card,
  .page-description-card,
  .intro-card {
    width: 100%;
    max-width: 100%;
    margin-top: 0.5rem;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* שורות כרטיסים / KPIs / סטטיסטיקות */
  /* דסקטופ: grid-template-columns: repeat(3, 1fr) */
  /* מובייל: grid-template-columns: 1fr */
  .cards-row,
  .kpi-row,
  .stats-row,
  .stats-grid,
  .dashboard-row,
  .grid-cards,
  .three-column,
  .two-column,
  .features-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    max-width: 100%;
  }

  /* טבלאות רחבות במנגנון scroll פנימי */
  .table-responsive,
  .table-wrapper,
  .datatable-container,
  .table-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
  }

  .table-responsive table,
  .table-wrapper table,
  .datatable-container table,
  .table-container table {
    width: 100%;
    min-width: 0;
  }

  /* דריסה של min-width קשיחים בטבלאות */
  .table[style*="min-width"],
  table[style*="min-width"] {
    min-width: 0;
  }

  /* טבלאות עם min-width קשיח - דריסה */
  .contract-invoices-page .table,
  .table[class*="min-width"],
  table[class*="min-width"] {
    min-width: 0;
    width: 100%;
  }

  /* טבלאות שצריכות גלילה אופקית - מינימום רוחב רק בתוך .table-responsive */
  .table-responsive table[data-scroll="true"],
  .table-wrapper table[data-scroll="true"] {
    min-width: 600px; /* רק לטבלאות שצריכות גלילה */
  }

  /* טפסים ושורות שדות */
  .form-row,
  .filters-row,
  .form-grid,
  .search-filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    width: 100%;
    max-width: 100%;
  }

  .form-group,
  .filter-item {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* כפתורים בשורה אחת – להפוך לעמודה במובייל */
  .actions-row,
  .page-actions,
  .header-actions,
  .projects-header-actions,
  .module-header-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    max-width: 100%;
  }

  .actions-row .btn,
  .page-actions .btn,
  .header-actions .btn,
  .projects-header-actions .btn,
  .module-header-actions .btn {
    flex: 1 1 100%;
    justify-content: center;
    min-width: 0;
    max-width: 100%;
  }

  /* כרטיסים - וידוא שהם לא יוצרים גלישה */
  .card,
  .kpi-card,
  .stat-card,
  .info-card,
  .feature-card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-left: 0;
    margin-right: 0;
  }

  /* ✅ תיקון: grid-cols-12 במובייל - Mobile-First */
  /* כל grid-cols-12 במובייל הופך ל-grid-cols-1 */
  .grid.grid-cols-12,
  .grid[class*="grid-cols-12"] {
    grid-template-columns: 1fr;
  }

  /* ✅ תיקון: col-span במובייל - כל col-span הופך ל-col-span-1 */
  .col-span-1,
  .col-span-2,
  .col-span-3,
  .col-span-4,
  .col-span-5,
  .col-span-6,
  .col-span-7,
  .col-span-8,
  .col-span-9,
  .col-span-10,
  .col-span-11,
  .col-span-12 {
    grid-column: span 1;
  }

  /* ✅ תיקון: grid-cols-12 במובייל - Mobile-First */
  /* כל grid-cols-12 במובייל הופך ל-grid-cols-1 */
  .grid.grid-cols-12,
  .grid[class*="grid-cols-12"] {
    grid-template-columns: 1fr;
  }

  /* ✅ תיקון: col-span במובייל - כל col-span הופך ל-col-span-1 */
  .col-span-1,
  .col-span-2,
  .col-span-3,
  .col-span-4,
  .col-span-5,
  .col-span-6,
  .col-span-7,
  .col-span-8,
  .col-span-9,
  .col-span-10,
  .col-span-11,
  .col-span-12 {
    grid-column: span 1;
  }

  /* ✅ תיקון: details-grid, info-grid, contract-info, contract-dates במובייל */
  .details-grid,
  .info-grid,
  .contract-info,
  .contract-dates {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  /* Grids - וידוא שהם מתקפלים למובייל */
  .projects-grid,
  .employees-grid,
  .contractors-grid,
  .suppliers-grid,
  .materials-grid,
  .orders-grid,
  .equipment-grid,
  .contracts-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    max-width: 100%;
  }

  /* Sidebars - להפוך לעמודה במובייל */
  .sidebar,
  .side-panel,
  .aside {
    width: 100%;
    max-width: 100%;
    margin-bottom: 1rem;
  }

  /* Flex containers - וידוא שהם מתקפלים */
  .d-flex,
  .flex,
  .flex-row {
    flex-wrap: wrap;
  }

  /* Navigation - וידוא שהוא לא יוצר גלישה */
  nav,
  .navbar,
  .premium-navbar {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* כל אלמנט עם padding או margin גדול - להקטין */
  [class*="px-"],
  [class*="mx-"],
  [class*="p-"],
  [class*="m-"] {
    box-sizing: border-box;
  }

  /* וידוא שאין אלמנטים שיוצאים מהמסך */
  /* לא להשתמש ב-* { max-width: 100% } כי זה יכול לשבור דברים */
  /* במקום זה - רק אלמנטים ספציפיים */
  div,
  section,
  article,
  aside,
  header,
  footer,
  nav,
  main {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* חריגות - אלמנטים שצריכים overflow-x: visible */
  .btn,
  button,
  .btn-group,
  .dropdown-menu,
  .tooltip,
  .popover,
  .kpi-tooltip {
    max-width: none;
  }

  /* Module Content Wrapper - תיקון ספציפי ל-base-module.html */
  .module-content-wrapper,
  .max-w-6xl {
    width: 100%;
    max-width: 100%;
    padding-inline: 12px;
    margin-inline: 0;
    box-sizing: border-box;
  }

  /* כותרת + הסבר בדפי פרויקטים ודפים דומים - זיהוי מחלקות אמיתיות */
  .projects-header,
  .module-header,
  .page-header-complex,
  [class*="page-header"],
  [class*="module-header"] {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .projects-intro-card,
  .module-intro-card,
  .page-description-card,
  [class*="intro-card"],
  [class*="description-card"] {
    width: 100%;
    max-width: 100%;
    margin-bottom: 12px;
    box-sizing: border-box;
  }

  .projects-header-actions,
  .module-header-actions,
  [class*="header-actions"] {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* תמונות ואובייקטים שלא "שוברים" את המסך */
  img,
  picture,
  video,
  canvas,
  svg,
  iframe,
  embed,
  object {
    max-width: 100%;
    height: auto;
    box-sizing: border-box;
  }

  /* Hub Tabs - טיפול בטאבים של Hub */
  .hub-tabs-max-w-6xl {
    width: 100%;
    max-width: 100%;
    padding-inline: 12px;
    margin-inline: 0;
    box-sizing: border-box;
    overflow-x: visible;
  }

  .hub-tabs-max-w-6xl * {
    overflow-x: visible;
  }

  .hub-tabs,
  .hub-tabs-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    padding-bottom: 4px;
    position: relative;
    /* וידוא שהגלילה עובדת */
    scroll-behavior: smooth;
    /* הוספת אינדיקציה ויזואלית שיש עוד תוכן */
    mask-image: linear-gradient(to left, transparent 0%, black 20px);
    -webkit-mask-image: linear-gradient(to left, transparent 0%, black 20px);
  }

  .hub-tab {
    flex-shrink: 0;
    min-width: fit-content;
    white-space: nowrap;
    padding: 10px 16px;
    font-size: 0.9rem;
    /* וידוא שהטאב לא מתכווץ */
    width: auto;
    max-width: none;
  }

  /* Hub Tabs - גלילה אופקית במובייל אם יש יותר מדי טאבים */
  .hub-tabs-container {
    position: relative;
    overflow-x: auto;
    overflow-y: visible;
  }

  /* כל אלמנט עם max-w-* - להפוך ל-100% במובייל */
  [class*="max-w-"] {
    max-width: 100%;
    width: 100%;
  }

  /* mx-auto - להסיר margin אוטומטי במובייל */
  .mx-auto {
    margin-left: 0;
    margin-right: 0;
  }

  /* ========= מודול מסמכים - Documents Module ========= */
  
  /* Container של מסמכים */
  .documents-hub,
  .max-w-7xl {
    width: 100%;
    max-width: 100%;
    padding-inline: 12px;
    margin-inline: 0;
    box-sizing: border-box;
  }

  /* File Manager - סייר קבצים */
  .cpanel-file-manager {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Header של File Manager */
  .fm-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .fm-title {
    width: 100%;
    font-size: 1.1rem;
  }

  .fm-header-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .fm-header-actions .btn-hub-link {
    flex: 1 1 100%;
    justify-content: center;
  }

  /* Search Bar */
  .fm-search-bar,
  .documents-search-bar {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .documents-search-box,
  .search-box {
    width: 100%;
    max-width: 100%;
  }

  .documents-search-input,
  .fm-search {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    font-size: 16px; /* מונע zoom ב-iOS */
  }

  /* Toolbar - סרגל כלים */
  .fm-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 8px 0;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .btn-toolbar {
    flex: 1 1 calc(50% - 3px);
    min-width: 0;
    font-size: 0.85rem;
    padding: 8px 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .btn-toolbar i {
    margin-left: 4px;
  }

  /* Secondary Toolbar */
  .fm-toolbar-secondary {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .toolbar-secondary-left,
  .toolbar-secondary-right {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .btn-toolbar-compact {
    flex: 1 1 calc(50% - 3px);
    min-width: 0;
    font-size: 0.85rem;
    padding: 8px 12px;
  }

  /* Breadcrumbs */
  .fm-breadcrumbs {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0;
  }

  /* Sidebar - עץ תיקיות */
  .fm-sidebar,
  .fm-sidebar-new {
    width: 100%;
    max-width: 100%;
    margin-bottom: 1rem;
    /* אפשר להסתיר או להפוך ל-Accordion */
    display: none; /* מוסתר במובייל - אפשר לשנות ל-block אם רוצים */
  }

  /* כפתור להצגת Sidebar במובייל */
  .fm-sidebar-toggle {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    background: var(--bg-secondary, #f8f9fa);
    border: 1px solid var(--border-subtle, #dee2e6);
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
  }

  /* Main Content - רשימת קבצים */
  .fm-content {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* File Grid - תצוגת כרטיסים */
  .documents-list,
  .file-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 100%;
  }

  /* File Card */
  .file-card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* File List - תצוגת רשימה */
  .file-list {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .file-list table {
    width: 100%;
    min-width: 600px; /* מינימום לגלילה אופקית */
  }

  /* Stats Cards - כרטיסי סטטיסטיקה */
  .stats-card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-bottom: 12px;
  }

  /* Grid של סטטיסטיקות */
  .flex.flex-wrap.-mx-4 {
    margin-left: 0;
    margin-right: 0;
  }

  .flex.flex-wrap.-mx-4 > [class*="w-"],
  .flex.flex-wrap.-mx-4 > [class*="lg:w-"],
  .flex.flex-wrap.-mx-4 > [class*="md:w-"] {
    width: 100%;
    padding-left: 0;
    padding-right: 0;
    margin-bottom: 12px;
  }

  /* View Toggle - כפתורי תצוגה */
  .view-toggle {
    display: flex;
    gap: 4px;
    width: 100%;
    justify-content: center;
  }

  .btn-view {
    flex: 1;
    max-width: 50%;
  }

  /* Modal - מודלים במובייל */
  .modal-content {
    width: 95%;
    max-width: 95%;
    margin: 10% auto;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-body {
    padding: 20px 16px;
  }

  /* Upload Area */
  .upload-area {
    padding: 30px 16px;
  }

  /* Info Panel */
  .fm-info-panel {
    width: 100%;
    max-width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 50vh;
    overflow-y: auto;
    z-index: 1000;
  }

  /* ========= כללים נוספים לפי הנחיות רספונסיביות ========= */
  
  /* דריסה של כל רוחבים קשיחים */
  [style*="width:"][style*="px"],
  [style*="min-width:"][style*="px"],
  [style*="max-width:"][style*="px"] {
    max-width: 100%;
  }

  /* אלמנטים עם רוחב קשיח - להפוך ל-gmax-width */
  [class*="w-"]:not([class*="max-w-"]):not([class*="min-w-"]) {
    max-width: 100%;
  }

  /* Flex containers - וידוא שהם מתקפלים נכון */
  .d-flex:not(.flex-column),
  .flex:not(.flex-column),
  .flex-row {
    flex-wrap: wrap;
  }

  /* Grid containers - וידוא שהם מתקפלים */
  [class*="grid"]:not([class*="grid-cols-1"]) {
    grid-template-columns: 1fr;
  }

  /* Containers נוספים */
  .container-sm,
  .container-md,
  .container-lg,
  .container-xl,
  .container-xxl {
    width: 100%;
    max-width: 100%;
    padding-inline: 12px;
  }

  /* תיקון ל-Tailwind classes */
  .max-w-sm,
  .max-w-md,
  .max-w-lg,
  .max-w-xl,
  .max-w-2xl,
  .max-w-3xl,
  .max-w-4xl,
  .max-w-5xl,
  .max-w-6xl,
  .max-w-7xl,
  .max-w-full {
    max-width: 100%;
    width: 100%;
  }

  /* תיקון ל-mx-auto */
  .mx-auto {
    margin-left: 0;
    margin-right: 0;
  }

  /* תיקון ל-px-* */
  [class*="px-"] {
    padding-left: 12px;
    padding-right: 12px;
  }

  /* תיקון ל-mx-* */
  [class*="mx-"]:not(.mx-auto) {
    margin-left: 0;
    margin-right: 0;
  }
}

}

