/*
 * Horizon V7 hardening layer
 * Source of visual truth: user-supplied horizon-builderkit-full-clone.zip.
 * Purpose: dark/light parity, modal reliability, form geometry, icon spacing,
 * subtle scrollbars and layout/footer collision prevention.
 */

/* ---------- Theme parity ---------- */
html[data-theme="light"],body.horizon[data-theme="light"]{color-scheme:light}
html[data-theme="dark"],body.horizon[data-theme="dark"]{color-scheme:dark}
html[data-theme="light"] body.horizon{background:oklch(0.9824 0.003 277.7)!important;color:oklch(0.2413 0.0099 277.7)!important}
html[data-theme="dark"] body.horizon{background:#18191b!important;color:#eeeef0!important}
body.horizon[data-theme="dark"]{
  --hz-bg:#18191b;--hz-surface:#202124;--hz-text:#eeeef0;--hz-muted:#aaaab4;--hz-faint:#85858f;
  --hz-card:#ffffff0e;--hz-border:#ffffff20;--hz-shadow:#0005;
  --ui-bg:var(--hz-bg);--ui-surface:var(--hz-surface);--ui-surface-soft:var(--hz-card);--ui-card:var(--hz-surface);
  --ui-text:var(--hz-text);--ui-text-soft:var(--hz-muted);--ui-text-faint:var(--hz-faint);--ui-border:var(--hz-border);
  --admin-canvas:var(--hz-bg);--admin-paper:var(--hz-surface);--admin-paper-2:var(--hz-card);--admin-ink:var(--hz-text);
  --admin-ink-2:var(--hz-text);--admin-muted:var(--hz-muted);--admin-faint:var(--hz-faint);--admin-line:var(--hz-border);
}
body.horizon[data-theme="light"]{
  --hz-bg:oklch(0.9824 0.003 277.7);--hz-surface:#fff;--hz-text:oklch(0.2413 0.0099 277.7);
  --hz-muted:oklch(0.09492 0.0438 257.5 / .616);--hz-faint:oklch(0.1149 0.0528 264.9 / .495);
  --hz-card:oklch(0.1555 0.1022 265.8 / .059);--hz-border:oklch(0.1877 0.0881 263 / .095);--hz-shadow:oklch(0.1744 0.0872 261.4 / .122);
}
.horizon :is(.card,.modal-content,.dropdown-menu,.list-group-item,.popover,.tooltip-inner,.dataTables_wrapper,.note-editor.note-frame,.note-toolbar,.note-editable){color:var(--hz-text)}
.horizon :is(.card,.modal-content,.dropdown-menu,.list-group-item,.popover,.dataTables_wrapper,.note-editor.note-frame,.note-toolbar,.note-editable){background:var(--hz-surface)!important;border-color:var(--hz-border)!important}
.horizon .table{color:var(--hz-text)!important;background:transparent!important}
.horizon .table :is(th,td){border-color:var(--hz-border)!important;background:transparent!important;color:inherit!important}
.horizon .table tbody tr:hover{background:var(--hz-card)!important}
.horizon .dropdown-item{color:var(--hz-text)!important}
.horizon .dropdown-item:hover,.horizon .dropdown-item:focus{background:var(--hz-card)!important;color:var(--hz-text)!important}
.horizon .page-link{background:var(--hz-surface)!important;border-color:var(--hz-border)!important;color:var(--hz-text)!important}
.horizon .page-item.active .page-link{background:var(--hz-primary)!important;border-color:var(--hz-primary)!important;color:#fff!important}
.horizon .custom-control-label,.horizon .form-check-label{color:var(--hz-text)!important}
.horizon .note-editor.note-frame .note-statusbar{background:var(--hz-card)!important;border-color:var(--hz-border)!important}
.horizon .note-btn{background:var(--hz-surface)!important;border-color:var(--hz-border)!important;color:var(--hz-text)!important}
.horizon .note-btn:hover{background:var(--hz-card)!important}

/* ---------- Layout collision prevention ---------- */
body.horizon{min-width:0!important;overflow-x:hidden!important}
.horizon :is(.hz-main,.hz-panel,.hz-app-content,.container,.container-fluid,.row,[class*="col-"],.card,.card-body,.glass-card,.data-card,.admin-panel,.dashboard-container,.main-content-wrapper,.dash-container,.dash-content){min-width:0!important;max-width:100%}
.horizon .hz-panel{overflow:visible!important}
.horizon .hz-app-content{position:relative!important;flex:1 1 auto!important;min-height:0!important;overflow:visible!important}
.horizon .hz-app-content> :first-child{min-width:0!important}
.horizon .row{row-gap:16px}
.horizon .row>[class*="col-"]{min-width:0!important}
.horizon img,.horizon svg{max-width:100%}
.horizon pre,.horizon code{max-width:100%}
.horizon pre{overflow:auto}

/* Footer must participate in normal flow and never sit on top of page content. */
.horizon .hz-site-footer{
  position:relative!important;inset:auto!important;clear:both!important;z-index:1!important;width:100%!important;max-width:1280px!important;
  margin:auto auto 0!important;padding:16px 40px 24px!important;flex:0 0 auto!important;background:transparent!important
}
.horizon .hz-site-footer__row{min-height:52px!important;padding-top:16px!important;border-top:1px solid var(--hz-border)!important;align-items:center!important}
.horizon .hz-site-footer__brand,.horizon .hz-site-footer__links{min-width:0!important}
.horizon .hz-site-footer__links a{white-space:nowrap}
.horizon-landing .hz-landing-footer{position:relative!important;inset:auto!important;z-index:1!important;clear:both!important}

/* Floating support remains under modals and moves clear of the footer. */
.api-floating-support{z-index:1010!important;transition:bottom .2s ease,opacity .2s ease,transform .2s ease!important}
body.modal-open .api-floating-support{opacity:.2!important;pointer-events:none!important}
.api-floating-support.is-footer-visible{bottom:86px!important}

/* ---------- Forms: one consistent Horizon primitive ---------- */
.horizon form{position:relative!important;min-width:0!important;max-width:100%!important}
.horizon form :is(.form-group,.form-field,.admin-form-group,.tcb-field,.hz-auth-field){position:relative!important;min-width:0!important}
.horizon form :is(label,.form-label,.control-label,.tcb-field label,.admin-form-group label){
  position:static!important;inset:auto!important;transform:none!important;float:none!important;display:flex!important;align-items:center!important;gap:6px!important;
  max-width:100%!important;white-space:normal!important;overflow-wrap:anywhere!important
}
.horizon form :is(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=color]),select,textarea,.form-control,.form-select,.custom-select,.dataTable-input,.dataTable-selector){
  position:relative!important;inset:auto!important;transform:none!important;float:none!important;max-width:100%!important;min-width:0!important;
  color:var(--hz-text)!important;background:var(--hz-surface)!important;border-color:var(--hz-border)!important
}
.horizon form :is(input,select,.form-control,.form-select,.custom-select,.dataTable-input,.dataTable-selector):not(textarea){
  height:var(--hz-control-h,34px)!important;min-height:var(--hz-control-h,34px)!important;line-height:20px!important;padding-top:6px!important;padding-bottom:6px!important
}
.horizon form textarea,.horizon textarea.form-control{height:auto!important;min-height:82px!important;line-height:20px!important;overflow:auto!important}
.horizon form :is(input,textarea)::placeholder{color:var(--hz-faint)!important;opacity:1!important}
.horizon form :is(input,select,textarea,.form-control,.form-select):focus{border-color:var(--hz-primary)!important;box-shadow:0 0 0 2px color-mix(in srgb,var(--hz-primary) 18%,transparent)!important;outline:0!important}
.horizon form :is(input,select,textarea,.form-control,.form-select):disabled,.horizon form .form-control[readonly]{background:var(--hz-card)!important;color:var(--hz-muted)!important;opacity:1!important}

