/* Every rule is phone-only. Desktop controls are restored to their original DOM
   positions by mobile-navigation.js when leaving this breakpoint. */
@media screen and (max-width: 767px) {
  html { scroll-padding-top: calc(72px + env(safe-area-inset-top)); }
  body .main { width:100%; max-width:100%; min-width:0; margin-inline:0; }
  body .main > .page { width:100%; min-width:0; max-width:100%; padding:12px max(10px,env(safe-area-inset-right)) calc(88px + env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left)); }
  body .topbar {
    display:grid; grid-template-columns:44px minmax(0,1fr) 44px;
    grid-template-areas:'menu brand empty'; grid-template-rows:1fr;
    height:calc(64px + env(safe-area-inset-top)); min-height:64px;
    padding:env(safe-area-inset-top) max(10px,env(safe-area-inset-right)) 0 max(10px,env(safe-area-inset-left));
    gap:0; align-items:center; position:sticky; top:0; z-index:100;
  }
  .topbar > .mobile-header-brand[hidden] { display:block !important; grid-area:brand; justify-self:center; width:156px; max-width:100%; height:52px; object-fit:contain; }
  .topbar > .topbar-date { display:none; }
  .mobile-page-heading { padding:16px max(12px,env(safe-area-inset-right)) 0 max(12px,env(safe-area-inset-left)); }
  .mobile-page-heading .topbar-title { font-size:23px; line-height:1.35; font-weight:800; color:var(--navy); overflow-wrap:anywhere; }
  .main:has(> .page.active > :is(.page-header,.dashboard-toolbar) .page-title) > .mobile-page-heading { display:none; }
  #global-sidebar { width:min(360px,calc(100vw - 28px)); display:block; }
  #global-sidebar .sidebar-main { display:flex; flex-direction:column; width:100%; height:100%; overflow-y:auto; overscroll-behavior:contain; padding-bottom:env(safe-area-inset-bottom); }
  #global-sidebar .sidebar-logo { flex:none; position:sticky; top:0; z-index:2; min-height:64px; padding:8px 12px; background:#fff; }
  #global-sidebar .sidebar-logo-home img { width:150px; height:50px; object-fit:contain; min-height:0; }
  #global-sidebar .sidebar-divider { display:none; }
  #global-sidebar .sidebar-main-nav { flex:none; overflow:visible; padding-inline:8px; }
  #global-sidebar .sidebar-context { flex:none; margin-inline:14px; padding-block:12px; }
  #global-sidebar .sidebar-context-title { font-size:17px; }
  #global-sidebar .sidebar-rail { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); flex:none; width:100%; height:auto; gap:6px; overflow:visible; padding:12px; border-block:1px solid #e4edf2; background:#f6fafc; }
  #global-sidebar .sidebar-rail .rail-item { display:flex; align-items:center; justify-content:flex-start; gap:8px; width:100%; height:auto; min-height:46px; padding:8px; border-radius:10px; color:#426579; }
  #global-sidebar .sidebar-rail .rail-item.active { color:#d8fcff; background:#21485c; }
  #global-sidebar .sidebar-rail .rail-item:hover { color:#fff; }
  #global-sidebar .sidebar-rail .rail-item::after { content:attr(aria-label); font-family:inherit; font-size:13px; line-height:1.4; white-space:normal; text-align:start; }
  #global-sidebar .sidebar-rail .rail-icon { width:20px; flex:0 0 20px; }
  #global-sidebar .sidebar-rail [hidden] { display:none !important; }
  .mobile-drawer-account,.mobile-drawer-tools { flex:none; padding:10px 12px; }
  .mobile-drawer-tools { display:grid; gap:10px; border-top:1px solid #e4edf2; }
  .mobile-drawer-account .topbar-user-wrap,.mobile-drawer-tools .topbar-actions-wrap { width:100%; position:relative; }
  .mobile-drawer-account .topbar-user-btn { width:100%; height:auto; min-height:60px; padding:10px; gap:10px; justify-content:flex-start; border-radius:12px; }
  .mobile-drawer-account .topbar-user-meta { display:flex; flex:1; min-width:0; text-align:start; }
  .mobile-drawer-account .topbar-user-btn > svg { display:block; }
  .mobile-drawer-account .topbar-user-name { white-space:normal; overflow-wrap:anywhere; font-size:16px; }
  .mobile-drawer-account .topbar-user-avatar { flex:0 0 36px; width:36px; height:36px; }
  .mobile-drawer-account .topbar-user-menu,.mobile-drawer-tools .topbar-actions-menu {
    position:static; width:100%; min-width:0; max-height:none; margin-top:8px; overflow:visible; box-shadow:none; border:1px solid #dce9ef;
  }
  .mobile-drawer-account .topbar-user-menu-email { overflow-wrap:anywhere; }
  .mobile-drawer-account .topbar-user-menu-action { width:100%; min-height:46px; height:auto; text-align:start; white-space:normal; gap:8px; }
  .mobile-drawer-tools .topbar-actions-btn,#global-sidebar #mobile-agenda-toggle { display:flex; width:100%; min-height:46px; height:auto; padding:10px 12px; gap:10px; justify-content:flex-start; font-family:inherit; font-size:15px; font-weight:700; }
  .mobile-drawer-tools .topbar-actions-btn > span,.mobile-drawer-tools .topbar-actions-btn > svg:last-child { display:block; }
  #global-sidebar #mobile-agenda-toggle { grid-area:auto; font-family:inherit; }
  .mobile-drawer-tools .topbar-actions-item { min-height:46px; }
  #global-sidebar .sidebar-bottom { flex:none; padding:16px 12px; }
  .main .page-header { min-width:0; gap:10px; flex-wrap:wrap; }
  .main .page-header > div { min-width:0; max-width:100%; }
  .main .page-title { font-size:22px; overflow-wrap:anywhere; }
  .page :is(input,select,textarea,[contenteditable=true]), .modal-overlay :is(input,select,textarea) { font-size:16px; }
  .page :is(button,.btn-primary,.btn-secondary) { white-space:normal; }
  :is(.page,.modal-overlay,.side-panel) :is(input,select,textarea) { scroll-margin-block:80px 110px; }
  .main > .page > * { min-width:0; max-width:100%; }
  #page-customer-card :is(.customer-tab-shell,.panel-section,#customer-card-content) { min-width:0; max-width:100%; }
  #page-customer-card .customer-tab-shell { grid-template-columns:minmax(0,1fr); }
  #page-customer-card .customer-contacts-table-wrap { width:100%; min-width:0; max-width:100%; overflow-x:auto; overscroll-behavior-inline:contain; -webkit-overflow-scrolling:touch; }
  #page-customer-card .customer-contacts-table { min-width:850px; }
  #page-customer-card .customer-agreement-section-head { min-width:0; flex-wrap:wrap; gap:10px; }
  #page-dashboard .kpi-grid { grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
  #page-dashboard .kpi-card { min-width:0; padding:12px 10px; }
  #page-dashboard .kpi-card-head { gap:6px; }
  #page-dashboard .kpi-chart-btn { flex:none; width:44px; height:44px; }
  #page-dashboard .kpi-value { font-size:26px; overflow-wrap:anywhere; }
  #page-dashboard .kpi-label { min-height:36px; font-size:12px; line-height:1.5; }
  #page-dashboard .kpi-trend { font-size:11px; line-height:1.6; overflow-wrap:anywhere; }
  #page-dashboard .kpi-breakdown { gap:5px; }
  #page-dashboard .kpi-breakdown-item { padding:7px; min-height:44px; }
  #page-dashboard .dashboard-column-track { height:90px; }
  .modal-overlay { top:var(--crm-viewport-top,0px); bottom:auto; height:var(--crm-viewport-height,100dvh); }
  .modal-overlay > .modal { max-height:100% !important; }
  body dialog.expense-dialog { top:calc(var(--crm-viewport-top,0px) + 8px); bottom:auto; left:max(8px,env(safe-area-inset-left)); right:max(8px,env(safe-area-inset-right)); width:auto; min-width:0; max-width:none; max-height:calc(var(--crm-viewport-height,100dvh) - 16px); margin:0; overflow-y:auto; scroll-padding-block:70px 100px; }
  body dialog.expense-dialog footer { position:sticky; bottom:0; z-index:1; background:#fff; padding-bottom:max(12px,env(safe-area-inset-bottom)); }
  body dialog.expense-dialog :is(input,select,textarea) { font-size:16px; min-height:44px; scroll-margin-block:80px 100px; }
  body dialog.expense-dialog .expense-form-grid { grid-template-columns:minmax(0,1fr); min-width:0; }
  body dialog.expense-dialog :is(.expense-form-body,.expense-form-grid label) { min-width:0; max-width:100%; }
  body dialog.expense-dialog .form-input { min-width:0; max-width:100%; box-sizing:border-box; }
  body dialog.expense-dialog button { min-height:44px; min-width:44px; }
  body .spec-table-menu[open] > div { position:fixed; top:auto; bottom:max(12px,env(safe-area-inset-bottom)); left:max(12px,env(safe-area-inset-left)); right:max(12px,env(safe-area-inset-right)); width:auto; max-height:min(60dvh,calc(var(--crm-viewport-height,100dvh) - 80px)); overflow-y:auto; z-index:10; }
  body .spec-table-menu[open] > div button { min-height:44px; font-size:14px; text-align:start; }
  body:has(#specification-workspace) .vp-host { z-index:1300; }
  /* Keep short record attributes side by side even on 320px phones. Long
     content and actions retain a full row, without dropping table fields. */
  body .main :is(#page-projects,#page-tasks,#page-leads) .mobile-cards-table > tbody > tr.mobile-table-card { grid-template-columns:repeat(2,minmax(0,1fr)); }
  body .main :is(#page-projects,#page-tasks,#page-leads) .mobile-cards-table > tbody > tr.mobile-table-card > td:is([data-mobile-label="לקוח"],[data-mobile-label="פרויקט"],[data-mobile-label="פרטי קשר"]) { grid-column:1 / -1; }
  body .main :is(#page-projects,#page-tasks,#page-leads) .mobile-cards-table > tbody > tr.mobile-table-band > td { width:100% !important; }
  body:has(> .login-shell),body:has(> main > #change-form) { min-height:100dvh; padding:max(12px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left)); overflow-y:auto; }
  body > .login-shell,body > main:has(> #change-form) { width:100%; min-width:0; padding:24px 18px; margin-block:auto; border-radius:20px; }
  .login-shell :is(input,button),#change-form :is(input,button) { min-height:46px; font-size:16px; }
  .login-shell :is(p,h1),body > main:has(> #change-form) :is(p,h1) { overflow-wrap:anywhere; }
}
