/* ── Permissions Management Panel ────────────────────────────────────────────── */

.pm-panel {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: #0d1117;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.pm-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: #161b22;
  border-bottom: 1px solid #21262d;
  flex-shrink: 0;
}

.pm-back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #8b949e;
  font-size: 13px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.pm-back-btn:hover { color: #dce3ed; border-color: #8b949e; }
.pm-back-btn .material-symbols-outlined { font-size: 16px; }

.pm-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: #dce3ed;
}
.pm-header-title .material-symbols-outlined { font-size: 20px; color: #c9f31d; }

.pm-header-team {
  margin-left: auto;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #dce3ed;
  padding: 6px 14px;
  border: 1px solid #2a3040;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(201,243,29,0.08), rgba(201,243,29,0.02));
  display: flex;
  align-items: center;
  gap: 8px;
}
.pm-header-team::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9f31d;
  box-shadow: 0 0 8px rgba(201,243,29,0.5);
}

/* Body: two columns */
.pm-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.pm-col {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pm-templates-col {
  width: 380px;
  min-width: 280px;
  border-right: 1px solid #21262d;
  flex-shrink: 0;
  overflow-y: auto;
}

.pm-members-col {
  flex: 1;
  overflow-y: auto;
}

.pm-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  font-size: 13px;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid #21262d;
  flex-shrink: 0;
}

