/* JKA Dealer Portal v1.6.18 — mobile display, spacing and modal hardening
   Loaded last. Keeps the mobile app header on one row, normalizes touch targets,
   reduces excess vertical whitespace, and guarantees scrollable/reachable modals. */

body.homeaid-system{overflow-x:hidden}
body.homeaid-system .app-shell,
body.homeaid-system .app-content,
body.homeaid-system .content-frame{min-width:0;max-width:100%}
body.homeaid-system .app-icon{flex:0 0 auto}

/* Prevent header controls from wrapping or floating over page content. */
@media(max-width:767.98px){
  body.homeaid-system .app-header{
    display:grid!important;
    grid-template-columns:auto minmax(0,1fr) auto!important;
    align-items:center!important;
    column-gap:.55rem!important;
    width:100%!important;
    height:60px!important;
    min-height:60px!important;
    padding:.45rem .7rem!important;
    overflow:visible!important;
  }
  body.homeaid-system .header-left{
    grid-column:1!important;
    width:auto!important;
    min-width:0!important;
    justify-self:start!important;
    gap:.45rem!important;
  }
  body.homeaid-system .header-copy{display:none!important}
  body.homeaid-system .header-actions{
    grid-column:3!important;
    width:auto!important;
    min-width:0!important;
    max-width:100%!important;
    margin:0!important;
    justify-self:end!important;
    justify-content:flex-end!important;
    flex-wrap:nowrap!important;
    gap:.32rem!important;
  }
  body.homeaid-system .app-header .btn-icon,
  body.homeaid-system .app-header #pwaInstallBtn,
  body.homeaid-system .app-header .avatar-button,
  body.homeaid-system .app-header .avatar{
    width:36px!important;
    min-width:36px!important;
    max-width:36px!important;
    height:36px!important;
    min-height:36px!important;
    max-height:36px!important;
    margin:0!important;
  }
  body.homeaid-system .app-header .btn-icon,
  body.homeaid-system .app-header #pwaInstallBtn{
    display:inline-grid!important;
    place-items:center!important;
    padding:0!important;
    border-radius:.7rem!important;
    line-height:1!important;
  }
  body.homeaid-system .app-header #pwaInstallBtn.d-none{display:none!important}
  body.homeaid-system .app-header .app-icon{width:1rem!important;height:1rem!important}
  body.homeaid-system .app-header .avatar{font-size:.7rem!important;box-shadow:0 0 0 2px rgba(216,182,52,.13)!important}
  body.homeaid-system .app-header .dropdown{line-height:1}
  body.homeaid-system .app-content{padding-top:.85rem!important}
}

