/* Phone and small tablet layout for the website, customer documents and admin portal. Loaded last. */
#sidebar>a.mobile-only,.mobile-only,.menu-close,.drawer-head{display:none}

@media (max-width:860px){
  /* Comfortable touch targets, and 16px fields so iPhones do not zoom when one is tapped. */
  input:not([type=checkbox]):not([type=radio]),select,textarea{font-size:16px!important}
  input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=color]),select{min-height:44px}
  input[type=checkbox],input[type=radio]{width:20px;height:20px;flex:none}
  .check{align-items:center;min-height:36px;gap:10px}.check input{margin-top:0}
  .btn,.site .btn{min-height:44px;display:inline-flex;align-items:center;justify-content:center;text-align:center}
  .btn.block,.site .btn.block{display:flex}
  .btn.small,.site .btn.small{min-height:40px;padding:6px 14px}
  .menu-toggle{width:46px;height:46px;padding:0;flex:none;align-items:center;justify-content:center}
  .menu-toggle{display:inline-flex}
  /* Long words, links and e-mail addresses never widen the page. */
  .panel,.card,.feed li,.details dd,.table td,.alert,.stat,.contact-cards>*{overflow-wrap:anywhere;min-width:0}
  img,video,table{max-width:100%}

  /* ---------- Admin portal ---------- */
  .admin{display:block}
  #sidebar,#sidebar.open{display:block;position:fixed;top:0;bottom:0;left:0;width:min(300px,84vw);height:auto;z-index:50;overflow-y:auto;overscroll-behavior:contain}
  #sidebar{transform:translateX(-105%);visibility:hidden;transition:transform .2s,visibility .2s}
  #sidebar.open{transform:none;visibility:visible;box-shadow:0 0 0 100vmax rgba(3,12,35,.55)}
  body.admin:has(#sidebar.open){overflow:hidden}
  #sidebar>a:not(.logo){padding:11px 12px;font-size:1rem}
  #sidebar>a.mobile-only{display:block;border-top:1px solid rgba(255,255,255,.18);border-radius:0;margin-top:16px}
  .topbar{position:sticky;top:0;z-index:20;flex-wrap:nowrap;gap:10px;padding:8px 12px}
  .topbar h1{font-size:1.05rem;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .who{gap:8px;flex:none}.who small,.who>a[target]{display:none}
  .who>a:first-child{max-width:76px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-weight:600}
  .admin main{padding:12px}
  .admin .panel{padding:14px;margin-bottom:14px}
  .split{grid-template-columns:minmax(0,1fr);gap:0}
  .stats{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}.stat{padding:12px}.stat strong{font-size:1.15rem}
  .toolbar{gap:10px}.toolbar>.btn{flex:1 1 140px}.toolbar>.btn.primary:last-child{margin-left:0}.toolbar>p{flex:1 1 100%;margin:0}
  .toolbar .filters{width:100%}
  .filters{align-items:stretch}.filters>input,.filters>select{flex:1 1 100%;width:100%}
  .filters>label{flex:1 1 100%;display:flex;align-items:center;gap:8px}.filters>label input{flex:1;min-width:0}
  .filters>.btn{flex:1 1 auto}.filters>span{flex:1 1 100%}
  .actions>.btn,.actions>form{flex:1 1 140px}.actions>form .btn{width:100%}
  .reason{flex-wrap:wrap}.reason input{width:100%;flex:1 1 140px}
  .copy{flex-wrap:wrap}.copy input{flex:1 1 100%}
  .row input,.row select{flex:1 1 100%}.row .btn{flex:1 1 100%}
  .row.item{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;border-bottom:2px solid var(--line);padding-bottom:12px;margin-bottom:12px}
  .row.item>[data-source],.row.item>[data-type-field],.row.item>[data-description],.row.item>.btn{grid-column:1/-1}
  .progress.big{width:auto;flex:1;min-width:120px}
  .images{gap:10px}.images figure{width:calc(50% - 5px)}.images img{width:100%;height:120px}
  .files{gap:10px}.files li{width:calc(50% - 5px)}.files img{width:100%}
  .totals{max-width:none}
  .pager a{min-width:42px;text-align:center;padding:9px 12px}

  /* ---------- Website ---------- */
  .site-header .bar{min-height:64px;gap:8px}.site-header .logo img{height:50px}.site-header .logo-name{font-size:1.1rem}
  .site-header nav{max-height:calc(100dvh - 80px)}
  .add{min-height:40px;display:inline-flex;align-items:center}
  .catalogue-bar{gap:12px}.catalogue-bar form{width:100%;margin-left:0}
  .catalogue-bar select{flex:1 1 100%}.catalogue-bar input{flex:1 1 150px;width:auto;min-width:0}
  .catalogue aside a{min-height:40px;display:flex;align-items:center}
  .site-footer .cols a:not(.logo){padding:8px 0}
  .whatsapp{width:54px;height:54px;justify-content:center;padding:0!important}.whatsapp span{display:none}
}

/* ---------- Tables become cards on phones (app.js adds the column names) ---------- */
@media (max-width:700px){
  .panel{overflow-x:auto}
  .table.stack,.table.stack tbody,.table.stack tr,.table.stack td{display:block;width:100%}
  .table.stack thead{position:absolute;left:-9999px}
  .table.stack.compact{max-width:none}
  .table.stack tr{border:1px solid var(--line);border-radius:10px;padding:4px 12px;margin-bottom:10px;background:#fff}
  .table.stack td{position:relative;min-height:38px;padding:8px 0 8px 40%;border:0;border-bottom:1px solid #eef0f4;text-align:left!important;white-space:normal!important}
  .table.stack tr td:last-child{border-bottom:0}
  .table.stack td::before{content:attr(data-label);position:absolute;left:0;top:10px;width:36%;font-size:.72rem;font-weight:700;text-transform:uppercase;letter-spacing:.02em;color:var(--muted);overflow-wrap:anywhere}
  .table.stack td[data-label=""]{padding-left:0}
  .table.stack td:empty{display:none}
  .table.stack td form.inline{display:inline-block;margin:0 4px 4px 0}
  .table.stack td .btn{margin-bottom:4px}
  .table.stack td input[type=number]{width:110px}
  .table.stack .progress{width:100%;margin-top:6px}
  .table.matrix td{padding-left:0;display:flex;justify-content:space-between;align-items:center;gap:12px}
  .table.matrix td::before{position:static;width:auto;order:0}
  .table.matrix td:first-child{font-weight:700;display:block}.table.matrix td:first-child::before{display:none}
  /* Tables without column headings wrap their cells. */
  .table:not(.stack),.table:not(.stack) tbody{display:block;width:100%}
  .table:not(.stack) tr{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:4px 12px;padding:8px 0;border-bottom:1px solid var(--line)}
  .table:not(.stack) td,.table:not(.stack) th{display:block;border:0;padding:3px 0;min-width:0}
  .table:not(.stack) td:first-child{flex:1 1 auto;max-width:100%}
  .specs th{width:42%}.result .specs th{width:50%}
}

@media (max-width:600px){
  .panel.form,.panel .form{grid-template-columns:minmax(0,1fr)}
  .hero{padding:28px 0 72px}.hero h1{font-size:1.75rem}.hero .lead{font-size:1rem}
  .hero-search{flex-wrap:wrap;padding:8px}.hero-search input{flex:1 1 100%;padding:0 8px}.hero-search .btn{flex:1 1 100%}
  .page-head{padding:20px 0 22px}.page-head h1{font-size:1.5rem}
  .section-head h2{font-size:1.3rem}
  .cta .actions{width:100%}.cta .btn{flex:1 1 100%}
  .site #request-form fieldset.services{grid-template-columns:minmax(0,1fr)}
  .contact-cards{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}.contact-cards>*{padding:18px 10px}
  .gallery .main{height:260px}
  .bare main{padding:12px 10px}.auth{margin:12px auto}.auth>img{height:104px}
  .bare .panel.narrow{margin:16px auto}
  .document{padding:14px}.doc-head img{height:64px}.doc-head h1{font-size:1.25rem}
  .document .actions .btn{flex:1 1 100%}
  .codes{columns:1}
  .stats{gap:8px}
}

@media (max-width:420px){
  .who>a:first-child{display:none}
}

@media (max-width:340px){
  .site-header .logo-name{display:none}
  .stats,.contact-cards{grid-template-columns:minmax(0,1fr)}
}

/* ---------- Menus slide over the page from the side; the page underneath does not move ---------- */
@media (max-width:960px){
  .site-header{z-index:45}
  .site-header nav,.site-header nav.open{display:flex;position:fixed;top:0;right:0;bottom:0;width:min(300px,84vw);height:100vh;height:100dvh;max-height:none;margin:0;padding:10px 14px 24px;background:#fff;flex-direction:column;flex-wrap:nowrap;align-items:stretch;gap:4px;overflow-y:auto;overscroll-behavior:contain;z-index:50}
  .site-header nav{transform:translateX(105%);visibility:hidden;transition:transform .2s,visibility .2s}
  .site-header nav.open{transform:none;visibility:visible;box-shadow:0 0 0 100vmax rgba(3,12,35,.55)}
  .site-header nav>*{flex:none}
  body.site:has(#site-nav.open){overflow:hidden}
  .site-header nav .menu-close{display:flex;align-self:flex-end}
}
@media (max-width:860px){
  /* Sign out and close stay at the top of the menu while it scrolls. */
  #sidebar .drawer-head{display:flex;align-items:center;justify-content:space-between;gap:10px;position:sticky;top:-14px;z-index:1;background:var(--blue-dark);margin:-14px -12px 10px;padding:12px}
  #sidebar .menu-close{display:flex;color:#fff;border-color:rgba(255,255,255,.35)}
  /* The top bar button never shrinks or leaves the screen; the page title gives way instead. */
  .topbar .menu-toggle{order:0}.topbar h1{flex:1 1 0;width:0}
  .topbar .who{margin-left:auto;flex:0 0 auto}.topbar .who .btn{white-space:nowrap;background:var(--red);border-color:var(--red);color:#fff}}
.menu-close{width:44px;height:44px;flex:none;align-items:center;justify-content:center;font-size:1.8rem;line-height:1;background:none;border:1px solid var(--line);border-radius:var(--radius);cursor:pointer;color:var(--ink);padding:0}
@media (min-width:961px){.site-header nav .menu-close{display:none}}
@media (min-width:861px){#sidebar .menu-close{display:none}}
