/* responsive.css — how the workspace and the builder pages fit each screen.
   Loaded after each page's own styles. Behaviour lives in src/core/responsive.js.

     > 1200px    two panes, each scrolling on its own; the sidebar can be hidden
     <= 1200px   tablets and phones: the page scrolls, the sidebar is a drawer
     <= 640px    phones: tables become cards, forms stack

   1200 keeps every iPad in landscape on the drawer layout: a sidebar there would
   leave too little room for the wide audit tables. */

:root{--side-w:340px;--hdr-h:52px;--gutter:14px}
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
button,a,summary,.drop,.calCell{touch-action:manipulation;-webkit-tap-highlight-color:rgba(31,58,95,.14)}

/* ---- header ---- */
header.top{padding-left:max(16px,env(safe-area-inset-left));padding-right:max(16px,env(safe-area-inset-right))}
header.top .titleBlock{min-width:0;flex:0 1 auto}
header.top h1,header.top .sub{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
header.top .status{flex:0 1 auto;min-width:0}
header.top .topnav,.batUser{flex:none}
.batName{max-width:150px;overflow:hidden;text-overflow:ellipsis}

.sideToggle{flex:none;display:inline-flex;align-items:center;gap:6px;height:34px;padding:0 10px;font:inherit;
  font-size:12px;font-weight:600;color:#fff;background:rgba(255,255,255,.1);cursor:pointer;
  border:1px solid rgba(255,255,255,.35);border-radius:7px}
.sideToggle:hover{background:rgba(255,255,255,.18);border-color:rgba(255,255,255,.6)}
.sideToggle svg{width:15px;height:15px;flex:none}
.sideToggle .count{min-width:18px;padding:0 5px;border-radius:9px;background:#fff;color:var(--accent);
  font-size:10.5px;font-weight:700;line-height:17px;text-align:center}
.sideToggle .count:empty{display:none}

/* Drawer furniture stays out of the way until the drawer layout needs it. */
.drawerHead,.drawerFoot,.scrim,.genDock{display:none}

/* ---- tables that are wider than their card ---- */
.tableScroll{overflow-x:auto;max-width:100%;-webkit-overflow-scrolling:touch}
.tableScroll.moreRight{-webkit-mask-image:linear-gradient(to right,#000 calc(100% - 26px),transparent);
  mask-image:linear-gradient(to right,#000 calc(100% - 26px),transparent)}
#views table.data th,#views table.data td{white-space:nowrap}
#views table.data td.wrapCol{white-space:normal;min-width:190px}
#views table.data td.sentenceCol{min-width:340px}

/* The builder pages leave the list unbounded, so any height set below needs this. */
#fileList{overflow-y:auto}

#metaForm{grid-template-columns:repeat(2,minmax(0,1fr))}
.fld input,.fld select{width:100%;min-width:0}

.card,.launchCard{max-width:100%}
.cfgBtns,.dayFile{flex-wrap:wrap}
.reportCalTable .rcalGrid{min-width:168px}
.dayFile>span:first-child{min-width:0;overflow-wrap:anywhere}

/* ---- two panes: laptops and desktops ---- */
@media (min-width:1201px){
  html,body{height:100%}
  body{display:flex;flex-direction:column;height:100vh;height:100dvh;overflow:hidden}
  header.top{flex:none;position:relative}
  .wrap{flex:1;min-height:0;height:auto;grid-template-columns:var(--side-w) minmax(0,1fr);
    grid-template-rows:minmax(0,1fr)}
  html.sideClosed .wrap{grid-template-columns:minmax(0,1fr)}
  html.sideClosed aside{display:none}

  /* Long tables keep their column headings in view while reading down. */
  .tableScroll{overflow:auto;max-height:calc(100vh - 150px);max-height:calc(100dvh - 150px)}
  #views table.data th,.reportCalTable th{position:sticky;top:0;z-index:1;box-shadow:inset 0 -1px #d8dce5}
}

/* 14-inch laptops: 1366x768 and 1536x864 lose most of their height to the browser. */
@media (min-width:1201px) and (max-width:1600px){
  :root{--side-w:290px}
  header.top{padding-top:8px;padding-bottom:8px;gap:12px}
  header.top .status{max-width:clamp(120px,20vw,300px)}
  main{padding:14px 20px}
  aside{padding:12px 14px}
  .tabbtn{padding:8px 10px;font-size:12px}
  .tabs{gap:2px}
  #subTabBar{margin:8px 0 12px}
  #subTabBar[hidden] ~ #views{padding-top:12px}
  .card{padding:14px 16px;margin-bottom:14px}
  .kpi{grid-template-columns:repeat(auto-fit,minmax(135px,1fr))}
  .kpiBox{padding:9px 12px}
  .kpiBox .val{font-size:16px}
  .drop{padding:12px}
  #fileList{max-height:200px}
  .doc{padding:30px 32px}
}
@media (min-width:1201px) and (max-width:1280px){
  header.top .sub{display:none}
}
@media (min-width:1201px) and (max-height:800px){
  header.top .sub{display:none}
  #fileList{max-height:150px}
  .tableScroll{max-height:calc(100vh - 124px);max-height:calc(100dvh - 124px)}
}

/* ---- touch: anything tapped gets a finger-sized target ---- */
@media (pointer:coarse){
  .tabbtn,button.ghost,button.primary,button.sec,button.exportBtn,.export-actions button,
  .single-export-list button.single-export-btn,.addrow,.cfgSave,.cfgReset,.sideToggle{min-height:44px}
  #subTabBar .subtab{min-height:38px}
  .rm{min-width:38px;min-height:38px;color:#8a93a3}
  .wsSync .wsBtn{min-height:36px}
  td.tools .del{min-width:32px;min-height:32px;font-size:13px;color:#8a93a3}
  .tbl .tools{width:34px}
  .filerow{min-height:44px;padding-top:2px;padding-bottom:2px}
  .cfgSummary{padding-top:13px;padding-bottom:13px}
  /* Under 16px Safari zooms the whole page every time a field is focused. */
  .fld input,.fld select,.cfgInput,.toolbar input:not([type=checkbox]),.toolbar select{font-size:16px;min-height:44px}
  #folderBtn{display:none} /* a phone or tablet has no folder picker to offer */
}

/* ---- drawer layout: tablets and phones ---- */
@media (max-width:1200px){
  html,body{height:auto;min-height:100%}
  body{overflow-x:hidden}
  html.drawerOpen,html.drawerOpen body{overflow:hidden}

  header.top{height:calc(var(--hdr-h) + env(safe-area-inset-top));padding-top:env(safe-area-inset-top);
    padding-bottom:0;gap:10px}
  header.top .sub{display:none}
  header.top .status{position:fixed;left:50%;transform:translateX(-50%);
    bottom:calc(16px + env(safe-area-inset-bottom));z-index:45;width:max-content;
    max-width:calc(100vw - 32px);padding:9px 14px;border-radius:9px;font-size:12.5px;color:#fff;
    background:rgba(20,28,42,.94);box-shadow:0 8px 24px rgba(15,25,45,.3);text-align:center;
    white-space:normal;opacity:0;visibility:hidden;transition:opacity .2s}
  header.top .status.show{opacity:1;visibility:visible}
  html.hasDock header.top .status{bottom:calc(84px + env(safe-area-inset-bottom))}

  /* An offline warning must survive the header losing its chips. */
  header.top .batCloud.warn{display:block;font-size:0;width:11px;height:11px;padding:0;border-radius:50%;
    background:#f0b13c;box-shadow:0 0 0 2px rgba(255,255,255,.3)}

  .wrap{display:block;height:auto}
  main{overflow:visible;padding:14px max(var(--gutter),env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
    max(var(--gutter),env(safe-area-inset-left))}

  aside{position:fixed;inset:0 auto 0 0;z-index:60;width:min(88vw,380px);padding:0 16px calc(16px + env(safe-area-inset-bottom));
    padding-left:max(16px,env(safe-area-inset-left));border-right:none;box-shadow:0 0 40px rgba(15,25,45,.35);
    overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;
    transform:translateX(-104%);visibility:hidden;transition:transform .22s ease,visibility 0s linear .22s}
  html.drawerOpen aside{transform:none;visibility:visible;transition:transform .22s ease}
  .scrim{display:block;position:fixed;inset:0;z-index:55;background:rgba(15,25,45,.45);opacity:0;
    visibility:hidden;transition:opacity .22s,visibility 0s linear .22s}
  html.drawerOpen .scrim{opacity:1;visibility:visible;transition:opacity .22s}

  .drawerHead{display:flex;align-items:center;justify-content:space-between;position:sticky;top:0;z-index:2;
    margin:0 -16px 12px;padding:calc(10px + env(safe-area-inset-top)) 8px 10px 16px;background:var(--panel);
    border-bottom:1px solid var(--line);font-size:14px;font-weight:700;color:var(--ink)}
  .drawerClose{width:44px;height:44px;border:none;background:none;color:var(--ink2);font-size:18px;cursor:pointer}
  #fileList{max-height:34vh}

  /* Section strip: one swipeable row that stays put under the header. */
  #tabBar,main>.tabs{position:sticky;top:calc(var(--hdr-h) + env(safe-area-inset-top));z-index:15;flex-wrap:nowrap;
    overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch;background:var(--bg);max-width:none;
    margin:-14px calc(-1 * max(var(--gutter),env(safe-area-inset-right))) 12px
      calc(-1 * max(var(--gutter),env(safe-area-inset-left)));
    padding:6px max(var(--gutter),env(safe-area-inset-right)) 0 max(var(--gutter),env(safe-area-inset-left))}
  #tabBar{padding-right:34px;-webkit-mask-image:linear-gradient(to right,#000 calc(100% - 28px),transparent);
    mask-image:linear-gradient(to right,#000 calc(100% - 28px),transparent)}
  #subTabBar{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;margin:0 calc(-1 * var(--gutter)) 12px;
    padding:0 var(--gutter)}
  #tabBar::-webkit-scrollbar,#subTabBar::-webkit-scrollbar,main>.tabs::-webkit-scrollbar{display:none}
  .tabbtn,.subtab{flex:none;white-space:nowrap}
  #subTabBar[hidden] ~ #views{padding-top:2px}

  .doc{padding:24px 22px}
  .checklist{padding:16px}
  .empty{margin:32px auto}

  /* Rows of Word-format tables must not be crushed into one-word columns. */
  .tbl.data{min-width:calc(var(--cols,4) * 96px)}

  /* The Generate button lives in the drawer; the page's main action stays in reach. */
  html.hasDock main{padding-bottom:calc(92px + env(safe-area-inset-bottom))}
  .genDock{display:block;position:fixed;left:0;right:0;bottom:0;z-index:30;background:rgba(255,255,255,.96);
    border-top:1px solid var(--line);box-shadow:0 -4px 16px rgba(15,25,45,.08);
    padding:10px max(14px,env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(14px,env(safe-area-inset-left))}
  .genDock button{margin:0;min-height:44px}
}

/* Landscape phones: too little height to pin a second row. */
@media (max-width:1200px) and (max-height:480px){
  #tabBar,main>.tabs{position:static}
}

/* ---- phones ---- */
@media (max-width:640px){
  :root{--gutter:10px}
  header.top{padding-left:max(10px,env(safe-area-inset-left));padding-right:max(10px,env(safe-area-inset-right));gap:8px}
  header.top .mark,header.top .topnav a:not(:first-child),.batUser>:not(.batCloud){display:none}
  header.top h1{font-size:14.5px}
  header.top .topnav a{font-size:0;padding:0 11px;height:40px;display:flex;align-items:center}
  header.top .topnav a::before{content:"\2190";font-size:18px}
  .sideToggle{height:40px;min-height:40px;padding:0 9px}

  /* The signed-in user moves out of the header and into the drawer. */
  .drawerFoot{display:block;margin-top:20px;padding-top:12px;border-top:1px solid var(--line);font-size:12.5px;color:var(--ink2)}
  .drawerFoot .who{font-weight:700;color:var(--ink);overflow-wrap:anywhere}
  .drawerFoot .mail{color:var(--muted);font-size:11.5px;overflow-wrap:anywhere}
  .drawerFoot .cloud{margin-top:6px;font-size:11.5px;color:var(--warn)}
  .drawerFoot .cloud:empty{display:none}
  .drawerFoot .row{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}
  .drawerFoot a,.drawerFoot button{flex:1 1 130px;display:flex;align-items:center;justify-content:center;min-height:44px;
    border:1px solid var(--line);border-radius:8px;background:#fff;color:var(--ink2);font:inherit;font-weight:600;
    text-decoration:none;cursor:pointer}

  .tabbtn{padding:9px 12px;font-size:13px}
  #views .card,.card{padding:14px 12px;border-radius:9px}
  .card h2{font-size:14.5px;line-height:1.35}
  .kpi{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
  .kpiBox{padding:10px 11px}
  .kpiBox .val{font-size:16px;overflow-wrap:anywhere}
  .export-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
  .export-actions button{font-size:12px;padding:8px 6px;line-height:1.25}
  .launchActions button{flex:1 1 100%}
  .cfgBody{grid-template-columns:1fr}
  .cfgBtns button{flex:1 1 40%}
  .cfgMsg{margin-left:0}

  /* Filter bars stack; the page-level inline widths are for desktop rows. */
  .toolbar{flex-direction:column;align-items:stretch;gap:6px}
  .toolbar label{margin-left:0!important}
  .toolbar input:not([type=checkbox]),.toolbar select,.toolbar button{width:100%!important;min-width:0!important;
    margin-left:0!important;height:auto!important}
  .toolbar>span{display:none}
  .toolbar .export-word{margin-top:6px;min-height:44px}

  /* Tables become cards; turning the phone sideways brings the full table back. */
  #views .tableScroll{overflow:visible;-webkit-mask-image:none;mask-image:none}
  #views table.data,#views table.data tbody{display:block;width:100%;background:none}
  #views table.data thead{display:none}
  #views table.data tr{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:9px 14px;padding:11px 12px;
    margin-bottom:8px;background:#fff;border:1px solid var(--line);border-left:3px solid #c9d0db;border-radius:8px}
  #views table.data tr.bad{background:#fdf0ee;border-left-color:var(--bad)}
  #views table.data tr.warn{background:#fdf6e8;border-left-color:var(--warn)}
  #views table.data td,#views table.data td.wrapCol,#views table.data td.sentenceCol{display:block;min-width:0;padding:0;border:none;background:none!important;text-align:left;
    white-space:normal;overflow-wrap:anywhere;font-size:13px;color:var(--ink)}
  #views table.data td::before{content:attr(data-label);display:block;margin-bottom:1px;font-size:10px;font-weight:700;
    letter-spacing:.3px;text-transform:uppercase;color:var(--muted)}
  #views table.data td.cardTitle{grid-column:1/-1;order:-1;font-size:14px;font-weight:700}
  #views table.data td.cardTitle::before,#views table.data td[colspan]::before{display:none}
  #views table.data td.cardWide,#views table.data td[colspan]{grid-column:1/-1}
  #views table.data td.cardHide,#views table.data td:empty{display:none}

  .calGrid{max-width:none;gap:4px;grid-template-columns:repeat(7,minmax(0,1fr))}
  .calCell{aspect-ratio:auto;min-width:0;min-height:42px;font-size:12.5px}
  .calLegend{gap:8px 14px}
  #calendar .reportCalTable,#calendar .reportCalTable tbody{display:block}
  #calendar .reportCalTable thead{display:none}
  #calendar .reportCalTable tr{display:grid;grid-template-columns:1fr auto;gap:6px 10px;padding:10px 0;
    border-bottom:1px solid var(--line)}
  #calendar .reportCalTable td{display:block;border:none;padding:0}
  #calendar .reportCalTable td:nth-child(2){grid-column:1/-1;order:3}

  /* Report preview */
  .doc{padding:14px 12px;border-radius:5px}
  .dh.h1{font-size:15px}
  .tabs .tabbtn{font-size:12.5px}
  .checkTop{grid-template-columns:1fr 1fr 1fr}
  .checkNum{font-size:18px}
  .checkLbl{font-size:10px}
  .reportCalTable th,.reportCalTable td{padding:6px}
  .empty{margin:24px auto;padding:20px 12px}
}

/* Smallest phones: the title needs the room more than the button's word. */
@media (max-width:350px){
  .sideToggle .lbl{display:none}
}
