.crmd-lib-modal-open {
  overflow: hidden;
}

.crmd-lib-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(2px);
}

.crmd-lib-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: 14px;
  box-shadow: 0 28px 90px rgba(15, 23, 42, 0.28);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.crmd-lib-header,
.crmd-lib-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  background: hsl(var(--muted));
}

.crmd-lib-header {
  border-bottom: 1px solid hsl(var(--border));
}

.crmd-lib-footer {
  justify-content: space-between;
  border-top: 1px solid hsl(var(--border));
}

.crmd-lib-title-wrap {
  min-width: 0;
  flex: 1;
}

.crmd-lib-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
  font-weight: 700;
}

.crmd-lib-subtitle {
  margin: 3px 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 12px;
}

.crmd-lib-content {
  min-height: 180px;
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  gap: 12px;
  padding: 14px;
}

.crmd-lib-group {
  overflow: hidden;
  border: 1px solid hsl(var(--border));
  border-radius: 10px;
  background: hsl(var(--background));
}

.crmd-lib-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 9px 12px;
  background: hsl(var(--muted));
  border-bottom: 1px solid hsl(var(--border));
}

.crmd-lib-group-heading {
  min-width: 0;
  flex: 1;
  color: hsl(var(--foreground));
  font-size: 12px;
  line-height: 1.35;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.crmd-lib-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 23px;
  height: 20px;
  margin-left: 8px;
  padding: 0 6px;
  border-radius: 999px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
}

.crmd-lib-items {
  display: grid;
  gap: 3px;
  padding: 7px;
}

.crmd-lib-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-height: 38px;
  border-radius: 7px;
}

.crmd-lib-item:hover,
.crmd-lib-item:focus-within {
  background: hsl(var(--muted));
}

.crmd-lib-item-label {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 7px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.42;
}

.crmd-lib-checkbox {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  margin: 1px 0 0;
  accent-color: hsl(var(--primary));
}

.crmd-lib-item-text {
  overflow-wrap: anywhere;
}

.crmd-lib-actions,
.crmd-lib-editor-actions,
.crmd-lib-confirm-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.crmd-lib-item-actions {
  flex: 0 0 auto;
  padding: 4px 3px 0 0;
  opacity: 0.68;
}

.crmd-lib-item:hover .crmd-lib-item-actions,
.crmd-lib-item:focus-within .crmd-lib-item-actions {
  opacity: 1;
}

.crmd-lib-button {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 9px;
  color: hsl(var(--foreground));
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.crmd-lib-button:hover {
  background: hsl(var(--accent));
}

.crmd-lib-button:focus-visible,
.crmd-lib-input:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.crmd-lib-button-primary {
  color: hsl(var(--primary-foreground));
  background: hsl(var(--primary));
  border-color: hsl(var(--primary));
}

.crmd-lib-button-primary:hover {
  background: hsl(var(--primary) / 0.9);
}

.crmd-lib-button-secondary {
  color: hsl(var(--primary));
  background: hsl(var(--background));
  border-color: hsl(var(--border));
}

.crmd-lib-button-danger,
.crmd-lib-button-danger-quiet {
  color: hsl(var(--destructive));
}

.crmd-lib-button-danger {
  color: hsl(var(--destructive-foreground));
  background: hsl(var(--destructive));
  border-color: hsl(var(--destructive));
}

.crmd-lib-button-danger:hover {
  background: hsl(var(--destructive) / 0.9);
}

.crmd-lib-close {
  position: relative;
  width: 32px;
  padding: 0;
  font-size: 0;
}

.crmd-lib-close::before,
.crmd-lib-close::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
}

.crmd-lib-close::before { transform: rotate(45deg); }
.crmd-lib-close::after { transform: rotate(-45deg); }

.crmd-lib-editor,
.crmd-lib-confirm {
  margin: 7px;
  padding: 10px;
  border: 1px solid hsl(var(--primary) / 0.5);
  border-radius: 8px;
  background: hsl(var(--primary) / 0.08);
}

.crmd-lib-editor-title {
  margin-bottom: 7px;
  color: hsl(var(--foreground));
  font-size: 12px;
  font-weight: 700;
}

.crmd-lib-input {
  width: 100%;
  min-height: 36px;
  box-sizing: border-box;
  resize: vertical;
  padding: 8px 10px;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
}

.crmd-lib-editor-actions {
  justify-content: flex-end;
  margin-top: 7px;
}

.crmd-lib-confirm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: hsl(var(--destructive));
  background: hsl(var(--destructive) / 0.08);
  border-color: hsl(var(--destructive) / 0.3);
  font-size: 12px;
}

.crmd-lib-empty,
.crmd-lib-empty-state {
  width: 100%;
  padding: 16px;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--background));
  border: 1px dashed hsl(var(--border));
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  text-align: center;
}

.crmd-lib-empty {
  cursor: pointer;
}

.crmd-lib-empty:hover {
  background: hsl(var(--muted));
}

.crmd-lib-loading {
  padding: 42px 16px;
  color: hsl(var(--muted-foreground));
  font-size: 13px;
  text-align: center;
}

.crmd-lib-status {
  min-height: 18px;
  color: hsl(var(--muted-foreground));
  font-size: 12px;
}

.crmd-lib-status-error {
  color: hsl(var(--destructive));
}

@media (max-width: 680px) {
  .crmd-lib-overlay {
    align-items: stretch;
    padding: 8px;
  }

  .crmd-lib-dialog {
    width: 100%;
    max-height: calc(100vh - 16px);
    border-radius: 10px;
  }

  .crmd-lib-header {
    flex-wrap: wrap;
    padding-right: 10px;
  }

  .crmd-lib-title-wrap {
    flex-basis: calc(100% - 44px);
  }

  .crmd-lib-group-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .crmd-lib-item {
    flex-direction: column;
  }

  .crmd-lib-item-actions {
    width: 100%;
    justify-content: flex-end;
    padding: 0 6px 6px;
  }

  .crmd-lib-confirm {
    align-items: flex-start;
    flex-direction: column;
  }
}
