/* =====================================================================
   INNOVATION CRM — MOBILE & TABLET LAYER
   Loaded after premium.css (see includes/header.php).
   Desktop (wider than 980px) is NOT changed by this file.
   ===================================================================== */

/* Hamburger + backdrop exist in the markup on every screen but only show on small ones. */
.menu-toggle{display:none}
.sidebar-backdrop{display:none}
.sidebar-close{display:none}
.topbar-brand{display:none}

/* Horizontal scroll container added around wide tables by assets/js/mobile.js */
.table-scroll{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
@media(min-width:981px){.table-scroll{overflow:visible}}

/* Images never push the page wider than the screen. */
.content img{max-width:100%;height:auto}

/* ---------------------------------------------------------------------
   TABLET + PHONE  (drawer navigation)
   --------------------------------------------------------------------- */
@media(max-width:980px){

  html,body{max-width:100%}
  body{overflow-x:hidden}
  .layout{display:block;min-height:100vh}
  .main{width:100%;min-width:0;overflow-x:clip}

  /* ---- sidebar becomes a slide-in drawer ---- */
  .sidebar{
    position:fixed;
    top:0;left:0;bottom:0;
    width:min(86vw,300px);
    height:100vh;height:100dvh;
    display:block;
    overflow-x:hidden;overflow-y:auto;
    -webkit-overflow-scrolling:touch;
    padding:16px 14px calc(28px + env(safe-area-inset-bottom));
    transform:translateX(-104%);
    visibility:hidden;
    transition:transform .26s ease,visibility 0s linear .26s;
    z-index:1001;
    box-shadow:none;
    align-self:auto;
  }
  body.nav-open .sidebar{
    transform:none;
    visibility:visible;
    transition:transform .26s ease,visibility 0s;
    box-shadow:0 0 50px rgba(0,0,0,.45);
  }
  /* brand + close button stay visible at the top while the menu list scrolls */
  .sidebar .brand{
    display:flex;
    position:sticky;top:-16px;z-index:3;
    margin:-16px -14px 8px;
    padding:16px 60px 18px 22px;
    background:var(--night);
  }
  .nav-label{display:block}
  .sidebar a.nav-link{
    display:flex;
    margin:2px 0;
    padding:12px 12px;
    min-height:44px;
    white-space:normal;
    font-size:14.5px;
  }
  .sidebar a.nav-link.active::before{display:block}
  .sidebar a.nav-link.logout{margin-top:18px}

  .sidebar-close{
    display:flex;align-items:center;justify-content:center;
    position:absolute;right:14px;top:50%;margin-top:-17px;
    width:40px;height:40px;margin-top:-20px;
    border:0;border-radius:10px;
    background:rgba(255,255,255,.07);color:#fff;
    font-size:22px;line-height:1;cursor:pointer;
  }

  .sidebar-backdrop{
    display:block;
    position:fixed;inset:0;
    background:rgba(16,18,22,.58);
    opacity:0;pointer-events:none;
    transition:opacity .22s ease;
    z-index:1000;
    -webkit-tap-highlight-color:transparent;
  }
  body.nav-open .sidebar-backdrop{opacity:1;pointer-events:auto}
  body.nav-open{overflow:hidden;touch-action:none}

  /* ---- topbar ---- */
  .topbar{
    padding:0 14px;
    padding-left:max(14px,env(safe-area-inset-left));
    padding-right:max(14px,env(safe-area-inset-right));
    min-height:58px;
    gap:10px;
  }
  .menu-toggle{
    display:inline-flex;align-items:center;justify-content:center;
    width:44px;height:44px;flex:0 0 44px;
    border:1px solid var(--line);border-radius:11px;
    background:#fff;color:var(--ink);cursor:pointer;
    -webkit-tap-highlight-color:transparent;
  }
  .menu-toggle:active{background:var(--gold-soft)}
  .menu-toggle svg{width:22px;height:22px;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round}
  .topbar-brand{
    display:flex;align-items:center;gap:9px;
    margin-right:auto;min-width:0;
    font-weight:800;font-size:15px;color:var(--ink);
  }
  .topbar-brand .brand-mark{width:30px;height:30px;flex:0 0 30px;font-size:15px;border-radius:8px}
  .topbar-brand span.t{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .topbar-date{display:none}
  .user-meta small{display:none}
  .user-chip{gap:9px}

  .content{
    padding:18px 16px calc(40px + env(safe-area-inset-bottom));
  }
}

/* ---------------------------------------------------------------------
   PHONE
   --------------------------------------------------------------------- */
@media(max-width:640px){

  .content{padding:14px 12px calc(40px + env(safe-area-inset-bottom))}
  .user-meta{display:none}
  .topbar-brand span.t{max-width:52vw}

  .page-title{font-size:20px;margin-bottom:14px}
  .panel{padding:15px;border-radius:12px;margin-bottom:16px}
  .panel-title{font-size:15px;margin-bottom:12px}

  /* stat cards: two per row */
  .cards{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:10px}
  .stat-card{padding:13px 14px}
  .stat-card .value{font-size:20px}
  .stat-card .label{font-size:11px}

  /* forms: one column, big touch targets, no iOS zoom on focus */
  .form-grid{grid-template-columns:1fr!important;gap:12px}
  .content input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=range]),
  .content select,
  .content textarea{
    font-size:16px;
    min-height:44px;
    max-width:100%;
  }
  .content textarea{min-height:90px}
  .search-box input{width:100%}

  /* buttons */
  .btn{min-height:44px;padding:10px 16px}
  .btn.small{min-height:38px}
  .form-actions{display:flex;flex-wrap:wrap;gap:8px}
  .form-actions .btn{flex:1 1 140px}
  .top-actions{flex-direction:column;align-items:stretch;gap:10px}
  .top-actions .btn,.top-actions a.btn{width:100%;justify-content:center}

  /* tables: comfortable cell size while scrolling sideways */
  :where(.content) th{padding:10px 11px;font-size:10.5px}
  :where(.content) td{padding:11px}
  .table-scroll{border-radius:10px}
  .table-scroll > table{min-width:560px}

  .alert{font-size:13.5px;padding:11px 13px}
}

/* login screen */
@media(max-width:640px){
  .login-wrap{
    padding:calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
    align-items:flex-start;
    padding-top:max(7vh,24px);
  }
  .login-box{padding:28px 20px 24px;max-width:none;border-radius:16px}
  .login-box input:not([type=checkbox]){font-size:16px;min-height:46px;max-width:100%}
  .login-box .btn{min-height:48px}
  .login-logo{width:180px}
}

/* very small phones */
@media(max-width:380px){
  .topbar-brand span.t{display:none}
  .cards{gap:8px}
  .stat-card .value{font-size:18px}
}

/* ---------------------------------------------------------------------
   PAGE-SPECIFIC FIXES (selectors that only exist on those pages)
   --------------------------------------------------------------------- */
@media(max-width:700px){
  .rr-cards{grid-template-columns:1fr!important}              /* rent / management receipts */
  .renew-form-wrap{width:100%!important;max-width:100%!important}   /* renewal invoice form */
  .expense-report-table,
  .lead-followup-form-page .history-table{min-width:560px}
}

/* ---------------------------------------------------------------------
   TABLETS in landscape / small laptops: keep desktop layout, tighten padding
   --------------------------------------------------------------------- */
@media(min-width:981px) and (max-width:1180px){
  .content{padding:24px 22px 44px}
  .sidebar{width:232px}
}

@media print{
  .menu-toggle,.sidebar-backdrop,.topbar-brand{display:none!important}
}
