/* JKA/WINDEV Dealer Portal v1.6.16 — visual display & spacing hardening
   Loaded last to normalize spacing, prevent overflow, and keep desktop/tablet/mobile
   layouts visually consistent without changing business logic. */

:root{
  --ui-space-1:.35rem;
  --ui-space-2:.55rem;
  --ui-space-3:.8rem;
  --ui-space-4:1rem;
  --ui-space-5:1.25rem;
  --ui-space-6:1.5rem;
  --ui-space-7:1.85rem;
  --ui-control-h:42px;
  --ui-card-radius:1rem;
}

/* Global containment / typography safety */
body.homeaid-system .content-frame,
body.homeaid-system .content-frame > *,
body.homeaid-system .premium-card,
body.homeaid-system .premium-card-head,
body.homeaid-system .premium-card-body,
body.homeaid-system .row > *,
body.homeaid-system form,
body.homeaid-system fieldset,
body.homeaid-system label{min-width:0}
body.homeaid-system img,body.homeaid-system svg,body.homeaid-system video,body.homeaid-system canvas{max-width:100%}
body.homeaid-system h1,body.homeaid-system h2,body.homeaid-system h3,body.homeaid-system h4,body.homeaid-system h5,body.homeaid-system h6{overflow-wrap:anywhere;text-wrap:balance}
body.homeaid-system p,body.homeaid-system small,body.homeaid-system dd,body.homeaid-system td,body.homeaid-system th,body.homeaid-system label{overflow-wrap:anywhere}
body.homeaid-system p:last-child,body.homeaid-system dl:last-child,body.homeaid-system ul:last-child,body.homeaid-system ol:last-child{margin-bottom:0}
body.homeaid-system hr{margin:var(--ui-space-6) 0;border-color:var(--ha-border);opacity:1}

/* Main page rhythm */
body.homeaid-system .app-content{padding-top:clamp(1rem,1.8vw,1.6rem);padding-bottom:clamp(1.35rem,2.2vw,2.2rem)}
body.homeaid-system .content-frame{max-width:1720px}
body.homeaid-system .page-heading,
body.homeaid-system .premium-page-head{margin-bottom:var(--ui-space-6)!important}
body.homeaid-system .premium-page-head{align-items:flex-start;gap:var(--ui-space-5)}
body.homeaid-system .premium-page-title{min-width:0;max-width:900px}
body.homeaid-system .premium-page-title h1,
body.homeaid-system .page-title h1{margin:.22rem 0 .42rem!important;line-height:1.18!important}
body.homeaid-system .premium-page-title>p,
body.homeaid-system .page-title>p,
body.homeaid-system .page-subtitle{margin:.2rem 0 0!important;line-height:1.6!important;max-width:900px}
body.homeaid-system .premium-page-actions{display:flex;align-items:center;justify-content:flex-end;gap:.65rem;flex-wrap:wrap;margin:0}
body.homeaid-system .premium-page-actions form{margin:0}

/* Consistent section/card spacing */
body.homeaid-system .premium-card,
body.homeaid-system .panel-card,
body.homeaid-system .table-card,
body.homeaid-system .card{border-radius:var(--ui-card-radius)!important;overflow:clip}
body.homeaid-system .premium-card + .premium-card,
body.homeaid-system .card + .card{margin-top:var(--ui-space-5)}
body.homeaid-system .premium-card-head{display:flex;align-items:flex-start;justify-content:space-between;gap:var(--ui-space-4);padding:1rem 1.2rem!important;margin:0!important;border-bottom:1px solid var(--ha-border)}
body.homeaid-system .premium-card-head>div:first-child{display:flex;align-items:flex-start;gap:.8rem;min-width:0}
body.homeaid-system .premium-card-head>div:first-child>div:last-child{min-width:0}
body.homeaid-system .premium-card-head h2,
body.homeaid-system .premium-card-head h3{margin:0 0 .2rem!important;line-height:1.28;font-size:1.03rem}
body.homeaid-system .premium-card-head p{margin:0!important;line-height:1.5;font-size:.78rem;max-width:920px}
body.homeaid-system .premium-card-body{padding:1.15rem 1.2rem 1.3rem!important}
body.homeaid-system .section-icon{flex:0 0 auto;margin-top:.05rem}
body.homeaid-system .mini-chip,
body.homeaid-system .status-pill{flex:0 0 auto;max-width:100%;white-space:normal;text-align:center}

