/* Department RBAC add-on for the web vault (see org_departments_vault.js).
   The sidebar entry is a clone of the vault's own nav-group markup, so it needs no styling here.
   Colors come from the web vault's own CSS variables, with fallbacks. */

/* The native "Members" entry is replaced by the "Departments" group. */
body.vw-dept-nav-ready bit-nav-item[route="members"],
body.vw-dept-nav-ready bit-nav-group[route="members"] {
  display: none !important;
}

/* Native elements we replace (the members page while the department list is shown,
   the role picker in the invite/edit dialogs). */
.vw-dept-native-hidden {
  display: none !important;
}

.vw-dept-hidden {
  display: none !important;
}

/* While the members page is reloaded by a quick hop through the vault route. */
body.vw-dept-bouncing app-layout router-outlet ~ *,
body.vw-dept-bouncing organization-layout router-outlet ~ * {
  visibility: hidden !important;
}

/* ——— Department list (shown in place of the members page) ——— */

#vw-dept-list-host {
  font-size: 0.875rem;
  color: rgb(var(--color-text-main, 27 32 41));
}

.vw-dept-shell {
  padding: 1.5rem 0 2.5rem;
}

.vw-dept-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgb(var(--color-secondary-100, 230 233 239));
}
.vw-dept-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.vw-dept-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.2;
}
.vw-dept-sub {
  max-width: 46rem;
  margin: 0.375rem 0 0;
  color: rgb(var(--color-text-muted, 96 109 145));
}

.vw-dept-table-wrap {
  overflow-x: auto;
  border: 1px solid rgb(var(--color-secondary-100, 230 233 239));
  border-radius: 8px;
  background: rgb(var(--color-background, 255 255 255));
}
.vw-dept-table {
  width: 100%;
  border-collapse: collapse;
}
.vw-dept-table th {
  padding: 0.625rem 1rem;
  text-align: start;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgb(var(--color-text-muted, 96 109 145));
  background: rgb(var(--color-background-alt, 243 246 249));
  border-bottom: 1px solid rgb(var(--color-secondary-100, 230 233 239));
}
.vw-dept-table td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid rgb(var(--color-secondary-100, 230 233 239));
}
.vw-dept-table tbody tr:last-child td {
  border-bottom: none;
}
.vw-dept-table tbody tr:hover td {
  background: rgb(var(--color-background-alt, 243 246 249));
}
.vw-dept-table .vw-dept-num {
  text-align: end;
  font-variant-numeric: tabular-nums;
}
.vw-dept-table .vw-dept-actions {
  text-align: end;
  white-space: nowrap;
}
.vw-dept-actions .vw-dept-btn + .vw-dept-btn {
  margin-inline-start: 0.375rem;
}
.vw-dept-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: rgb(var(--color-text-muted, 96 109 145));
}

.vw-dept-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  color: rgb(var(--color-primary-700, 38 126 137));
  background: rgb(var(--color-primary-100, 215 242 245));
  white-space: nowrap;
}

/* ——— Buttons, links, fields ——— */

.vw-dept-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: 2.25rem;
  padding: 0 1rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
}
.vw-dept-btn:focus-visible,
.vw-dept-link:focus-visible,
.vw-dept-input:focus-visible {
  outline: 2px solid rgb(var(--color-primary-600, 55 176 190));
  outline-offset: 2px;
}
.vw-dept-btn-sm {
  min-height: 1.875rem;
  padding: 0 0.75rem;
  font-size: 0.8125rem;
}
.vw-dept-btn-primary {
  color: rgb(var(--color-text-contrast, 255 255 255));
  background: rgb(var(--color-primary-600, 55 176 190));
}
.vw-dept-btn-primary:hover {
  background: rgb(var(--color-primary-700, 38 126 137));
}
.vw-dept-btn-secondary {
  color: rgb(var(--color-text-main, 27 32 41));
  background: rgb(var(--color-background, 255 255 255));
  border-color: rgb(var(--color-secondary-300, 168 179 200));
}
.vw-dept-btn-secondary:hover {
  background: rgb(var(--color-background-alt, 243 246 249));
}
.vw-dept-btn-danger {
  color: rgb(var(--color-danger-600, 203 38 58));
  background: transparent;
  border-color: rgb(var(--color-danger-600, 203 38 58));
}
.vw-dept-btn-danger:hover {
  background: rgb(var(--color-danger-100, 255 236 239));
}

.vw-dept-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-weight: 600;
  color: rgb(var(--color-primary-600, 55 176 190));
  cursor: pointer;
}
.vw-dept-link:hover {
  text-decoration: underline;
}

