/* Phone layout (Peter, 2026-11-02: the CRM must be usable on the road). Loaded after styles.css; see mobile.js. */
.mobile-more,.mobile-filter-toggle,.mobile-only{display:none}
@media(max-width:900px){
  html,body{overflow-x:clip}
  .app-shell{display:block;min-height:100dvh}
  input,select,textarea{font-size:16px!important;max-width:100%}
  main{min-width:0;width:100%}
  img,video,svg{max-width:100%}

  /* Bottom bar: the five road tools plus More */
  .sidebar{position:fixed;left:0;right:0;top:auto;bottom:0;width:100%;height:auto;flex-direction:row;padding:4px 4px calc(4px + env(safe-area-inset-bottom));z-index:10;background:var(--brand-white);border-top:1px solid var(--brand-line);border-right:0}
  .sidebar .brand,.sidebar .sidebar-bottom,.sidebar:before,.sidebar:after{display:none}
  #nav{display:flex;flex:1;width:100%;min-width:0;gap:2px;justify-content:space-between;overflow:visible}
  #nav .nav-item{display:none;position:relative;flex:1 1 0;min-width:0;min-height:52px;margin:0;padding:6px 2px;flex-direction:column;align-items:center;justify-content:center;gap:2px;font-size:10px!important;line-height:1.1;letter-spacing:0;text-transform:none;text-align:center;white-space:normal;border-left:0;background:none}
  #nav .nav-item>span{width:auto;font-size:18px;line-height:1}
  #nav .nav-item[data-view="gps"]>span{font-size:0}
  #nav .nav-item[data-view="gps"]>span:before{content:"📍";font-size:18px}
  #nav .nav-item>b{display:block;position:absolute;top:2px;left:calc(50% + 6px);margin:0;padding:1px 5px;min-width:0;font-size:9px;line-height:1.3;border-radius:9px}
  #nav .nav-item.active{background:var(--brand-cream);color:var(--brand-blue)}
  #nav .nav-item[data-view="funnel"],#nav .nav-item[data-view="companies"],#nav .nav-item[data-view="tasks"],#nav .nav-item[data-view="gps"],#nav .nav-item[data-view="inbox"],#nav .mobile-more{display:flex}
  #nav .nav-item[hidden]{display:none!important}

  /* More: the whole menu as a full-screen list */
  body.mobile-nav-open{overflow:hidden}
  body.mobile-nav-open .sidebar{top:0;flex-direction:column;overflow-y:auto;padding:12px 12px calc(12px + env(safe-area-inset-bottom));z-index:15}
  body.mobile-nav-open .sidebar .sidebar-bottom{display:block;flex:none;margin:0;width:100%}
  body.mobile-nav-open .sidebar .sidebar-bottom .nav-item{display:flex!important;width:100%;min-height:48px;justify-content:flex-start;gap:14px;padding:10px 12px;font-size:15px!important;letter-spacing:0;text-transform:none}
  body.mobile-nav-open .sidebar .sidebar-bottom .nav-item[hidden]{display:none!important}
  body.mobile-nav-open .sidebar .system-status{display:none}
  body.mobile-nav-open #nav{flex:none;flex-direction:column;gap:0}
  body.mobile-nav-open #nav .nav-item{display:flex;flex:none;flex-direction:row;justify-content:flex-start;gap:14px;width:100%;min-height:48px;padding:10px 12px;font-size:15px!important;text-align:left;border-bottom:1px solid var(--brand-line)}
  body.mobile-nav-open #nav .nav-item>span{width:24px;text-align:center}
  body.mobile-nav-open #nav .nav-item>b{position:static;margin-left:auto;font-size:11px}
  body.mobile-nav-open #nav .mobile-more{order:-1;font-weight:700}
  #nav .nav-item[hidden],body.mobile-nav-open #nav .nav-item[hidden]{display:none!important}

  /* Header scrolls away so the data gets the screen */
  .topbar{position:static;height:auto;flex-wrap:wrap;gap:8px;padding:10px 12px}
  .topbar .eyebrow{display:none}
  .topbar>div:first-child{flex:1 1 0;min-width:0}
  .topbar h1{margin:0;font-size:20px;overflow-wrap:anywhere}
  .top-actions{display:contents}
  .top-actions .button{min-height:40px;padding:8px 12px;font-size:11px}
  .top-actions .button:after{content:none}
  #new-company{font-size:0;min-width:40px;padding:8px}
  #new-company:after{content:"+";font-size:20px}
  .global-search{display:flex;order:3;flex:1 0 100%;width:100%;min-width:0;margin:0}
  .global-search input{width:100%;min-width:0}

  .view{padding:12px 12px calc(84px + env(safe-area-inset-bottom));min-width:0}
  .panel,.table-wrap,.form-card{max-width:100%}
  .table-wrap{overflow-x:auto}
  .panel{min-width:0}
  .panel-head{flex-wrap:wrap;gap:8px}
  .button{min-height:40px}
  .gps-actions a,.ticket-company a,.link-button,.tfilter{display:inline-flex;align-items:center;min-height:40px;padding:0 10px}
  .gps-customer{display:inline-block;padding:10px 0}
  .button.small{min-height:36px}

  /* Filters fold behind one button */
  .section-tools{display:block}
  .section-tools>.button,.section-tools>a.button{margin-top:8px}
  .mobile-filter-toggle{display:flex;width:100%;justify-content:space-between;align-items:center;margin-bottom:8px;background:white}
  .filters.mobile-folded{display:none}
  .filters:not(.mobile-folded){display:grid;grid-template-columns:minmax(0,1fr);gap:8px;margin-bottom:8px}
  .filters .filter{display:flex;justify-content:space-between;align-items:center;gap:8px;width:100%;min-width:0;min-height:44px;box-sizing:border-box}
  .filters .filter select,.filters .filter input{flex:1;min-width:0}
  .filters>select,.filters>input{min-height:44px;padding:0 10px;border:1px solid var(--line);width:100%;box-sizing:border-box}
  .ticket-filters.mobile-folded{display:none}
  .ticket-tabs{display:flex;flex-wrap:wrap;gap:6px}
  .ticket-tabs .filter{flex:1 1 auto;min-height:44px}

  /* Everything that was side by side goes under each other */
  .metrics{grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:8px}
  .dashboard-grid,.tasks-layout,.settings-grid,.form-grid,.detail-grid,.hero,.sample-details,.trade-profile,.gps-columns,.gps-charts{grid-template-columns:minmax(0,1fr)!important}
  .field.full,.detail-section.full{grid-column:auto}
  .hero{padding:18px}

  /* Funnel: one stage at a time, see renderFunnel() */
  .funnel-wrap{max-height:none;overflow:visible;padding:0}
  .funnel{display:block;min-width:0}
  .funnel-stage-pick{display:flex;justify-content:space-between;align-items:center;gap:8px;min-height:48px;margin-bottom:8px;background:white;font-weight:700}
  .funnel-stage-pick select{flex:1;min-width:0}
  .funnel-more{width:100%;margin-top:8px}
  .funnel-col{width:100%;min-height:0}
  .funnel-head{position:static;margin:-10px -10px 0}
  .funnel-cards{min-height:60px}
  .funnel-phone{padding:6px 0;font-size:15px}

  /* Company page */
  .company-page,.company-page .drawer-body{min-width:0}
  .company-page{min-height:0}
  .company-page .drawer-head{top:0;flex-wrap:wrap;gap:8px;padding:12px}
  .company-page .drawer-body{padding:12px 0}
  .drawer-head{flex-wrap:wrap;gap:8px}
  .drawer-actions .button{flex:1 1 auto}
  .drawer:not(.company-page){width:100vw}
  .drawer-body{padding:12px}
  .detail-section{padding:14px}
  .detail-kv{grid-template-columns:minmax(90px,34%) minmax(0,1fr);font-size:13px;overflow-wrap:anywhere}
  .detail-kv a{word-break:break-word}

  .drawer-head>div{flex:1 1 0;min-width:0}
  .drawer-head a{overflow-wrap:anywhere}
  .drawer-topline{flex-wrap:wrap}
  .drawer-actions{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:8px}
  .drawer-actions .button{width:100%;min-width:0;padding:8px 6px;white-space:normal;line-height:1.2;justify-content:center;text-align:center}
  .drawer-actions .mobile-only{display:inline-flex;align-items:center}
  .drawer-actions .mobile-actions-toggle{grid-column:1/-1}
  .drawer-actions .mobile-extra{display:none}
  .drawer-actions.show-extra .mobile-extra{display:inline-flex;align-items:center}

  /* GPS: map and nearest companies first */
  *:has(>.gps-map-panel){display:flex;flex-direction:column;gap:12px}
  .gps-map-panel{order:-3}
  .gps-nearby-panel{order:-2}
  .gps-head{order:-1}
  .gps-map{height:56dvh;min-height:320px}

  /* Dialogs fill the phone */
  .modal{position:fixed;inset:0;left:0;top:0;width:100%;height:100dvh;max-height:none;border-radius:0;transform:none;display:flex;flex-direction:column}
  .modal-body{flex:1;overflow-y:auto;padding:14px}
  .modal-head{padding:14px}
  .modal-foot{padding:10px 14px calc(10px + env(safe-area-inset-bottom));background:white}
  .icon-button{min-width:40px;min-height:40px}

  .toast-region{left:12px;right:12px;bottom:calc(72px + env(safe-area-inset-bottom))}
  .toast{max-width:none}
  .login-screen{padding:12px}
  .login-card{width:100%;max-width:420px;padding:26px}
  .settings-menu{display:flex;overflow-x:auto}
  .settings-menu button{white-space:nowrap}

  /* Tables without a card layout scroll inside their own box */
  .view table:not(.mobile-cards){display:block;max-width:100%;overflow-x:auto}
}
@media(max-width:760px){
  /* Data tables become one card per row */
  table.mobile-cards{display:block;width:100%;min-width:0!important;border:0;background:none}
  table.mobile-cards thead{display:none}
  table.mobile-cards tbody{display:grid;gap:8px}
  table.mobile-cards tr{display:block;background:white;border:1px solid var(--line);padding:10px 12px}
  table.mobile-cards td{display:grid;grid-template-columns:minmax(84px,32%) minmax(0,1fr);gap:8px;align-items:start;width:auto!important;max-width:none!important;padding:5px 0;border:0;font-size:13px;white-space:normal;overflow-wrap:anywhere;text-align:left}
  table.mobile-cards td:before{content:attr(data-label);font-size:11px;color:var(--muted)}
  table.mobile-cards td>*{min-width:0}
  table.mobile-cards td:first-child{display:block;font-size:14px;padding-top:0}
  table.mobile-cards td:first-child:before{content:none}
  table.mobile-cards td:nth-child(3),table.mobile-cards td:nth-child(5){display:grid}
  table.mobile-cards td.mobile-empty,table.mobile-cards td[data-label="Enrichment"],table.mobile-cards td[data-label="Monthly estimate"]{display:none}
  table.mobile-cards tr[data-company]{cursor:pointer}
  table.mobile-cards tr[hidden]{display:none}
  .mobile-more-rows{width:100%;margin-top:8px;display:flex;justify-content:center}
  .mobile-more-rows[hidden]{display:none}
  .influencer-grid>[hidden],.social-grid>[hidden],#ticket-list>[hidden]{display:none!important}
  table.mobile-cards a[href^="tel:"]{display:inline-flex;align-items:center;min-height:40px;font-size:15px}
  .table-wrap{overflow:visible;background:none;border:0}
}

@media (max-width:900px){
  .map-search{grid-template-columns:1fr}
  .map-main{order:-1}
  .company-map{height:56dvh}
  .map-list{max-height:none}
}
