/* =========================================================================
   PermissionsDialogV2 — role-comparison permissions matrix.
   Ported from the Claude Design handoff ("Permissions Redesign" / direction-b).
   Palette is intentionally distinct from the app theme (faithful recreation);
   everything is scoped under .pdv2-root / .pdv2-toolbar so nothing leaks.
   ========================================================================= */

.pdv2-root,
.pdv2-toolbar {
    --pdv2-bg: #0f0f12;
    --pdv2-panel: #1b1b1f;
    --pdv2-panel2: #212127;
    --pdv2-border: #2c2c33;
    --pdv2-border2: #3a3a43;
    --pdv2-text: #e9e9ec;
    --pdv2-muted: #9a9aa4;
    --pdv2-faint: #6a6a73;
    --pdv2-purple: #8b5cf6;
    --pdv2-purple-soft: rgba(139, 92, 246, .16);
    --pdv2-gold: #e9b949;
    --pdv2-gold-soft: rgba(233, 185, 73, .13);
    --pdv2-danger: #e5645d;
    --pdv2-danger-soft: rgba(229, 100, 93, .14);

    --pdv2-labelw: 340px;
    --pdv2-colw: 150px;
}

/* ---------- toolbar (search + segmented filter, lives in the dialog title bar) ---------- */
.pdv2-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.pdv2-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    width: 240px;
    background: var(--pdv2-panel2);
    border: 1px solid var(--pdv2-border);
    border-radius: 10px;
}

.pdv2-search input {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    outline: none;
    color: var(--pdv2-text);
    font-family: inherit;
    font-size: 13px;
}

.pdv2-search input::placeholder { color: var(--pdv2-faint); }
.pdv2-search-ico { color: var(--pdv2-faint); font-size: 16px; line-height: 1; }

.pdv2-clear {
    background: none;
    border: none;
    color: var(--pdv2-faint);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    line-height: 1;
}

.pdv2-clear:hover { color: var(--pdv2-text); }

.pdv2-seg {
    display: flex;
    background: var(--pdv2-panel);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--pdv2-border);
}

.pdv2-seg button {
    border: none;
    background: none;
    color: var(--pdv2-muted);
    padding: 7px 14px;
    border-radius: 7px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: .13s;
    white-space: nowrap;
}

.pdv2-seg button:hover { color: var(--pdv2-text); }
.pdv2-seg button.on { background: var(--pdv2-purple); color: #fff; }

/* ---------- shared chips ---------- */
.pdv2-tag {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    border-radius: 5px;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: .3px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--pdv2-purple-soft);
    color: #b9a3ff;
}