.vw-dept-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}
.vw-dept-label {
  font-size: 0.8125rem;
  font-weight: 600;
}
.vw-dept-hint {
  font-size: 0.75rem;
  color: rgb(var(--color-text-muted, 96 109 145));
}
.vw-dept-input {
  width: 100%;
  box-sizing: border-box;
  min-height: 2.5rem;
  padding: 0.375rem 0.75rem;
  font: inherit;
  color: rgb(var(--color-text-main, 27 32 41));
  background: rgb(var(--color-background, 255 255 255));
  border: 1px solid rgb(var(--color-secondary-500, 90 109 145));
  border-radius: 8px;
}
.vw-dept-input-sm {
  width: auto;
  min-width: 16rem;
  min-height: 2rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
}

.vw-dept-perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 0.375rem 1rem;
}
.vw-dept-perm {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.vw-dept-alert {
  margin: 0 0 1rem;
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  border-radius: 8px;
  color: rgb(var(--color-danger-700, 149 27 42));
  background: rgb(var(--color-danger-100, 255 236 239));
  border: 1px solid rgb(var(--color-danger-600, 203 38 58));
}

/* ——— Dialog (create / edit department) ——— */

.vw-dept-dialog {
  width: min(32rem, calc(100vw - 2rem));
  padding: 1.5rem;
  border: none;
  border-radius: 12px;
  color: rgb(var(--color-text-main, 27 32 41));
  background: rgb(var(--color-background, 255 255 255));
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.2);
}
.vw-dept-dialog::backdrop {
  background: rgb(0 0 0 / 0.35);
}
.vw-dept-dialog-title {
  margin: 0 0 1.25rem;
  font-size: 1.25rem;
  font-weight: 600;
}
.vw-dept-dialog-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* ——— Department members page (bar above the vault's members table) ——— */

.vw-dept-members-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  border: 1px solid rgb(var(--color-secondary-100, 230 233 239));
  border-radius: 8px;
  background: rgb(var(--color-background-alt, 243 246 249));
}
.vw-dept-members-bar .vw-dept-alert {
  flex-basis: 100%;
  margin: 0;
}
.vw-dept-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.vw-dept-move {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* ——— Role panel inside the vault's invite / edit-member dialogs ———
   The radio buttons are clones of the vault's own, so only the optional department field needs style. */

.vw-dept-role-panel .vw-dept-field {
  margin-bottom: 1.25rem;
}

.vw-dept-badge-warn {
  color: rgb(var(--color-warning-700, 142 64 0));
  background: rgb(var(--color-warning-100, 255 244 212));
}

/* ——— Add member / reset password dialogs ——— */

.vw-dept-dialog {
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}
.vw-acct-intro {
  display: block;
  margin: -0.75rem 0 1rem;
}
.vw-acct-roles {
  margin: 0 0 1rem;
  padding: 0;
  border: none;
}
.vw-acct-roles legend {
  margin-bottom: 0.375rem;
  padding: 0;
}
.vw-dept-radio {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.375rem 0;
  cursor: pointer;
}
.vw-dept-radio input {
  margin-top: 0.2rem;
  accent-color: rgb(var(--color-primary-600, 55 176 190));
}
.vw-dept-radio > span {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}
.vw-dept-radio-title {
  font-weight: 600;
}
.vw-acct-password-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.vw-acct-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.vw-acct-credentials {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 0.8125rem;
  border-radius: 8px;
  background: rgb(var(--color-background-alt, 243 246 249));
  border: 1px solid rgb(var(--color-secondary-100, 230 233 239));
}

/* ——— Organization-created (employee) accounts ———
   The server refuses these features for such accounts; hide them so the vault only shows
   the organization's items and the settings the account may use. */

body.vw-managed-account bit-nav-item[route="sends"],
body.vw-managed-account bit-nav-group[route="tools"],
body.vw-managed-account bit-nav-item:has(a[href$="/settings/domain-rules"]),
body.vw-managed-account bit-nav-item:has(a[href$="/settings/emergency-access"]),
body.vw-managed-account bit-tab-link:has(a[href$="/security/security-keys"]),
body.vw-managed-account app-vault-onboarding,
body.vw-managed-account app-change-email,
body.vw-managed-account :has(+ app-change-email),
body.vw-managed-account app-danger-zone,
body.vw-managed-account app-profile button,
/* "My vault" and "New organization" in the vault filters, and the organization's menu (Leave). */
body.vw-managed-account li.filter-option:has(> .filter-buttons > .filter-button i.bwi-user),
body.vw-managed-account li.filter-option:has(> .filter-buttons > a.filter-button i.bwi-plus),
body.vw-managed-account li.filter-option:has(> a.filter-button i.bwi-plus),
body.vw-managed-account li.filter-option .filter-options-icon {
  display: none !important;
}

/* Result of emailing login details / the SMTP test. */
.vw-acct-status {
  margin: 0 0 1rem;
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  border-radius: 8px;
  color: rgb(var(--color-success-700, 21 104 57));
  background: rgb(var(--color-success-100, 221 247 230));
  border: 1px solid rgb(var(--color-success-600, 23 125 66));
}
.vw-acct-status-warn {
  color: rgb(var(--color-warning-700, 142 64 0));
  background: rgb(var(--color-warning-100, 255 244 212));
  border-color: rgb(var(--color-warning-600, 196 118 0));
}

/* Picking agency members for a client. */
.vw-client-team-list {
  max-height: 16rem;
  overflow-y: auto;
  margin: 0 0 1rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid rgb(var(--color-secondary-100, 230 233 239));
  border-radius: 8px;
}
.vw-client-team-row {
  padding: 0.375rem 0;
  border-bottom: 1px solid rgb(var(--color-secondary-100, 230 233 239));
}
.vw-client-team-row:last-child {
  border-bottom: none;
}

/* A client's team page. */
.vw-client-team-off {
  opacity: 0.6;
}
.vw-client-team-reason {
  display: block;
}
.vw-client-pending {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: rgb(var(--color-warning-700, 142 64 0));
  background: rgb(var(--color-warning-100, 255 244 212));
  border-color: rgb(var(--color-warning-600, 196 118 0));
}
.vw-client-access-select {
  width: auto;
  min-width: 8rem;
  padding: 0.25rem 0.5rem;
}
#vw-client-back {
  margin-bottom: 0.75rem;
}


