/* Jazzmin/AdminLTE layout fix
   目的：解决 change 页面加载后主内容被推到右侧（出现大空白）。
   原因通常是某些脚本/样式给 main/content 叠加了额外的 left/margin/padding。 */

/* 主体区域不要额外横向偏移 */
#main.app-main,
main#main.app-main,
.app-main#main {
  margin-left: 0 !important;
  left: auto !important;
  right: auto !important;
  transform: none !important;
}

/* 内容包装层（AdminLTE 兼容类名） */
.content-wrapper,
.content,
.container-fluid {
  transform: none !important;
}

/* Grid 布局：确保 main 紧贴 sidebar 右侧 */
.app-wrapper {
  /* 保持两列：sidebar + main */
  grid-template-columns: var(--lte-sidebar-width, 250px) 1fr !important;
}

/*
 * 侧栏「能滚很远但下面什么也没有」：
 * AdminLTE 网格中间行是 1fr，侧栏跨行后那一格与主区同高；Jazzmin 又给 #jazzy-sidebar 设了 overflow-y:scroll
 * 且隐藏滚动条，于是像在空白里滚。不是菜单被藏住，是滚动容器比可见菜单高太多。
 * 做法：侧栏外壳固定视口高度并裁切，只在 .sidebar-wrapper 内滚动菜单。
 */
.layout-fixed .app-wrapper > aside#jazzy-sidebar.app-sidebar {
  max-height: 100vh !important;
  height: auto !important;
  min-height: 0 !important;
  align-self: start !important;
  overflow: hidden !important;
}

.layout-fixed #jazzy-sidebar .sidebar-wrapper {
  max-height: calc(100vh - 9.5rem);
  overflow-y: auto !important;
  overflow-x: hidden;
  scrollbar-width: thin;
}

.layout-fixed #jazzy-sidebar .sidebar-wrapper::-webkit-scrollbar {
  width: 6px;
}

.layout-fixed #jazzy-sidebar .sidebar-wrapper::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 6px;
}

/*
 * Jazzmin「UI Builder」面板（Customize）：固定在视口右侧滑入，避免参与主侧栏布局/滚动。
 * 顶栏齿轮（show_ui_builder）打开；默认 translateX(100%) 藏到屏外。
 */
aside.control-sidebar.ui-customiser {
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: auto !important;
  width: min(400px, calc(100vw - 48px)) !important;
  max-width: 100vw !important;
  height: 100vh !important;
  max-height: 100vh !important;
  margin: 0 !important;
  z-index: 1040 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  transform: translateX(100%);
  transition: transform 0.28s ease, box-shadow 0.28s ease;
  box-shadow: none;
}

body.control-sidebar-open aside.control-sidebar.ui-customiser,
body.control-sidebar-slide-open aside.control-sidebar.ui-customiser {
  transform: translateX(0) !important;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
}

/* 侧边栏折叠/隐藏时，让主内容撑满 */
body.sidebar-collapse .app-wrapper,
body.sidebar-collapse.sidebar-mini .app-wrapper,
body.sidebar-collapse.sidebar-open .app-wrapper {
  grid-template-columns: 0 1fr !important;
}
body.sidebar-collapse aside#jazzy-sidebar {
  width: 0 !important;
  overflow: hidden !important;
}

/* QuoteConfig change form: inlines table columns equal width */
body.change-form.model-quoteconfig #process_schemes-group table,
body.change-form.model-quoteconfig #ladder_rules-group table {
  table-layout: fixed;
  width: 100%;
}

/* Process schemes inline: 6 data columns (exclude original/delete) */
body.change-form.model-quoteconfig #process_schemes-group thead th.column-process,
body.change-form.model-quoteconfig #process_schemes-group thead th.column-name,
body.change-form.model-quoteconfig #process_schemes-group thead th.column-formula_type,
body.change-form.model-quoteconfig #process_schemes-group thead th.column-params,
body.change-form.model-quoteconfig #process_schemes-group thead th.column-is_active,
body.change-form.model-quoteconfig #process_schemes-group thead th.column-sort_order {
  width: 16.66%;
}

/* Ladder rules inline: 5 data columns (exclude original/delete) */
body.change-form.model-quoteconfig #ladder_rules-group thead th.column-min_sheets,
body.change-form.model-quoteconfig #ladder_rules-group thead th.column-max_sheets,
body.change-form.model-quoteconfig #ladder_rules-group thead th.column-multiplier,
body.change-form.model-quoteconfig #ladder_rules-group thead th.column-is_active,
body.change-form.model-quoteconfig #ladder_rules-group thead th.column-sort_order {
  width: 20%;
}

/* QuoteConfig inlines: keep params(JSON) single-line height, show full on hover */
body.change-form.model-quoteconfig #process_schemes-group td.field-params textarea {
  height: 34px !important;
  min-height: 34px !important;
  max-height: 34px !important;
  resize: none;
  overflow: hidden;
  white-space: nowrap;
}
body.change-form.model-quoteconfig #process_schemes-group td.field-params textarea:hover,
body.change-form.model-quoteconfig #process_schemes-group td.field-params textarea:focus {
  overflow: auto;
  white-space: pre;
}

