.view-ap-allocation-add.gs-page-detail,
.view-ap-allocation-detail.gs-page-detail,
.view-or-allocation-add.gs-page-detail,
.view-or-allocation-detail.gs-page-detail {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.view-ap-allocation-add > .ap-allocation-toolbar-card.rz-card,
.view-ap-allocation-detail .ap-allocation-toolbar-card.rz-card,
.view-or-allocation-add > .ap-allocation-toolbar-card.rz-card,
.view-or-allocation-detail .ap-allocation-toolbar-card.rz-card {
  flex: 0 0 auto;
  margin-bottom: 1rem;
}

.ap-allocation-detail-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.ap-allocation-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 1rem;
  overflow: hidden;
}

.ap-allocation-right-column {
  flex: 1.4;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: hidden;
}

/* Left card fills column height */
.view-ap-allocation-add .ap-allocation-left-card.rz-card,
.view-ap-allocation-detail .ap-allocation-left-card.rz-card,
.view-or-allocation-add .ap-allocation-left-card.rz-card,
.view-or-allocation-detail .ap-allocation-left-card.rz-card {
  flex: 1;
  min-width: 320px;
  max-width: 42%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view-ap-allocation-add .ap-allocation-left-card > .rz-card-body,
.view-ap-allocation-detail .ap-allocation-left-card > .rz-card-body,
.view-or-allocation-add .ap-allocation-left-card > .rz-card-body,
.view-or-allocation-detail .ap-allocation-left-card > .rz-card-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 1rem;
}

/* Right sections: equal half (JournalRuleTest pattern) */
.ap-allocation-grid-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: hidden;
}

.ap-allocation-section-title {
  flex-shrink: 0;
  font-weight: 600;
}

.ap-allocation-left-inputs {
  flex-shrink: 0;
  margin-bottom: 0.75rem;
}

.ap-allocation-left-inputs .gs-form-fields.rz-row {
  margin: 0;
}

.ap-allocation-left-inputs .gs-form-control {
  display: block;
  min-height: 0;
  background: transparent;
  padding: 0;
}

.ap-allocation-left-inputs .gs-form-field-control,
.ap-allocation-left-inputs .gs-form-field-control.rz-textbox {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box;
}

.ap-allocation-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--rz-border-color, #e5e7eb);
  border-radius: 0.5rem;
  background: var(--rz-base-100, #f8fafc);
  flex-shrink: 0;
}