/* Keep add-on forms and long department names usable in narrow vault layouts. */
.vw-dept-header > *, .vw-dept-crumbs > *, .vw-dept-move > * {
  min-width: 0;
  max-width: 100%;
}
.vw-dept-title, .vw-dept-dialog-title, .vw-dept-crumbs, .vw-dept-badge {
  overflow-wrap: break-word;
}
.vw-dept-badge {
  white-space: normal;
  line-height: 1.4;
}
.vw-dept-input-sm {
  min-width: min(16rem, 100%);
  max-width: 100%;
}
.vw-dept-dialog-actions, .vw-client-pending {
  flex-wrap: wrap;
}
.vw-dept-btn:disabled {
  cursor: default;
  opacity: .65;
}
.vw-dept-perm input:focus-visible,
.vw-dept-radio input:focus-visible,
.vw-client-access-select:focus-visible {
  outline: 2px solid rgb(var(--color-text-main, 27 32 41));
  outline-offset: 3px;
}
@media (max-width: 575.98px) {
  .vw-dept-dialog { padding: 1rem; box-sizing: border-box; }
  .vw-dept-header-actions { width: 100%; }
  .vw-dept-header-actions .vw-dept-btn { flex: 1 1 auto; }
  .vw-dept-btn, .vw-dept-input-sm { min-height: 2.5rem; }
  .vw-dept-dialog-actions .vw-dept-btn { flex: 1 1 auto; }
  .vw-dept-table { min-width: 32rem; }
  .vw-acct-password-row { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  .vw-dept-dialog, .vw-dept-btn, .vw-dept-input {
    transition: none !important;
    animation: none !important;
  }
}

/* ——— Workspace bar (org_workspaces_vault.js): where you are, and a switcher grouped by agency ——— */

#vw-ws-bar {
  /* Whole colors: the theme gives some tokens as RGB channels and others (purple) as hex. */
  --vw-ws-accent: rgb(var(--color-primary-600, 55 176 190));
  --vw-ws-accent-text: rgb(var(--color-primary-700, 31 128 140));
  --vw-ws-tint: rgb(var(--color-primary-100, 219 241 243));
  position: relative;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  /* The vault's page headers pull themselves 1.5rem up. */
  margin: 0 0 2.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid rgb(var(--color-secondary-300, 168 179 200));
  border-inline-start: 4px solid var(--vw-ws-accent);
  border-radius: 0.75rem;
  background: rgb(var(--color-background, 255 255 255));
  color: rgb(var(--color-text-main, 27 32 41));
  font-size: 0.875rem;
}

#vw-ws-bar.vw-ws-kind-client {
  --vw-ws-accent: var(--color-brand-600, #0b7a83);
  --vw-ws-accent-text: var(--color-brand-800, #0b5d64);
  --vw-ws-tint: var(--color-brand-050, #e6f3f4);
}

#vw-ws-bar.vw-ws-kind-personal,
#vw-ws-bar.vw-ws-kind-plain {
  --vw-ws-accent: rgb(var(--color-secondary-600, 89 99 128));
  --vw-ws-accent-text: rgb(var(--color-secondary-700, 68 77 102));
  --vw-ws-tint: rgb(var(--color-secondary-100, 230 233 239));
}

body.khp-soc-open #vw-ws-bar {
  margin-bottom: 2rem;
}

