/* =====================================================================
   TrakFi — responsive hardening layer
   ---------------------------------------------------------------------
   Loaded AFTER theme-minimal.css and theme-bento.css, and written inside
   the same `@layer tf-min` they use: layered !important beats the app's own
   unlayered !important, and (equal specificity, later in source) beats the
   theme files too. Nothing here changes colours or branding — it only stops
   things from overlapping, getting cut off or going invisible when the phone
   is narrower, shorter or uses a different system font / display size than
   the one the UI was tuned on (a 412dp-wide Samsung S25 Ultra).

   Why Moto / OnePlus / Realme / Oppo / Vivo / Infinix looked broken:
     1. Their usable WebView width is often 360-390 CSS px (display-size
        setting, smaller screens) — several rows were sized for >= 400px.
     2. Each OEM ships its own system font, and the web fonts (Hind, Bricolage,
        Inter, Space Grotesk) are fetched from Google Fonts — until they load
        (or if the phone is offline) text is drawn in the OEM font, which is
        wider than Samsung's. Fixed-width layouts overflow.
     3. Android "Font size" and "Display size" settings. The native side now
        caps the WebView text zoom (see MainActivity.java), and the rules
        below are written so nothing depends on exact text widths.
     4. Things positioned with vh/% offsets (the "Where to?" picker hero, the
        SMS consent dialog) landed on top of other content on shorter screens.
   ===================================================================== */

