/* V3.3 mobile layout (phones and small tablets, up to 900px wide). Loaded after app.css so it wins.
   - bottom tab bar (OLTs / Info / Config / ONTs / Alarms / More); "More" opens the side menu as a drawer with a dimmed
     backdrop (Settings, Logout, plugins)
   - tables become compact cards: label above value, two per line; the ONT list and the port list get their own card
     layout; a row with many buttons shows the first one plus "More", which opens an action sheet
   - dialogs open as bottom sheets with the buttons always visible
   - nothing scrolls sideways except the tab strips */

/* desktop: the mobile-only parts stay hidden */
.mnav,.side-scrim,.row-more,.act-sheet-ov{display:none}

@media(max-width:900px){
  :root{--mnav-h:62px}
  body{overflow-x:hidden}
  /* ---- navigation ---- */
  .topbar .burger{display:none!important}
  .mnav{display:flex;position:fixed;left:0;right:0;bottom:0;z-index:40;height:calc(var(--mnav-h) + env(safe-area-inset-bottom,0px));padding:4px 4px env(safe-area-inset-bottom,0px);background:var(--panel);border-top:1px solid var(--line);box-shadow:0 -6px 20px rgba(0,0,0,.22)}
  .mnav a{flex:1 1 0;min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;border-radius:12px;color:var(--muted);font-size:11px;font-weight:600;text-decoration:none;-webkit-tap-highlight-color:transparent;padding:4px 2px}
  .mnav a .ico{width:34px;height:26px;border-radius:999px;display:flex;align-items:center;justify-content:center;transition:background .15s}
  .mnav a span.lbl{max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .mnav a.on{color:var(--accent)}
  .mnav a.on .ico{background:rgba(34,211,238,.16);color:var(--accent)}
  .mnav a:active .ico{background:var(--hover)}
  .side{z-index:60;width:min(300px,84vw);box-shadow:none}
  .side.open{box-shadow:8px 0 30px rgba(0,0,0,.45)}
  .side-scrim{display:block;position:fixed;inset:0;z-index:55;background:rgba(3,8,18,.55);opacity:0;pointer-events:none;transition:opacity .2s}
  body.side-open .side-scrim{opacity:1;pointer-events:auto}
  body.side-open{overflow:hidden}
  .view{padding:12px 12px calc(var(--mnav-h) + 22px + env(safe-area-inset-bottom,0px))!important}
  #toasts{left:12px;right:12px;bottom:calc(var(--mnav-h) + 12px + env(safe-area-inset-bottom,0px))}
  .toast{max-width:none}

  /* ---- top bar ---- */
  .topbar{height:54px;padding:0 10px;gap:6px}
  .topbar>.chip:first-of-type{flex:1 1 0;min-width:0;overflow:hidden}
  .topbar>*:not(.chip:first-of-type){flex:none}
  .topbar>.chip:first-of-type>span:not(.dot){max-width:none;flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis}
  .topbar>.right{display:none}
  .topbar>.chip:last-child .badge{display:none}
  .topbar>.chip:last-child>span.ico{display:inline-flex!important;font-size:17px}
  .topbar>.chip:last-child{padding:7px 9px}
  .warm-box{flex:none}

  /* ---- page header, tabs, toolbars ---- */
  .ph{flex-wrap:wrap;gap:8px 10px}
  .ph h1{font-size:20px}
  .ph p{font-size:13px}
  .ph>.btn,.ph>div>.btn{padding:7px 12px}
  .tabs.seg{position:relative;-webkit-overflow-scrolling:touch;scroll-behavior:smooth;margin-bottom:14px;padding:4px}
  .tabs.seg a{padding:9px 13px;font-size:14px;flex:none}
  .tabs:not(.seg){display:flex;overflow-x:auto;flex-wrap:nowrap;scrollbar-width:none}
  .tabs:not(.seg)::-webkit-scrollbar{display:none}
  .tabs:not(.seg) a{flex:none;white-space:nowrap}
  .toolbar .right{margin-left:0}
  .toolbar span.right:empty{display:none}
  .toolbar>.muted{flex:1 1 100%;font-size:12.5px}
  .seg:not(.tabs){display:flex;max-width:100%;overflow-x:auto;scrollbar-width:none}
  .seg:not(.tabs)::-webkit-scrollbar{display:none}
  .toolbar .seg{width:100%}
  .seg:not(.tabs) button{flex:1 0 auto}
  .card>.hd{flex-wrap:wrap;row-gap:8px}
  .card>.hd>*{min-width:0}
  .card>.hd>.muted,.card>.hd>.sub{order:2;flex:1 1 100%;font-size:12.5px;font-weight:400}
  .card>.hd>.btn,.card>.hd>select,.card>.hd>label,.card>.hd>.right{order:3}
  .card>.hd>.right{margin-left:0}
  .card>.bd{padding:12px}
  .note{font-size:13px}
  .note .btn{flex:none}

  /* touch-friendly controls; 16px inputs so phones don't zoom in when a field is tapped */
  input:not([type=checkbox]):not([type=radio]),select,textarea{font-size:16px;min-height:42px}
  input[type=checkbox],input[type=radio]{width:20px;height:20px}
  .btn{min-height:38px}
  .btn.sm,.btn.xs{min-height:34px;padding:6px 11px;font-size:13px}
  .btn.ico-only{min-width:38px;justify-content:center}
  dd,.kv dd{min-width:0;overflow-wrap:anywhere}
  .kv{grid-template-columns:minmax(96px,38%) minmax(0,1fr)}
  label.row,.row{flex-wrap:wrap}
  pre,code{white-space:pre-wrap;overflow-wrap:anywhere}

  /* ---- generic table -> compact cards (label above value, two per line) ---- */
  .tblwrap tr{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 14px;padding:10px 12px!important;margin:8px 10px!important;border-radius:12px}
  .tblwrap td{display:block!important;text-align:left!important;padding:0!important;min-width:0;overflow-wrap:break-word}
  .tblwrap td::before{display:block;font-size:10.5px!important;margin-bottom:2px;letter-spacing:.04em!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .tblwrap td>.chips{justify-content:flex-start}
  .tblwrap td.act{grid-column:1/-1;display:flex!important;flex-wrap:wrap;gap:6px;padding-top:9px!important;margin-top:2px;border-top:1px dashed var(--line)!important}
  .tblwrap td.act::before{display:none}
  .tblwrap td.act .btn,.tblwrap td.act .row-acts .btn{flex:1 1 auto;justify-content:center}
  .tblwrap td.act .row-acts{display:flex;flex-wrap:wrap;gap:6px;width:100%}
  .tblwrap td:empty{display:none!important}
  .tblwrap td:not([data-label]):not(.act):has(>input[type=checkbox]:only-child){grid-column:1/-1}

  /* rows with many buttons: first button + "More" (the rest are in the action sheet) */
  .row-more{display:inline-flex}
  .has-more>.btn:not(.row-more):not(:first-child),.has-more>.row-acts>.btn:not(.row-more):not(:first-child){display:none!important}

  /* ---- ONT list card ---- */
  .ont-tbl tr{grid-template-columns:24px repeat(6,minmax(0,1fr))!important;gap:8px 10px!important;padding:12px!important;margin:10px 8px!important}
  .ont-tbl td{flex-direction:column}
  .ont-tbl td:nth-child(1){grid-column:1;grid-row:1;align-self:center}
  .ont-tbl td:nth-child(2){grid-column:2/6;grid-row:1;align-self:center}
  .ont-tbl td:nth-child(2)::before,.ont-tbl td:nth-child(5)::before{display:none!important}
  .ont-tbl td:nth-child(2) .ont-id{font-size:17px}
  .ont-tbl td:nth-child(5){grid-column:6/8;grid-row:1;justify-self:end;text-align:right!important}
  .ont-tbl td:nth-child(5) .state-cell{display:flex;flex-direction:column;align-items:flex-end;gap:4px}
  .ont-tbl td:nth-child(5) .badge.reason{max-width:150px!important;white-space:nowrap!important}
  .ont-tbl td:nth-child(3){grid-column:1/5;max-width:none!important;white-space:normal!important}
  .ont-tbl td:nth-child(3) span{max-width:100%!important;display:inline;white-space:normal}
  .ont-tbl td:nth-child(4){grid-column:5/8;white-space:normal!important}
  .ont-tbl td:nth-child(6){grid-column:1/4}
  .ont-tbl td:nth-child(7){grid-column:4/6}
  .ont-tbl td:nth-child(8){grid-column:6/8}
  .ont-tbl td:nth-child(9){grid-column:1/-1;display:flex!important;flex-direction:row!important;align-items:center!important;justify-content:space-between!important;gap:10px!important}
  .ont-tbl td:nth-child(9)::before{margin:0}
  .ont-tbl td:nth-child(9) .btn{min-height:30px;padding:4px 12px}
  .ont-tbl td.act-col{grid-column:1/-1!important;grid-row:auto}
  .ont-tbl .row-acts{flex-wrap:nowrap!important}
  .ont-tbl .ont-sn{font-size:13.5px}

  /* ---- port list card (OLT Config > Ports): Port | Link | Admin / Type | Speed | Wavelength / Module /
     Tx | Rx | Temp / buttons ---- */
  .port-tbl tr{grid-template-columns:repeat(3,minmax(0,1fr))!important;gap:10px 12px!important}
  .port-tbl td{white-space:normal!important;max-width:none!important}
  .port-tbl td:nth-child(1){grid-area:1/1;font-size:16px;font-weight:700}
  .port-tbl td:nth-child(3){grid-area:1/2}
  .port-tbl td:nth-child(4){grid-area:1/3}
  .port-tbl td:nth-child(2){grid-area:2/1}
  .port-tbl td:nth-child(5){grid-area:2/2}
  .port-tbl td:nth-child(10){grid-area:2/3}
  .port-tbl td:nth-child(6){grid-area:3/1/4/4}
  .port-tbl td:nth-child(7){grid-area:4/1}
  .port-tbl td:nth-child(8){grid-area:4/2}
  .port-tbl td:nth-child(9){grid-area:4/3}
  .port-tbl td:nth-child(11){grid-area:5/1/6/4}

  /* ---- ONT List action bars ---- */
  .ont-bar{flex-wrap:wrap!important;overflow:visible!important;padding:10px 12px!important;gap:6px!important}
  .ont-bar .bar-lbl{flex:1 1 100%!important;min-width:0!important}
  .ont-bar>.muted{flex:1 1 100%;font-size:12.5px!important}
  .ont-bar .btn{flex:1 1 calc(50% - 6px)!important;justify-content:center;min-width:0}
  .cap-strip{padding:10px 12px;gap:6px}
  .cap-strip .bar-lbl{flex:1 1 100%;min-width:0}

  /* ---- dialogs: bottom sheets ---- */
  .ov{padding:0!important;align-items:flex-end!important;overflow:hidden}
  .modal,.modal.wide,.modal.xl,.modal.xxl{max-width:none!important;width:100%;max-height:calc(100dvh - 24px);display:flex;flex-direction:column;border-radius:18px 18px 0 0!important;border-bottom:0;animation:sheet .2s ease-out}
  .modal .mh{flex:none;padding:14px 14px 12px;position:relative}
  .modal .mh::before{content:"";position:absolute;left:50%;top:5px;width:38px;height:4px;margin-left:-19px;border-radius:4px;background:var(--line)}
  .modal .mb{flex:1 1 auto;overflow-y:auto;overflow-x:hidden;padding:14px;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}
  .modal .mf{flex:none;flex-wrap:wrap;padding:10px 14px calc(10px + env(safe-area-inset-bottom,0px));background:var(--panel)}
  .modal .mf .merr{flex:1 1 100%;order:-1}
  .modal .mf .btn{flex:1 1 0;justify-content:center;min-height:44px}
  .modal .mb table:not(.tblwrap table){display:block;overflow-x:auto;max-width:100%}
  .modal .tblwrap{max-height:none!important}
  .modal .tblwrap tr{margin:8px 0!important}
  @keyframes sheet{from{transform:translateY(40px);opacity:.4}to{transform:none;opacity:1}}

  /* ---- action sheet (row "More") ---- */
  .act-sheet-ov{display:flex;position:fixed;inset:0;z-index:120;background:rgba(3,8,18,.55);align-items:flex-end}
  .act-sheet{width:100%;background:var(--panel);border-radius:18px 18px 0 0;padding:8px 12px calc(12px + env(safe-area-inset-bottom,0px));animation:sheet .18s ease-out;max-height:80dvh;overflow:auto}
  .act-sheet .grab{width:38px;height:4px;border-radius:4px;background:var(--line);margin:2px auto 10px}
  .act-sheet h4{margin:0 4px 10px;font-size:15px}
  .act-sheet .btn{width:100%;justify-content:flex-start;min-height:48px;font-size:15px;margin-bottom:6px;gap:12px;padding:10px 14px}
  .act-sheet .btn.bad{color:var(--bad)}
  .act-sheet .btn.cancel{justify-content:center;margin-top:4px;font-weight:600}

  /* ---- OLT list, info, config pieces ---- */
  .kpis{gap:10px}
  .kpi .kv,.kpi b{overflow-wrap:anywhere}
  .vl-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;max-height:none!important;padding:12px!important}
  .gx-cards{grid-template-columns:minmax(0,1fr)!important;max-height:none!important}
  .prof-grid{grid-template-columns:minmax(0,1fr)!important;gap:12px!important;padding:12px!important}
  .warm-box{margin-left:0}
  .warm-box .warm-run{display:inline-flex!important;font-size:0;gap:0;padding:6px!important}
  .warm-box .warm-run .spin{margin:0}
}
@media(max-width:380px){
  .mnav a{font-size:10px}
  .vl-grid{grid-template-columns:minmax(0,1fr)!important}
  .ont-tbl td:nth-child(3),.ont-tbl td:nth-child(4){grid-column:1/-1}
}

@media(max-width:700px){.act-busy{font-size:11px;max-width:52vw;padding:3px 8px}}