.vw-ws-where {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.vw-ws-badge {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.625rem;
  background: var(--vw-ws-tint);
  color: var(--vw-ws-accent-text);
}

.vw-ws-badge-svg,
.vw-ws-item-svg,
.vw-ws-chevron,
.vw-ws-item-check {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.vw-ws-badge-svg {
  width: 1.375rem;
  height: 1.375rem;
  stroke-width: 1.75;
}

.vw-ws-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.vw-ws-eyebrow {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--vw-ws-accent-text);
}

.vw-ws-name {
  font-size: 1.0625rem;
  font-weight: 700;
  overflow-wrap: break-word;
}

.vw-ws-parent {
  font-size: 0.75rem;
  color: rgb(var(--color-text-muted, 96 109 145));
}

.vw-ws-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.vw-ws-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 2.25rem;
  padding: 0.375rem 0.875rem;
  border: 1px solid rgb(var(--color-secondary-300, 168 179 200));
  border-radius: 9999px;
  background: rgb(var(--color-background, 255 255 255));
  color: rgb(var(--color-text-main, 27 32 41));
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.vw-ws-btn:hover {
  background: rgb(var(--color-background-alt, 243 246 249));
}

.vw-ws-switch {
  border-color: var(--vw-ws-accent);
  color: var(--vw-ws-accent-text);
}

.vw-ws-chevron {
  width: 1rem;
  height: 1rem;
  stroke-width: 2;
  transition: transform 0.15s ease;
}

.vw-ws-menu-open .vw-ws-chevron {
  transform: rotate(180deg);
}

.vw-ws-btn:focus-visible,
.vw-ws-item:focus-visible,
.vw-ws-search:focus-visible {
  outline: 2px solid rgb(var(--color-primary-600, 55 176 190));
  outline-offset: 2px;
}

.vw-ws-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: min(24rem, calc(100vw - 2rem));
  max-height: min(30rem, 70vh);
  padding: 0.5rem;
  border: 1px solid rgb(var(--color-secondary-300, 168 179 200));
  border-radius: 0.75rem;
  background: rgb(var(--color-background, 255 255 255));
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
}

.vw-ws-menu[hidden],
.vw-ws-group[hidden],
.vw-ws-item[hidden] {
  display: none;
}

.vw-ws-search {
  margin: 0.25rem 0.25rem 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid rgb(var(--color-secondary-300, 168 179 200));
  border-radius: 0.5rem;
  background: rgb(var(--color-background, 255 255 255));
  color: inherit;
  font: inherit;
}

.vw-ws-list {
  overflow-y: auto;
}

.vw-ws-group + .vw-ws-group {
  margin-top: 0.25rem;
  padding-top: 0.25rem;
  border-top: 1px solid rgb(var(--color-secondary-100, 230 233 239));
}

.vw-ws-group-title {
  padding: 0.5rem 0.75rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgb(var(--color-text-muted, 96 109 145));
}

.vw-ws-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.vw-ws-item:hover {
  background: rgb(var(--color-background-alt, 243 246 249));
}

.vw-ws-item[aria-current="true"] {
  background: rgb(var(--color-primary-100, 219 241 243));
  font-weight: 600;
}

.vw-ws-item-nested {
  padding-inline-start: 2.25rem;
}

.vw-ws-item-svg {
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  stroke-width: 1.75;
  color: rgb(var(--color-text-muted, 96 109 145));
}

.vw-ws-item-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
}

.vw-ws-item-check {
  flex: none;
  width: 1rem;
  height: 1rem;
  stroke-width: 2.25;
  color: rgb(var(--color-primary-700, 31 128 140));
}

.vw-ws-pill {
  flex: none;
  padding: 0.0625rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

.vw-ws-pill-org {
  background: rgb(var(--color-primary-100, 219 241 243));
  color: rgb(var(--color-primary-700, 31 128 140));
}

.vw-ws-pill-client {
  background: var(--color-brand-050, #e6f3f4);
  color: var(--color-brand-800, #0b5d64);
}

.vw-ws-pill-plain {
  background: rgb(var(--color-secondary-100, 230 233 239));
  color: rgb(var(--color-text-muted, 96 109 145));
}

.vw-ws-pill-inline {
  margin-inline-start: 0.5rem;
  vertical-align: middle;
}

.vw-ws-empty {
  display: none;
  margin: 0;
  padding: 0.75rem;
  color: rgb(var(--color-text-muted, 96 109 145));
}

.vw-ws-no-match .vw-ws-empty {
  display: block;
}

/* The vault's own filter: "All vaults" would mix every client's items, so it is not offered. */
body.vw-ws-on app-filter-section:has(#allVaults-filters) .filter-heading button.filter-button {
  display: none !important;
}

@media (max-width: 640px) {
  .vw-ws-actions {
    width: 100%;
  }

  .vw-ws-menu {
    left: 0;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .vw-ws-chevron {
    transition: none;
  }
}
