/* ============================================================
 * RQL Builder – styly modálního dialogu a Builder tlačítka
 * ============================================================ */

/* Parent cellu rql inputu označíme jako positioning context, aby Builder button
 * (náš sourozenec inputu) mohl být absolute pozicovaný. DŮLEŽITÉ: NEOBALUJEME
 * input, jen stylujeme jeho existujícího parenta — jakákoliv nová obálka by
 * rozbila React reconciliation Swagger UI. */
.rql-input-parent {
  position: relative;
}
/* Input má padding-right aby ikonka Builder nepřekrývala text */
.rql-input-parent > input[type="text"],
.rql-input-parent > input[type="search"],
.rql-input-parent > input:not([type]) {
  padding-right: 36px !important;
}

/* Builder tlačítko – ikonka absolute vůči .rql-input-parent, přesný top/right
 * se počítá v JS z offsetu inputu. Tyto hodnoty jsou výchozí fallback. */
.rql-builder-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #4990e2;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  line-height: 0;
  z-index: 2;
}
.rql-builder-btn:hover {
  background: rgba(73, 144, 226, 0.12);
  border-color: #4990e2;
  color: #357ac9;
}
.rql-builder-btn:focus-visible {
  outline: 2px solid #4990e2;
  outline-offset: 1px;
}
.rql-builder-btn svg { display: block; }

