/* Phones (≤760px): compact top bar, bottom tab bar, tables as cards. Loaded last; desktop untouched.
   Card classes (m-row, m-head, m-key, m-wide, m-nil, data-label) are set by mobile.js. */

/* tab icons and short labels exist in the markup but only show on phones */
.tab .ti{display:none}
.tab .ls{display:none}

@media (max-width:760px){
  :root{--gutter:16px;--tabbar:62px}
  body{padding-bottom:calc(var(--tabbar) + env(safe-area-inset-bottom,0px))}
  .wrap{gap:22px;padding-block:0 28px}

  /* ---- top bar: one slim row (brand · sync · Real/Paper) ---- */
  .top{-webkit-backdrop-filter:none;backdrop-filter:none;background:color-mix(in srgb,var(--ground) 94%,transparent)}
  .top-in{flex-wrap:nowrap;height:54px;gap:10px;padding-top:0}
  .brand{order:1;gap:9px;min-width:0}
  .brand h1{font-size:16.5px;white-space:nowrap}
  .sync{order:2;flex-basis:auto;padding-top:0;font-size:11px;min-width:0;overflow:hidden}
  .sync #syncText{overflow:hidden;text-overflow:ellipsis}
  .modeseg{order:3;margin-left:auto}
  .modeseg button{padding:5px 10px}

  /* ---- bottom tab bar ---- */
  .tabs{position:fixed;left:0;right:0;bottom:0;z-index:40;order:9;margin:0;height:auto;
    display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:0;overflow:visible;
    padding:6px 4px calc(6px + env(safe-area-inset-bottom,0px));
    background:color-mix(in srgb,var(--surface) 92%,transparent);
    -webkit-backdrop-filter:blur(14px) saturate(140%);backdrop-filter:blur(14px) saturate(140%);
    border-top:1px solid var(--line);box-shadow:0 -10px 30px -12px rgb(0 0 0 / .6)}
  .tabs .gl,.tabs .sep{display:none}
  .tab,.tab[aria-selected="true"]{position:relative;height:50px;align-self:auto;flex-direction:column;justify-content:center;gap:3px;
    padding:0 2px;border:0;border-radius:12px;background:none;box-shadow:none;font-size:10.5px;font-weight:700;letter-spacing:.01em;color:var(--faint);
    -webkit-tap-highlight-color:transparent}
  .tab .ti{display:block;width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;transition:transform .18s}
  .tab .tl{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .tab .lf{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
  .tab .ls{display:inline}
  .tab[aria-selected="true"]{color:var(--accent);padding-top:0}
  .tab.r[aria-selected="true"]{color:var(--research)}
  .tab.c[aria-selected="true"]{color:#F0A6CA}
  .tab[aria-selected="true"] .ti{transform:translateY(-1px);filter:drop-shadow(0 0 8px currentColor)}
  .tab[aria-selected="true"]::before{content:"";position:absolute;top:-7px;left:50%;width:22px;height:3px;margin-left:-11px;border-radius:0 0 3px 3px;background:currentColor;box-shadow:0 0 10px currentColor}
  .tab:active{background:var(--raised)}
  /* counts become a small badge on the icon */
  .tab .count,.tab[aria-selected="true"] .count{position:absolute;top:2px;left:calc(50% + 6px);font-size:9.5px;line-height:1;padding:2px 5px;
    min-width:16px;text-align:center;color:var(--text);background:var(--line-strong);font-weight:700;border:2px solid var(--surface);border-radius:999px}
  .tab[aria-selected="true"] .count{color:var(--ground);background:currentColor}
  .tab[aria-selected="true"] .count{background:var(--accent)}
  .tab.r[aria-selected="true"] .count{background:var(--research)}
  .tab.c[aria-selected="true"] .count{background:#F0A6CA}

  /* toasts and modals must clear the tab bar */
  .toast{bottom:calc(var(--tabbar) + 14px + env(safe-area-inset-bottom,0px))!important}

  /* iPhone zooms the page into any field under 16px; keep fields at 16px so it doesn't */
  input:not([type=checkbox]):not([type=radio]),select,textarea,[contenteditable]{font-size:16px!important}
  .hsearch{flex:1 1 100%;min-width:0}
  .hsearch input{padding-block:9px}

  /* ---- section heads and toolbars wrap cleanly ---- */
  .sec-head{flex-wrap:wrap;gap:12px}
  .sec-head h2{font-size:18px}
  .seg{max-width:100%;overflow-x:auto;scrollbar-width:none}

  /* ---- tables → cards ---- */
  .tablewrap:has(> .m-cards),.tw:has(> .m-cards){overflow:visible!important;border:0!important;border-radius:0!important;background:none!important}
  table.m-cards{display:block;width:100%;min-width:0!important;border:0}
  table.m-cards tbody{display:flex;flex-direction:column;gap:10px}

  /* header row → a strip of sort chips */
  table.m-cards thead{display:block;margin-bottom:12px}
  table.m-cards thead tr{display:none}
  table.m-cards thead tr:last-child{display:flex;gap:6px;align-items:center;overflow-x:auto;scrollbar-width:none;padding:2px 0 4px;margin-inline:calc(-1 * var(--gutter));padding-inline:var(--gutter)}
  table.m-cards thead tr:last-child::-webkit-scrollbar{display:none}
  table.m-cards thead:not(:has(button)){display:none}
  table.m-cards thead tr:last-child::before{content:"Sort";flex:none;font-size:10.5px;font-weight:800;letter-spacing:.12em;text-transform:uppercase;color:var(--faint);margin-right:2px}
  table.m-cards thead th{position:static!important;display:block;flex:none;padding:0!important;border:0!important;background:none!important;min-width:0!important;width:auto!important}
  table.m-cards thead th:not(:has(button)){display:none}
  table.m-cards thead th button{all:unset;cursor:pointer;display:inline-flex!important;align-items:center;gap:4px;white-space:nowrap;
    font-size:12px!important;font-weight:600;color:var(--muted);padding:6px 11px!important;border:1px solid var(--line)!important;border-radius:999px!important;background:var(--surface)!important}
  table.m-cards thead th[aria-sort] button{color:var(--text);border-color:color-mix(in srgb,var(--accent) 55%,transparent);background:color-mix(in srgb,var(--accent) 10%,var(--surface))}
  table.m-cards thead th .arr{font-size:10px}

  /* one card per row */
  table.m-cards tr.m-row{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px 12px;position:relative;
    padding:14px 15px 15px;background:var(--surface);border:1px solid var(--line);border-radius:14px;height:auto!important}
  table.m-cards tr.m-row:hover td{background:none}
  table.m-cards tr.m-row td{display:block;min-width:0;padding:0!important;border:0!important;box-shadow:none!important;background:none!important;text-align:left!important;
    position:static!important;width:auto!important;max-width:none!important;white-space:normal!important;overflow-wrap:break-word;font-size:13px}
  table.m-cards tr.m-row td[data-label]::before{content:attr(data-label);display:block;margin-bottom:3px;
    font-family:var(--sans);font-size:10px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:var(--faint);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  table.m-cards tr.m-row td.m-nil{display:none}
  table.m-cards tr.m-row td.m-head{grid-column:1 / span 2;grid-row:1;align-self:center;font-size:15px}
  table.m-cards tr.m-row td.m-head::before,table.m-cards tr.m-row td.m-key::before{display:none}
  table.m-cards tr.m-row td.m-key{grid-column:3;grid-row:1;justify-self:end;align-self:center;text-align:right}
  table.m-cards tr.m-row td.m-key .num{font-size:17px}
  table.m-cards tr.m-row td.m-wide{grid-column:1 / -1}
  table.m-cards tr.m-row td.m-span2{grid-column:span 2}
  table.m-cards tr.m-row td:not(.m-head):not(.m-key):not(.m-wide){align-self:start}

  /* full-width rows (group headers, expanded details) */
  table.m-cards tr.m-full{display:block}
  table.m-cards tr.m-full td{display:block;position:static!important;padding:0!important;border:0!important;background:none!important}

  /* editable tags / notes look tappable */
  table.m-cards .edit{width:100%!important;max-width:none!important;min-height:34px;padding:7px 10px;border:1px dashed var(--line-strong);border-radius:8px;font-size:13px}
  table.m-cards .edit:empty::before{color:var(--faint)}
  table.m-cards .edit:focus{border-style:solid;border-color:var(--accent);outline:none}

  /* per-table touches */
  #trades .coincell,#openTbl .coincell{font-size:16px;gap:8px}
  #trades .pbar,#openTbl .pbar{display:block;margin-top:6px;max-width:120px}
  #openTbl td.m-wide:not([data-label]):empty{display:none}
  #openTbl .held{display:flex!important;flex-direction:column;align-items:flex-start;gap:1px}

  #view-strategies #sTbl tr.m-row td{text-align:left!important;border-left:0!important}
  #view-strategies #sTbl tr.m-row td.m-key{text-align:right!important}
  #sTbl tr.m-row .vs{justify-content:flex-start}
  #sTbl tr.m-row td.m-head .namecell{display:flex;align-items:center;gap:9px;min-width:0}
  #sTbl tr.m-row td.m-head .t{min-width:0}
  #sTbl tr.m-row td.m-head .t b{display:block;white-space:normal;font-size:15px;line-height:1.3}
  #sTbl tr.m-row td:not([data-label]){grid-column:1 / -1}
  #sTbl tr.m-row .acts{display:flex;gap:8px}
  #sTbl tr.m-row .acts .btn{flex:1;justify-content:center;min-height:38px}
  #sTbl tr.m-row .hwhy{white-space:normal}
  #sTbl tr.m-row .vs .track{max-width:110px}
  #sTbl tr.grp td .g{position:static;width:auto;flex-wrap:wrap;padding:14px 2px 2px;font-size:13px}
  #sTbl tr.grp td .gname{font-size:15px}
  #sTbl tr.grp td .gmeta{display:block;margin-top:2px}
  #sTbl tr.row.sel{border-color:color-mix(in srgb,var(--accent) 60%,transparent)}
  #sTbl tr.detail{margin-top:-6px}
  #sTbl tr.detail > td{border:1px solid var(--line)!important;border-radius:14px;background:var(--surface)!important;overflow:hidden}

  #labTbl tr.m-row{cursor:pointer}
  #labTbl tr.m-row td:first-child{position:absolute!important;right:10px;bottom:10px}
  #labTbl tr.m-row td:first-child::before{display:none}
  #labTbl tr.m-row td:nth-child(2){grid-column:span 2}
  #labTbl tr.m-row td:nth-child(2) .idbtn{max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  #labTbl tr.m-row td.lesson{white-space:normal;color:var(--muted)}
  #labTbl tr.m-row .nm b{white-space:normal}

  .ov-table.m-cards tr.m-row td.m-head .ov-sn{display:flex;align-items:center;gap:8px}
  .ov-table.m-cards tr.m-row td.m-key b{font-size:16px}
}

@media (max-width:380px){
  .sync #syncText{display:none}
  .tab,.tab[aria-selected="true"]{font-size:9.5px}
}
