/* ============================================================
   Sabana Family Portal — mobile app (PWA) layer  ·  v2
   Loaded AFTER style.css. Desktop is untouched; everything here
   applies at phone widths or in the installed (standalone) app.
   Tested against iOS Safari quirks: dynamic viewport (dvh),
   safe areas, rubber-band overscroll, input zoom, tap highlight.
   ============================================================ */

/* ---------- Install button (sidebar foot) ---------- */
.installbtn{
  width:100%;
  margin-bottom:12px;
  padding:11px 12px;
  border-radius:10px;
  border:1px solid var(--gold);
  background:linear-gradient(180deg, rgba(201,162,75,0.22), rgba(201,162,75,0.10));
  color:var(--goldl);
  font-size:12.5px;
  font-weight:700;
  font-family:var(--sans);
  letter-spacing:0.2px;
}
.installbtn:active{transform:scale(0.98);}

/* ---------- Bottom navigation (phones only) ---------- */
.bottomnav{display:none;}

@media screen and (max-width: 900px){
  .bottomnav{
    display:flex;
    position:fixed;
    left:0;right:0;bottom:0;
    z-index:60;
    background:rgba(255,255,255,0.88);
    -webkit-backdrop-filter:saturate(180%) blur(16px);
    backdrop-filter:saturate(180%) blur(16px);
    border-top:1px solid rgba(228,231,240,0.9);
    box-shadow:0 -8px 28px rgba(11,27,58,0.10);
    padding:8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .bottomnav-item{
    flex:1;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:3px;
    padding:6px 2px;
    border:none;
    background:none;
    border-radius:12px;
    color:#8A93A6;
    font-family:var(--sans);
    min-height:50px;
    transition:color .18s ease, background .18s ease, transform .1s ease;
  }
  .bottomnav-item:active{transform:scale(0.94);}
  .bottomnav-item.active{
    color:var(--navy);
    background:linear-gradient(180deg, rgba(201,162,75,0.20), rgba(201,162,75,0.08));
  }
  .bottomnav-item.active .bottomnav-icon{color:var(--gold);}
  .bottomnav-icon{display:flex;line-height:1;}
  .bottomnav-icon svg{display:block;}
  .bottomnav-label{font-size:10px;font-weight:700;letter-spacing:0.2px;}

  /* Content must clear the fixed bottom bar. */
  .content{padding-bottom:calc(92px + env(safe-area-inset-bottom, 0px));}
  /* The drawer sidebar slides over the bottom bar. */
  .sidebar{z-index:70;}
  .sidebar-overlay{z-index:65;}
}

/* ---------- Phone-width refinements ---------- */
@media screen and (max-width: 900px){
  /* App-like sticky frosted header. */
  .topbar{
    position:sticky;
    top:0;
    z-index:30;
    background:rgba(245,246,250,0.90);
    -webkit-backdrop-filter:saturate(180%) blur(14px);
    backdrop-filter:saturate(180%) blur(14px);
    border-bottom:1px solid rgba(228,231,240,0.9);
    padding-top:calc(14px + env(safe-area-inset-top, 0px));
    padding-bottom:12px;
  }
  .pagetitle{font-size:17px;}
  .pagesub{font-size:11px;}

  /* One compact header row: title truncates instead of wrapping the
     language toggle + avatar onto a tall second line. */
  .topbar{flex-wrap:nowrap;gap:10px;}
  .topbar-left{min-width:0;flex:1;}
  .topbar-left > div{min-width:0;}
  .pagetitle, .pagesub{
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
  .topbar-right{flex-shrink:0;}
  .menubtn{
    width:40px;height:40px;font-size:17px;
    border-radius:12px;
    box-shadow:0 1px 3px rgba(11,27,58,0.08);
    flex-shrink:0;
  }

  /* Softer, deeper cards. */
  .card{
    border-radius:16px;
    border-color:rgba(228,231,240,0.9);
    box-shadow:0 1px 2px rgba(11,27,58,0.04), 0 10px 30px rgba(11,27,58,0.05);
  }
  .cardhead{padding:16px 16px;}
  .cardbody{padding:16px;}
  .formgrid{padding:0 16px 16px;}

  /* Buttons: rounder, tactile, with a proper gold primary. */
  .btn{
    min-height:40px;
    border-radius:11px;
    transition:transform .1s ease, box-shadow .15s ease;
  }
  .btn:active{transform:scale(0.97);}
  .btn-gold{
    background:linear-gradient(180deg, var(--goldl), var(--gold));
    box-shadow:0 3px 10px rgba(201,162,75,0.35);
    border:none;
  }
  .tab{padding:10px 16px;}
  .chip{border-radius:9px;}

  /* Every data table scrolls sideways inside its card instead of
     blowing out the page width. */
  .card table, .content table{
    display:block;
    width:100%;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
    overscroll-behavior-x:contain;
  }
  .card table th, .card table td,
  .content table th, .content table td{
    white-space:nowrap;
  }

  /* Comfortable touch targets. */
  .navitem{padding:12px;font-size:14px;min-height:44px;border-radius:10px;}

  /* Toolbars and filters stack cleanly. */
  .filterbar > *, .cardhead .btn{max-width:100%;}

  /* Drawer sidebar: rounded edge, real device height (dvh follows the
     iOS Safari collapsing URL bar; vh does not), safe-area padding. */
  .sidebar{
    width:min(300px, 86vw);
    height:100vh;
    height:100dvh;
    border-radius:0 20px 20px 0;
    padding-top:calc(24px + env(safe-area-inset-top, 0px));
    padding-bottom:calc(20px + env(safe-area-inset-bottom, 0px));
    transition:transform .28s cubic-bezier(.32,.72,.32,1);
  }
  .sidebar.open{box-shadow:16px 0 48px rgba(11,27,58,0.35);}
  .sidebar-overlay{
    background:rgba(11,27,58,0.45);
    -webkit-backdrop-filter:blur(2px);
    backdrop-filter:blur(2px);
  }
}

@media screen and (max-width: 720px){
  /* 16px inputs stop iOS Safari from zooming the page on focus. */
  .field2 input, .field2 select, .field2 textarea,
  .searchbox input, .selectbox, input, select, textarea{
    font-size:16px !important;
  }
  .field2 input, .field2 select{min-height:44px;}

  /* Native pickers keep working, but the closed control looks ours:
     no default iOS bevel, a custom chevron, roomy touch height. */
  .field2 select, .selectbox, select{
    -webkit-appearance:none;
    appearance:none;
    background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1.5 7 7.5 13 1.5' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat:no-repeat;
    background-position:right 12px center;
    padding-right:34px;
    border-radius:11px;
    min-height:44px;
    background-color:var(--white);
  }
  .field2 input, .field2 textarea{
    -webkit-appearance:none;
    appearance:none;
    border-radius:11px;
  }
  .field2 input:focus, .field2 select:focus, .field2 textarea:focus,
  .selectbox:focus{
    outline:none;
    border-color:var(--gold);
    box-shadow:0 0 0 3px rgba(201,162,75,0.22);
  }

  /* Modals become bottom sheets with a grab handle. */
  .modal{align-items:flex-end;padding:0;}
  .modalbox{
    max-width:100%;
    width:100%;
    border-radius:20px 20px 0 0;
    max-height:calc(100dvh - 40px);
    padding-bottom:env(safe-area-inset-bottom, 0px);
    animation:sheetup .28s cubic-bezier(.32,.72,.32,1);
  }
  .modalbox::before{
    content:"";
    display:block;
    width:40px;height:4px;
    border-radius:2px;
    background:var(--border);
    margin:10px auto 0;
  }
  .modalfoot{
    position:sticky;
    bottom:0;
    background:var(--white);
    padding-bottom:calc(14px + env(safe-area-inset-bottom, 0px));
  }
  .modalfoot .btn{flex:1;min-height:46px;}

  /* KPI cards read better with a touch more height on phones. */
  .kpicard{padding:16px 18px;}
  .kpivalue{font-size:20px;}
}

@keyframes sheetup{
  from{transform:translateY(24px);opacity:0.6;}
  to{transform:translateY(0);opacity:1;}
}

@media screen and (max-width: 560px){
  /* The avatar chip is redundant next to the drawer identity chip. */
  .topbar-right .avatar.small{display:none;}
}

/* ---------- iOS "Add to Home Screen" hint ---------- */
.ioshint{
  position:fixed;
  left:0;right:0;
  bottom:calc(78px + env(safe-area-inset-bottom, 0px));
  z-index:80;
  display:flex;
  justify-content:center;
  padding:0 14px;
  pointer-events:none;
  animation:hintup .45s cubic-bezier(.32,.72,.32,1);
}
@keyframes hintup{
  from{transform:translateY(30px);opacity:0;}
  to{transform:translateY(0);opacity:1;}
}
.ioshint-card{
  pointer-events:auto;
  display:flex;
  align-items:center;
  gap:12px;
  width:100%;
  max-width:430px;
  background:linear-gradient(180deg, var(--navy2), var(--navy));
  color:var(--white);
  border:1px solid rgba(201,162,75,0.45);
  border-radius:16px;
  padding:12px 14px;
  box-shadow:0 16px 44px rgba(11,27,58,0.45);
}
.ioshint-appicon{
  width:42px;height:42px;
  border-radius:10px;
  flex-shrink:0;
  box-shadow:0 2px 8px rgba(0,0,0,0.35);
}
.ioshint-text{flex:1;min-width:0;}
.ioshint-title{
  font-size:13px;
  font-weight:700;
  margin-bottom:3px;
  letter-spacing:0.2px;
}
.ioshint-steps{
  display:flex;
  flex-direction:column;
  gap:1px;
  font-size:11.5px;
  color:var(--cream);
  line-height:1.5;
}
.ioshint-step{display:flex;align-items:center;gap:4px;flex-wrap:wrap;}
.ioshint-glyph{
  display:inline-flex;
  color:var(--goldl);
  vertical-align:middle;
}
.ioshint-glyph svg{display:block;width:15px;height:15px;}
.ioshint-close{
  flex-shrink:0;
  align-self:center;
  background:rgba(201,162,75,0.18);
  border:1px solid var(--gold);
  color:var(--goldl);
  font-family:var(--sans);
  font-size:12px;
  font-weight:700;
  padding:9px 13px;
  border-radius:10px;
}
.ioshint-close:active{transform:scale(0.96);}
/* Desktop shouldn't ever see it (belt over the JS check's braces). */
@media screen and (min-width: 901px){
  .ioshint{display:none;}
}

/* ---------- Installed app (standalone) polish ---------- */
@media all and (display-mode: standalone){
  body{background:var(--lightbg);}
  *{-webkit-tap-highlight-color:transparent;}
  .navitem, .btn, .tab, .bottomnav-item{user-select:none;-webkit-user-select:none;}
  html{overscroll-behavior-y:none;}
  /* iOS rubber-band above the header shows the page background —
     keep the app canvas color, never a white void. */
  html, body{background:var(--lightbg);}
}