/* Inputs with append/prepend actions never stack text and icons on top of each other. */
.horizon .input-group{position:relative!important;display:flex!important;align-items:stretch!important;flex-wrap:nowrap!important;width:100%!important;min-width:0!important;isolation:isolate}
.horizon .input-group>*{position:relative!important;inset:auto!important;transform:none!important}
.horizon .input-group>.form-control,.horizon .input-group>input,.horizon .input-group>select{flex:1 1 auto!important;width:1%!important;min-width:0!important;margin:0!important}
.horizon .input-group :is(.input-group-prepend,.input-group-append){display:flex!important;flex:0 0 auto!important;margin:0!important}
.horizon .input-group :is(.input-group-text,.btn){display:inline-flex!important;align-items:center!important;justify-content:center!important;flex:0 0 auto!important;min-width:34px!important;height:var(--hz-control-h,34px)!important;min-height:var(--hz-control-h,34px)!important;margin:0 0 0 -1px!important;padding:0 10px!important;white-space:nowrap!important}
.horizon .input-group :is(.input-group-text,.btn)>:is(i,svg){position:static!important;inset:auto!important;transform:none!important;flex:0 0 auto!important;margin:0!important}
.horizon .account-token-control,.horizon .profile-control-v3,.horizon .hz-auth-control{position:relative!important;min-width:0!important;overflow:hidden!important}
.horizon .account-token-control input,.horizon .profile-control-v3 input,.horizon .hz-auth-control input{min-width:0!important}

