/*
 * Keyword rule-set console
 *
 * This file intentionally scopes every selector to the rule-set feature.
 * The feature has several dialogs that share the base console styles, so
 * keeping these rules together prevents later page-level polish from
 * changing the rule-set layout by accident.
 */
:root {
  --rule-blue: #2f64d6;
  --rule-blue-strong: #2454bd;
  --rule-blue-soft: #f3f7ff;
  --rule-line: #e2e8f2;
  --rule-line-strong: #cbd8ec;
  --rule-text: #263753;
  --rule-muted: #7c899e;
  --rule-danger: #bb5962;
  --rule-shadow: 0 10px 30px rgba(25, 43, 74, .045);
}

/* Main two-column library */
.rule-sets-view {
  width: 100%;
  min-width: 0;
  margin-top: 18px;
}

.rule-set-layout {
  display: grid;
  grid-template-columns: minmax(255px, .36fr) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}

.rule-set-layout > .panel {
  min-width: 0;
  overflow: hidden;
  box-shadow: var(--rule-shadow);
}

.rule-set-list-panel {
  position: sticky;
  top: 18px;
}

.rule-set-list-panel .panel-head,
.rule-set-detail-panel .panel-head {
  padding: 20px 22px 17px;
}

.rule-set-list-panel .panel-head h3 {
  color: var(--rule-text);
}

.rule-set-list-panel .panel-head p {
  max-width: 230px;
  line-height: 1.5;
}

.rule-set-list {
  display: grid;
  gap: 9px;
  max-height: calc(100vh - 205px);
  overflow: auto;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: #cbd6e8 transparent;
}

.rule-set-list::-webkit-scrollbar,
.profile-rule-sets-list::-webkit-scrollbar {
  width: 7px;
}

.rule-set-list::-webkit-scrollbar-thumb,
.profile-rule-sets-list::-webkit-scrollbar-thumb {
  background: #cbd6e8;
  border-radius: 8px;
}

.rule-set-list-item {
  width: 100%;
  min-width: 0;
  display: block;
  text-align: left;
  border: 1px solid var(--rule-line);
  border-radius: 10px;
  background: #fff;
  padding: 13px 14px 12px;
  color: var(--rule-text);
  box-shadow: 0 2px 8px rgba(35, 54, 87, .025);
}

.rule-set-list-item:hover,
.rule-set-list-item:focus-visible {
  border-color: #9bb4e6;
  background: #f8faff;
  outline: 0;
}

.rule-set-list-item.active {
  border-color: #7092dc;
  background: var(--rule-blue-soft);
  box-shadow: inset 3px 0 0 var(--rule-blue), 0 4px 12px rgba(47, 100, 214, .08);
}

.rule-set-list-item strong {
  display: block;
  overflow: hidden;
  color: #304260;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-set-list-item span {
  display: inline-flex;
  align-items: center;
  margin-top: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: #69788f;
  font-size: 10px;
  line-height: 1.2;
}

.rule-set-list-item.active span {
  background: #e3edff;
  color: #4268b1;
}

.rule-set-list-item .rule-set-list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 12px;
  margin-top: 8px;
}

.rule-set-list-item small {
  display: block;
  margin: 0;
  color: #8a96a9;
  font-size: 10px;
  line-height: 1.35;
}

/* Selected rule-set editor */
.rule-set-editor {
  min-width: 0;
  padding: 24px 26px 22px;
}

.rule-set-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 17px;
  border-bottom: 1px solid #edf1f6;
}

.rule-set-editor-head h3 {
  margin: 6px 0 0;
  color: #1e2e49;
  font-size: 21px;
  letter-spacing: -.25px;
}

.rule-set-editor-head .eyebrow {
  color: #6b86bd;
}

.rule-set-status {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 25px;
  padding: 5px 10px;
  border: 1px solid #dfe5ed;
  border-radius: 999px;
  background: #f4f6f9;
  color: #69778d;
  font-size: 10px;
  white-space: nowrap;
}

.rule-set-status.published {
  border-color: #cce9d9;
  background: #ecf8f1;
  color: #27825b;
}

.rule-set-meta-form {
  display: grid;
  grid-template-columns: minmax(150px, .85fr) minmax(220px, 1.35fr) auto;
  align-items: end;
  gap: 12px;
  padding: 18px 0 17px;
}

.rule-set-meta-form label {
  min-width: 0;
  color: #62718a;
  font-size: 11px;
  font-weight: 600;
}

.rule-set-meta-form input,
.rule-set-meta-form textarea {
  box-sizing: border-box;
  display: block;
  width: 100%;
  margin-top: 7px;
  border: 1px solid #dce4ef;
  border-radius: 8px;
  padding: 9px 10px;
  background: #fbfcfe;
  color: var(--rule-text);
  font: inherit;
  font-size: 12px;
}

.rule-set-meta-form input {
  height: 39px;
}

.rule-set-meta-form textarea {
  height: 66px;
  resize: vertical;
  line-height: 1.45;
}

