/* Elegant Query Manager Styles */
.query-manager-expandable {
  border: 1px solid rgba(167, 182, 194, 0.4);
  border-radius: 8px;
  background: inherit;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  position: relative;
}

.full-results-main-content .bp3-popover-wrapper {
  z-index: 6;
}

/* Header - always visible */
.query-manager-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  cursor: pointer;
  background: inherit;
  border-radius: 8px 8px 0 0;
  transition: background-color 0.2s ease;
}

.query-manager-header:hover {
  background: rgba(167, 182, 194, 0.15);
}

.query-manager-current-query {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.query-manager-current-text {
  font-size: 14px;
  font-weight: 500;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.query-manager-header-actions {
  flex-shrink: 0;
}

/* Query Composer Header */
.query-composer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.query-composer-header h6 {
  margin: 0;
  flex: 1;
}

.query-composer-model-selector {
  flex-shrink: 0;
}

/* Expanded content */
.query-manager-expanded {
  max-height: 550px;
  overflow-y: scroll;
  padding: 8px;
  border-top: 1px solid rgba(167, 182, 194, 0.4);
  background: inherit;
  /* Remove position: relative to not interfere with popover positioning */
  /* position: relative; */
}

/* Ensure query manager isn't clipped by parent containers */
.full-results-main-content:has(.query-manager-container) {
  overflow: visible !important;
}

/* Query Details */
.query-manager-query-details {
  margin-bottom: 10px;
}

.query-manager-query-item {
  margin-bottom: 12px;
}

.query-manager-query-item:last-child {
  margin-bottom: 0;
}

.query-manager-query-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: inherit;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.query-manager-query-content {
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid rgba(167, 182, 194, 0.3);
  background: inherit;
  overflow-y: auto;
  word-wrap: break-word;
  transition: border-color 0.2s ease;
}

.query-manager-query-content.user-query {
  border-left: 4px solid #137cbd;
  background: rgba(19, 124, 189, 0.1);
}

.query-manager-query-content.formal-query {
  border-left: 4px solid #a854f7;
  background: rgba(168, 84, 247, 0.1);
  font-family: "SF Mono", "Monaco", "Inconsolata", "Fira Code", "Fira Mono",
    "Droid Sans Mono", "Consolas", monospace;
  font-size: 13px;
}

/* Query Selector */
.query-manager-selector {
  display: flex;
  align-items: center;
  gap: 12px;
}

.query-manager-selector-main {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.query-manager-dropdown {
  min-width: 200px;
}

.query-manager-dropdown optgroup {
  font-weight: 600;
  color: #495057;
  background: #f8f9fa;
}

.query-manager-dropdown option {
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.query-manager-loading {
  color: #6c757d;
  font-size: 13px;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
}

.query-manager-selector-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.query-manager-query-actions {
  display: flex;
  align-items: center;
}

/* Execution Progress */
.query-manager-execution-progress {
  padding: 10px 12px;
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  color: #1565c0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid #90caf9;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.query-manager-execution-progress::before {
  content: "⏳";
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Dialog Styles */
.save-query-dialog .bp3-dialog,
.rename-query-dialog .bp3-dialog {
  min-width: 450px;
  max-width: 90vw;
}

.current-query-preview,
.stored-query-preview {
  margin-bottom: 8px;
  padding: 8px;
  background: rgba(19, 124, 189, 0.1);
  border: 1px solid rgba(167, 182, 194, 0.4);
  border-left: 4px solid #137cbd;
  border-radius: 6px;
  font-size: 13px;
  word-wrap: break-word;
  line-height: 1.4;
  color: inherit;
}

.current-formal-query-preview,
.stored-formal-query-preview {
  margin: 8px 0 4px 0;
  padding: 8px;
  background: rgba(168, 84, 247, 0.1);
  border: 1px solid rgba(167, 182, 194, 0.4);
  border-left: 4px solid #a854f7;
  border-radius: 6px;
  font-size: 13px;
  word-wrap: break-word;
  line-height: 1.4;
  color: inherit;
}

/* Responsive Design */
@media (max-width: 768px) {
  .query-manager-header {
    padding: 10px 12px;
  }

  .query-manager-current-text {
    font-size: 13px;
  }

  .query-manager-expanded {
    padding: 12px;
  }

  .query-manager-selector {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .query-manager-selector-main {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .query-manager-dropdown {
    min-width: unset;
  }

  .query-manager-selector-actions {
    justify-content: center;
    padding-top: 8px;
    border-top: 1px solid #e9ecef;
  }

  .query-manager-query-content {
    max-height: 72px; /* Allow more space on mobile */
    font-size: 13px;
  }

  .save-query-dialog .bp3-dialog,
  .rename-query-dialog .bp3-dialog {
    min-width: 300px;
    margin: 20px;
  }
}

@media (max-width: 480px) {
  .query-manager-header {
    padding: 8px 10px;
  }

  .query-manager-current-text {
    font-size: 12px;
  }

  .query-manager-expanded {
    padding: 10px;
  }

  .query-manager-query-label {
    font-size: 10px;
  }

  .query-manager-query-content {
    font-size: 12px;
    padding: 8px 10px;
  }
}

/* Query Composer Styles */

/* Main container with query manager and composer button */
.query-manager-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.query-manager-container > .query-manager-wrapper {
  flex: 1;
}

/* Query composer expandable interface */
.query-composer-interface {
  background: inherit;
  border: 1px solid rgba(167, 182, 194, 0.4);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Query composer */
.query-composer-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.query-composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.query-composer-actions .bp3-button {
  font-size: 14px;
  padding: 5px 8px;
  transition: all 0.2s ease;
  width: 135px;
  justify-content: start;
}

.query-composer-actions .query-composer-model-selector .bp3-button {
  width: fit-content;
}

/* Tool sections within the interface */
.query-tool-section {
  margin-bottom: 8px;
  /* padding-bottom: 8px; */
  /* border-bottom: 1px solid rgba(167, 182, 194, 0.2); */
}

.query-tool-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.query-tool-section h6 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: inherit;
  opacity: 0.8;
  letter-spacing: 0.5px;
}

.direct-content-section .query-tool-section h6 {
  margin: 8px 0;
}

/* Mode selector */
.query-composer-mode-selector {
  margin-bottom: 16px;
}

.query-composer-mode-selector .bp3-html-select select {
  font-size: 14px;
  padding: 8px 32px 8px 12px;
  min-width: 200px;
  border: 1px solid rgba(167, 182, 194, 0.4);
  border-radius: 6px;
  background: inherit;
  color: inherit;
}

/* Input area */
.query-composer-input {
  flex: 1;
}

.query-composer-textarea {
  width: 100%;
  /* min-height: 70px; */
  border: 1px solid rgba(167, 182, 194, 0.4);
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  color: inherit;
  /* background: inherit; */
  line-height: 1.5;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.query-composer-textarea:focus {
  outline: none;
  border-color: #137cbd;
  box-shadow: 0 0 0 2px rgba(19, 124, 189, 0.2);
}

.query-composer-textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: rgba(167, 182, 194, 0.1);
}

.query-composer-textarea::placeholder {
  /* color: rgba(167, 182, 194, 0.8); */
  font-style: italic;
}

/* Responsive design for query composer */
@media (max-width: 768px) {
  .query-manager-container {
    flex-direction: column;
    gap: 12px;
  }

  .query-composer-toggle {
    margin-top: 0;
    margin-right: 3px;
    align-self: center;
  }

  .query-composer-interface {
    padding: 8px;
  }

  .query-composer-textarea {
    font-size: 13px;
    padding: 8px;
  }

  .query-composer-actions {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
  }

  .query-composer-actions .bp3-button {
    font-size: 13px;
    padding: 6px 14px;
  }
}

@media (max-width: 480px) {
  .query-composer-interface {
    padding: 6px;
  }

  .query-composer-textarea {
    font-size: 12px;
    padding: 6px;
    min-height: 48px;
  }

  .query-composer-actions .bp3-button {
    font-size: 12px;
    padding: 5px 12px;
  }
}

/* Direct Content Selector Styles */

.direct-content-page-selector {
  margin-bottom: 8px;
}

/* Input row with MultiSelect and Add button on same line */
.direct-content-input-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

/* Wrapper for MultiSelect to create proper positioning context */
.direct-content-multiselect-wrapper {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 10;
  /* Ensure popover isn't clipped */
  overflow: visible;
}

/* Make sure the popover appears above other content */
.direct-content-multiselect-wrapper .bp3-popover {
  z-index: 20;
}

/* Ensure the popover has proper styling when not using portal */
.direct-content-multiselect-wrapper .direct-content-popover-multiselect {
  max-height: 400px;
  overflow-y: auto;
}

.direct-content-multiselect-wrapper .direct-content-popover-multiselect .bp3-menu {
  max-height: 350px;
  overflow-y: auto;
}

.direct-content-input-row .direct-content-page-multiselect {
  width: 100%;
}

.direct-content-add-button {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  white-space: nowrap;
  width: 135px;
  justify-content: start;
}

.direct-content-page-select {
  width: 100%;
  font-size: 14px;
}

.direct-content-types {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.direct-content-checkbox {
  margin: 0;
  font-size: 13px;
}

.direct-content-checkbox .bp3-control-indicator {
  margin-right: 6px;
}

/* Enhanced DNP Period Selector */
.direct-content-dnp-period {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 4px 0;
}

.direct-content-period-label {
  font-size: 12px;
  color: var(--color-text-secondary, #666);
  white-space: nowrap;
}

.direct-content-dnp-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.direct-content-dnp-button {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--color-border, #ccc);
  border-radius: 3px;
  background: var(--color-background, white);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.direct-content-dnp-button:hover:not(:disabled) {
  background: var(--color-background-hover, #f5f5f5);
}

.direct-content-dnp-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.direct-content-custom-days {
  width: 60px !important;
  font-size: 12px !important;
}

.direct-content-custom-days .bp3-input {
  padding: 4px 6px !important;
  font-size: 12px !important;
}

.direct-content-dnp-label {
  font-size: 12px;
  color: var(--color-text-secondary, #666);
  white-space: nowrap;
}

/* Inline DNP selector (on same line as checkboxes) */
.direct-content-dnp-inline {
  display: flex;
  align-items: center;
  gap: 6px;
}

.direct-content-dnp-separator {
  color: var(--color-text-secondary, #666);
  font-size: 12px;
  font-weight: 600;
  margin: 0 4px;
}

.direct-content-dnp-button-inline {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border: 1px solid var(--color-border, #ccc);
  border-radius: 3px;
  background: var(--color-background, white);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.direct-content-dnp-button-inline:hover:not(:disabled) {
  background: var(--color-background-hover, #f5f5f5);
}

.direct-content-dnp-button-inline:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.direct-content-custom-days-inline {
  font-size: 11px !important;
}

.direct-content-custom-days-inline .bp3-input {
  width: 45px !important;
  padding: 2px 4px !important;
  font-size: 11px !important;
  height: 20px !important;
}

/* Blueprint Select for Page Selection */
.page-select-button {
  width: 100%;
  justify-content: space-between;
  text-align: left;
}

.page-select-option {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 3px;
  margin: 2px 4px;
}

.page-select-option:hover,
.page-select-option.active {
  background-color: var(--color-background-secondary, #f5f8fa);
}

.page-select-option.special-option {
  font-weight: 600;
  color: var(--color-primary, #137cbd);
}

.page-option-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Blueprint MultiSelect for Page Selection */
.direct-content-page-multiselect {
  width: 100%;
}

.direct-content-page-multiselect .bp3-tag-input {
  min-height: 35px;
}

.direct-content-page-multiselect .bp3-tag,
.query-page-selections .bp3-tag {
  /* Match full-results-type-badge.page styling */
  background: #e3f2fd !important;
  color: #1565c0 !important;
  border: none !important;
  border-radius: 12px !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  letter-spacing: 0.5px !important;
  padding: 3px 6px !important;
  /* margin: 2px !important; */
  max-width: 180px;
}

.direct-content-page-multiselect .bp3-tag .bp3-icon {
  margin-right: 2px;
}

/* Special pages (primary intent) with slightly different styling */
.direct-content-page-multiselect .bp3-tag.bp3-intent-primary {
  background: #1565c0 !important;
  color: white !important;
}

/* Ensure popover has proper z-index */
.bp3-portal .bp3-transition-container:has(.direct-content-popover-multiselect) {
  z-index: 100;
}

/* When the popover opens, recalculate its position using JavaScript */
.bp3-portal .direct-content-popover-multiselect.bp3-popover {
  max-height: 400px;
  overflow-y: auto;
}

.bp3-portal .direct-content-popover-multiselect.bp3-popover .bp3-popover-content {
  max-height: 350px;
  overflow-y: auto;
}

/* Ensure the popover content is properly sized */
.direct-content-popover-multiselect.bp3-popover {
  max-height: 400px;
  overflow-y: auto;
}

.direct-content-popover-multiselect .bp3-menu {
  max-height: 350px;
  overflow-y: auto;
}

/* Page Selections Display in Query composer */
.query-page-selections {
  /* margin-top: 8px; */
  margin-bottom: 8px;
  padding: 8px;
  /* background-color: #f5f8fa; */
  border: 1px solid #e1e8ed;
  border-radius: 4px;
}

.page-selections-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 500;
  color: #5c7080;
}

.page-selections-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Dark mode */
.bp3-dark .query-page-selections {
  background-color: #30404d;
  border-color: #5c7080;
}

/* Compact mode adjustments */
@media (max-width: 768px) {
  .direct-content-types {
    flex-direction: column;
    gap: 8px;
  }

  .query-tool-section {
    margin-bottom: 6px;
    padding-bottom: 5px;
  }

  .query-tool-section h6 {
    font-size: 12px;
  }
}