/* Grid/metric rhythm */
body.homeaid-system .premium-metrics,
body.homeaid-system .stats{gap:var(--ui-space-4)!important;margin-bottom:var(--ui-space-5)!important}
body.homeaid-system .premium-metric,
body.homeaid-system .metric-card,
body.homeaid-system .stats>div{padding:1rem 1.05rem!important;min-height:104px;display:flex;flex-direction:column;justify-content:center}
body.homeaid-system .premium-lower-grid,
body.homeaid-system .dealer-dashboard-grid,
body.homeaid-system .request-detail-grid{gap:var(--ui-space-5)!important;margin-top:var(--ui-space-5)!important}
body.homeaid-system .settings-grid{gap:var(--ui-space-5)!important}

/* Forms: clean vertical rhythm and aligned controls */
body.homeaid-system form>label:not(.form-check):not(.email-pref-row),
body.homeaid-system .premium-card-body>label:not(.form-check),
body.homeaid-system .field-wrap{margin-bottom:var(--ui-space-4)!important}
body.homeaid-system form>label:last-of-type{margin-bottom:var(--ui-space-4)!important}
body.homeaid-system .form-label,
body.homeaid-system label{line-height:1.4}
body.homeaid-system .form-control,
body.homeaid-system .form-select,
body.homeaid-system input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
body.homeaid-system select,
body.homeaid-system textarea{min-height:var(--ui-control-h);margin-top:.38rem}
body.homeaid-system textarea.form-control,body.homeaid-system textarea{min-height:96px;line-height:1.5}
body.homeaid-system .row.g-3{--bs-gutter-x:1rem;--bs-gutter-y:1rem}
body.homeaid-system .form-text,body.homeaid-system .field-help{display:block;margin-top:.35rem;line-height:1.48}
body.homeaid-system fieldset{margin:0;padding:1rem;border-color:var(--ha-border)}
body.homeaid-system legend{margin-bottom:.6rem}
body.homeaid-system .form-check{min-height:1.45rem;margin-bottom:.42rem}
body.homeaid-system .form-check:last-child{margin-bottom:0}
body.homeaid-system .form-check-label{margin:0!important;line-height:1.45}

/* Buttons/action bars: even sizing and no accidental overflows */
body.homeaid-system .btn{min-height:40px;line-height:1.25;padding:.55rem .85rem;white-space:normal}
body.homeaid-system .btn-sm{min-height:34px;padding:.38rem .65rem}
body.homeaid-system .btn-icon{padding:0;white-space:nowrap}
body.homeaid-system .dealer-actions,
body.homeaid-system .save-actions,
body.homeaid-system .danger-zone-actions,
body.homeaid-system .premium-modal-footer,
body.homeaid-system .email-pref-actions{gap:.6rem!important}
body.homeaid-system .dealer-actions form,
body.homeaid-system .save-actions form,
body.homeaid-system .danger-zone-actions form{margin:0}

/* Alerts/info blocks */
body.homeaid-system .alert,
body.homeaid-system .notice,
body.homeaid-system .error,
body.homeaid-system .premium-info,
body.homeaid-system .identifier-missing,
body.homeaid-system .activation-disabled-banner{margin:0 0 var(--ui-space-4);padding:.85rem 1rem;line-height:1.55;border-radius:.85rem}
body.homeaid-system .premium-card-body>.alert:last-child{margin-bottom:0}

