.page-roles {
  padding: 18px 0 40px;
}

.roles-hero {
  margin-bottom: 18px;
  padding: 30px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.roles-hero__copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  max-width: 760px;
}

.roles-hero__actions {
  flex: 0 0 auto;
}

.roles-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.roles-stat {
  padding: 18px;
  border-radius: 24px;
}

.roles-stat__label {
  display: block;
  color: #c9c1b3;
  font-size: 0.86rem;
  margin-bottom: 8px;
}

.roles-stat__value {
  color: #fff8ef;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
  line-height: 1;
}

.roles-toolbar {
  padding: 18px;
  margin-bottom: 18px;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.roles-filters,
.roles-toolbar__inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.roles-select {
  min-height: 48px;
  min-width: min(100%, 220px);
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.04);
  color: #f8f3ea;
  padding: 0 14px;
  outline: none;
}

.roles-select option {
  background: #2f3841;
  color: #fff;
}

.roles-search {
  min-width: min(100%, 320px);
}

.roles-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  align-items: start;
}

.roles-help {
  padding: 22px;
  border-radius: 28px;
  position: sticky;
  top: 116px;
}

.roles-help h2 {
  margin: 0 0 10px;
  color: #fff8ef;
  font-size: 1.25rem;
}

.roles-help p {
  margin: 0;
  color: #c9c1b3;
  line-height: 1.6;
}

.roles-help code {
  color: #efe3c8;
}

.roles-help__legend {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.linked-roles-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 18px;
}

.linked-role-card {
  position: relative;
  overflow: hidden;
  min-height: 292px;
  padding: 22px;
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-color: rgba(255,255,255,.08);
}

.linked-role-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top right, color-mix(in srgb, var(--role-color) 26%, transparent), transparent 32%),
    linear-gradient(180deg, rgba(255,255,255,.035), transparent);
  pointer-events: none;
}

.linked-role-card > * {
  position: relative;
  z-index: 1;
}

.linked-role-card__top {
  display: flex;
  align-items: center;
  gap: 14px;
}

.linked-role-card__icon {
  width: 62px;
  height: 62px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--role-color) 25%, rgba(255,255,255,.06));
  border: 1px solid color-mix(in srgb, var(--role-color) 34%, rgba(255,255,255,.1));
  color: #fff8ef;
  font-weight: 900;
  letter-spacing: .02em;
  flex: 0 0 auto;
}

.linked-role-card__icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.linked-role-card__title-wrap {
  min-width: 0;
}

.linked-role-card__title {
  margin: 0 0 7px;
  color: #fff8ef;
  font-size: 1.2rem;
  line-height: 1.1;
}

.linked-role-card__server {
  margin: 0;
  color: #c9c1b3;
  font-size: .92rem;
}

.linked-role-card__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.role-pill {
  min-height: 30px;
  padding: 6px 11px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.045);
  color: #e7dfd2;
  font-size: .78rem;
  font-weight: 800;
}

.role-pill--linked {
  background: rgba(158,214,163,.12);
  border-color: rgba(158,214,163,.18);
  color: #d8f4da;
}

.role-pill--configured {
  background: rgba(171,201,255,.12);
  border-color: rgba(171,201,255,.18);
  color: #dbe8ff;
}

.role-pill--warning {
  background: rgba(255,196,112,.12);
  border-color: rgba(255,196,112,.2);
  color: #ffe2b6;
}

.role-pill--owned {
  background: rgba(35,165,90,.14);
  border-color: rgba(35,165,90,.26);
  color: #c9f7d4;
}

.role-pill--metadata {
  background: rgba(88,101,242,.18);
  border-color: rgba(88,101,242,.34);
  color: #dde1ff;
}

.role-pill--metadata-soft {
  background: rgba(88,101,242,.1);
  border-color: rgba(88,101,242,.18);
  color: #cfd4ff;
}

.role-pill--muted {
  background: rgba(148,155,164,.1);
  border-color: rgba(148,155,164,.16);
  color: #c7cbd1;
}

.roles-user-status {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(49,51,56,.58), rgba(30,31,36,.5)),
    rgba(255,255,255,.035);
  border: 1px solid rgba(255,255,255,.08);
}

.roles-user-status__head,
.roles-status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.roles-user-status__head {
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.roles-user-status__head span,
.roles-status-line span {
  color: #aeb7bf;
  font-size: .78rem;
  font-weight: 800;
}

.roles-user-status__head strong {
  color: #fff8ef;
  font-size: .82rem;
}

.roles-status-line strong {
  min-width: 0;
  color: #e7dfd2;
  text-align: right;
  font-size: .8rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.roles-status-line--ok strong {
  color: #c9f7d4;
}

.roles-status-line--warn strong {
  color: #ffe2b6;
}

.roles-rule-grid {
  display: grid;
  gap: 10px;
}

.roles-rule {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(255,255,255,.07);
}

.roles-rule__label {
  display: block;
  margin-bottom: 10px;
  color: #aeb7bf;
  font-size: .82rem;
  font-weight: 800;
}

.roles-rule__items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.roles-rule__empty {
  color: #c9c1b3;
  font-size: .9rem;
}

.mini-role {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  color: #f9f5ee;
  background: color-mix(in srgb, var(--role-color) 28%, rgba(255,255,255,.05));
  border: 1px solid color-mix(in srgb, var(--role-color) 38%, rgba(255,255,255,.08));
  font-size: .8rem;
  font-weight: 800;
}

.linked-role-card__foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #aeb7bf;
  font-size: .84rem;
}

.linked-role-card__foot code {
  color: #efe3c8;
  font-size: .78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.linked-role-card__actions {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.linked-role-card__actions .secondary-btn {
  min-height: 38px;
  padding: 9px 12px;
  font-size: 0.82rem;
}

.linked-role-card.is-appear {
  opacity: 0;
  transform: translateY(18px) scale(.985);
  animation: linkedRoleIn .55s cubic-bezier(.2,.75,.2,1) forwards;
  animation-delay: var(--delay, 0ms);
}

@keyframes linkedRoleIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.linked-role-card--skeleton {
  min-height: 250px;
}

.skeleton-role-icon {
  width: 62px;
  height: 62px;
  border-radius: 22px;
}

.page-roles .empty-state {
  margin-top: 0;
  grid-column: 1 / -1;
}

@media (max-width: 980px) {
  .roles-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .roles-layout {
    grid-template-columns: 1fr;
  }

  .roles-help {
    position: static;
  }
}

@media (max-width: 720px) {
  .roles-hero,
  .roles-toolbar {
    align-items: stretch;
  }

  .roles-hero {
    flex-direction: column;
    padding: 22px;
  }

  .roles-hero__actions,
  .roles-toolbar__inputs,
  .roles-select,
  .roles-search {
    width: 100%;
  }

  .linked-roles-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .roles-stats-grid {
    grid-template-columns: 1fr;
  }

  .linked-role-card,
  .roles-help {
    padding: 18px;
  }
}
