/* Phone and small-tablet layout. Loaded last (stylesheets are linked alphabetically), so these rules win over
   the desktop ones at equal specificity. Breakpoint 860px matches the rest of the app. */

.menu-btn,.rail-cur{display:none}
.auth-top .wordmark .logo-svg{height:30px}
.banner code,pre{overflow-wrap:anywhere}

@media (max-width:860px){
  /* ---- header bar: logo · current page · menu button; the rail becomes a full-screen menu sheet ---- */
  .app{display:block}
  .rail{position:sticky;top:0;z-index:15;height:auto;overflow:visible;flex-direction:row;flex-wrap:nowrap;align-items:center;gap:10px;
        padding:10px max(16px,env(safe-area-inset-right,0px)) 10px max(16px,env(safe-area-inset-left,0px));padding-top:max(10px,env(safe-area-inset-top,0px))}
  .brand{display:flex;align-items:center;gap:8px;width:100%;min-width:0}
  .wordmark .logo-svg{height:24px}
  .admin-badge{margin-top:0;font-size:10px}
  .rail-cur{display:block;min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--rail-mute);font-size:14px;font-weight:500;
            padding-left:10px;border-left:1px solid rgba(255,255,255,.18)}
  .menu-btn{display:grid;place-items:center;margin-left:auto;flex:none;width:44px;height:44px;border:0;border-radius:10px;background:var(--rail-field);color:var(--rail-ink);cursor:pointer;position:relative}
  .menu-btn .i-close,.menu-open .menu-btn .i-open{display:none}
  .menu-open .menu-btn .i-close{display:block}
  .rail-nav,.rail-foot,.rail-search{display:none}

  .rail.menu-open{position:fixed;inset:0;z-index:45;flex-direction:column;flex-wrap:nowrap;align-items:stretch;gap:14px;overflow-y:auto;overscroll-behavior:contain;
                  padding-bottom:max(20px,env(safe-area-inset-bottom,0px))}
  .menu-open .brand{flex:none}
  .menu-open .rail-nav{display:flex;flex-direction:column;gap:12px;width:100%}
  .menu-open .rail-search{display:flex}
  .menu-open .nav{flex-direction:column;overflow:visible;gap:1px}
  .menu-open .nav a.navlink{padding:12px 10px;font-size:16px}
  .menu-open .nav-head{padding:10px 10px 6px}
  .menu-open .rail-foot{display:flex;margin-top:8px}
  .menu-open .rail-acct{flex-wrap:wrap;gap:16px;font-size:14px}
  .menu-open .rail-acct a,.menu-open .rail-acct button{padding:6px 0}
  html.menu-lock,html.menu-lock body{overflow:hidden}
  body::before{display:none}

  /* ---- page frame ---- */
  .main{border-radius:0;margin:0;min-height:0;padding:14px max(16px,env(safe-area-inset-right,0px)) max(48px,env(safe-area-inset-bottom,0px)) max(16px,env(safe-area-inset-left,0px))}
  .topbar{flex-wrap:nowrap;gap:8px;margin-bottom:18px}
  .topbar .btn-home{padding:10px 12px;flex:none}
  .topbar .pill-dark{min-width:0;flex:0 1 auto;max-width:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .topbar .sq-dark{flex:none}
  .top-ava{flex:none}
  .head{margin-bottom:18px;gap:12px}
  .head h1{font-size:26px;line-height:1.2}
  .head p{font-size:14.5px}
  .head .acts,.head > .acts{display:flex;flex-wrap:wrap;gap:8px;width:100%}
  .sec-h{font-size:19px}
  .kpis{grid-template-columns:repeat(2,minmax(0,1fr));gap:18px 16px;margin-bottom:22px}
  .kpi .v,.kpi.lead .v{font-size:23px;gap:6px}
  .kpi .k,.kpi.lead .k{font-size:11.5px}
  .kpi .s,.kpi.lead .s{font-size:12.5px}
  .grid2{grid-template-columns:minmax(0,1fr) !important}

  /* ---- forms: 16px text stops iOS zooming on focus; fields and buttons get finger-sized ---- */
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]),select,textarea{font-size:16px !important}
  .field input,.field select,.filters select,.filters input{min-height:42px}
  .filters{gap:8px}
  .filters > select,.filters > input,.filters > .btn{flex:1 1 auto;min-width:0}
  .btn{min-height:40px;display:inline-flex;align-items:center;justify-content:center;gap:6px}
  .btn.small{min-height:34px;padding:6px 10px;font-size:13px}
  .toolbar{gap:8px}
  .toolbar .sp{display:none}
  .org-grid{grid-template-columns:minmax(0,1fr)}
  .ev-row{grid-template-columns:minmax(0,1fr) 92px 64px 36px}

  /* ---- tables scroll sideways inside their card ---- */
  .tw{-webkit-overflow-scrolling:touch;overscroll-behavior-x:contain}
  th,td{padding-left:10px;padding-right:10px}
  .lines input{min-width:72px}
  .lines .del{width:36px;height:36px}

  /* ---- drawer: full screen; modal: bottom sheet ---- */
  .drawer{width:100%;box-shadow:none}
  .drawer-head{padding:12px 16px 0}
  .drawer-head h2{font-size:17px}
  .drawer-head .x{width:40px;height:40px}
  .drawer-body{padding:14px 16px max(40px,env(safe-area-inset-bottom,0px));overscroll-behavior:contain}
  .modal,.modal.wide{left:0;right:0;top:auto;bottom:0;transform:none;width:100%;max-height:92vh;border-radius:16px 16px 0 0;
                     padding:18px 16px max(18px,env(safe-area-inset-bottom,0px))}
  .toast{z-index:50;left:16px;right:16px;bottom:max(16px,env(safe-area-inset-bottom,0px));transform:none;max-width:none;text-align:center}

  /* ---- documents ---- */
  .paper-wrap{padding:12px 8px;margin-left:-8px;margin-right:-8px}

  /* ---- sign-in pages ---- */
  .auth{padding:max(24px,env(safe-area-inset-top,0px)) 16px 32px}
}

@media (max-width:420px){
  .topbar .btn-home{padding:10px}
  .kpis{gap:16px 12px}
  .kpi .v,.kpi.lead .v{font-size:21px}
}

/* Wide tables keep scrolling sideways on phones; the first column stays put so each row keeps its label. */
@media (max-width:860px){
  .tw > table > thead > tr > th:first-child,.tw > table > tbody > tr > td:first-child{position:sticky;left:0;z-index:1;background:var(--surface);box-shadow:1px 0 0 var(--line)}
  .tw > table > thead > tr > th:first-child{background:var(--surface-2)}
}