/* Tables and DataTables */
body.homeaid-system .dealer-table-wrap,
body.homeaid-system .table-responsive{width:100%;overflow-x:auto;overscroll-behavior-inline:contain;-webkit-overflow-scrolling:touch}
body.homeaid-system .dealer-table-wrap{padding:.15rem 1rem 1rem!important}
body.homeaid-system .premium-table,
body.homeaid-system .table{width:100%;margin:0!important}
body.homeaid-system .premium-table th,
body.homeaid-system .premium-table td,
body.homeaid-system .table th,
body.homeaid-system .table td{padding:.72rem .72rem!important;line-height:1.42;vertical-align:middle}
body.homeaid-system .premium-table thead th,
body.homeaid-system .table thead th{padding-top:.68rem!important;padding-bottom:.68rem!important}
body.homeaid-system .premium-table td form,
body.homeaid-system .table td form{margin:0}
body.homeaid-system .dt-local-toolbar,
body.homeaid-system .dt-container .dt-layout-row{gap:.75rem!important;margin:.75rem 0!important}
body.homeaid-system .dt-local-footer{margin-top:.6rem!important;padding-top:.85rem!important}
body.homeaid-system .dt-container .dt-search,
body.homeaid-system .dt-container .dt-length{gap:.45rem!important;flex-wrap:wrap}
body.homeaid-system .dt-container .dt-input{margin:0!important}

/* Definition/detail layouts */
body.homeaid-system .premium-definition,
body.homeaid-system .request-definition{margin:0!important}
body.homeaid-system .premium-definition dt,
body.homeaid-system .premium-definition dd,
body.homeaid-system .request-definition dt,
body.homeaid-system .request-definition dd{padding:.72rem 0!important;line-height:1.48}
body.homeaid-system .premium-definition dd,
body.homeaid-system .request-definition dd{padding-left:.7rem!important}
body.homeaid-system .machine-code-emphasis,
body.homeaid-system .activation-code-emphasis,
body.homeaid-system code{max-width:100%;overflow-wrap:anywhere;word-break:break-word}
body.homeaid-system p code,
body.homeaid-system li code,
body.homeaid-system dd code,
body.homeaid-system .fine code{display:inline!important;width:auto!important;margin:0 .1rem!important;padding:.08rem .34rem!important;white-space:normal!important;vertical-align:baseline!important}

/* Notification / email center alignment */
body.homeaid-system .notification-channel-toggle{gap:.8rem;padding:.9rem 1rem}
body.homeaid-system .notification-channel-toggle input{flex:0 0 auto;margin-top:.12rem}
body.homeaid-system .notification-recipient-card+ .notification-recipient-card{margin-top:.75rem}
body.homeaid-system .notification-recipient-card>summary{padding:.9rem 1rem}
body.homeaid-system .notification-choice-grid{gap:.85rem}
body.homeaid-system .notification-choice-grid fieldset{padding:.9rem}
body.homeaid-system .email-preferences-form{gap:.75rem}
body.homeaid-system .email-pref-row{grid-template-columns:3rem minmax(0,1fr);gap:.9rem;padding:.9rem 1rem}
body.homeaid-system .email-pref-copy>small{line-height:1.5}
body.homeaid-system .email-security-note{margin-top:0!important;padding-top:.15rem;line-height:1.65}

/* Settings / branding */
body.homeaid-system .settings-card .premium-card-body{padding:1.1rem 1.2rem 1.25rem!important}
body.homeaid-system .settings-save-bar{gap:.8rem;padding:.75rem .85rem}
body.homeaid-system .brand-guidance{margin-bottom:1rem}
body.homeaid-system .brand-asset-grid{gap:1rem}
body.homeaid-system .brand-asset-card{gap:.85rem 1rem}

/* Audit/activity lists */
body.homeaid-system .activity-list{padding:.15rem 1.2rem .45rem!important}
body.homeaid-system .activity-item{padding:.9rem 0!important;gap:.75rem!important}
body.homeaid-system .audit-event{padding:.7rem 0!important;gap:.55rem .8rem!important}
body.homeaid-system .dealer-list{gap:.85rem}
body.homeaid-system .dealer-item{padding:1rem}