@media(max-width:575.98px){
  :root{--ha-content-gutter:.72rem}
  body.homeaid-system .app-header{height:58px!important;min-height:58px!important;padding:.4rem .62rem!important}
  body.homeaid-system .app-content{padding:.8rem .68rem 1.15rem!important}
  body.homeaid-system .app-footer{padding:.8rem .68rem!important}
  body.homeaid-system .premium-page-head,
  body.homeaid-system .page-heading{gap:.7rem!important;margin-bottom:.85rem!important}
  body.homeaid-system .premium-page-title h1,
  body.homeaid-system .page-title h1{font-size:1.38rem!important;line-height:1.16!important;margin:.18rem 0 .3rem!important}
  body.homeaid-system .premium-page-title>p,
  body.homeaid-system .page-title>p,
  body.homeaid-system .page-subtitle{font-size:.8rem!important;line-height:1.48!important}
  body.homeaid-system .premium-kicker,
  body.homeaid-system .eyebrow{display:flex;align-items:center;gap:.38rem;flex-wrap:wrap;line-height:1.35}
  body.homeaid-system .release-chip{position:static!important;margin:0!important;transform:none!important}

  body.homeaid-system .premium-card,
  body.homeaid-system .panel-card,
  body.homeaid-system .table-card,
  body.homeaid-system .card{border-radius:.82rem!important}
  body.homeaid-system .premium-card + .premium-card,
  body.homeaid-system .card + .card{margin-top:.8rem!important}
  body.homeaid-system .premium-card-head{padding:.78rem .8rem!important;gap:.62rem!important}
  body.homeaid-system .premium-card-body{padding:.8rem!important}
  body.homeaid-system .premium-card-head>div:first-child{gap:.62rem!important}
  body.homeaid-system .section-icon{width:36px!important;height:36px!important;min-width:36px!important;border-radius:.68rem!important}

  /* Compact dashboard metrics instead of very tall single-column cards. */
  body.homeaid-system .premium-metrics,
  body.homeaid-system .stats{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:.62rem!important;
    margin-bottom:.85rem!important;
  }
  body.homeaid-system .premium-metric,
  body.homeaid-system .metric-card,
  body.homeaid-system .stats>div{
    min-height:112px!important;
    padding:.78rem!important;
    border-radius:.82rem!important;
    align-items:flex-start!important;
    justify-content:center!important;
  }
  body.homeaid-system .premium-metric .metric-icon,
  body.homeaid-system .metric-card .metric-icon,
  body.homeaid-system .stats>div .metric-icon{width:34px!important;height:34px!important;margin-bottom:.5rem!important}
  body.homeaid-system .premium-metric strong,
  body.homeaid-system .metric-card strong,
  body.homeaid-system .stats>div strong{line-height:1.05}
  body.homeaid-system .premium-metric small,
  body.homeaid-system .metric-card small,
  body.homeaid-system .stats>div small{line-height:1.35}

  body.homeaid-system .premium-page-actions{gap:.45rem!important}
  body.homeaid-system .premium-page-actions .btn,
  body.homeaid-system .btn:not(.btn-icon):not(.avatar-button){min-height:40px!important}
  body.homeaid-system .dealer-table-wrap{padding:.05rem .55rem .65rem!important}
  body.homeaid-system .premium-table th,
  body.homeaid-system .premium-table td,
  body.homeaid-system .table th,
  body.homeaid-system .table td{padding:.58rem .52rem!important;font-size:.78rem!important}
  body.homeaid-system .dt-container .dt-layout-row,
  body.homeaid-system .dt-local-toolbar,
  body.homeaid-system .dt-local-footer{margin:.55rem 0!important;gap:.5rem!important}

  /* Toasts respect mobile safe areas and do not cover footer controls. */
  body.homeaid-system .app-toast-container{
    right:.5rem!important;
    left:.5rem!important;
    bottom:max(.5rem,env(safe-area-inset-bottom))!important;
    width:auto!important;
  }

  /* All Bootstrap modals are viewport-safe and scroll internally. */
  body.homeaid-system .modal{padding:0!important}
  body.homeaid-system .modal-dialog,
  body.homeaid-system .premium-modal .modal-dialog,
  body.homeaid-system .modal-dialog.modal-lg,
  body.homeaid-system .modal-dialog.modal-xl{
    width:calc(100% - .7rem)!important;
    max-width:calc(100% - .7rem)!important;
    min-height:0!important;
    height:calc(100dvh - .7rem)!important;
    max-height:calc(100dvh - .7rem)!important;
    margin:.35rem!important;
    align-items:stretch!important;
  }
  body.homeaid-system .modal-dialog .modal-content,
  body.homeaid-system .premium-modal .modal-dialog .modal-content{
    display:flex!important;
    flex-direction:column!important;
    width:100%!important;
    min-height:0!important;
    height:100%!important;
    max-height:100%!important;
    overflow:hidden!important;
    border-radius:.8rem!important;
  }
  body.homeaid-system .modal-content>form,
  body.homeaid-system .modal-content>form.modal-form-shell{
    display:flex!important;
    flex-direction:column!important;
    flex:1 1 auto!important;
    min-height:0!important;
    overflow:hidden!important;
  }
  body.homeaid-system .modal-header,
  body.homeaid-system .premium-modal .modal-header{
    flex:0 0 auto!important;
    align-items:flex-start!important;
    padding:.76rem .82rem!important;
  }
  body.homeaid-system .modal-header>div:first-child{min-width:0;padding-right:.35rem}
  body.homeaid-system .modal-header .modal-title{font-size:1rem!important;line-height:1.25!important}
  body.homeaid-system .modal-header p{font-size:.75rem!important;line-height:1.42!important;margin:.2rem 0 0!important}
  body.homeaid-system .modal-header .btn-close{margin:0!important;flex:0 0 auto!important}
  body.homeaid-system .modal-body,
  body.homeaid-system .premium-modal .modal-body,
  body.homeaid-system .modal-content>form>.modal-body{
    flex:1 1 auto!important;
    min-height:0!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    overscroll-behavior:contain!important;
    -webkit-overflow-scrolling:touch!important;
    padding:.82rem!important;
  }
  body.homeaid-system .modal-footer,
  body.homeaid-system .premium-modal .modal-footer{
    flex:0 0 auto!important;
    padding:.68rem .82rem calc(.68rem + env(safe-area-inset-bottom))!important;
    gap:.45rem!important;
    flex-wrap:wrap!important;
    background:var(--ha-surface)!important;
    border-top:1px solid var(--ha-border)!important;
  }
  body.homeaid-system .modal-footer>.btn,
  body.homeaid-system .modal-footer>button,
  body.homeaid-system .modal-footer>form,
  body.homeaid-system .modal-footer .save-actions,
  body.homeaid-system .modal-footer .danger-zone-actions{min-width:0!important}
  body.homeaid-system .modal-footer .save-actions,
  body.homeaid-system .modal-footer .danger-zone-actions{display:flex!important;flex:1 1 100%!important;gap:.45rem!important}
  body.homeaid-system .modal-footer .save-actions .btn,
  body.homeaid-system .modal-footer .danger-zone-actions .btn{flex:1 1 0!important;width:auto!important}
  body.homeaid-system .dealer-modal-workspace{padding:.82rem!important}
  body.homeaid-system .dealer-modal-summary{padding:.82rem!important}
  body.homeaid-system .modal-tabs{margin-bottom:.75rem!important}
  body.homeaid-system .modal-tabs .nav-link{min-height:38px!important;padding:.48rem .6rem!important;font-size:.7rem!important}
}

