/* FarmManagerPro Stage 6.1 — responsive/mobile fit fix.
   Presentation only. No business/data writes. */

@media (max-width:1099px){
  html,body{max-width:100%;overflow-x:hidden}
  body.authenticated{max-width:100%;overflow-x:hidden}
  body.authenticated *,body.authenticated *::before,body.authenticated *::after{box-sizing:border-box}
  body.authenticated #appMain{width:100%;max-width:100%;padding-left:clamp(8px,3vw,14px)!important;padding-right:clamp(8px,3vw,14px)!important;overflow-x:hidden}
  body.authenticated .view,body.authenticated .card,body.authenticated .stat,body.authenticated .ops-subcard,
  body.authenticated .section-card592,body.authenticated .fmp6-surface,body.authenticated .table-scroll,
  body.authenticated .dashboard-panel-v561,body.authenticated .dashboard-kpi-v561{min-width:0!important;max-width:100%!important}

  /* Header: marka i przyciski nie mogą wypychać szerokości. */
  body.authenticated .header-inner{width:100%;max-width:100%;min-width:0;gap:clamp(5px,2vw,9px)!important;padding-left:clamp(9px,3vw,13px)!important;padding-right:clamp(9px,3vw,13px)!important}
  body.authenticated .brand-wrap{flex:1 1 auto;min-width:0;max-width:100%;overflow:hidden;gap:8px!important}
  body.authenticated .brand-wrap>div{min-width:0;overflow:hidden}
  body.authenticated .brand-wrap h1{font-size:clamp(13px,4.15vw,17px)!important;line-height:1.05!important;white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important;word-break:normal!important;overflow-wrap:normal!important}
  body.authenticated .header-sub{font-size:clamp(9px,2.5vw,11px)!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  body.authenticated .brand-mark{flex:0 0 auto}
  body.authenticated .header-actions{flex:0 0 auto;min-width:0;gap:5px!important}
  body.authenticated .header-button{flex:0 0 auto;min-width:36px!important;width:clamp(36px,10vw,42px)!important;height:clamp(36px,10vw,42px)!important;padding:0!important}

  /* Plantacja / sezon zawsze równo po połowie. */
  body.authenticated .scope-bar-inner{width:100%;grid-template-columns:minmax(0,1fr) minmax(0,1fr)!important;gap:clamp(6px,2vw,9px)!important}
  body.authenticated .scope-bar label{min-width:0!important;max-width:100%!important}
  body.authenticated .scope-bar select{min-width:0!important;max-width:100%!important;font-size:clamp(10px,2.8vw,12px)!important;text-overflow:ellipsis}

  /* Nigdy nie łam krótkich wartości liczbowych w połowie. */
  body.authenticated h1,body.authenticated h2,body.authenticated h3,body.authenticated h4,
  body.authenticated strong,body.authenticated b{word-break:normal!important;overflow-wrap:normal!important}
  body.authenticated .muted,body.authenticated p,body.authenticated small,body.authenticated span{min-width:0}

  /* Nagłówki modułów skalują się do szerokości urządzenia. */
  body.authenticated .fmp6-page-heading{width:100%;min-width:0!important;padding:clamp(10px,3vw,13px)!important}
  body.authenticated .fmp6-page-heading>div:first-child{min-width:0!important;padding-left:clamp(45px,13vw,50px)!important}
  body.authenticated .fmp6-page-heading h2{font-size:clamp(18px,5.2vw,22px)!important;line-height:1.08!important;hyphens:auto}
  .fmp6-heading-icon{left:0!important;width:clamp(37px,10.5vw,41px)!important;height:clamp(37px,10.5vw,41px)!important}

  /* Hero Start. */
  #dashboard>.page-heading.dashboard-hero-heading{width:100%;height:clamp(126px,37vw,150px)!important;min-height:126px!important;padding:clamp(15px,4.5vw,20px)!important}
  #dashboard>.page-heading.dashboard-hero-heading>div:first-child{max-width:60%!important;min-width:0!important}
  #dashboard>.page-heading.dashboard-hero-heading h2{font-size:clamp(20px,6.1vw,25px)!important;line-height:1.03!important}
  #dashboard>.page-heading.dashboard-hero-heading .page-description{font-size:clamp(9.5px,2.9vw,11.5px)!important;line-height:1.32!important}

  /* Akcje: nie ściskaj 3 kafelków na małym telefonie. */
  #dashboardQuickActions.dashboard-quick-actions{width:100%;grid-template-columns:repeat(3,minmax(0,1fr))!important;gap:clamp(7px,2vw,10px)!important}
  #dashboardQuickActions.dashboard-quick-actions button{min-width:0!important;max-width:100%!important;overflow:hidden!important}
  #dashboardQuickActions.dashboard-quick-actions button>div{min-width:0!important}
  #dashboardQuickActions.dashboard-quick-actions button b{font-size:clamp(10px,3vw,12px)!important;line-height:1.15!important;overflow-wrap:normal!important;word-break:normal!important}
  #dashboardQuickActions.dashboard-quick-actions button small{font-size:clamp(7.5px,2.15vw,9px)!important;line-height:1.2!important}

  /* KPI: 2 kolumny, liczby nigdy nie nachodzą na sąsiedni kafel. */
  .dashboard-kpi-grid-v561{width:100%;grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:clamp(7px,2vw,10px)!important}
  .dashboard-kpi-v561{width:100%;min-width:0!important;grid-template-columns:clamp(31px,9vw,38px) minmax(0,1fr)!important;gap:clamp(7px,2vw,10px)!important;padding:clamp(10px,3.2vw,13px)!important;overflow:hidden!important}
  .dashboard-kpi-v561>div{min-width:0!important;max-width:100%!important;overflow:hidden!important}
  .dashboard-kpi-v561 small{font-size:clamp(8px,2.35vw,9.5px)!important;line-height:1.15!important;white-space:normal!important}
  .dashboard-kpi-v561 strong{display:block!important;max-width:100%!important;font-size:clamp(16px,4.7vw,20px)!important;line-height:1.08!important;white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important;letter-spacing:-.025em!important}
  .dashboard-kpi-v561 em{display:block!important;max-width:100%!important;font-size:clamp(7.5px,2.2vw,9px)!important;white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important}
  .dashboard-sparkline{max-width:35%!important;pointer-events:none}

  /* Dashboard niżej: pełna szerokość, zero ściskania tekstu. */
  .dashboard-core-grid-v561{width:100%;grid-template-columns:minmax(0,1fr)!important;gap:10px!important}
  .dashboard-panel-v561{width:100%;overflow:hidden!important;padding:clamp(12px,3.5vw,15px)!important}
  .dashboard-panel-title{min-width:0;flex-wrap:wrap!important;gap:7px!important}
  .dashboard-panel-title h3{min-width:0;font-size:clamp(13px,3.9vw,16px)!important;line-height:1.15!important}
  .dashboard-panel-title button{flex:0 0 auto;max-width:100%;font-size:clamp(8px,2.3vw,10px)!important}
  .dashboard-donut-layout{width:100%;grid-template-columns:minmax(96px,34%) minmax(0,1fr)!important;gap:clamp(9px,3vw,14px)!important}
  .dashboard-donut{width:min(30vw,118px)!important;height:min(30vw,118px)!important;min-width:96px!important;min-height:96px!important}
  .dashboard-crop-legend,.dashboard-crop-legend>*{min-width:0!important;max-width:100%!important}
  .dashboard-crop-legend b,.dashboard-crop-legend span{font-size:clamp(8.5px,2.5vw,10px)!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

  .dashboard-system-v561,.dashboard-system-v561 *{min-width:0}
  .dashboard-system-stat{max-width:100%!important;overflow:hidden!important}
  .dashboard-system-stat strong{font-size:clamp(18px,5vw,22px)!important;white-space:nowrap!important;overflow:hidden;text-overflow:ellipsis}
  .dashboard-system-stat span,.dashboard-system-stat small{font-size:clamp(8.5px,2.45vw,10px)!important;line-height:1.25!important;white-space:normal!important}
  .dashboard-cloud-list>div{display:grid!important;grid-template-columns:minmax(0,1fr) max-content!important;gap:8px!important;align-items:center!important}
  .dashboard-cloud-list b,.dashboard-cloud-list span{font-size:clamp(8.2px,2.35vw,9.5px)!important;min-width:0!important}
  .dashboard-cloud-list b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .dashboard-cloud-list span{text-align:right;white-space:nowrap}
  .dashboard-system-primary,.dashboard-system-secondary{width:100%!important;white-space:normal!important;line-height:1.2!important}

  /* TOP / rankingi. Nazwa ma elastyczne miejsce, wynik pozostaje z prawej. */
  .dashboard-worker-row{width:100%;grid-template-columns:20px 28px minmax(0,1fr) max-content!important;gap:7px!important}
  .dashboard-worker-row>div{min-width:0!important}
  .dashboard-worker-row b{display:block;min-width:0;font-size:clamp(9px,2.8vw,11px)!important;white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important}
  .dashboard-worker-row strong{font-size:clamp(8px,2.4vw,10px)!important;white-space:nowrap!important}
  .sales-ranking-row{width:100%;grid-template-columns:clamp(30px,9vw,36px) minmax(0,1fr)!important;gap:9px!important}
  .sales-ranking-main{min-width:0!important}
  .sales-ranking-main>div:first-child{display:grid!important;grid-template-columns:minmax(0,1fr) max-content!important;gap:8px!important;min-width:0!important}
  .sales-ranking-main b{min-width:0!important;white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important;font-size:clamp(10px,3vw,12px)!important}
  .sales-ranking-main strong{font-size:clamp(9px,2.7vw,11px)!important;white-space:nowrap!important}
  .sales-ranking-main small{font-size:clamp(8.5px,2.5vw,10px)!important;line-height:1.25!important}

  /* Rekordy i wszystkie duże tabele: przewijamy TYLKO tabelę, nie cały ekran. */
  body.authenticated .table-scroll{display:block!important;width:100%!important;max-width:100%!important;overflow-x:auto!important;overflow-y:hidden!important;-webkit-overflow-scrolling:touch!important;overscroll-behavior-inline:contain;scrollbar-width:thin}
  body.authenticated .table-scroll table{width:max-content!important;min-width:680px!important;max-width:none!important;table-layout:auto!important}
  #adminRecords .table-scroll table{min-width:650px!important}
  #sales .table-scroll table{min-width:900px!important}
  #inventory .table-scroll table{min-width:760px!important}
  #operations .table-scroll table{min-width:820px!important}
  body.authenticated .table-scroll th,body.authenticated .table-scroll td{white-space:nowrap!important;word-break:normal!important;overflow-wrap:normal!important}
  body.authenticated .table-scroll td button{white-space:nowrap!important}

  /* Karty, listy, formularze i paginacja nie wychodzą poza ekran. */
  body.authenticated .section-title{min-width:0;max-width:100%;gap:7px!important}
  body.authenticated .section-title>div{min-width:0!important}
  body.authenticated .section-title h3{font-size:clamp(13px,3.9vw,16px)!important;line-height:1.15!important}
  body.authenticated .section-title .muted{max-width:100%;font-size:clamp(9px,2.5vw,11px)!important}
  body.authenticated .form-grid,body.authenticated .ops-form-grid,body.authenticated .ops-two-column,
  body.authenticated .finance-layout,body.authenticated .sales-layout,body.authenticated .settings-layout{min-width:0!important;max-width:100%!important}
  body.authenticated input,body.authenticated select,body.authenticated textarea{max-width:100%!important;min-width:0!important}
  body.authenticated .button-row{max-width:100%;flex-wrap:wrap!important}
  body.authenticated .button-row>*{min-width:min(140px,100%);max-width:100%}
  body.authenticated .history-pager{display:flex!important;flex-wrap:wrap!important;gap:8px!important;align-items:center!important}
  body.authenticated .history-pager>span{flex:1 1 150px;min-width:0}
  body.authenticated .history-pager-actions{display:flex;gap:6px;flex:0 0 auto}

  /* Pracownicy/listy — żadnego łamania nazw w połowie. */
  #employees #employeeList>*,#contractorList>*,#backupHistory>*{max-width:100%!important;min-width:0!important}
  .employee-main,.employee-info,.title-line{min-width:0!important}
  .employee-info h3,.employee-info h2,.title-line h3,.title-line h2{min-width:0;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

  /* More — równe kafelki. */
  .more-menu-grid{width:100%;grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:8px!important}
  .more-menu-grid button{min-width:0!important;max-width:100%!important;overflow:hidden!important;padding:10px!important}
  .more-menu-grid button b,.more-menu-grid button strong,.more-menu-grid button:not(:has(b)){word-break:normal!important;overflow-wrap:normal!important}

  /* Dolna nawigacja mieści się również na 320–360 px. */
  .bottom-nav{width:100%!important;max-width:100%!important;grid-template-columns:repeat(5,minmax(0,1fr))!important;padding-left:max(2px,env(safe-area-inset-left))!important;padding-right:max(2px,env(safe-area-inset-right))!important}
  .bottom-nav>button{min-width:0!important;padding-left:2px!important;padding-right:2px!important;font-size:clamp(8.5px,2.5vw,10px)!important}
  .bottom-nav>button span{max-width:100%}
}

/* Typowy telefon / terminal 360–430 CSS px. */
@media (max-width:430px){
  body.authenticated #appMain{padding-left:8px!important;padding-right:8px!important}
  body.authenticated .header-sub{display:none!important}
  #dashboardQuickActions.dashboard-quick-actions{grid-template-columns:repeat(2,minmax(0,1fr))!important}
  #dashboardQuickActions.dashboard-quick-actions button:first-child{grid-column:1/-1!important}
  #dashboardQuickActions.dashboard-quick-actions button:last-child{grid-column:auto!important}
  #dashboardQuickActions.dashboard-quick-actions button{min-height:66px!important;grid-template-columns:34px minmax(0,1fr)!important;padding:9px!important}
  #dashboardQuickActions.dashboard-quick-actions button small{display:none!important}
  #dashboardQuickActions.dashboard-quick-actions button b{font-size:11px!important}
  .dashboard-sparkline{display:none!important}
  .dashboard-kpi-v561{min-height:92px!important}
  .dashboard-kpi-v561 strong{font-size:clamp(15px,4.5vw,18px)!important}
  .dashboard-kpi-v561 em{font-size:8px!important}
  .dashboard-donut-layout{grid-template-columns:minmax(92px,34%) minmax(0,1fr)!important}
  .dashboard-cloud-list>div{grid-template-columns:1fr!important;gap:2px!important}
  .dashboard-cloud-list span{text-align:left!important}
  .bottom-nav>button#quickScanNavStage5 span{width:54px!important;height:54px!important;margin:-28px auto 3px!important}
}

/* Bardzo wąski ekran — nadal bez poziomego rozjechania. */
@media (max-width:350px){
  .dashboard-kpi-grid-v561{grid-template-columns:1fr!important}
  .dashboard-kpi-v561{min-height:82px!important}
  .more-menu-grid{grid-template-columns:1fr!important}
  body.authenticated .scope-bar-inner{grid-template-columns:1fr!important}
  #dashboard>.page-heading.dashboard-hero-heading>div:first-child{max-width:68%!important}
  .bottom-nav>button{font-size:8px!important}
}

/* Landscape: wykorzystaj szerokość, ale nadal bez stałych wymiarów. */
@media (max-width:1099px) and (orientation:landscape) and (min-width:620px){
  .dashboard-kpi-grid-v561{grid-template-columns:repeat(4,minmax(0,1fr))!important}
  #dashboardQuickActions.dashboard-quick-actions{grid-template-columns:repeat(4,minmax(0,1fr))!important}
  #dashboardQuickActions.dashboard-quick-actions button:first-child{grid-column:span 2!important}
  #dashboardQuickActions.dashboard-quick-actions button:last-child{grid-column:auto!important}
}


/* FarmManagerPro Stage 6.3 — mobile action/ranking hard fix */
@media (max-width:1099px){
  #dashboardQuickActions.dashboard-quick-actions button{grid-template-rows:auto auto!important;align-items:center!important}
  #dashboardQuickActions.dashboard-quick-actions button>span{grid-column:1!important;grid-row:1 / span 2!important}
  #dashboardQuickActions.dashboard-quick-actions button>b{grid-column:2!important;grid-row:1!important;align-self:end!important}
  #dashboardQuickActions.dashboard-quick-actions button>small{grid-column:2!important;grid-row:2!important;align-self:start!important}
  #dashboardQuickActions.dashboard-quick-actions button:first-child{grid-template-columns:58px minmax(0,1fr)!important;min-height:82px!important;padding:12px 14px!important}
  #dashboardQuickActions.dashboard-quick-actions button:first-child>span{width:52px!important;height:52px!important;border-radius:15px!important;font-size:27px!important}
  #dashboardQuickActions.dashboard-quick-actions button:first-child>b{font-size:17px!important;line-height:1.1!important;font-weight:900!important;padding-left:2px!important;white-space:nowrap!important}
  .dashboard-workers-v561.fmp63-ranking-visible{display:block!important;visibility:visible!important;opacity:1!important;grid-column:1/-1!important;grid-row:auto!important;order:3!important;min-height:0!important}
  .dashboard-crops-v561{order:2!important}.dashboard-system-v561{order:4!important}
}
@media (max-width:430px){
  #dashboardQuickActions.dashboard-quick-actions button:first-child{grid-template-columns:56px minmax(0,1fr)!important}
  #dashboardQuickActions.dashboard-quick-actions button:first-child>b{font-size:16px!important}
  #dashboardQuickActions.dashboard-quick-actions button:last-child{grid-column:auto!important}
}