.rule-set-meta-form input:focus,
.rule-set-meta-form textarea:focus {
  outline: 0;
  border-color: #7395e3;
  background: #fff;
  box-shadow: 0 0 0 3px #eaf0ff;
}

.rule-set-meta-form .secondary {
  white-space: nowrap;
}

.rule-set-warning {
  margin: 0 0 15px;
  padding: 11px 13px;
  border: 1px solid #f0d6ac;
  border-left: 3px solid #e5a14e;
  border-radius: 8px;
  background: #fff9ef;
  color: #8b632f;
  font-size: 11px;
  line-height: 1.6;
}

.rule-set-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0 0 13px;
}

.rule-set-toolbar p {
  min-width: 0;
  margin: 0;
  color: var(--rule-muted);
  font-size: 11px;
  line-height: 1.45;
}

.rule-set-toolbar-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.rule-set-toolbar-actions button {
  white-space: nowrap;
}

.rule-set-rule-list {
  display: grid;
  gap: 9px;
}

/* A row remains a row on desktop and deliberately collapses at breakpoints. */
.rule-set-rule-row {
  display: grid;
  grid-template-columns: 36px minmax(150px, .95fr) minmax(180px, 1.3fr) 92px minmax(170px, auto);
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 12px 13px;
  border: 1px solid #e5eaf2;
  border-radius: 9px;
  background: #fcfdff;
  color: var(--rule-text);
  font-size: 11px;
  transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

.rule-set-rule-row:hover {
  border-color: #bfd0ec;
  background: #fff;
  box-shadow: 0 3px 12px rgba(38, 62, 104, .045);
}

.rule-set-rule-row.disabled {
  opacity: .58;
}

.rule-set-rule-row > .switch {
  justify-self: start;
}

.rule-set-rule-row strong,
.rule-set-rule-row p,
.rule-set-rule-row small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rule-set-rule-row strong {
  color: #3158aa;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
  white-space: nowrap;
}

.rule-set-rule-row p {
  display: -webkit-box;
  margin: 0;
  color: #5e697a;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.rule-set-rule-row small {
  color: #8290a5;
  font-size: 10px;
  line-height: 1.4;
  white-space: nowrap;
}

.rule-set-row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 3px;
  min-width: 0;
}

.rule-set-row-actions button {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #5b6e91;
  padding: 5px 6px;
  font-size: 10px;
  white-space: nowrap;
}

.rule-set-row-actions button:hover {
  border-color: #d8e4fb;
  background: #edf3ff;
  color: #3158aa;
}

.rule-set-row-actions button:disabled {
  color: #c8ced8;
  cursor: not-allowed;
}

.rule-set-row-actions button:disabled:hover {
  border-color: transparent;
  background: transparent;
}

.rule-set-row-actions .delete-link {
  color: var(--rule-danger);
}

.rule-set-linked {
  margin-top: 16px;
  padding: 12px 13px;
  border: 1px solid #e5eaf2;
  border-radius: 8px;
  background: #fafbfe;
  color: #768298;
  font-size: 11px;
  line-height: 1.55;
}

.rule-set-linked strong {
  color: #40506a;
}

.rule-set-danger-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px solid #edf0f4;
}

.rule-set-danger-zone .field-hint {
  margin: 0;
}

/* Shared empty state */
.rule-sets-view .rule-empty {
  padding: 25px 12px;
  border: 1px dashed #d6dfed;
  border-radius: 9px;
  color: #9aa4b3;
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
}

/* Association dialog */
.profile-rule-sets-list {
  display: grid;
  gap: 9px;
  max-height: 52vh;
  overflow: auto;
  padding-right: 3px;
}

.profile-rule-set-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 12px 13px;
  border: 1px solid #e3e9f2;
  border-radius: 9px;
  background: #fff;
}

.profile-rule-set-row.selected {
  border-color: #9bb4e6;
  background: #f6f8ff;
  box-shadow: inset 3px 0 0 var(--rule-blue);
}

.profile-rule-set-row > input {
  width: 16px;
  height: 16px;
  accent-color: var(--rule-blue);
}

.profile-rule-set-main {
  min-width: 0;
}

.profile-rule-set-main strong {
  display: block;
  overflow: hidden;
  color: #30415f;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-rule-set-main small {
  display: block;
  margin-top: 4px;
  color: #8994a5;
  font-size: 10px;
  line-height: 1.4;
}

.profile-rule-set-order {
  display: flex;
  gap: 4px;
}

.profile-rule-set-order button {
  border: 1px solid #dfe5ee;
  border-radius: 6px;
  background: #fff;
  color: #526688;
  padding: 5px 7px;
  font-size: 10px;
}

.profile-rule-set-order button:hover {
  border-color: #b9cae8;
  background: #edf3ff;
}

.profile-rule-set-order button:disabled {
  color: #c5ccd7;
  cursor: not-allowed;
}