@media(max-width:389.98px){
  body.homeaid-system .app-header{padding-left:.5rem!important;padding-right:.5rem!important;column-gap:.35rem!important}
  body.homeaid-system .header-actions{gap:.22rem!important}
  body.homeaid-system .app-header .btn-icon,
  body.homeaid-system .app-header #pwaInstallBtn,
  body.homeaid-system .app-header .avatar-button,
  body.homeaid-system .app-header .avatar{width:34px!important;min-width:34px!important;max-width:34px!important;height:34px!important;min-height:34px!important;max-height:34px!important}
  body.homeaid-system .premium-metrics,
  body.homeaid-system .stats{grid-template-columns:1fr 1fr!important}
  body.homeaid-system .premium-metric,
  body.homeaid-system .metric-card,
  body.homeaid-system .stats>div{min-height:104px!important;padding:.7rem!important}
  body.homeaid-system .modal-footer .save-actions,
  body.homeaid-system .modal-footer .danger-zone-actions{display:grid!important;grid-template-columns:1fr!important}
  body.homeaid-system .modal-footer .save-actions .btn,
  body.homeaid-system .modal-footer .danger-zone-actions .btn{width:100%!important}
}

@media(max-width:339.98px){
  body.homeaid-system .premium-metrics,
  body.homeaid-system .stats{grid-template-columns:1fr!important}
}

@media(orientation:landscape) and (max-height:520px){
  body.homeaid-system .app-header{height:52px!important;min-height:52px!important}
  body.homeaid-system .modal-dialog,
  body.homeaid-system .premium-modal .modal-dialog{height:calc(100dvh - .4rem)!important;max-height:calc(100dvh - .4rem)!important;margin:.2rem!important}
  body.homeaid-system .modal-header{padding:.55rem .75rem!important}
  body.homeaid-system .modal-footer{padding:.5rem .75rem calc(.5rem + env(safe-area-inset-bottom))!important}
}
