/* =========================
   BOOTSTRAP REPLACEMENTS (SAFE)
========================= */

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

[class*="col-"] {
  flex: 1 1 200px;
  max-width: 25em;
}

.mb-2 {
  margin-bottom: 10px;
}
.mb-3 {
  margin-bottom: 15px;
}
.p-3 {
  padding: 15px;
}

.me-2 {
  margin-right: 10px;
}
.ms-auto {
  margin-left: auto;
}

.d-flex {
  display: flex;
}
.align-items-center {
  align-items: center;
}

/* =========================
   GLOBAL WIDTH
========================= */

body.wp-admin #wpbody-content > .wrap {
  width: 100% !important;
  max-width: 100% !important;
}

/* =========================
   CONTAINER
========================= */

#hscrm-options-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* =========================
   ROLE CARD
========================= */

.hscrm-card {
  width: 100%;
  box-sizing: border-box;
  background: #fff;
  border: 1px solid #ccd0d4;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition:
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.hscrm-card:hover {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  border-color: #999;
}

.hscrm-card.dragging {
  opacity: 0.5;
  border: 2px dashed #007cba;
  background: #f0f6fc;
}

/* =========================
   HEADER
========================= */

.hscrm-header,
.hscrm-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hscrm-header {
  border-bottom: 1px solid #ddd;
  padding-bottom: 10px;
  margin: 0 auto 20px;
}

.hscrm-header-row {
  margin-bottom: 10px;
}

/* =========================
   INPUT ROW
========================= */

.hscrm-row-header {
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
  align-items: flex-start;
  margin-bottom: 28px;
}

.hscrm-col-type {
  flex: 0 0 auto;
  min-width: 180px;
}

.hscrm-row-header .role-name,
.hscrm-row-header .role-slug {
  flex: 1 1 240px;
  max-width: 25em;
}

.hscrm-row-header input,
.hscrm-row-header select,
.draggable-item input:not([type="checkbox"]),
.draggable-item select {
  width: 100%;
  height: 36px;
  line-height: 36px;
  flex-shrink: 0;
}

.hscrm-row-header .hscrm-col {
  position: relative; /* REQUIRED anchor */
}

/* =========================
   REMOVE BUTTON
========================= */

.hscrm-remove-wrap {
  margin-left: auto;
  padding-left: 20px;
}

.hscrm-remove-wrap .remove-row {
  min-width: 90px;
}

/* =========================
   MOBILE
========================= */

@media (max-width: 768px) {
  .hscrm-row-header {
    flex-wrap: wrap;
  }

  .hscrm-col-type,
  .hscrm-row-header .role-name,
  .hscrm-row-header .role-slug {
    width: 100%;
    max-width: 100%;
  }

  .hscrm-remove-wrap {
    margin-left: 0;
    padding-left: 0;
    width: 100%;
  }

  .hscrm-remove-wrap .remove-row {
    width: 100%;
  }
}

/* =========================
   CAP GRID
========================= */

.hscrm-cap-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  gap: 6px 16px;
}

@media (max-width: 1024px) {
  .hscrm-cap-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 600px) {
  .hscrm-cap-grid {
    grid-template-columns: 1fr;
  }
}

/* =========================
   CAP ITEMS
========================= */

.hscrm-cap-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px;
  border-radius: 6px;
  min-height: 28px;
  overflow: visible;

  /* ✅ FIX: create stacking context */
  position: relative;
  z-index: 1;
}

/* ✅ FIX: bring hovered item above others */
.hscrm-cap-item:hover {
  z-index: 999;
}

/* ensure label aligns perfectly */
.hscrm-cap-item label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hscrm-cap-label {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: visible;
  line-height: 1;
  transform: translateY(-1px);

  /* ✅ ensure above toggle */
  z-index: 2;
}

/* =========================
   STATES (RISK / LOCKED)
========================= */

.hscrm-cap-risk {
  background: #fff5f5;
}
.hscrm-cap-risk:hover {
  background: #fde8e8;
}

.hscrm-cap-risk input:checked ~ .hscrm-cap-label {
  color: #b32d2e;
  font-weight: 600;
}

.hscrm-cap-risk:has(input:checked) {
  background: #fde8e8;
}

.hscrm-cap-locked {
  background: #f6f7f7;
  opacity: 0.7;
}

/* =========================
   TOGGLE
========================= */