/*
 * Jazzmin change 页：主表单全宽；保存条放在主内容区下方、靠右（原 col-lg-3 在 DOM 中位于卡片后）。
 * 用 flex column + order：先 col-lg-9（卡片），再操作列，最后脚本。
 */
body.change-form #content-main form > .row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

body.change-form #content-main form > .row > .col-12.col-lg-9 {
  order: 1;
  flex: 0 0 auto !important;
  width: 100% !important;
  max-width: 100% !important;
}

body.change-form #content-main form > .row > .col-12.col-lg-3:has(#jazzy-actions) {
  order: 2;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  flex: 0 0 auto !important;
  width: 100% !important;
  max-width: 100% !important;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
}

/* 表单底部脚本：保持在主内容之后（默认 order:0 会跑到最上） */
body.change-form #content-main form > .row > script {
  order: 30;
  align-self: flex-start;
}

body.change-form #jazzy-actions {
  position: relative !important;
  top: auto !important;
  display: inline-flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 auto;
  width: fit-content;
  max-width: 100%;
  gap: 8px 10px;
  padding: 8px 10px;
  margin: 0;
  margin-left: auto;
  border: 1px solid rgba(226, 232, 240, 1);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

/* 保存区 + object-tools：不占满父级，子项不拉伸 */
body.change-form #jazzy-actions > .d-flex,
body.change-form #jazzy-actions > .object-tools {
  margin: 0;
  flex: 0 0 auto !important;
  display: inline-flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;
  align-items: center;
  gap: 6px 8px;
  width: auto !important;
  max-width: 100% !important;
}

body.change-form #jazzy-actions .d-flex.flex-wrap,
body.change-form #jazzy-actions .object-tools.d-flex {
  flex-wrap: wrap !important;
}

body.change-form #jazzy-actions .object-tools .btn.w-100 {
  width: auto !important;
}

/* 提交按钮：内容宽度、略小字号与内边距，禁止 100% 拉满 */
body.change-form #jazzy-actions input[type="submit"],
body.change-form #jazzy-actions .btn,
body.change-form #jazzy-actions a.button {
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
  white-space: nowrap;
  padding: 0.28rem 0.65rem !important;
  font-size: 0.8125rem !important;
  line-height: 1.35 !important;
}

/* 小屏：内联表横向滚动，避免撑破布局 */
@media (max-width: 990px) {
  body.change-form .js-inline-admin-formset.inline-group {
    overflow-x: auto;
  }
  body.change-form .js-inline-admin-formset.inline-group table {
    min-width: 900px;
  }
}

/* 统一后台数字输入框样式（避免浏览器默认 3D） */
.app-main input[type="number"],
.app-main input[type="text"],
.app-main input[type="search"],
.app-main input[type="email"],
.app-main input[type="url"],
.app-main input[type="tel"],
.app-main input[type="password"],
.app-main textarea,
.app-main select,
.app-main input.vTextField,
.app-main input.vIntegerField,
.app-main input.vDecimalField {
  -webkit-appearance: none;
  appearance: none;
  background: #fff;
  border: 1px solid rgba(209, 213, 219, 1);
  border-radius: 10px;
  box-shadow: none;
  color: inherit;
  padding: 6px 10px;
  line-height: 1.2;
  height: 34px;
}

/* Focus 状态更现代 */
.app-main input[type="number"]:focus,
.app-main input[type="text"]:focus,
.app-main input[type="search"]:focus,
.app-main input[type="email"]:focus,
.app-main input[type="url"]:focus,
.app-main input[type="tel"]:focus,
.app-main input[type="password"]:focus,
.app-main textarea:focus,
.app-main select:focus,
.app-main input.vTextField:focus,
.app-main input.vIntegerField:focus,
.app-main input.vDecimalField:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.9);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

/* textarea 不固定高度 */
.app-main textarea {
  height: auto;
  min-height: 34px;
}

/* Select2 下拉搜索框也统一 */
.select2-container .select2-search__field {
  -webkit-appearance: none;
  appearance: none;
  background: #fff;
  border: 1px solid rgba(209, 213, 219, 1) !important;
  border-radius: 10px !important;
  box-shadow: none !important;
  color: inherit;
  padding: 6px 10px !important;
  line-height: 1.2;
  height: 34px;
}
.select2-container .select2-search__field:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.9) !important;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18) !important;
}

/* 让 select2 的宽度不受影响（仅保护） */
.app-main .select2-container .select2-selection--single {
  height: 34px;
  border-radius: 10px;
}
.app-main .select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 32px;
}
.app-main .select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 32px;
}

/* 内联阶梯表：保存区在页面底部时，长表滚动中间看不到保存 —— 浮动条由 admin_papergsm.js 按需显示 */
#qs-admin-inline-save-hint {
  margin-bottom: 0.75rem;
}

#qs-admin-float-save {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 1080;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  max-width: min(420px, calc(100vw - 28px));
  border-radius: 10px;
  border: 1px solid rgba(226, 232, 240, 1);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(6px);
}

body.qs-show-float-save #qs-admin-float-save {
  display: flex;
}

#qs-admin-float-save .qs-float-save-text {
  font-size: 0.8125rem;
  line-height: 1.35;
  color: #475569;
}

#qs-admin-float-save .qs-float-save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

#qs-admin-float-save button.btn {
  white-space: nowrap;
}