/* Icon/text alignment across all buttons and clickable controls. */
.horizon :is(.btn,.hz-button,.hz-small-button,.hz-primary-button,.btn-gradient,.btn-gradient-sm,.btn-save,.btn-login,.btn-reset,.login-do-btn,.tcb-btn,.captcha-btn,.profile-btn-v3,.action-icon,.hz-icon-button){
  vertical-align:middle!important;text-decoration:none!important
}
.horizon :is(.btn,.hz-button,.hz-small-button,.hz-primary-button,.btn-gradient,.btn-gradient-sm,.btn-save,.btn-login,.btn-reset,.login-do-btn,.tcb-btn,.captcha-btn,.profile-btn-v3){
  display:inline-flex!important;align-items:center!important;justify-content:center!important;gap:7px!important;max-width:100%!important
}
.horizon :is(.btn,.hz-button,.hz-small-button,.hz-primary-button,.btn-gradient,.btn-gradient-sm,.btn-save,.btn-login,.btn-reset,.login-do-btn,.tcb-btn,.captcha-btn,.profile-btn-v3)>:is(i,svg){
  position:static!important;inset:auto!important;transform:none!important;display:inline-flex!important;align-items:center!important;justify-content:center!important;
  flex:0 0 16px!important;width:16px!important;height:16px!important;min-width:16px!important;margin:0!important;line-height:16px!important
}
.horizon :is(.hz-icon-button,.action-icon,.btn-icon)>:is(i,svg){margin:0!important}
.horizon :is(.page-title,.dashboard-title,.card-title,.modal-title,h1,h2,h3,h4,h5,h6)>i{position:static!important;vertical-align:-1px!important;margin-right:6px!important}
.horizon .form-check{position:relative!important;display:flex!important;align-items:flex-start!important;gap:8px!important;min-height:20px!important;padding-left:0!important}
.horizon .form-check-input{position:static!important;float:none!important;flex:0 0 16px!important;width:16px!important;height:16px!important;min-height:16px!important;margin:2px 0 0!important;padding:0!important}
.horizon .form-check-label{margin:0!important;line-height:20px!important}

