/*
 * Cashback Pro V36.7.123
 * - Improve Light-mode marketplace maintenance badges and logo visibility.
 * - Constrain Knowledge Base add / edit forms to the available viewport width.
 * - Preserve the form's collapsed-by-default behavior.
 */

/* =========================================================================
   1) MARKETPLACE BADGES — "Đang bảo trì" readable in Light mode
   ========================================================================= */
#marketplace-public-badges .marketplace-public-badge.is-maintenance {
  filter: none !important;
  opacity: 1 !important;
  color: #40536d !important;
  background: rgba(224, 233, 246, .96) !important;
  border: 1px dashed rgba(111, 135, 169, .68) !important;
  box-shadow: 0 3px 10px rgba(55, 76, 111, .08) !important;
  text-shadow: none !important;
}

#marketplace-public-badges .marketplace-public-badge.is-maintenance img {
  filter: saturate(.82) !important;
  opacity: .96 !important;
  background: #fff !important;
  border: 1px solid rgba(82, 105, 140, .20) !important;
  box-shadow: 0 2px 7px rgba(28, 48, 82, .13) !important;
}

#marketplace-public-badges .marketplace-public-badge.is-maintenance strong {
  color: #344a67 !important;
  opacity: 1 !important;
  font-weight: 800 !important;
}

#marketplace-public-badges .marketplace-public-badge.is-maintenance small {
  color: #955617 !important;
  opacity: 1 !important;
  font-size: 10.5px !important;
  font-weight: 800 !important;
  letter-spacing: .01em;
}

/* Explicit light selector beats the muted mobile V36.7.71 rules. */
html body.theme-default.default-light-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance,
html body.default-light-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance {
  color: #40536d !important;
  background: linear-gradient(125deg, rgba(231, 239, 250, .98), rgba(222, 233, 248, .96)) !important;
  border-color: rgba(104, 132, 171, .70) !important;
}
html body.theme-default.default-light-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance strong,
html body.default-light-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance strong {
  color: #344a67 !important;
}
html body.theme-default.default-light-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance small,
html body.default-light-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance small {
  color: #8c5010 !important;
}

/* Keep status readable in Dark and seasonal themes without washing out their
   distinctive marketplace logo colors. */
html body.default-dark-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance,
html body.theme-default.default-dark-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance,
html body.theme-halloween:not(.default-light-mode) #marketplace-public-badges .marketplace-public-badge.is-maintenance,
html body.theme-winter:not(.default-light-mode) #marketplace-public-badges .marketplace-public-badge.is-maintenance,
html body.theme-ocean:not(.default-light-mode) #marketplace-public-badges .marketplace-public-badge.is-maintenance {
  filter: none !important;
  opacity: 1 !important;
}
html body.default-dark-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance strong,
html body.theme-default.default-dark-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance strong {
  color: #e0eaf9 !important;
}
html body.default-dark-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance small,
html body.theme-default.default-dark-mode #marketplace-public-badges .marketplace-public-badge.is-maintenance small {
  color: #ffd18b !important;
}

/* =========================================================================
   2) KNOWLEDGE BASE — prevent the Add Document form from overflowing
   ========================================================================= */
html body #tab-admin,
html body #admin-pane-knowledge,
html body .admin-pane#admin-pane-knowledge {
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

html body #admin-pane-knowledge > *,
html body #admin-pane-knowledge .kb-table-toolbar,
html body #admin-pane-knowledge > div[style*="overflow-x:auto"] {
  box-sizing: border-box !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

/* Closed stays closed. When opened, the panel occupies only its parent's width. */
html body #admin-pane-knowledge #kb-add-panel[hidden],
html body #admin-pane-knowledge #kb-file-panel[hidden] {
  display: none !important;
}

html body #admin-pane-knowledge #kb-add-panel:not([hidden]) {
  display: block !important;
  position: relative !important;
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  margin: 12px 0 0 !important;
  padding: clamp(10px, 3vw, 16px) !important;
  overflow: hidden !important;
  border-radius: 16px !important;
}

html body #admin-pane-knowledge #kb-add-panel .form-grid {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 10px !important;
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  margin: 0 !important;
}

html body #admin-pane-knowledge #kb-add-panel .form-grid > *,
html body #admin-pane-knowledge #kb-add-panel .form-grid > label,
html body #admin-pane-knowledge #kb-add-panel .form-grid > button,
html body #admin-pane-knowledge #kb-file-panel > * {
  box-sizing: border-box !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

html body #admin-pane-knowledge #kb-add-panel input,
html body #admin-pane-knowledge #kb-add-panel select,
html body #admin-pane-knowledge #kb-add-panel textarea,
html body #admin-pane-knowledge #kb-add-panel .form-control {
  display: block !important;
  box-sizing: border-box !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

html body #admin-pane-knowledge #kb-add-panel textarea {
  min-height: 150px !important;
  resize: vertical !important;
  white-space: pre-wrap !important;
  overflow-wrap: anywhere !important;
}

html body #admin-pane-knowledge #kb-add-panel button {
  white-space: normal !important;
  overflow-wrap: anywhere !important;
  justify-content: center !important;
}

html body #admin-pane-knowledge #kb-file-panel:not([hidden]) {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 9px !important;
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  overflow: hidden !important;
}

html body #admin-pane-knowledge #kb-file-panel input[type="file"] {
  min-width: 0 !important;
  max-width: 100% !important;
  width: 100% !important;
  font-size: 13px !important;
}

/* The edit-document modal uses a fixed 760px max-width. Make its box shrink
   to the viewport and scroll internally instead of widening the page. */
html body #kb-edit-modal {
  box-sizing: border-box !important;
  width: 100% !important;
  max-width: 100vw !important;
  overflow-x: hidden !important;
}
html body #kb-edit-modal .modal-card {
  box-sizing: border-box !important;
  width: min(760px, calc(100vw - 24px)) !important;
  min-width: 0 !important;
  max-width: calc(100vw - 24px) !important;
  max-height: calc(100vh - 24px) !important;
  max-height: calc(100dvh - 24px) !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  margin: auto !important;
}

html body #kb-edit-modal .form-group,
html body #kb-edit-modal .form-grid,
html body #kb-edit-modal label,
html body #kb-edit-modal input,
html body #kb-edit-modal select,
html body #kb-edit-modal textarea,
html body #kb-edit-modal .form-control {
  box-sizing: border-box !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

html body #kb-edit-modal textarea {
  display: block !important;
  resize: vertical !important;
  overflow-wrap: anywhere !important;
}

@media (max-width: 640px) {
  html body #kb-edit-modal {
    align-items: flex-start !important;
    padding: 12px 10px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  }

  html body #kb-edit-modal .modal-card {
    width: 100% !important;
    max-width: 100% !important;
    max-height: calc(100vh - 24px) !important;
    max-height: calc(100dvh - 24px) !important;
    padding: 16px !important;
    border-radius: 18px !important;
  }

  html body #admin-pane-knowledge #kb-add-panel:not([hidden]) {
    padding: 10px !important;
  }
}
