/*
 * Role ↔ Policy permission matrix (RBAC inline).
 * Renders each policy as a row of View / Create / Edit / Delete toggle
 * switches, grouped by app. Pure CSS — no JS.
 */

/* Matrix grid: resource column + 4 action columns. Rows/groups become grid
   items via display:contents so every row shares the same column track. */
.rpc-matrix {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) repeat(4, 64px);
    align-items: center;
    min-width: 480px;
    background: #ffffff;
}
@media (prefers-color-scheme: dark) {
    .rpc-matrix {
        background: #111827;
    }
}

.rpc-matrix__head,
.rpc-matrix__row {
    display: contents;
}

/* Header cells */
.rpc-matrix__col {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.625rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}
.rpc-matrix__col--resource {
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.rpc-matrix__col:not(.rpc-matrix__col--resource) {
    justify-content: center;
}
.rpc-matrix__col-icon {
    font-size: 16px !important;
    line-height: 1;
}
@media (prefers-color-scheme: dark) {
    .rpc-matrix__col {
        color: #9ca3af;
        background: #1f2937;
        border-bottom-color: #374151;
    }
}

/* App group band */
.rpc-matrix__group {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-top: 0.25rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: #4f46e5;
    background: linear-gradient(90deg, #eef2ff 0%, rgba(238, 242, 255, 0) 100%);
    border-radius: 0.5rem;
}
.rpc-matrix__group:first-of-type {
    margin-top: 0;
}
.rpc-matrix__group-icon {
    font-size: 18px !important;
    line-height: 1;
}
.rpc-matrix__group-count {
    margin-left: auto;
    padding: 0.05rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: #6366f1;
    background: #ffffff;
    border: 1px solid #c7d2fe;
    border-radius: 9999px;
}
@media (prefers-color-scheme: dark) {
    .rpc-matrix__group {
        color: #a5b4fc;
        background: linear-gradient(90deg, #1e2540 0%, rgba(30, 37, 64, 0) 100%);
    }
    .rpc-matrix__group-count {
        color: #c7d2fe;
        background: #111827;
        border-color: #374151;
    }
}

/* Policy rows */
.rpc-matrix__cell {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid #f1f5f9;
}
.rpc-matrix__resource {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
}
.rpc-matrix__name {
    font-size: 0.875rem;
    font-weight: 600;
    color: #111827;
    line-height: 1.25;
}
.rpc-matrix__code {
    font-size: 0.7rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: #94a3b8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rpc-matrix__cell--action {
    display: flex;
    justify-content: center;
}
.rpc-matrix__row:hover > .rpc-matrix__cell {
    background: #f8fafc;
}
@media (prefers-color-scheme: dark) {
    .rpc-matrix__cell {
        border-bottom-color: #1f2937;
    }
    .rpc-matrix__name {
        color: #f3f4f6;
    }
    .rpc-matrix__row:hover > .rpc-matrix__cell {
        background: #161e2e;
    }
}

/* Modern toggle switch */
.rpc-switch {
    position: relative;
    display: inline-flex;
    cursor: pointer;
}
.rpc-switch__input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.rpc-switch__track {
    position: relative;
    width: 34px;
    height: 20px;
    border-radius: 9999px;
    background: #cbd5e1;
    transition: background-color 0.15s ease;
}
.rpc-switch__thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 9999px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s ease;
}
.rpc-switch__input:focus-visible + .rpc-switch__track {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
}
.rpc-switch__input:checked + .rpc-switch__track {
    background: var(--rpc-color, #0ea5e9);
}
.rpc-switch__input:checked + .rpc-switch__track .rpc-switch__thumb {
    transform: translateX(14px);
}

/* Per-action colors */
.rpc-switch[data-control="retrieve"] {
    --rpc-color: #0ea5e9;
}
.rpc-switch[data-control="create"] {
    --rpc-color: #10b981;
}
.rpc-switch[data-control="update"] {
    --rpc-color: #f59e0b;
}
.rpc-switch[data-control="delete"] {
    --rpc-color: #ef4444;
}