.pdv2-tag.danger { background: var(--pdv2-danger-soft); color: #f08a85; }

.pdv2-pill {
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 20px;
    background: var(--pdv2-gold-soft);
    color: var(--pdv2-gold);
    border: 1px solid rgba(233, 185, 73, .25);
    white-space: nowrap;
}

.pdv2-empty {
    color: var(--pdv2-faint);
    padding: 40px;
    text-align: center;
    font-size: 14px;
}

/* ---------- matrix shell ---------- */
.pdv2-root {
    /* cancel the template's pl-3/pr-3 so the matrix runs edge to edge */
    margin: 0 -12px;
    background: var(--pdv2-bg);
    color: var(--pdv2-text);
    font-size: 14px;
}

.pdv2-scroll {
    overflow: auto;
    max-height: 72vh;
}

.pdv2-scroll::-webkit-scrollbar { height: 12px; width: 12px; }

.pdv2-scroll::-webkit-scrollbar-thumb {
    background: #3a3a43;
    border-radius: 7px;
    border: 3px solid var(--pdv2-bg);
}

.pdv2-scroll::-webkit-scrollbar-thumb:hover { background: #4a4a55; }

/* ---------- Wide Screen / fullscreen: let the matrix fill the whole dialog height ----------
   In normal mode the matrix is capped at 72vh (above) and scrolls internally. When the user
   hits "Wide Screen" the dialog becomes full-height (.mud-dialog-fullscreen), so we turn the
   dialog → content → matrix chain into a flex column and let .pdv2-scroll grow to fill.
   Scoped with :has(.pdv2-root) so only THIS dialog (not other fullscreen Kenny dialogs) is affected. */
.mud-dialog-fullscreen:has(.pdv2-root) {
    display: flex;
    flex-direction: column;
}

.mud-dialog-fullscreen:has(.pdv2-root) .mud-dialog-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mud-dialog-fullscreen:has(.pdv2-root) .kenny-scroll-container,
.mud-dialog-fullscreen:has(.pdv2-root) .kenny-form-section,
.mud-dialog-fullscreen:has(.pdv2-root) .pdv2-root {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

.mud-dialog-fullscreen:has(.pdv2-root) .pdv2-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

/* ---------- header row ---------- */
.pdv2-head {
    display: grid;
    align-items: stretch;
    width: max-content;
    min-width: 100%;
    position: sticky;
    top: 0;
    z-index: 4;
    background: #161619;
    border-bottom: 1px solid var(--pdv2-border2);
}

.pdv2-h-label {
    padding: 0 24px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--pdv2-faint);
    font-weight: 700;
    display: flex;
    align-items: center;
    position: sticky;
    left: 0;
    z-index: 6;
    background: #161619;
    border-right: 1px solid var(--pdv2-border2);
}

.pdv2-h-role {
    padding: 13px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    border-left: 1px solid var(--pdv2-border);
    justify-content: center;
    text-align: center;
}

.pdv2-h-name { font-size: 12.5px; font-weight: 600; line-height: 1.2; }
.pdv2-h-count { font-size: 12px; font-weight: 700; color: var(--pdv2-muted); font-variant-numeric: tabular-nums; }
.pdv2-h-den { color: var(--pdv2-faint); font-weight: 600; }

.pdv2-h-role.gold .pdv2-h-name { color: var(--pdv2-gold); }
.pdv2-h-role.gold .pdv2-h-count { color: rgba(233, 185, 73, .7); }

/* launched-from role gets a subtle purple wash + underline */
.pdv2-h-role.launched {
    background: var(--pdv2-purple-soft);
    box-shadow: inset 0 -2px 0 0 var(--pdv2-purple);
}

/* ---------- group row ---------- */
.pdv2-grp {
    display: grid;
    align-items: center;
    width: max-content;
    min-width: 100%;
    background: #1c1c21;
    border-bottom: 1px solid var(--pdv2-border);
    border-top: 1px solid var(--pdv2-border);
}

.pdv2-grp-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 24px;
    background: #1c1c21;
    border: none;
    color: var(--pdv2-text);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    width: 100%;
    position: sticky;
    left: 0;
    z-index: 3;
    border-right: 1px solid var(--pdv2-border);
}

.pdv2-caret {
    color: var(--pdv2-faint);
    font-size: 19px;
    transition: .15s;
    display: inline-block;
}

.pdv2-caret.open { transform: rotate(90deg); }
.pdv2-grp-name { font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.pdv2-grp.danger .pdv2-grp-name { color: #f08a85; }

.pdv2-grp-count {
    border-left: 1px solid var(--pdv2-border);
    height: 100%;
    background: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    color: var(--pdv2-muted);
    font-variant-numeric: tabular-nums;
    transition: .12s;
}

.pdv2-grp-count:hover { background: var(--pdv2-panel2); color: var(--pdv2-text); }
.pdv2-grp-count.full { color: #b9a3ff; }
.pdv2-grp-count.zero { color: var(--pdv2-faint); }

/* ---------- permission row ---------- */
.pdv2-item {
    display: grid;
    align-items: center;
    width: max-content;
    min-width: 100%;
    border-bottom: 1px solid rgba(44, 44, 51, .6);
}

.pdv2-item:hover { background: var(--pdv2-panel); }

.pdv2-item-label {
    padding: 12px 24px 12px 25px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    line-height: 1.4;
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--pdv2-bg);
    border-right: 1px solid rgba(44, 44, 51, .6);
}

.pdv2-item:hover .pdv2-item-label { background: var(--pdv2-panel); }

.pdv2-item-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    border-left: 1px solid rgba(44, 44, 51, .6);
    padding: 9px 0;
}

.pdv2-cell {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 1.5px solid #41414b;
    background: var(--pdv2-panel2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: .12s;
    padding: 0;
}

.pdv2-cell:hover { border-color: var(--pdv2-purple); }
.pdv2-cell.on { background: var(--pdv2-purple); border-color: var(--pdv2-purple); }
.pdv2-cell.on.danger { background: var(--pdv2-danger); border-color: var(--pdv2-danger); }

.pdv2-check {
    width: 11px;
    height: 6px;
    border-left: 2.5px solid #fff;
    border-bottom: 2.5px solid #fff;
    transform: rotate(-45deg) translateY(-1px);
}
