/* ============================================================================
   crm-mobile.css — phone/tablet layer for the CRM, ERP and partner portal.
   Loaded by shell() AFTER the inline <style>, so it overrides it.

   Design intent: on a phone the portal should feel like an app, not a shrunken
   desktop page. Three moves do most of the work —
     1. wide data tables become stacked cards (labels injected by crm-mobile.js)
     2. the top bar's link row becomes a fixed bottom tab bar
     3. touch targets grow to >=44px and the safe-area insets are respected.
   Desktop (>760px) is deliberately left exactly as it was.
   ========================================================================== */

/* ---------- shared: honour notches / home indicator on all sizes ---------- */
.top{padding-top:env(safe-area-inset-top,0)}

@media (max-width:760px){

  /* ---------- layout ---------- */
  .wrap{padding:0 15px}
  main{padding:18px 0 96px}                 /* bottom padding clears the tab bar */
  h1{font-size:21px;line-height:1.25}
  h2{font-size:15px}
  .panel{padding:16px 14px;border-radius:14px;margin-top:14px}
  .panel::before{left:16px;right:16px}
  .cards{grid-template-columns:1fr;gap:12px}

  /* ---------- top bar: brand only, actions move to the bottom bar ---------- */
  .top{height:auto;min-height:56px;padding-bottom:6px}
  .top .wrap{flex-wrap:wrap;gap:6px;padding-top:6px}
  .brand img{height:26px}
  .brand span{font-size:13px}
  .who{font-size:12px;gap:7px;width:100%;justify-content:space-between;align-items:center}
  .who > span{font-size:11.5px;color:#8b948e;line-height:1.3}
  /* links are duplicated into the bottom bar, so hide them up here */
  .who a.btn{display:none}
  .who form{margin-left:auto}
  .who form .btn{margin-top:0;padding:7px 13px;font-size:12px}

  /* ---------- bottom tab bar (built by crm-mobile.js) ---------- */
  #crmTabs{
    position:fixed;left:0;right:0;bottom:0;z-index:40;display:flex;
    background:rgba(8,12,10,.93);backdrop-filter:blur(14px);
    border-top:1px solid rgba(111,227,136,.18);
    padding-bottom:env(safe-area-inset-bottom,0);
    box-shadow:0 -6px 22px rgba(0,0,0,.45)}
  #crmTabs a{
    flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;
    padding:9px 3px 8px;min-height:54px;color:#8b948e;font-size:10px;font-weight:600;
    font-family:'Inter',sans-serif;text-align:center;line-height:1.2;
    -webkit-tap-highlight-color:transparent;transition:color .18s,background .18s;position:relative}
  #crmTabs a .ti{font-size:17px;line-height:1}
  #crmTabs a.on{color:var(--neon)}
  #crmTabs a.on::before{
    content:'';position:absolute;top:0;left:22%;right:22%;height:2px;border-radius:0 0 3px 3px;
    background:linear-gradient(90deg,var(--neon),var(--orange))}
  #crmTabs a:active{background:rgba(111,227,136,.08)}

  /* ---------- tables → stacked cards ---------- */
  /* crm-mobile.js adds data-label to each cell and .stacked to safe tables */
  table.stacked{font-size:13.5px}
  /* .hrow is set by crm-mobile.js — these tables have no <thead>, the header is
     just the first <tr>, so hiding `thead` alone would miss it. */
  table.stacked thead,
  table.stacked tr.hrow{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;padding:0;margin:0;border:none}
  table.stacked tr{
    display:block;border:1px solid rgba(255,255,255,.1);border-radius:12px;
    background:rgba(17,24,20,.5);padding:4px 12px;margin-bottom:10px}
  table.stacked td{
    display:flex;justify-content:space-between;align-items:flex-start;gap:14px;
    padding:8px 0;border-bottom:1px solid rgba(255,255,255,.055);text-align:right;word-break:break-word}
  table.stacked tr td:last-child{border-bottom:none}
  table.stacked td::before{
    content:attr(data-label);flex:0 0 42%;text-align:left;
    font-family:'JetBrains Mono';font-size:9.5px;letter-spacing:.1em;text-transform:uppercase;
    color:var(--orange);opacity:.85;padding-top:2px}
  /* a cell with no header (action buttons etc.) spans the full width */
  table.stacked td[data-label=""]{justify-content:flex-end}
  table.stacked td[data-label=""]::before{display:none}
  table.stacked td .btn{margin-top:4px}

  /* tables we could not safely stack still scroll, with a visible hint */
  .tscroll{overflow-x:auto;-webkit-overflow-scrolling:touch;position:relative}
  .tscroll table{min-width:520px}
  .tscroll::after{
    content:'swipe →';position:sticky;right:0;bottom:0;float:right;
    font-family:'JetBrains Mono';font-size:9px;letter-spacing:.1em;color:#7d8a82;
    background:rgba(8,12,10,.9);padding:2px 7px;border-radius:7px}

  /* ---------- touch targets & forms ---------- */
  .btn{padding:12px 20px;font-size:14px;min-height:44px}
  .btn.sm{padding:9px 15px;font-size:12.5px;min-height:38px}
  input,select,textarea{font-size:16px;padding:12px 13px}   /* 16px stops iOS zoom-on-focus */
  label{margin:12px 0 5px}

  /* ---------- KPI / stat grids ---------- */
  .kpirow{grid-template-columns:1fr 1fr;gap:10px}
  .finkpi{grid-template-columns:1fr 1fr;gap:9px}
  .fgrid,.taxbox{grid-template-columns:1fr}
  .grid2{gap:14px}

  /* ---------- pipeline track scrolls instead of squashing ---------- */
  .track{gap:10px;padding:12px 2px 8px;-webkit-overflow-scrolling:touch;scroll-snap-type:x mandatory}
  .track > *{scroll-snap-align:start}
}

@media (max-width:420px){
  .kpirow,.finkpi{grid-template-columns:1fr}
  #crmTabs a{font-size:9px}
  #crmTabs a .ti{font-size:16px}
  table.stacked td::before{flex-basis:46%}
}

@media (prefers-reduced-motion:reduce){
  .panel{animation:none}
  .brand img{animation:none}
}