/* Select2 / Choices / DataTables inherit Horizon colors. */
.horizon .select2-container,.horizon .choices{max-width:100%!important;min-width:0!important;width:100%!important}
.horizon .select2-container .select2-selection--single,.horizon .choices__inner{background:var(--hz-surface)!important;border-color:var(--hz-border)!important;color:var(--hz-text)!important}
.horizon .select2-dropdown,.horizon .choices__list--dropdown{background:var(--hz-surface)!important;border-color:var(--hz-border)!important;color:var(--hz-text)!important}
.horizon .select2-results__option--highlighted,.horizon .choices__item--choice.is-highlighted{background:var(--hz-card)!important;color:var(--hz-text)!important}
.horizon .dataTables_wrapper :is(.dataTables_filter,.dataTables_length,.dataTables_info,.dataTables_paginate){color:var(--hz-muted)!important}
.horizon .dataTables_wrapper input,.horizon .dataTables_wrapper select{background:var(--hz-surface)!important;color:var(--hz-text)!important;border:1px solid var(--hz-border)!important;border-radius:8px!important}

/* ---------- Modals: click/scroll/stacking reliability ---------- */
body.horizon .modal{z-index:1080!important;padding-right:0!important;overflow-x:hidden!important;overflow-y:auto!important;pointer-events:none}
body.horizon .modal.show{pointer-events:auto}
body.horizon .modal-backdrop{z-index:1070!important;background:#000!important}
body.horizon .modal-backdrop.show{opacity:.38!important;backdrop-filter:blur(2px)}
body.horizon .modal-dialog{position:relative!important;z-index:1!important;width:auto!important;max-width:min(94vw,720px)!important;margin:24px auto!important;pointer-events:none!important}
body.horizon .modal-dialog.modal-lg{max-width:min(94vw,860px)!important}
body.horizon .modal-dialog.modal-xl{max-width:min(96vw,1140px)!important}
body.horizon .modal-content{position:relative!important;pointer-events:auto!important;max-height:calc(100dvh - 48px)!important;overflow:hidden!important;background:var(--hz-surface)!important;color:var(--hz-text)!important;border:1px solid var(--hz-border)!important}
body.horizon .modal-header,body.horizon .modal-footer{flex:0 0 auto!important;background:var(--hz-surface)!important;border-color:var(--hz-border)!important}
body.horizon .modal-body{position:relative!important;flex:1 1 auto!important;min-height:0!important;overflow:auto!important;overscroll-behavior:contain!important;background:var(--hz-surface)!important;color:var(--hz-text)!important}
body.horizon .modal-header .btn-close,body.horizon .modal-header .close{position:relative!important;z-index:3!important;pointer-events:auto!important;flex:0 0 auto!important;margin-left:auto!important}
body.horizon[data-theme="dark"] .btn-close{filter:invert(1) grayscale(100%) brightness(180%)}
body.horizon .modal-footer{gap:8px!important;flex-wrap:wrap!important}
body.horizon #modalHome .modal-dialog{max-width:min(92vw,620px)!important}
body.horizon #modalHome .modal-body{text-align:center!important;line-height:1.75!important;padding:18px 22px!important}
body.horizon #modalHome .modal-footer{justify-content:flex-end!important}
body.horizon #modalHome .btn-close{width:32px!important;height:32px!important;min-height:32px!important;padding:8px!important;border-radius:8px!important}
body.horizon #dontShowAgainBtn{white-space:normal!important;height:auto!important;min-height:34px!important;line-height:18px!important}

/* ---------- Small, quiet scrollbars ---------- */
html{scrollbar-width:thin;scrollbar-color:color-mix(in srgb,currentColor 24%,transparent) transparent}
body.horizon :is(.hz-site-sidebar,.modal-body,.table-responsive,.data-table-wrapper,.hz-table-scroll,.hz-wide-table-wrap,pre,.dropdown-menu,.select2-results__options,.choices__list--dropdown,.note-editable){
  scrollbar-width:thin;scrollbar-color:color-mix(in srgb,var(--hz-muted) 32%,transparent) transparent
}
body.horizon :is(.hz-site-sidebar,.modal-body,.table-responsive,.data-table-wrapper,.hz-table-scroll,.hz-wide-table-wrap,pre,.dropdown-menu,.select2-results__options,.choices__list--dropdown,.note-editable)::-webkit-scrollbar{width:6px;height:6px}
body.horizon :is(.hz-site-sidebar,.modal-body,.table-responsive,.data-table-wrapper,.hz-table-scroll,.hz-wide-table-wrap,pre,.dropdown-menu,.select2-results__options,.choices__list--dropdown,.note-editable)::-webkit-scrollbar-track{background:transparent}
body.horizon :is(.hz-site-sidebar,.modal-body,.table-responsive,.data-table-wrapper,.hz-table-scroll,.hz-wide-table-wrap,pre,.dropdown-menu,.select2-results__options,.choices__list--dropdown,.note-editable)::-webkit-scrollbar-thumb{background:color-mix(in srgb,var(--hz-muted) 34%,transparent);border-radius:999px;border:1px solid transparent;background-clip:padding-box}
body.horizon :is(.hz-site-sidebar,.modal-body,.table-responsive,.data-table-wrapper,.hz-table-scroll,.hz-wide-table-wrap,pre,.dropdown-menu,.select2-results__options,.choices__list--dropdown,.note-editable)::-webkit-scrollbar-thumb:hover{background:color-mix(in srgb,var(--hz-muted) 52%,transparent);background-clip:padding-box}

/* ---------- Responsive hardening ---------- */
@media(max-width:767px){
  .horizon .hz-app-content{padding-left:12px!important;padding-right:12px!important}
  .horizon .hz-site-footer{padding:12px 14px 20px!important}
  .horizon .hz-site-footer__row{align-items:flex-start!important;gap:10px!important}
  .horizon .hz-site-footer__links{gap:10px 14px!important}
  .api-floating-support.is-footer-visible{bottom:132px!important}
  body.horizon .modal{padding:8px!important}
  body.horizon .modal-dialog,body.horizon .modal-dialog.modal-lg,body.horizon .modal-dialog.modal-xl{width:100%!important;max-width:100%!important;margin:0!important;min-height:100%!important;display:flex!important;align-items:center!important}
  body.horizon .modal-content{width:100%!important;max-height:calc(100dvh - 16px)!important}
  body.horizon .modal-header,body.horizon .modal-body,body.horizon .modal-footer{padding-left:14px!important;padding-right:14px!important}
  body.horizon .modal-footer>*{max-width:100%!important}
  .horizon form .row{row-gap:12px!important}
  .horizon :is(.form-actions,.admin-form-actions,.modal-footer){align-items:stretch!important}
  .horizon :is(.form-actions,.admin-form-actions)>.btn{width:100%!important}
}

@media(prefers-reduced-motion:reduce){
  .horizon *, .horizon *::before, .horizon *::after{scroll-behavior:auto!important;animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}
}

/* Universal fallback for any page-local scroll container not covered above. */
html::-webkit-scrollbar,body.horizon::-webkit-scrollbar,body.horizon *::-webkit-scrollbar{width:6px;height:6px}
html::-webkit-scrollbar-track,body.horizon::-webkit-scrollbar-track,body.horizon *::-webkit-scrollbar-track{background:transparent}
html::-webkit-scrollbar-thumb,body.horizon::-webkit-scrollbar-thumb,body.horizon *::-webkit-scrollbar-thumb{background:color-mix(in srgb,var(--hz-muted,#85858f) 30%,transparent);border-radius:999px}
body.horizon *{scrollbar-width:thin;scrollbar-color:color-mix(in srgb,var(--hz-muted) 30%,transparent) transparent}