.ap-allocation-summary > div {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ap-allocation-summary span {
  font-size: 0.75rem;
  color: var(--rz-text-secondary-color, #64748b);
}

.ap-allocation-summary strong {
  font-size: 1rem;
}

/* Left Preview / History: fill + scroll */
.ap-allocation-left-tabs {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

.ap-allocation-left-tabs .ap-allocation-tabs,
.ap-allocation-left-tabs > .rz-tabs,
.ap-allocation-left-tabs > .rz-tabview,
.ap-allocation-left-tabs > div {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.ap-allocation-left-tabs .rz-tabview-nav,
.ap-allocation-left-tabs .rz-tabs-nav {
  flex-shrink: 0;
}

.ap-allocation-left-tabs .rz-tabview-panels,
.ap-allocation-left-tabs .rz-tabs-panels {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.ap-allocation-left-tabs .rz-tabview-panel,
.ap-allocation-left-tabs .rz-tabs-panel,
.ap-allocation-left-tabs .rz-tabview-panel-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  height: auto !important;
}

.ap-allocation-tab-scroll {
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 0.25rem;
}

.ap-allocation-empty {
  padding: 1rem;
  color: var(--rz-text-secondary-color, #64748b);
}

.view-ap-allocation-add .ap-allocation-history-list,
.view-ap-allocation-detail .ap-allocation-history-list,
.view-or-allocation-add .ap-allocation-history-list,
.view-or-allocation-detail .ap-allocation-history-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.view-ap-allocation-add .ap-allocation-history-item,
.view-ap-allocation-detail .ap-allocation-history-item,
.view-or-allocation-add .ap-allocation-history-item,
.view-or-allocation-detail .ap-allocation-history-item {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #e5e7eb;
}

.view-ap-allocation-add .ap-allocation-history-item:hover,
.view-ap-allocation-detail .ap-allocation-history-item:hover,
.view-or-allocation-add .ap-allocation-history-item:hover,
.view-or-allocation-detail .ap-allocation-history-item:hover {
  background: #f3f4f6;
}

.view-ap-allocation-add .ap-allocation-history-action,
.view-ap-allocation-detail .ap-allocation-history-action,
.view-or-allocation-add .ap-allocation-history-action,
.view-or-allocation-detail .ap-allocation-history-action {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-weight: 600;
  color: #111827;
  margin-bottom: 0.45rem;
}

.view-ap-allocation-add .ap-allocation-history-fields,
.view-ap-allocation-detail .ap-allocation-history-fields,
.view-or-allocation-add .ap-allocation-history-fields,
.view-or-allocation-detail .ap-allocation-history-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem 0.75rem;
}

.view-ap-allocation-add .ap-allocation-history-field--primary,
.view-ap-allocation-detail .ap-allocation-history-field--primary,
.view-or-allocation-add .ap-allocation-history-field--primary,
.view-or-allocation-detail .ap-allocation-history-field--primary {
  grid-column: 1 / -1;
}

.view-ap-allocation-add .ap-allocation-history-label,
.view-ap-allocation-detail .ap-allocation-history-label,
.view-or-allocation-add .ap-allocation-history-label,
.view-or-allocation-detail .ap-allocation-history-label {
  font-size: 0.7rem;
  color: #6b7280;
  line-height: 1.2;
}

.view-ap-allocation-add .ap-allocation-history-value,
.view-ap-allocation-detail .ap-allocation-history-value,
.view-or-allocation-add .ap-allocation-history-value,
.view-or-allocation-detail .ap-allocation-history-value {
  font-size: 0.875rem;
  color: #111827;
  font-weight: 500;
  word-break: break-word;
}

.view-ap-allocation-add .ap-allocation-history-field--primary .ap-allocation-history-value,
.view-ap-allocation-detail .ap-allocation-history-field--primary .ap-allocation-history-value,
.view-or-allocation-add .ap-allocation-history-field--primary .ap-allocation-history-value,
.view-or-allocation-detail .ap-allocation-history-field--primary .ap-allocation-history-value {
  font-size: 0.9rem;
  font-weight: 300;
}

.view-ap-allocation-add .ap-allocation-history-meta,
.view-ap-allocation-detail .ap-allocation-history-meta,
.view-or-allocation-add .ap-allocation-history-meta,
.view-or-allocation-detail .ap-allocation-history-meta {
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: #6b7280;
  line-height: 1.4;
  word-break: break-word;
}

@media (max-width: 1100px) {
  .view-ap-allocation-add.gs-page-detail,
  .view-ap-allocation-detail.gs-page-detail,
  .view-or-allocation-add.gs-page-detail,
  .view-or-allocation-detail.gs-page-detail {
    overflow-y: auto;
  }

  .ap-allocation-workspace {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .view-ap-allocation-add .ap-allocation-left-card.rz-card,
  .view-ap-allocation-detail .ap-allocation-left-card.rz-card,
  .view-or-allocation-add .ap-allocation-left-card.rz-card,
  .view-or-allocation-detail .ap-allocation-left-card.rz-card {
    max-width: none;
    flex: none;
    height: auto;
  }

  .ap-allocation-right-column,
  .ap-allocation-grid-section {
    flex: none;
    height: auto;
    min-height: 280px;
  }

  .ap-allocation-left-tabs,
  .ap-allocation-tab-scroll {
    height: auto;
    max-height: 420px;
  }

  .ap-allocation-summary {
    grid-template-columns: 1fr;
  }
}

/* Open item allocation panel (Payment / Collection 頁 grid 下方) */
.gs-allocation-panel {
  margin-top: 0.75rem;
  border: 1px solid var(--rz-base-300, #e4e7ec);
  border-radius: 6px;
  background: var(--rz-base-50, #f9fafb);
  overflow: hidden;
}

/* 共用 toolbar：panel 內與 allocation grid 上方 */
.gs-allocation-toolbar,
.gs-allocation-panel__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--rz-base-200, #eef0f3);
  background: var(--rz-base-100, #f3f4f6);
}

.ap-allocation-grid-section > .gs-allocation-toolbar {
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
  border: 1px solid var(--rz-base-300, #e4e7ec);
  border-radius: 6px;
}

.gs-allocation-toolbar__error {
  margin-left: auto;
  font-size: 0.8125rem;
  color: var(--rz-danger, #ef4444);
}

.gs-allocation-panel__auto-label {
  margin: 0;
  font-size: 0.8125rem;
  cursor: pointer;
  user-select: none;
  color: var(--rz-text-color, #1f2937);
}

/* 共用 numeric：panel 表格與 DataGrid 欄位 */
.gs-allocation-numeric.rz-numeric,
.gs-allocation-numeric .rz-inputtext {
  font-size: 0.8125rem;
}

.gs-allocation-numeric--error.rz-numeric,
.gs-allocation-numeric--error .rz-inputtext {
  border-color: var(--rz-danger, #ef4444) !important;
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.15);
}

.gs-allocation-panel__scroll,
.gs-allocation-panel__grid {
  max-height: 180px;
  overflow: auto;
}

.gs-allocation-panel__grid .gs-data-grid-host {
  border: none;
  border-radius: 0;
}

.gs-allocation-panel__grid .gs-scroll-grid {
  border: none;
  box-shadow: none;
}

.gs-allocation-panel__grid .rz-datatable-scrollable .rz-grid-table thead th {
  background: var(--rz-base-50, #f9fafb);
}

.gs-allocation-panel__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.gs-allocation-panel__table th,
.gs-allocation-panel__table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--rz-base-200, #eef0f3);
  vertical-align: middle;
}

.gs-allocation-panel__table th {
  position: sticky;
  top: 0;
  background: var(--rz-base-50, #f9fafb);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.gs-allocation-panel__col-order {
  width: 2rem;
  text-align: center;
}

.gs-allocation-panel__col-num {
  width: 7.5rem;
  text-align: right;
}

.gs-allocation-panel__col-actions {
  width: auto;
  white-space: nowrap;
  text-align: right;
}

.gs-allocation-panel__col-actions .rz-button {
  margin-left: 0.15rem;
}

.gs-allocation-panel__row--error td {
  background: rgba(239, 68, 68, 0.06);
}

.gs-allocation-panel__error {
  padding: 0.35rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--rz-danger, #ef4444);
  border-top: 1px solid rgba(239, 68, 68, 0.2);
  background: rgba(239, 68, 68, 0.04);
}

.gs-allocation-panel__empty {
  padding: 0.75rem;
  text-align: center;
  color: var(--ap-muted, #6b7280);
  font-size: 0.8125rem;
}

.ap-payment-open-items-grid {
  max-height: 240px;
  overflow: auto;
}
