/*
 * Horizon V9 precision layer.
 * Source of truth: user supplied horizon-builderkit-full-clone.zip.
 * Loaded last on every Horizon surface.
 */

/* Exact neutral light/dark tokens from Horizon BuilderKit globals.css. */
html[data-theme="light"] body.horizon,
body.horizon[data-theme="light"] {
  --hz-bg: oklch(1 0 0);
  --hz-surface: oklch(1 0 0);
  --hz-text: oklch(0.145 0 0);
  --hz-muted: oklch(0.556 0 0);
  --hz-faint: oklch(0.556 0 0 / .78);
  --hz-card: oklch(0.97 0 0);
  --hz-border: oklch(0.922 0 0);
  --hz-input: oklch(0.922 0 0);
  --hz-ring: oklch(0.708 0 0);
  --hz-primary: var(--ui-accent, #2563eb);
  --hz-primary-foreground: var(--ui-accent-foreground, #fff);
  --hz-secondary: oklch(0.97 0 0);
  --hz-secondary-foreground: oklch(0.205 0 0);
  --hz-shadow: oklch(0.145 0 0 / .08);
  color-scheme: light;
}
html[data-theme="dark"] body.horizon,
body.horizon[data-theme="dark"] {
  --hz-bg: oklch(0.145 0 0);
  --hz-surface: oklch(0.205 0 0);
  --hz-text: oklch(0.985 0 0);
  --hz-muted: oklch(0.708 0 0);
  --hz-faint: oklch(0.708 0 0 / .78);
  --hz-card: oklch(0.269 0 0);
  --hz-border: oklch(1 0 0 / 10%);
  --hz-input: oklch(1 0 0 / 15%);
  --hz-ring: oklch(0.556 0 0);
  --hz-primary: var(--ui-accent, #2563eb);
  --hz-primary-foreground: var(--ui-accent-foreground, #fff);
  --hz-secondary: oklch(0.269 0 0);
  --hz-secondary-foreground: oklch(0.985 0 0);
  --hz-shadow: oklch(0 0 0 / .28);
  color-scheme: dark;
}

body.horizon {
  --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);
  background: var(--hz-bg) !important;
  color: var(--hz-text) !important;
}

/* Horizon button contrast: background and foreground always come as a pair. */
body.horizon :is(.btn-primary,.btn-gradient,.btn-gradient-sm,.btn-save,.btn-login,.login-do-btn,.hz-primary-button,.profile-btn-v3--primary,.tcb-btn-primary,.captcha-btn--primary,.captcha-primary-action,.filter-btn,.btn-edit,.btn-edit-sm,.admin-overview__button--primary,.renew-pay-button) {
  background: var(--hz-primary) !important;
  border-color: var(--hz-primary) !important;
  color: var(--hz-primary-foreground) !important;
  -webkit-text-fill-color: var(--hz-primary-foreground) !important;
}
body.horizon :is(.btn-primary,.btn-gradient,.btn-gradient-sm,.btn-save,.btn-login,.login-do-btn,.hz-primary-button,.profile-btn-v3--primary,.tcb-btn-primary,.captcha-btn--primary,.captcha-primary-action,.filter-btn,.btn-edit,.btn-edit-sm,.admin-overview__button--primary,.renew-pay-button):is(:hover,:focus-visible) {
  filter: brightness(.94);
  color: var(--hz-primary-foreground) !important;
}
body.horizon :is(.btn-secondary,.btn-light,.btn-outline-secondary,.profile-btn-v3:not(.profile-btn-v3--primary),.hz-button,.hz-small-button,.btn-outline-glass,.btn-cancel-edit,.btn-back,.captcha-btn--secondary,.tcb-btn-soft,.tcb-icon-btn,.btn-copy,.copy-btn,.captcha-copy-btn,.admin-overview__button:not(.admin-overview__button--primary)) {
  background: var(--hz-surface) !important;
  border-color: var(--hz-border) !important;
  color: var(--hz-text) !important;
  -webkit-text-fill-color: var(--hz-text) !important;
}

/* ------------------------------------------------------------------------ */
/* Profile inputs: icon is a dedicated grid cell, never painted over text. */
/* ------------------------------------------------------------------------ */
body.client-app.horizon .profile-page-v3 .profile-input-v3 {
  position: relative !important;
  display: grid !important;
  grid-template-columns: 36px minmax(0,1fr) auto !important;
  align-items: stretch !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 40px !important;
  overflow: hidden !important;
  border: 1px solid var(--hz-border) !important;
  border-radius: 8px !important;
  background: var(--hz-surface) !important;
  box-shadow: 0 1px 2px var(--hz-shadow) !important;
}
body.client-app.horizon .profile-page-v3 .profile-input-v3:focus-within {
  border-color: var(--hz-ring) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb,var(--hz-ring) 22%,transparent) !important;
}
body.client-app.horizon .profile-page-v3 .profile-input-v3 > i:first-child {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  z-index: auto !important;
  grid-column: 1 !important;
  display: grid !important;
  place-items: center !important;
  width: 36px !important;
  height: 100% !important;
  min-width: 36px !important;
  margin: 0 !important;
  border-right: 1px solid var(--hz-border) !important;
  background: var(--hz-card) !important;
  color: var(--hz-muted) !important;
  line-height: 1 !important;
  pointer-events: none !important;
}
body.client-app.horizon .profile-page-v3 .profile-input-v3 > input.profile-control-v3 {
  position: static !important;
  grid-column: 2 !important;
  width: 100% !important;
  min-width: 0 !important;
  height: 40px !important;
  min-height: 40px !important;
  margin: 0 !important;
  padding: 8px 10px !important;
  border: 0 !important;
  border-radius: 0 !important;
  outline: 0 !important;
  background: transparent !important;
  color: var(--hz-text) !important;
  -webkit-text-fill-color: currentColor !important;
  box-shadow: none !important;
  line-height: 22px !important;
}
body.client-app.horizon .profile-page-v3 .profile-input-v3 > input.profile-control-v3:focus {
  border: 0 !important;
  outline: 0 !important;
  box-shadow: none !important;
}
body.client-app.horizon .profile-page-v3 .profile-input-v3 > input.profile-control-v3[readonly] {
  background: transparent !important;
  color: var(--hz-muted) !important;
  -webkit-text-fill-color: var(--hz-muted) !important;
}
body.client-app.horizon .profile-page-v3 .profile-password-toggle-v3 {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  grid-column: 3 !important;
  align-self: stretch !important;
  width: 38px !important;
  height: 40px !important;
  min-width: 38px !important;
  min-height: 40px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-left: 1px solid var(--hz-border) !important;
  border-radius: 0 !important;
  background: var(--hz-surface) !important;
  color: var(--hz-muted) !important;
  box-shadow: none !important;
}
body.client-app.horizon .profile-page-v3 .profile-password-toggle-v3:is(:hover,:focus-visible) {
  background: var(--hz-card) !important;
  color: var(--hz-text) !important;
}

/* Keep fields visually balanced: one outer panel + one control boundary only. */
body.client-app.horizon .profile-page-v3 .profile-form-v3__body {
  padding: 20px !important;
}
body.client-app.horizon .profile-page-v3 .profile-form-grid-v3 {
  display: grid !important;
  grid-template-columns: repeat(2,minmax(0,1fr)) !important;
  gap: 18px !important;
  align-items: start !important;
}
body.client-app.horizon .profile-page-v3 .profile-form-field-v3 {
  min-width: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
body.client-app.horizon .profile-page-v3 .profile-form-field-v3 > label {
  min-height: 16px !important;
  margin: 0 0 7px !important;
}
body.client-app.horizon .profile-page-v3 .profile-form-v3__footer {
  position: static !important;
  inset: auto !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  flex-wrap: wrap !important;
  gap: 12px 18px !important;
  margin: 0 !important;
  padding: 16px 20px !important;
  border-top: 1px solid var(--hz-border) !important;
  background: var(--hz-surface) !important;
}

/* ------------------------------------------------------------------------ */
/* Footer: separate sibling of app content and guaranteed normal document flow. */
/* ------------------------------------------------------------------------ */
body.horizon .hz-main {
  min-height: 100vh !important;
  height: auto !important;
}
body.horizon .hz-panel {
  position: relative !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 100vh !important;
  height: auto !important;
  overflow: visible !important;
}
@media (min-width:1024px) {
  body.horizon .hz-panel { min-height: calc(100vh - 16px) !important; }
}
body.horizon .hz-app-content {
  position: relative !important;
  display: block !important;
  flex: 1 0 auto !important;
  width: 100% !important;
  max-width: 1280px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: auto !important;
  margin: 0 auto !important;
  overflow: visible !important;
}
body.horizon .hz-site-footer {
  position: relative !important;
  inset: auto !important;
  float: none !important;
  clear: both !important;
  flex: 0 0 auto !important;
  width: calc(100% - 80px) !important;
  max-width: 1200px !important;
  min-height: 0 !important;
  height: auto !important;
  margin: 28px auto 0 !important;
  padding: 0 0 24px !important;
  background: transparent !important;
  color: var(--hz-muted) !important;
  z-index: 1 !important;
}
body.horizon .hz-site-footer__row {
  position: relative !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  flex-wrap: wrap !important;
  gap: 12px 16px !important;
  width: 100% !important;
  min-height: 52px !important;
  padding: 16px 0 0 !important;
  border-top: 1px solid var(--hz-border) !important;
}
body.horizon .hz-site-footer,
body.horizon .hz-site-footer * { transform: none !important; }

/* Floating support must never cover the footer. */
body.horizon .api-floating-support { z-index: 20 !important; }
body.horizon .api-floating-support.is-footer-visible { bottom: 96px !important; }

/* Generic icon + label separation for legacy action controls. */
body.horizon :is(.btn,.hz-button,.hz-small-button,.hz-primary-button,.profile-btn-v3,.tcb-btn,.captcha-btn,.action-btn,.admin-action-btn,.table-action-btn):not(.btn-icon):not(.hz-icon-button):not(.action-icon) {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 7px !important;
}
body.horizon :is(.btn,.hz-button,.hz-small-button,.hz-primary-button,.profile-btn-v3,.tcb-btn,.captcha-btn,.action-btn,.admin-action-btn,.table-action-btn):not(.btn-icon):not(.hz-icon-button):not(.action-icon) > :is(i,svg) {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  flex: 0 0 16px !important;
  width: 16px !important;
  height: 16px !important;
  margin: 0 !important;
  line-height: 16px !important;
}

@media (max-width: 767px) {
  body.horizon .hz-site-footer {
    width: calc(100% - 28px) !important;
    margin-top: 22px !important;
    padding-bottom: 20px !important;
  }
  body.horizon .hz-site-footer__row {
    align-items: flex-start !important;
    flex-direction: column !important;
  }
}
@media (max-width: 680px) {
  body.client-app.horizon .profile-page-v3 .profile-form-grid-v3 {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
  body.client-app.horizon .profile-page-v3 .profile-form-field-v3--full { grid-column: auto !important; }
  body.client-app.horizon .profile-page-v3 .profile-form-v3__footer {
    align-items: stretch !important;
    flex-direction: column !important;
  }
  body.client-app.horizon .profile-page-v3 .profile-form-actions-v3 {
    display: grid !important;
    grid-template-columns: repeat(2,minmax(0,1fr)) !important;
    width: 100% !important;
  }
}
@media (max-width: 420px) {
  body.client-app.horizon .profile-page-v3 .profile-form-actions-v3 { grid-template-columns: 1fr !important; }
}

/* Authentication controls use the same dedicated icon/action cells. */
body.horizon .hz-auth-control {
  position: relative !important;
  display: grid !important;
  grid-template-columns: 36px minmax(0,1fr) !important;
  align-items: stretch !important;
  width: 100% !important;
  min-width: 0 !important;
  overflow: hidden !important;
  border: 1px solid var(--hz-border) !important;
  border-radius: 8px !important;
  background: var(--hz-surface) !important;
  box-shadow: 0 1px 2px var(--hz-shadow) !important;
}
body.horizon .hz-auth-control.has-action { grid-template-columns: 36px minmax(0,1fr) 36px !important; }
body.horizon .hz-auth-control > i {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  display: grid !important;
  place-items: center !important;
  width: 36px !important;
  height: 36px !important;
  margin: 0 !important;
  border: 0 !important;
  border-right: 1px solid var(--hz-border) !important;
  border-radius: 0 !important;
  background: var(--hz-card) !important;
  color: var(--hz-muted) !important;
}
body.horizon .hz-auth-control > input {
  width: 100% !important;
  min-width: 0 !important;
  height: 36px !important;
  min-height: 36px !important;
  margin: 0 !important;
  padding: 7px 10px !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: var(--hz-text) !important;
  box-shadow: none !important;
}
body.horizon .hz-auth-control > .hz-auth-control-action {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  width: 36px !important;
  height: 36px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-left: 1px solid var(--hz-border) !important;
  border-radius: 0 !important;
  background: var(--hz-surface) !important;
  color: var(--hz-muted) !important;
}
body.horizon .hz-auth-control:focus-within {
  border-color: var(--hz-ring) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb,var(--hz-ring) 22%,transparent) !important;
}
body.horizon .hz-auth-control > input:focus { outline: 0 !important; box-shadow: none !important; }

/* Bootstrap-style input groups: no negative overlap between siblings. */
body.horizon .input-group > :not(:first-child) { margin-left: 0 !important; }
body.horizon .input-group > .input-icon,
body.horizon .input-group > .input-group-text {
  flex: 0 0 36px !important;
  width: 36px !important;
  min-width: 36px !important;
  padding: 0 !important;
  display: grid !important;
  place-items: center !important;
}

/* Defeat older literal theme colors at equal-or-higher specificity. */
html[data-theme="light"] body.horizon,
html[data-theme="dark"] body.horizon {
  background: var(--hz-bg) !important;
  color: var(--hz-text) !important;
}
html[data-theme="light"] body.horizon :is(.form-control,.form-select,input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range]):not([type=file]),textarea,select),
html[data-theme="dark"] body.horizon :is(.form-control,.form-select,input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range]):not([type=file]),textarea,select) {
  background-color: var(--hz-surface) !important;
  background-image: none !important;
  color: var(--hz-text) !important;
  border-color: var(--hz-input) !important;
  -webkit-text-fill-color: currentColor !important;
}
html[data-theme="light"] body.horizon :is(.form-control[readonly],input[readonly],.form-control:disabled,input:disabled,select:disabled,textarea:disabled),
html[data-theme="dark"] body.horizon :is(.form-control[readonly],input[readonly],.form-control:disabled,input:disabled,select:disabled,textarea:disabled) {
  background-color: var(--hz-card) !important;
  color: var(--hz-muted) !important;
  -webkit-text-fill-color: var(--hz-muted) !important;
  opacity: 1 !important;
}
html[data-theme="light"] body.horizon input:-webkit-autofill,
html[data-theme="light"] body.horizon textarea:-webkit-autofill,
html[data-theme="dark"] body.horizon input:-webkit-autofill,
html[data-theme="dark"] body.horizon textarea:-webkit-autofill {
  -webkit-text-fill-color: var(--hz-text) !important;
  -webkit-box-shadow: 0 0 0 1000px var(--hz-surface) inset !important;
  box-shadow: 0 0 0 1000px var(--hz-surface) inset !important;
  caret-color: var(--hz-text) !important;
}
body.client-app.horizon .profile-tab-v3.is-active > i:first-child {
  background: var(--hz-primary) !important;
  color: var(--hz-primary-foreground) !important;
}