.pm-new-btn {
  padding: 5px 12px;
  background: #c9f31d;
  color: #0d1117;
  border: none;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.pm-new-btn:hover { opacity: .85; }

.pm-col-header-members { gap: 12px; flex-wrap: wrap; }

.pm-members-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.pm-members-search,
.pm-members-sort {
  padding: 5px 10px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 5px;
  color: #dce3ed;
  font-size: 12px;
  font-family: inherit;
}
.pm-members-search { width: 220px; }
.pm-members-sort { cursor: pointer; }
.pm-members-search::placeholder { color: #3a4555; }
.pm-members-search:focus,
.pm-members-sort:focus { outline: none; border-color: #c9f31d; }

/* Empty state */
.pm-empty {
  padding: 24px 20px;
  font-size: 12px;
  color: #3a4555;
  line-height: 1.5;
}

/* Template cards */
.pm-tpl-card {
  padding: 14px 20px;
  border-bottom: 1px solid #21262d;
  transition: background .1s;
}
.pm-tpl-card:hover { background: #161b22; }

.pm-tpl-name {
  font-size: 14px;
  font-weight: 600;
  color: #dce3ed;
  margin-bottom: 6px;
}

.pm-tpl-meta {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.pm-tpl-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #8b949e;
  background: #21262d;
  padding: 2px 8px;
  border-radius: 10px;
}
.pm-tpl-badge .material-symbols-outlined { font-size: 13px; }

.pm-tpl-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.pm-tpl-perms {
  display: flex;
  align-items: center;
  gap: 3px;
}

.pm-perm-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  cursor: default;
}
.pm-perm-badge.on  { background: rgba(201,243,29,.18); color: #c9f31d; }
.pm-perm-badge.off { background: #21262d; color: #3a4555; }

.pm-tpl-divider { color: #21262d; margin: 0 2px; }

.pm-tpl-btn {
  padding: 4px 10px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 5px;
  color: #8b949e;
  font-size: 11px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.pm-tpl-btn:hover { color: #dce3ed; border-color: #8b949e; }
.pm-tpl-btn.danger:hover { color: #f85149; border-color: #f85149; }

.pm-tpl-used {
  font-size: 11px;
  color: #3a4555;
}

/* Template editor */
.pm-template-editor {
  margin: 0;
  padding: 16px 20px;
  background: #161b22;
  border-top: 1px solid #21262d;
}

.pm-te-title {
  font-size: 13px;
  font-weight: 600;
  color: #dce3ed;
  margin-bottom: 12px;
}

/* Member rows */
.pm-member-row {
  border-bottom: 1px solid #21262d;
}

.pm-member-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background .1s;
}
.pm-member-top:hover { background: #161b22; }

.pm-member-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #21262d;
  color: #8b949e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.pm-member-info {
  flex: 1;
  min-width: 0;
}
.pm-member-name {
  font-size: 13px;
  font-weight: 600;
  color: #dce3ed;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pm-member-email {
  font-size: 11px;
  color: #3a4555;
}

.pm-member-summary {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 12px;
  color: #8b949e;
  text-align: right;
  min-width: 120px;
}
.pm-member-access-hint {
  font-size: 10px;
  color: #3a4555;
}

.pm-bypass-badge {
  font-size: 11px;
  background: rgba(201,243,29,.1);
  color: #c9f31d;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.pm-member-chevron {
  font-size: 18px;
  color: #3a4555;
  flex-shrink: 0;
}

.pm-member-bypassed .pm-member-top { opacity: .6; }
.pm-member-bypassed .pm-member-top:hover { background: transparent; cursor: default; }

/* Member editor */
.pm-member-editor {
  padding: 16px 20px 20px 68px;
  background: #0d1117;
  border-top: 1px solid #21262d;
}

/* Shared form elements */
.pm-me-section {
  margin-bottom: 16px;
}

.pm-me-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}

.pm-me-select,
.pm-me-input {
  padding: 7px 10px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #dce3ed;
  font-size: 13px;
  min-width: 200px;
}
.pm-me-select:focus,
.pm-me-input:focus {
  outline: none;
  border-color: #c9f31d;
}

.pm-me-perms-grid {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.pm-me-perms-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 140px;
}

.pm-me-perms-head {
  font-size: 11px;
  font-weight: 700;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 4px;
}

.pm-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #8b949e;
  cursor: pointer;
  user-select: none;
}
.pm-check-label:hover { color: #dce3ed; }
.pm-check-label input[type=checkbox] {
  accent-color: #c9f31d;
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.pm-access-picker {
  padding: 10px 12px;
  background: #161b22;
  border: 1px solid #21262d;
  border-radius: 6px;
}

.pm-pick-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
  padding-top: 6px;
  border-top: 1px solid #21262d;
  margin-top: 6px;
}

.pm-me-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.pm-me-save-btn {
  padding: 7px 18px;
  background: #c9f31d;
  color: #0d1117;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.pm-me-save-btn:hover { opacity: .85; }

.pm-me-reset-btn {
  padding: 7px 14px;
  background: transparent;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #8b949e;
  font-size: 13px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.pm-me-reset-btn:hover { color: #f85149; border-color: #f85149; }

/* Role guide button in the header */
.pm-role-guide-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; margin-left: 12px;
  background: transparent; border: 1px solid #30363d; border-radius: 6px;
  color: #8b949e; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.pm-role-guide-btn:hover { color: #c9f31d; border-color: #c9f31d; }
.pm-role-guide-btn .material-symbols-outlined { font-size: 16px; }

/* Shared overlay for reassign + role-guide modals.
   Must sit ABOVE .pm-panel (z-index 3000) — both are appended to <body>. */
.pm-reassign-overlay {
  position: fixed; inset: 0; z-index: 3100;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.pm-reassign-modal {
  width: 100%; max-width: 420px;
  background: #0f1318; border: 1px solid #21262d; border-radius: 14px;
  padding: 22px; display: flex; flex-direction: column; gap: 14px;
}
.pm-reassign-title { font-size: 17px; font-weight: 700; color: #dce3ed; }
.pm-reassign-msg { font-size: 13px; color: #8b949e; line-height: 1.5; }
.pm-reassign-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.pm-guide-modal { max-width: 480px; }
.pm-guide-list { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow-y: auto; }
.pm-guide-row { display: flex; flex-direction: column; gap: 2px; padding-bottom: 8px; border-bottom: 1px solid #1a2030; }
.pm-guide-row:last-child { border-bottom: none; }
.pm-guide-role { font-size: 13px; font-weight: 700; color: #c9f31d; }
.pm-guide-desc { font-size: 12px; color: #8b949e; line-height: 1.5; }

body.light-mode .pm-reassign-modal { background: #ffffff; border-color: #dde2ec; }
body.light-mode .pm-reassign-title { color: #1a2030; }
body.light-mode .pm-role-guide-btn { border-color: #dde2ec; color: #6b7a8d; }
body.light-mode .pm-role-guide-btn:hover { color: #5a7a00; border-color: #7aa400; }
body.light-mode .pm-guide-role { color: #5a7a00; }

/* Mobile adjustments */
@media (max-width: 700px) {
  .pm-body { flex-direction: column; }
  .pm-templates-col { width: 100%; border-right: none; border-bottom: 1px solid #21262d; max-height: 50vh; }
  .pm-member-editor { padding-left: 20px; }
  .pm-header { flex-wrap: wrap; gap: 8px; }
}

/* ── Tab permission grid ───────────────────────────────────────────────────── */

.pm-tab-perm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 4px;
}

.pm-tab-perm-table thead th {
  padding: 4px 8px 6px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid #21262d;
}
.pm-tab-perm-table thead th:first-child {
  text-align: left;
  width: 110px;
}

.pm-tab-perm-table tbody tr:hover { background: rgba(255,255,255,.03); }

.pm-tab-label {
  padding: 5px 8px 5px 0;
  color: #8b949e;
  font-size: 12px;
  white-space: nowrap;
  vertical-align: middle;
}

.pm-tab-action-cell {
  text-align: center;
  vertical-align: middle;
  padding: 4px 2px;
  position: relative;
}

.pm-tab-action-cell input[type=checkbox] {
  accent-color: #c9f31d;
  width: 14px;
  height: 14px;
  cursor: pointer;
  display: block;
  margin: 0 auto;
}

.pm-tab-from-tpl {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 9px;
  color: #3a4555;
  line-height: 1;
  pointer-events: none;
}

/* ── Light mode ────────────────────────────────────────────────────────────── */
body.light-mode .pm-panel { background: #f0f3f8; }

body.light-mode .pm-header { background: #ffffff; border-bottom-color: #dde2ec; }
body.light-mode .pm-back-btn { background: #eef0f5; border-color: #dde2ec; color: #6b7a8d; }
body.light-mode .pm-back-btn:hover { color: #1a2030; border-color: #8899aa; }
body.light-mode .pm-header-title { color: #1a2030; }
body.light-mode .pm-header-title .material-symbols-outlined { color: #5a7a00; }
body.light-mode .pm-header-team {
  color: #1a2030;
  border-color: #dde2ec;
  background: linear-gradient(180deg, rgba(122,164,0,0.10), rgba(122,164,0,0.02));
}
body.light-mode .pm-header-team::before { background: #7aa400; box-shadow: 0 0 8px rgba(122,164,0,0.4); }

body.light-mode .pm-templates-col { border-right-color: #dde2ec; }
body.light-mode .pm-col-header { color: #8899aa; border-bottom-color: #dde2ec; }

body.light-mode .pm-empty { color: #b0b8c4; }

body.light-mode .pm-members-search,
body.light-mode .pm-members-sort { background: #ffffff; border-color: #dde2ec; color: #1a2030; }
body.light-mode .pm-members-search::placeholder { color: #b0b8c4; }
body.light-mode .pm-members-search:focus,
body.light-mode .pm-members-sort:focus { border-color: #5a7a00; }

body.light-mode .pm-tpl-card { border-bottom-color: #dde2ec; }
body.light-mode .pm-tpl-card:hover { background: #f5f7fb; }
body.light-mode .pm-tpl-name { color: #1a2030; }
body.light-mode .pm-tpl-badge { background: #eef0f5; color: #6b7a8d; }
body.light-mode .pm-perm-badge.on  { background: rgba(90,122,0,.15); color: #5a7a00; }
body.light-mode .pm-perm-badge.off { background: #eef0f5; color: #c8d0dc; }
body.light-mode .pm-tpl-btn { background: #eef0f5; border-color: #dde2ec; color: #6b7a8d; }
body.light-mode .pm-tpl-btn:hover { color: #1a2030; border-color: #8899aa; }
body.light-mode .pm-tpl-btn.danger:hover { color: #dc2626; border-color: #ef4444; }
body.light-mode .pm-tpl-used { color: #b0b8c4; }

body.light-mode .pm-template-editor { background: #ffffff; border-top-color: #dde2ec; }
body.light-mode .pm-te-title { color: #1a2030; }

body.light-mode .pm-member-row { border-bottom-color: #dde2ec; }
body.light-mode .pm-member-top:hover { background: #f5f7fb; }
body.light-mode .pm-member-avatar { background: #eef0f5; color: #6b7a8d; }
body.light-mode .pm-member-name { color: #1a2030; }
body.light-mode .pm-member-email { color: #b0b8c4; }
body.light-mode .pm-member-summary { color: #6b7a8d; }
body.light-mode .pm-member-access-hint { color: #b0b8c4; }
body.light-mode .pm-bypass-badge { background: rgba(90,122,0,.1); color: #5a7a00; }
body.light-mode .pm-member-chevron { color: #c8d0dc; }
body.light-mode .pm-member-bypassed .pm-member-top:hover { background: transparent; }

body.light-mode .pm-member-editor { background: #f5f7fb; border-top-color: #dde2ec; }

body.light-mode .pm-me-label { color: #8899aa; }
body.light-mode .pm-me-select,
body.light-mode .pm-me-input { background: #ffffff; border-color: #dde2ec; color: #1a2030; }
body.light-mode .pm-me-select:focus,
body.light-mode .pm-me-input:focus { border-color: #5a7a00; }
body.light-mode .pm-me-perms-head { color: #8899aa; }

body.light-mode .pm-check-label { color: #6b7a8d; }
body.light-mode .pm-check-label:hover { color: #1a2030; }

body.light-mode .pm-access-picker { background: #ffffff; border-color: #dde2ec; }
body.light-mode .pm-pick-list { border-top-color: #dde2ec; }

body.light-mode .pm-me-reset-btn { border-color: #dde2ec; color: #6b7a8d; }
body.light-mode .pm-me-reset-btn:hover { color: #dc2626; border-color: #ef4444; }

body.light-mode .pm-tab-perm-table thead th { color: #8899aa; border-bottom-color: #dde2ec; }
body.light-mode .pm-tab-perm-table tbody tr:hover { background: rgba(0,0,0,.03); }
body.light-mode .pm-tab-label { color: #6b7a8d; }
body.light-mode .pm-tab-from-tpl { color: #c8d0dc; }