/* Modal density and reachability */
body.homeaid-system .premium-modal .modal-header,
body.homeaid-system .modal-header{padding:1rem 1.1rem!important}
body.homeaid-system .premium-modal .modal-body,
body.homeaid-system .modal-body{padding:1.05rem 1.1rem 1.15rem!important}
body.homeaid-system .premium-modal .modal-footer,
body.homeaid-system .modal-footer{padding:.85rem 1.1rem!important;gap:.6rem}
body.homeaid-system .premium-form-grid{gap:1rem!important}
body.homeaid-system .dealer-modal-form{padding:1.15rem!important}
body.homeaid-system .form-section-title{margin-bottom:1rem;padding-bottom:.7rem}

/* Setup/recovery page visual consistency */
body.homeaid-system.setup-page .setup-main{padding-top:1.25rem!important;padding-bottom:1.75rem!important}
body.homeaid-system.setup-page .setup-grid{gap:1rem!important}
body.homeaid-system.setup-page .setup-grid>.card{margin:0!important}
body.homeaid-system.setup-page .card-title{margin-bottom:.9rem}
body.homeaid-system.setup-page .card-title h2{margin:.2rem 0 .35rem}
body.homeaid-system.setup-page .setup-health{display:grid;gap:.65rem}
body.homeaid-system.setup-page .health-item{margin:0;padding:.8rem .9rem}
body.homeaid-system.setup-page .setup-inline{margin-top:.9rem}

/* Desktop/tablet */
@media(max-width:1199.98px){
  body.homeaid-system .content-frame{max-width:100%}
  body.homeaid-system .premium-card-head{padding:1rem!important}
  body.homeaid-system .premium-card-body{padding:1rem!important}
}

@media(max-width:991.98px){
  body.homeaid-system .app-content{padding-left:1rem!important;padding-right:1rem!important}
  body.homeaid-system .premium-page-head{flex-direction:column;align-items:stretch}
  body.homeaid-system .premium-page-actions{justify-content:flex-start;width:100%}
  body.homeaid-system .premium-lower-grid,
  body.homeaid-system .dealer-dashboard-grid,
  body.homeaid-system .request-detail-grid{grid-template-columns:1fr!important}
}

@media(max-width:767.98px){
  :root{--ui-space-6:1.2rem;--ui-space-5:1rem}
  body.homeaid-system .premium-card-head{flex-direction:column;align-items:stretch;gap:.8rem}
  body.homeaid-system .premium-card-head>div:first-child{width:100%}
  body.homeaid-system .premium-card-head>.mini-chip,
  body.homeaid-system .premium-card-head>.status-pill{align-self:flex-start}
  body.homeaid-system .premium-page-actions .btn,
  body.homeaid-system .premium-page-actions form{flex:1 1 auto}
  body.homeaid-system .premium-page-actions form>.btn{width:100%}
  body.homeaid-system .notification-choice-grid{grid-template-columns:1fr!important}
  body.homeaid-system .premium-definition,
  body.homeaid-system .request-definition{grid-template-columns:1fr!important}
  body.homeaid-system .premium-definition dt,
  body.homeaid-system .request-definition dt{padding-bottom:.12rem!important;border-bottom:0!important}
  body.homeaid-system .premium-definition dd,
  body.homeaid-system .request-definition dd{padding:.15rem 0 .7rem!important}
  body.homeaid-system .dealer-table-wrap{padding:.1rem .75rem .8rem!important}
  body.homeaid-system .premium-table th,
  body.homeaid-system .premium-table td,
  body.homeaid-system .table th,
  body.homeaid-system .table td{padding:.66rem .62rem!important}
  body.homeaid-system .modal-footer{flex-wrap:wrap!important}
}