html.dark .rql-builder-btn { color: #6ab0f3; }
html.dark .rql-builder-btn:hover {
  background: rgba(106, 176, 243, 0.16);
  border-color: #6ab0f3;
  color: #9cc9f5;
}

/* Inline validační chyba pod rql inputem */
.rql-input-error {
  margin-top: 6px;
  padding: 6px 10px;
  background: #fdecea;
  border: 1px solid #f5c2c7;
  color: #842029;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.4;
  max-width: 600px;
}
html.dark .rql-input-error {
  background: #3a1c1c;
  border-color: #6b2f2f;
  color: #ffac82;
}

/* Vizuální označení neplatného RQL inputu */
.swagger-ui input.rql-invalid {
  border-color: #c0392b !important;
  box-shadow: 0 0 0 1px #c0392b;
}
html.dark .swagger-ui input.rql-invalid {
  border-color: #ff7474 !important;
  box-shadow: 0 0 0 1px #ff7474;
}

/* Modal layout – plnohodnotný fixed overlay (nespoléháme na Swagger UI built-in
 * styly, protože ty samy o sobě nemají position: fixed ani backdrop). */
.rql-builder-dialog {
  position: fixed;
  inset: 0;
  z-index: 2147483600; /* nad #auth-overlay (2147483000) i nad ostatním */
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: sans-serif;
}
.rql-builder-dialog .backdrop-ux {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.rql-builder-dialog .modal-ux {
  position: relative;
  z-index: 1;
  width: 92%;
  max-width: 900px;
  max-height: 90vh;
  background: #fff;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.rql-builder-dialog .modal-dialog-ux {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 100%;
}
.rql-builder-dialog .modal-ux-inner {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 100%;
}
.rql-builder-dialog .modal-ux-header {
  flex: 0 0 auto;
  padding: 14px 20px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f6f6f6;
}
.rql-builder-dialog .modal-ux-header h3 {
  margin: 0;
  font-size: 16px;
  color: #3b4151;
}
.rql-builder-dialog .modal-ux-header .close-modal {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 2px 10px;
  font-size: 18px;
  cursor: pointer;
  color: #3b4151;
}
.rql-builder-dialog .modal-ux-header .close-modal:hover {
  background: #fff;
  border-color: #d9d9d9;
}
.rql-modal-content {
  padding: 16px 24px 24px;
  overflow-y: auto;
  flex: 1;
}

/* Dark mode pro samotný modal */
html.dark .rql-builder-dialog .modal-ux {
  background: #252525;
  border-color: #444;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
html.dark .rql-builder-dialog .modal-ux-header {
  background: #1f1f1f;
  border-bottom-color: #444;
}
html.dark .rql-builder-dialog .modal-ux-header h3 {
  color: #e0e0e0;
}
html.dark .rql-builder-dialog .modal-ux-header .close-modal {
  color: #e0e0e0;
}
html.dark .rql-builder-dialog .modal-ux-header .close-modal:hover {
  background: #2a2a2a;
  border-color: #555;
}

/* WHERE sekce – header s nadpisem vlevo a Simple/Advanced tab togglem vpravo */
.rql-where-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.rql-where-head h4 {
  margin: 0;
}
.rql-where-tabs {
  display: inline-flex;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  overflow: hidden;
}
.rql-where-tab {
  padding: 5px 14px;
  background: transparent;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  border-right: 1px solid #d9d9d9;
}
.rql-where-tab:last-child { border-right: none; }
.rql-where-tab.active {
  background: #4990e2;
  color: #fff;
}
.rql-where-tab:hover:not(.active) {
  background: rgba(73, 144, 226, 0.08);
  color: #4990e2;
}

/* Sections */
.rql-section {
  margin-bottom: 22px;
  padding: 0;
}
.rql-section h4,
.rql-section-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  color: #3b4151;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Info ikonka (ⓘ) s tooltipem */
.rql-info {
  display: inline-block;
  margin-left: 4px;
  color: #a0a8b2;
  font-size: 13px;
  cursor: help;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1;
  vertical-align: middle;
  user-select: none;
}
.rql-info:hover,
.rql-info:focus {
  color: #4990e2;
  outline: none;
}
html.dark .rql-info { color: #666; }
html.dark .rql-info:hover,
html.dark .rql-info:focus { color: #6ab0f3; }

.rql-preview-title {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.rql-section-inline {
  display: flex;
  gap: 24px;
  align-items: center;
  flex-wrap: wrap;
}
.rql-section-inline > label,
.rql-section-inline > .rql-take-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #3b4151;
}
.rql-section-inline input[type="number"],
.rql-section-inline input[type="text"] {
  width: 110px;
  padding: 6px 10px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
  color: #3b4151;
}
.rql-section-inline input[type="number"]:disabled,
.rql-section-inline input[type="text"]:disabled {
  background: #f0f0f0;
  color: #888;
  cursor: not-allowed;
}

/* Take "Vše" checkbox */
.rql-take-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  cursor: pointer;
  color: #3b4151;
}
.rql-take-all input[type="checkbox"] {
  width: auto !important;
  padding: 0 !important;
  margin: 0;
  cursor: pointer;
}
html.dark .rql-take-all { color: #e0e0e0; }
html.dark .rql-section-inline input[type="number"]:disabled,
html.dark .rql-section-inline input[type="text"]:disabled {
  background: #1f1f1f;
  color: #666;
}

/* Members list */
.rql-members-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px 14px;
  max-height: 260px;
  overflow-y: auto;
  padding: 12px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  background: #fafafa;
}
.rql-member-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: #3b4151;
  cursor: pointer;
  line-height: 1.35;
  word-break: break-word;
}
.rql-member-item input {
  margin: 4px 0 0 0;
  flex-shrink: 0;
}
.rql-member-item .rql-member-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
/* Primární – raw název property (jde do $m=); monospace, zvýrazněný */
.rql-member-item .rql-member-name {
  font-family: monospace;
  font-size: 13px;
  font-weight: 600;
  color: #3b4151;
  word-break: break-all;
}
/* Sekundární – humanized popis, menší a šedý */
.rql-member-item .rql-member-desc {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
}
html.dark .rql-member-item { color: #e0e0e0; }
html.dark .rql-member-item .rql-member-name { color: #e0e0e0; }
html.dark .rql-member-item .rql-member-desc { color: #888; }
.rql-empty {
  grid-column: 1 / -1;
  margin: 0;
  font-style: italic;
  color: #888;
  font-size: 13px;
}
/* Where rows */
.rql-where-rows,
.rql-order-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.rql-cond-row,
.rql-order-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.rql-cond-row select,
.rql-cond-row input,
.rql-order-row select {
  padding: 6px 10px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
  color: #3b4151;
  font-family: inherit;
}
.rql-cond-row .rql-field { flex: 2; min-width: 120px; }
.rql-cond-row .rql-op    { flex: 0 0 110px; min-width: 90px; }
.rql-cond-row .rql-val   { flex: 3; min-width: 120px; font-family: monospace; }
.rql-cond-row .rql-no-value {
  flex: 3;
  font-style: italic;
  color: #888;
  font-size: 13px;
}
.rql-order-row .rql-field { flex: 2; }
.rql-order-row .rql-dir   { flex: 0 0 90px; }

.rql-del {
  width: 28px;
  height: 28px;
  background: transparent;
  color: #c0392b;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.rql-del:hover {
  background: rgba(192, 57, 43, 0.1);
  border-color: #c0392b;
}
.rql-group-head .rql-del {
  width: auto;
  height: auto;
  padding: 4px 10px;
  font-size: 12px;
}

.rql-add-row,
.rql-add-order,
.rql-add-cond,
.rql-add-grp {
  padding: 6px 14px;
  background: transparent;
  color: #4990e2;
  border: 1px dashed #4990e2;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.rql-add-row:hover,
.rql-add-order:hover,
.rql-add-cond:hover,
.rql-add-grp:hover {
  background: rgba(73, 144, 226, 0.08);
}

/* Advanced mode tree */
.rql-group {
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
  background: #fafbfc;
}
.rql-group-head {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.rql-group-head select {
  padding: 4px 10px;
  border: 1px solid #4990e2;
  border-radius: 4px;
  font-weight: 700;
  color: #4990e2;
  background: #fff;
  font-size: 12px;
}
.rql-group-children {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-left: 14px;
  border-left: 2px solid #d9d9d9;
}

/* Validation */
.rql-validation {
  margin: 12px 0 4px;
}
.rql-warning {
  padding: 8px 12px;
  background: #fff3cd;
  border: 1px solid #ffe69c;
  border-radius: 4px;
  color: #664d03;
  font-size: 12px;
  margin-bottom: 6px;
  line-height: 1.4;
}
.rql-error {
  padding: 6px 12px;
  background: #fdecea;
  border: 1px solid #f5c2c7;
  border-radius: 4px;
  color: #842029;
  font-size: 12px;
  margin-bottom: 4px;
}

/* Preview panel */
.rql-preview {
  margin-top: 14px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  background: #f6f6f6;
}
.rql-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #ececec;
  border-bottom: 1px solid #d9d9d9;
  font-size: 12px;
  font-weight: 700;
  color: #3b4151;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.rql-copy {
  padding: 4px 14px;
  background: transparent;
  color: #4990e2;
  border: 1px solid #4990e2;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
}
.rql-copy:hover {
  background: #4990e2;
  color: #fff;
}
.rql-preview-code {
  margin: 0;
  padding: 12px;
  font-family: monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  color: #3b4151;
  min-height: 18px;
}

/* Footer */
.rql-modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #e0e0e0;
}
.rql-cancel,
.rql-apply {
  padding: 8px 24px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.rql-cancel {
  background: #fff;
  color: #3b4151;
  border: 1px solid #d9d9d9;
}
.rql-cancel:hover {
  border-color: #4990e2;
  color: #4990e2;
}
.rql-apply {
  background: #4990e2;
  color: #fff;
  border: 1px solid #4990e2;
}
.rql-apply:hover {
  background: #357ac9;
  border-color: #357ac9;
}

/* === DARK MODE === */
html.dark .rql-builder-dialog .modal-ux-inner { background: #252525; }
html.dark .rql-where-tabs { border-color: #444; }
html.dark .rql-where-tab { color: #aaa; border-right-color: #444; }
html.dark .rql-where-tab.active { background: #4990e2; color: #fff; }
html.dark .rql-where-tab:hover:not(.active) {
  background: rgba(106, 176, 243, 0.1);
  color: #6ab0f3;
}
html.dark .rql-section h4 { color: #e0e0e0; }
html.dark .rql-section-inline label { color: #e0e0e0; }
html.dark .rql-section-inline input,
html.dark .rql-cond-row select,
html.dark .rql-cond-row input,
html.dark .rql-order-row select {
  background: #2a2a2a;
  color: #e0e0e0;
  border-color: #444;
}
html.dark .rql-members-list {
  background: #1f1f1f;
  border-color: #444;
}
html.dark .rql-member-item { color: #e0e0e0; }
html.dark .rql-empty { color: #888; }
html.dark .rql-cond-row .rql-no-value { color: #888; }
html.dark .rql-add-row,
html.dark .rql-add-order,
html.dark .rql-add-cond,
html.dark .rql-add-grp {
  color: #6ab0f3;
  border-color: #6ab0f3;
}
html.dark .rql-add-row:hover,
html.dark .rql-add-order:hover,
html.dark .rql-add-cond:hover,
html.dark .rql-add-grp:hover {
  background: rgba(106, 176, 243, 0.1);
}
html.dark .rql-group {
  background: #1f1f1f;
  border-color: #444;
}
html.dark .rql-group-head select {
  background: #2a2a2a;
  color: #6ab0f3;
  border-color: #6ab0f3;
}
html.dark .rql-group-children { border-left-color: #444; }
html.dark .rql-warning {
  background: #3a2f1c;
  border-color: #6b5e2f;
  color: #ffd97a;
}
html.dark .rql-error {
  background: #3a1c1c;
  border-color: #6b2f2f;
  color: #ffac82;
}
html.dark .rql-preview {
  background: #1b1b1b;
  border-color: #444;
}
html.dark .rql-preview-header {
  background: #252525;
  border-bottom-color: #444;
  color: #e0e0e0;
}
html.dark .rql-preview-code { color: #e0e0e0; }
html.dark .rql-copy {
  color: #6ab0f3;
  border-color: #6ab0f3;
}
html.dark .rql-copy:hover {
  background: #6ab0f3;
  color: #1b1b1b;
}
html.dark .rql-modal-footer { border-top-color: #444; }
html.dark .rql-cancel {
  background: #2a2a2a;
  color: #e0e0e0;
  border-color: #444;
}
html.dark .rql-cancel:hover {
  border-color: #6ab0f3;
  color: #6ab0f3;
}
html.dark .rql-del { color: #ff7474; }
html.dark .rql-del:hover {
  background: rgba(255, 116, 116, 0.12);
  border-color: #ff7474;
}