.rule-conflict-box:not(:empty) {
  margin-top: 11px;
  padding: 10px 12px;
  border: 1px solid #f0d6ac;
  border-radius: 8px;
  background: #fff7eb;
  color: #8b632f;
  font-size: 11px;
  line-height: 1.6;
}

/* Rule-set creation and rule editing dialogs */
#rule-set-dialog {
  width: min(530px, calc(100vw - 32px));
  padding: 0;
}

#rule-set-dialog form {
  padding: 25px 27px 22px;
}

#rule-set-dialog .dialog-head {
  margin-bottom: 22px;
}

#rule-set-dialog .dialog-head p,
#profile-rule-sets-dialog .dialog-head p,
#rules-dialog .dialog-head p {
  margin: 6px 0 0;
  color: #8793a6;
  font-size: 11px;
  line-height: 1.5;
}

#rule-set-dialog form > label {
  display: block;
  margin-bottom: 16px;
  color: #51617a;
  font-size: 12px;
  font-weight: 600;
}

#rule-set-dialog form > label > input,
#rule-set-dialog form > label > textarea {
  box-sizing: border-box;
  display: block;
  width: 100%;
  margin-top: 7px;
  border: 1px solid #dce4ef;
  border-radius: 9px;
  padding: 11px 12px;
  background: #fbfcfe;
  color: var(--rule-text);
  font: inherit;
  font-size: 13px;
}

#rule-set-dialog form > label > input:focus,
#rule-set-dialog form > label > textarea:focus {
  outline: 0;
  border-color: #7395e3;
  background: #fff;
  box-shadow: 0 0 0 3px #eaf0ff;
}

#rule-set-dialog form > label > textarea {
  min-height: 94px;
  resize: vertical;
  line-height: 1.55;
}

#rule-set-dialog .dialog-actions {
  margin-top: 23px;
}

#rules-dialog,
#profile-rule-sets-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid #dfe6f1;
  border-radius: 15px;
  box-shadow: 0 24px 80px rgba(20, 34, 61, .24);
}

#rules-dialog::backdrop,
#profile-rule-sets-dialog::backdrop,
#rule-set-dialog::backdrop {
  background: rgba(15, 27, 48, .48);
  backdrop-filter: blur(2px);
}

.rules-dialog-body {
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 25px 27px 23px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e5 transparent;
}

.rules-dialog-body .dialog-head {
  margin-bottom: 20px;
}

.rules-dialog-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 13px;
  color: #69778d;
  font-size: 12px;
}

.rules-dialog-toolbar strong {
  color: #3158aa;
}

.rule-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 17px;
  color: #768298;
  font-size: 12px;
}

.rule-pagination button {
  border: 1px solid #dbe3f2;
  border-radius: 7px;
  background: #fff;
  color: #4566a5;
  padding: 7px 11px;
  font-size: 12px;
}

.rule-pagination button:disabled {
  border-color: #edf0f5;
  color: #bbc3d0;
  cursor: not-allowed;
}

.rules-dialog-body > .dialog-actions {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid #edf1f6;
}

@media (max-width: 1120px) {
  .rule-set-rule-row {
    grid-template-columns: 34px minmax(130px, .9fr) minmax(160px, 1.2fr) 82px minmax(145px, auto);
    gap: 8px;
  }

  .rule-set-row-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 1000px) {
  .rule-set-layout {
    grid-template-columns: 1fr;
  }

  .rule-set-list-panel {
    position: static;
  }

  .rule-set-list {
    max-height: 270px;
  }

  .rule-set-rule-row {
    grid-template-columns: 34px minmax(0, 1fr) auto;
  }

  .rule-set-rule-row p {
    grid-column: 2 / 4;
  }

  .rule-set-rule-row > small {
    grid-column: 2 / 3;
  }

  .rule-set-row-actions {
    grid-column: 3 / 4;
    grid-row: 2 / span 2;
  }
}

@media (max-width: 650px) {
  .rule-sets-view {
    margin-top: 12px;
  }

  .rule-set-editor {
    padding: 20px 16px 18px;
  }

  .rule-set-editor-head,
  .rule-set-toolbar,
  .rule-set-danger-zone {
    align-items: flex-start;
    flex-direction: column;
  }

  .rule-set-meta-form {
    grid-template-columns: 1fr;
    gap: 11px;
  }

  .rule-set-meta-form .secondary {
    justify-self: start;
  }

  .rule-set-toolbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .rule-set-rule-row {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 8px;
    padding: 11px;
  }

  .rule-set-rule-row p,
  .rule-set-rule-row > small,
  .rule-set-row-actions {
    grid-column: 2 / 3;
  }

  .rule-set-row-actions {
    grid-row: auto;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .profile-rule-set-row {
    grid-template-columns: 20px minmax(0, 1fr);
  }

  .profile-rule-set-order {
    grid-column: 2 / 3;
  }

  #rule-set-dialog form,
  .rules-dialog-body {
    padding: 21px 18px 18px;
  }

  #rules-dialog,
  #profile-rule-sets-dialog,
  #rule-set-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    border-radius: 13px;
  }
}