@media(max-width:575.98px){
  :root{--ui-card-radius:.86rem}
  body.homeaid-system .app-content{padding:.9rem .75rem 1.25rem!important}
  body.homeaid-system .premium-page-head,
  body.homeaid-system .page-heading{margin-bottom:1rem!important}
  body.homeaid-system .premium-page-title h1,
  body.homeaid-system .page-title h1{font-size:1.42rem!important}
  body.homeaid-system .premium-page-title>p,
  body.homeaid-system .page-title>p{font-size:.82rem!important;line-height:1.55!important}
  body.homeaid-system .premium-card-head,
  body.homeaid-system .premium-card-body{padding:.85rem!important}
  body.homeaid-system .premium-card-head h2,
  body.homeaid-system .premium-card-head h3{font-size:.98rem}
  body.homeaid-system .premium-card-head p{font-size:.75rem}
  body.homeaid-system .section-icon{width:38px;height:38px}
  body.homeaid-system .premium-page-actions{display:grid;grid-template-columns:1fr;width:100%;gap:.5rem}
  body.homeaid-system .premium-page-actions .btn,
  body.homeaid-system .premium-page-actions form,
  body.homeaid-system .premium-page-actions form>.btn{width:100%}
  body.homeaid-system .btn:not(.btn-icon):not(.avatar-button){min-height:42px}
  body.homeaid-system .premium-metrics,
  body.homeaid-system .stats{grid-template-columns:1fr!important;gap:.65rem!important}
  body.homeaid-system .premium-metric,
  body.homeaid-system .metric-card,
  body.homeaid-system .stats>div{min-height:0;padding:.85rem!important}
  body.homeaid-system .email-pref-row{grid-template-columns:2.8rem minmax(0,1fr);gap:.7rem;padding:.8rem}
  body.homeaid-system .email-pref-title-line{align-items:flex-start;gap:.4rem}
  body.homeaid-system .email-pref-state{margin-top:.05rem}
  body.homeaid-system .dealer-actions,
  body.homeaid-system .save-actions,
  body.homeaid-system .danger-zone-actions{display:grid!important;grid-template-columns:1fr;width:100%}
  body.homeaid-system .dealer-actions form,
  body.homeaid-system .save-actions form,
  body.homeaid-system .danger-zone-actions form,
  body.homeaid-system .dealer-actions .btn,
  body.homeaid-system .save-actions .btn,
  body.homeaid-system .danger-zone-actions .btn{width:100%}
  body.homeaid-system .dt-container .dt-layout-row{align-items:stretch!important}
  body.homeaid-system .dt-container .dt-search,
  body.homeaid-system .dt-container .dt-length{width:100%!important;align-items:center}
  body.homeaid-system .dt-container .dt-search .dt-input,
  body.homeaid-system .dt-container .dt-length .dt-input{flex:1;min-width:0!important;width:auto!important}
  body.homeaid-system .activity-list{padding:.1rem .85rem .35rem!important}
  body.homeaid-system .activity-item{grid-template-columns:30px minmax(0,1fr)!important}
  body.homeaid-system .activity-meta{grid-column:2!important;text-align:left!important;min-width:0!important}
  body.homeaid-system .notification-recipient-card>summary{align-items:flex-start;flex-direction:column}
  body.homeaid-system .notification-recipient-card>summary>.status-pill{align-self:flex-start}
  body.homeaid-system .modal-dialog{margin:.35rem!important}
  body.homeaid-system .premium-modal .modal-header,
  body.homeaid-system .premium-modal .modal-body,
  body.homeaid-system .premium-modal .modal-footer,
  body.homeaid-system .modal-header,
  body.homeaid-system .modal-body,
  body.homeaid-system .modal-footer{padding-left:.85rem!important;padding-right:.85rem!important}
  body.homeaid-system.setup-page .setup-main{padding:.9rem .75rem 1.25rem!important}
}

@media(max-width:380px){
  body.homeaid-system .app-content{padding-left:.6rem!important;padding-right:.6rem!important}
  body.homeaid-system .premium-card-head,
  body.homeaid-system .premium-card-body{padding:.78rem!important}
  body.homeaid-system .email-pref-row{grid-template-columns:1fr;gap:.55rem}
  body.homeaid-system .email-pref-switch-wrap{justify-content:flex-start}
  body.homeaid-system .status-pill,
  body.homeaid-system .mini-chip{max-width:100%}
}

@media(prefers-reduced-motion:reduce){
  body.homeaid-system .premium-card,body.homeaid-system .premium-metric{transition:none!important}
}
