/* Insert Keyword modal (Wiley-style) */

.kw-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10050;
  background: rgba(0, 40, 60, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.kw-modal-panel {
  width: 100%;
  max-width: 640px;
  max-height: min(92vh, 820px);
  background: #ececec;
  border: 1px solid #b0b8bf;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: "Open Sans", system-ui, sans-serif;
}

.kw-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 10px;
  background: #f5f5f5;
  border-bottom: 3px solid #e87722;
}

.kw-modal-heading {
  margin: 0;
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: #1c1d1e;
}

.kw-modal-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: #6c757d;
  cursor: pointer;
  padding: 0 4px;
}

.kw-modal-close:hover {
  color: #1c1d1e;
}

.kw-modal-body {
  padding: 14px 18px 10px;
  overflow-y: auto;
  flex: 1;
}

.kw-modal-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.kw-modal-label {
  font-size: 14px;
  font-weight: 600;
  color: #1c1d1e;
}

.kw-sort-group {
  display: flex;
  gap: 6px;
}

.kw-sort-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 2px;
  background: #005274;
  color: #fff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  gap: 0;
}

.kw-sort-btn:hover {
  background: #003d56;
}

.kw-sort-btn span {
  display: block;
  font-size: 9px;
  letter-spacing: -0.02em;
}

.kw-sort-btn[data-sort="asc"]::after {
  content: "▼";
  font-size: 8px;
  margin-top: 1px;
}

.kw-sort-btn[data-sort="desc"]::after {
  content: "▲";
  font-size: 8px;
  margin-top: 1px;
}

.kw-format-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #c8c8c8;
  margin-bottom: 12px;
}

.kw-format-btn {
  width: 32px;
  height: 28px;
  border: none;
  background: transparent;
  color: #005274;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 2px;
  padding: 0;
}

.kw-format-btn:hover,
.kw-format-btn.active {
  background: rgba(0, 82, 116, 0.1);
}

.kw-format-btn em {
  font-style: italic;
  font-weight: 600;
}

.kw-format-btn u {
  text-decoration: underline;
}

.kw-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kw-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.kw-row.kw-row--drag-over {
  outline: 2px dashed #005274;
  outline-offset: 2px;
}

.kw-drag {
  flex: 0 0 32px;
  width: 32px;
  height: auto;
  min-height: 40px;
  border: 1px solid #adb5bd;
  background: #fff;
  color: #5a738e;
  cursor: grab;
  font-size: 14px;
  padding: 0;
  align-self: stretch;
}

.kw-drag:active {
  cursor: grabbing;
}

.kw-input-wrap {
  flex: 1;
  display: flex;
  align-items: stretch;
  min-width: 0;
  border: 1px solid #adb5bd;
  background: #fff;
}

.kw-input {
  flex: 1;
  min-height: 40px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.4;
  outline: none;
  overflow-wrap: anywhere;
}

.kw-input:empty::before {
  content: attr(data-placeholder);
  color: #9aa5b1;
  pointer-events: none;
}

.kw-delete {
  flex: 0 0 40px;
  width: 40px;
  border: none;
  border-left: 1px solid #adb5bd;
  background: #f8f9fa;
  color: #005274;
  cursor: pointer;
  font-size: 16px;
  padding: 0;
}

.kw-delete:hover {
  background: #eef4f7;
  color: #c00;
}

.kw-add-row {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  align-self: center;
  border: 2px solid #005274;
  border-radius: 50%;
  background: #fff;
  color: #005274;
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.kw-add-row:hover {
  background: #005274;
  color: #fff;
}

.kw-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px 16px;
  background: #e4e4e4;
  border-top: 1px solid #c8c8c8;
}

.kw-symbol-popover {
  position: absolute;
  z-index: 10060;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 220px;
  padding: 8px;
  background: #fff;
  border: 1px solid #b0b8bf;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.kw-symbol-popover button {
  width: 28px;
  height: 28px;
  border: 1px solid #d8d9da;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
}

.kw-symbol-popover button:hover {
  background: #eef4f7;
  border-color: #005274;
}