.hscrm-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 18px;
  flex: 0 0 36px;
  margin-right: 6px;

  /* ✅ keep below tooltip */
  z-index: 1;
}

/* clickable overlay */
.hscrm-toggle input {
  position: relative;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

/* track */
.hscrm-toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccd0d4;
  border-radius: 999px;
  transition: background-color 0.2s ease;

  /* ✅ keep below tooltip */
  z-index: 1;
}

/* knob */
.hscrm-toggle-slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  top: 2px;
  left: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* checked */
.hscrm-toggle input:checked + .hscrm-toggle-slider {
  background: #2271b1;
}

.hscrm-toggle input:checked + .hscrm-toggle-slider::before {
  transform: translateX(18px);
}

/* high risk override */
.hscrm-cap-risk .hscrm-toggle input:checked + .hscrm-toggle-slider {
  background: #d63638;
}

/* locked */
.hscrm-cap-locked .hscrm-toggle-slider {
  background: #e0e0e0;
  cursor: not-allowed;
}

.hscrm-cap-locked .hscrm-toggle-slider::before {
  background: #bbb;
}

/* =========================
   TOOLTIP
========================= */

.hscrm-tooltip-trigger {
  position: relative;
  cursor: help;
  pointer-events: auto;
  color: #d63638;
}

.hscrm-tooltip {
  position: absolute;
  bottom: 140%;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: #1d2327;
  color: #fff;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.15s ease,
    transform 0.15s ease;

  /* ✅ FINAL FIX */
  z-index: 1000000 !important;
  pointer-events: none;
}

.hscrm-tooltip-trigger:hover .hscrm-tooltip,
.hscrm-tooltip-trigger:focus .hscrm-tooltip {
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateX(-50%) translateY(0);
}

/* =========================
   UTIL
========================= */

.d-none {
  display: none !important;
}

/* lock tooltip color */
.hscrm-lock-tooltip {
  color: #666;
}

/* =========================
   INLINE VALIDATION (NO SHIFT)
========================= */

.hscrm-error,
.hscrm-success {
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
}

.hscrm-error {
  font-weight: 700;
  color: #d63638;
}

.hscrm-success {
  font-weight: 500;
  color: #46b450;
}

.role-slug + .hscrm-error {
  right: 0;
  left: auto;
}

.hscrm-col:has(.role-slug) .hscrm-success {
  right: 0;
  left: auto;
  text-align: right;
}

.hscrm-inline-error {
  position: absolute;
  right: 0;
  top: 100%;
  font-size: 12px;
  white-space: nowrap;
}

/* =========================
   CAP PRESETS LAYOUT
========================= */

.hscrm-cap-presets {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hscrm-cap-presets-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hscrm-toggle-caps {
  margin-left: auto;
  white-space: nowrap;
}

.hscrm-uninstall-setting {
  margin-bottom: 16px;
}

.hscrm-group-label {
  font-size: 13px;
  color: #1d2327;
  margin-top: 12px;
}

.hscrm-role-row hr {
  border: none;
  border-top: 1px solid #ccd0d4;
}

.hscrm-group-label {
  font-weight: 600;
  margin: 12px 0 6px;
  color: #1d2327;
}

.hscrm-separator {
  border-top: 1px solid #ccd0d4;
  margin: 10px 0;
}

.hscrm-role-item {
  display: block;
  margin: 4px 0 4px 10px;
}

#hscrm-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;

  padding: 12px 16px;
  border-radius: 6px;

  font-size: 13px;
  font-weight: 500;

  background: #1d2327;
  color: #fff;

  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);

  display: none;
}

#hscrm-toast.success {
  background: #00a32a;
}

#hscrm-toast.error {
  background: #d63638;
}

#hscrm-toast.info {
  background: #2271b1;
}

.hscrm-slug-error {
  color: #d63638;
  font-size: 12px;
}

.hscrm-col input.role-slug.hscrm-invalid {
  border-color: #d63638;
}

.hscrm-support-wrap {
  text-align: center;
  margin: 20px 0;
}

.hscrm-support-button {
  display: inline-block;
  padding: 10px 18px;
  background: #ffdd00;
  color: #000;
  font-weight: 600;
  text-decoration: none;
  border-radius: 6px;
  border: 1px solid #d4b800;
  transition: all 0.2s ease;
}

.hscrm-support-button:hover {
  background: #ffd000;
  color: #000;
  text-decoration: none;
}