@layer tf-min{

  /* ---------- Global safety nets ---------- */
  html{-webkit-text-size-adjust:100%!important;text-size-adjust:100%!important}
  html.tf-min body{min-width:0!important}
  html.tf-min :is(img,svg,video,canvas,iframe){max-width:100%}
  html.tf-min :is(.card,.tile,.modal-card,.stat-tile,.budget-row){min-width:0}
  /* long names / merchants / emails wrap instead of pushing the layout wider */
  html.tf-min :is(.card,.modal-card,.sms-legend-item,.hint,.sms-row-head) {overflow-wrap:break-word}
  html.tf-min :is(button,.btn,.btn-secondary,.small-btn){max-width:100%}
  html.tf-min :is(select,input,textarea){max-width:100%;min-width:0}

  /* ---------- Header (screenshot 5: "Launch Offer" chip sitting on top of "TrakFi") ---------- */
  html.tf-min .topbar .topbar-header-row{gap:clamp(4px,1.6vw,8px)!important}
  html.tf-min .topbar .topbar-brand{flex:1 1 0!important;min-width:0!important;gap:clamp(4px,1.6vw,7px)!important}
  html.tf-min .topbar .brand-icon-trigger{gap:clamp(4px,1.8vw,8px)!important;flex:0 0 auto!important}
  html.tf-min .topbar .brand-text{flex:1 1 auto!important;min-width:0!important;overflow:hidden}
  html.tf-min .topbar .brand-title-row{display:flex!important;flex-wrap:nowrap!important;align-items:center!important;
    gap:6px!important;min-width:0!important;max-width:100%!important}
  /* the wordmark never shrinks or gets covered — the chip is the flexible part */
  html.tf-min .topbar .brand-title{flex:0 0 auto!important;min-width:max-content!important;white-space:nowrap!important}
  html.tf-min .topbar .fest-chip{margin-left:0!important;flex:0 1 auto!important;min-width:0!important;max-width:100%!important;
    white-space:nowrap!important;overflow:hidden}
  /* The chip is only meant to exist while the offer is on (JS adds .on). The bento theme forced
     display:inline-flex!important, which kept an empty chip in the bar after the offer ended. */
  html.tf-min .topbar .fest-chip:not(.on){display:none!important}
  html.tf-min .topbar .fest-chip .fc-txt{display:block!important;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  /* Step 1 (set from responsive.js when the full label doesn't fit): shorter label */
  html.tf-min .topbar .fest-chip.tf-chip-s{padding:0 7px!important;font-size:9.5px!important}
  html.tf-min .topbar .fest-chip.tf-chip-s .fc-txt{font-size:0!important}
  html.tf-min .topbar .fest-chip.tf-chip-s .fc-txt::after{content:"\1F381  Offer";font-size:9.5px;font-weight:700}
  /* Step 2: icon only */
  html.tf-min .topbar .fest-chip.tf-chip-xs{padding:0 6px!important;min-width:24px!important}
  html.tf-min .topbar .fest-chip.tf-chip-xs .fc-txt{font-size:0!important}
  html.tf-min .topbar .fest-chip.tf-chip-xs .fc-txt::after{content:"\1F381";font-size:12px}
  html.tf-min .topbar .brand-tagline-row{display:block!important;max-width:100%;overflow:hidden}
  html.tf-min .topbar .brand-tagline{white-space:nowrap!important;overflow:hidden!important;text-overflow:clip;max-width:100%;
    font-size:clamp(8px,2.5vw,9px)!important;letter-spacing:min(.2em,.5vw)!important}
  html.tf-min .topbar .brand-title{font-size:clamp(16px,5.2vw,20px)!important}
  /* right-hand round buttons */
  html.tf-min .topbar .topbar-header-row > div:last-child{flex:0 0 auto!important;gap:clamp(4px,1.6vw,8px)!important}
  html.tf-min .topbar #topbarAiBtn.topbar-account-btn,
  html.tf-min .topbar #topbarReminderBtn.topbar-account-btn,
  html.tf-min .topbar #toolbarMenuBtn{width:clamp(30px,9.4vw,38px)!important;height:clamp(30px,9.4vw,38px)!important;min-width:0!important;flex:0 0 auto}
  html.tf-min .topbar .brand-icon{width:clamp(28px,8.6vw,34px)!important;height:clamp(28px,8.6vw,34px)!important}

  /* ---------- "Where to?" picker (screenshots 2 and 3: huge gap / text on top of the pill) ----------
     The hero (rupee bag, TrakFi, tagline, CASH·UPI pill) was position:absolute at top:6-9vh while the
     title + cards were centred as a separate group — so on a shorter or larger-text phone the two
     collided and on a taller one a big hole opened between them. Now everything is ONE column in normal
     flow: hero -> "Where to?" -> cards, centred as a group, spacing scales with screen height. */
  html.tf-min .spends-petals{
    justify-content:flex-start!important;align-items:center!important;
    gap:clamp(10px,2.2vh,16px)!important;gap:clamp(10px,2.2dvh,16px)!important;
    padding:12px clamp(14px,6vw,28px) clamp(40px,15vh,150px)!important;padding-bottom:clamp(40px,15dvh,150px)!important;overflow:visible!important}
  html.tf-min .spends-petals > :first-child{margin-top:auto!important}
  html.tf-min .spends-petals > :last-child{margin-bottom:auto!important}
  html.tf-min .spends-petal-hero{
    position:static!important;top:auto!important;left:auto!important;right:auto!important;
    width:100%!important;max-width:420px;padding:0!important;gap:clamp(4px,1vh,8px)!important;
    margin:0 0 clamp(6px,2.4vh,26px)!important;margin:0 0 clamp(6px,2.4dvh,26px)!important}
  html.tf-min .spends-petal-hero-icon{width:clamp(40px,7.5vh,56px)!important;height:clamp(40px,7.5vh,56px)!important;
    width:clamp(40px,7.5dvh,56px)!important;height:clamp(40px,7.5dvh,56px)!important}
  html.tf-min .spends-petal-hero-title{font-size:clamp(21px,6.4vw,26px)!important}
  html.tf-min .spends-petal-hero-sub{max-width:min(300px,86vw)!important;font-size:clamp(11.5px,3.3vw,13px)!important}
  html.tf-min[data-look="bento"] .spends-petal-hero::after{margin-top:clamp(6px,1.6vh,12px)!important;
    font-size:clamp(9.5px,2.9vw,11px)!important;padding:7px clamp(10px,3.6vw,15px)!important;white-space:nowrap;max-width:100%}
  html.tf-min .spends-petal-title-row{margin:0!important;flex:0 0 auto}
  html.tf-min .spends-petal{
    min-height:clamp(84px,14vh,120px)!important;min-height:clamp(84px,14dvh,120px)!important;
    margin:0!important;flex:0 0 auto;padding:clamp(12px,2.2vh,18px) clamp(14px,4.6vw,20px)!important;
    gap:clamp(10px,3.6vw,16px)!important}
  html.tf-min .spends-petal-label{font-size:clamp(16px,4.9vw,18px)!important}
  html.tf-min .spends-petal-sub{font-size:clamp(11px,3.3vw,12.5px)!important}
  @media (max-height:640px){
    html.tf-min .spends-petal-hero-sub{display:none!important}
    html.tf-min .spends-petal-hero-icon{width:36px!important;height:36px!important}
    html.tf-min .spends-petal{min-height:76px!important}
  }
  @media (max-height:520px){
    html.tf-min .spends-petal-hero-icon,html.tf-min[data-look="bento"] .spends-petal-hero::after{display:none!important}
    html.tf-min .spends-petal-icon-wrap{display:none!important}
  }

  /* ---------- SMS consent / battery dialog (screenshots 1 and 4: see-through, text on top of the panel) ----------
     The minimal theme strips every background-image, and this dialog only had a gradient — so it ended up
     with NO background at all and the SMS sheet showed straight through it. Solid colour + proper centring. */
  html.tf-min #smsPermExplainerBackdrop{background-color:rgba(4,12,11,.78)!important;z-index:10040!important}
  html.tf-min #smsPermExplainerModal{
    background-color:#0C302C!important;color:#fff!important;z-index:10041!important;
    position:fixed!important;left:50%!important;top:50%!important;right:auto!important;bottom:auto!important;
    transform:translate(-50%,-50%)!important;width:min(92vw,420px)!important;box-sizing:border-box!important;
    max-height:calc(100vh - 32px)!important;max-height:calc(100dvh - 32px)!important;overflow-y:auto!important;
    overscroll-behavior:contain;-webkit-overflow-scrolling:touch;padding:clamp(14px,4.4vw,20px)!important;
    border:1px solid rgba(255,255,255,.18)!important;box-shadow:0 18px 44px rgba(0,0,0,.6)!important}
  html.tf-min #smsPermExplainerTitle{font-size:clamp(16px,4.8vw,18px)!important;line-height:1.3!important;margin-bottom:10px!important;color:#fff!important}
  html.tf-min #smsPermExplainerBody{display:flex!important;flex-direction:column!important;gap:8px!important}
  html.tf-min #smsPermExplainerBody .sms-legend-item{font-size:clamp(12px,3.5vw,13.5px)!important;line-height:1.45!important;
    padding:9px 11px!important;color:#EAF6F3!important;background-color:rgba(255,255,255,.08)!important;overflow-wrap:break-word}
  html.tf-min #smsPermExplainerModal .sms-btn{min-height:44px!important;height:auto!important;font-size:clamp(13px,3.8vw,15px)!important;padding:10px 12px!important}
  html.tf-min #smsPermExplainerContinue{background-color:#0E8C82!important;color:#fff!important;border:1px solid #0A6F67!important}
  html.tf-min #smsPermExplainerSkip{background-color:#fff!important;color:#0B2422!important}

  /* SMS import sheet: height is set by sms-bridge.js (positionSmsBox) from the real header height — do not override it here */
  html.tf-min #smsImportBox{overscroll-behavior:contain;-webkit-overflow-scrolling:touch}

  /* ---------- Modals: always fit and scroll on short screens ---------- */
  html.tf-min .modal-overlay{padding:clamp(8px,3vw,20px)!important;overscroll-behavior:contain}
  html.tf-min .modal-card{max-width:min(380px,100%)!important;padding:clamp(16px,5vw,26px) clamp(14px,5vw,24px)!important}
  html.tf-min .qe-card,html.tf-min #quickExpenseModal .qe-card{max-height:calc(100vh - 24px)!important;max-height:calc(100dvh - 24px)!important}
  html.tf-min .cat-filter-panel{left:max(8px,3vw)!important;right:max(8px,3vw)!important}
  html.tf-min .cat-tx-modal-panel{left:max(8px,3vw)!important;right:max(8px,3vw)!important;top:max(8px,3vh)!important;bottom:max(8px,3vh)!important}
  html.tf-min #sideNavDrawer{width:min(90vw,420px)!important;height:min(90vh,860px)!important;height:min(90dvh,860px)!important}

  /* Bottom floating tab bar: never wider than the screen, labels never wrap onto 2 lines */
  html.tf-min #appBottomNav{max-width:calc(100vw - 16px)!important}
  /* labels stay on one line; NEVER overflow:hidden on the item — the raised Spends "+" circle sticks out of the bar */
  html.tf-min #appBottomNav .nav-item{min-width:0!important;white-space:nowrap;font-size:clamp(9.5px,2.8vw,11px)!important}
  html.tf-min #appBottomNav .nav-item-spends-bulge{overflow:visible!important}

  /* ---------- Narrow phones (<= 360 CSS px: 1080p phones at larger display size, small Motos, Infinix, Realme C) ---------- */
  @media (max-width:360px){
    html.tf-min .wrap{padding-left:10px!important;padding-right:10px!important}
    html.tf-min[data-look="bento"] .brand-icon-hamburger{padding:2px 0!important}
    html.tf-min .modal-card{padding:16px 14px!important}
  }
  @media (max-width:330px){
    html.tf-min .topbar{padding-left:8px!important;padding-right:8px!important}
    html.tf-min .brand-icon-hamburger span{width:15px!important}
  }
}
