  /*
      The `hidden` attribute is honoured only by the user-agent stylesheet, which
      any author-level `display` declaration beats. .controls, .stat-strip and
      .instance-picker all set display:flex, so `hidden` on those was being
      silently ignored and the users control bar showed in Roles mode. This makes
      the attribute authoritative wherever it is used.
  */
  [hidden] { display: none !important; }

  :root {
    --deep-forest: #213f39;
    --forest-mid: #6B7F7B;
    --forest-pale: #DADFDE;
    --sage: #C8DCCA;
    --sage-mid: #DAE8DC;
    --sage-pale: #EDF3ED;
    --kelly: #149F69;
    --highlighter: #E9F800;
    --peach: #FF9D6F;
    --cream: #F5F3E7;
    --mocha: #D6C4B6;
    --white: #ffffff;
    --row-height: 26px;
    --col-width: 30px;
    --perm-col-width: 300px;
    --head-height: 250px;
  }

  * { box-sizing: border-box; }

  html, body {
    height: 100%;
    margin: 0;
  }

  body {
    background: var(--cream);
    color: var(--deep-forest);
    font-family: Inter, "Segoe UI", system-ui, Arial, sans-serif;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  button, select, input { font-family: inherit; font-size: inherit; color: inherit; }

  /* ---------- top bar ---------- */

  .topbar {
    background: var(--deep-forest);
    color: var(--sage);
    padding: 10px 22px;
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    flex: none;
  }

  .topbar h1 {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    color: var(--white);
    letter-spacing: -0.01em;
  }

  .instance-picker { display: flex; align-items: center; gap: 8px; }

  .instance-picker label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--forest-pale);
  }

  select {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(200,220,202,0.35);
    color: var(--sage);
    border-radius: 999px;
    padding: 5px 12px;
    cursor: pointer;
  }

  select option { color: var(--deep-forest); background: var(--white); }

  select:hover { background: rgba(255,255,255,0.16); }

  .stat-strip { margin-left: auto; display: flex; gap: 20px; }

  .stat { text-align: right; line-height: 1.15; }
  .stat b { display: block; font-size: 16px; color: var(--white); font-weight: 600; font-variant-numeric: tabular-nums; }
  .stat span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--forest-pale); }

  /* ---------- control bar ---------- */

  .controls {
    background: var(--white);
    border-bottom: 1px solid var(--forest-pale);
    padding: 9px 22px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex: none;
  }

  .search-box {
    border: 1px solid var(--forest-pale);
    border-radius: 999px;
    padding: 6px 14px;
    width: 260px;
    background: var(--sage-pale);
  }
  .search-box:focus { outline: 2px solid var(--kelly); outline-offset: 1px; }

  .chip-group { display: flex; gap: 4px; }

  .chip {
    border: 1px solid var(--forest-pale);
    background: var(--white);
    border-radius: 999px;
    padding: 5px 13px;
    cursor: pointer;
    white-space: nowrap;
  }
  .chip:hover { border-color: var(--deep-forest); }
  .chip[aria-pressed="true"] {
    background: var(--deep-forest);
    color: var(--sage);
    border-color: var(--deep-forest);
  }
  .chip:focus-visible { outline: 2px solid var(--kelly); outline-offset: 1px; }

  .divider { width: 1px; height: 22px; background: var(--forest-pale); }

  .control-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--forest-mid); }

  .ghost-button {
    border: 1px solid var(--deep-forest);
    background: transparent;
    border-radius: 999px;
    padding: 5px 13px;
    cursor: pointer;
  }
  .ghost-button:hover { background: var(--deep-forest); color: var(--sage); }

  /* ---------- layout ---------- */

  .layout { display: flex; flex: 1; min-height: 0; }

  .matrix-region { flex: 1; overflow: auto; min-width: 0; background: var(--white); }

  .side-panel {
    width: 330px;
    flex: none;
    border-left: 1px solid var(--forest-pale);
    background: var(--sage-pale);
    overflow-y: auto;
    padding: 16px 18px 40px;
  }

  .side-panel h2 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--forest-mid);
    margin: 0 0 8px;
    font-weight: 600;
  }

  .side-panel h3 { font-size: 13px; margin: 18px 0 6px; font-weight: 600; }

  .panel-block { background: var(--white); border-radius: 10px; padding: 12px 13px; margin-bottom: 12px; }

  .panel-block p { margin: 0 0 6px; line-height: 1.45; }

  .perm-list { margin: 0; padding: 0; list-style: none; }
  .perm-list li {
    padding: 3px 0 3px 10px;
    border-left: 3px solid var(--forest-pale);
    line-height: 1.35;
    margin-bottom: 2px;
  }
  .perm-list li.only-a { border-left-color: var(--kelly); background: rgba(20,159,105,0.07); }
  .perm-list li.only-b { border-left-color: var(--peach); background: rgba(255,157,111,0.14); }

  .legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

  .hint { color: var(--forest-mid); line-height: 1.5; }

  /* ---------- matrix ---------- */

  table.matrix { border-collapse: separate; border-spacing: 0; }

  table.matrix th, table.matrix td { margin: 0; }

  th.corner {
    position: sticky;
    left: 0;
    top: 0;
    z-index: 5;
    background: var(--white);
    width: var(--perm-col-width);
    min-width: var(--perm-col-width);
    height: var(--head-height);
    border-right: 2px solid var(--deep-forest);
    border-bottom: 2px solid var(--deep-forest);
    vertical-align: bottom;
    text-align: left;
    padding: 0 10px 8px 22px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--forest-mid);
    font-weight: 600;
  }

  th.role-head {
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--white);
    height: var(--head-height);
    width: var(--col-width);
    min-width: var(--col-width);
    max-width: var(--col-width);
    border-bottom: 2px solid var(--deep-forest);
    border-left: 1px solid var(--sage-pale);
    vertical-align: bottom;
    cursor: pointer;
    user-select: none;
  }

  th.role-head .role-label {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    height: calc(var(--head-height) - 34px);
    max-height: calc(var(--head-height) - 34px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    font-weight: 500;
    margin: 0 auto 4px;
    display: block;
  }

  th.role-head .role-count {
    display: block;
    text-align: center;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 9px;
    color: var(--forest-mid);
    padding-bottom: 6px;
  }

  th.role-head.selected-a { background: var(--kelly); }
  th.role-head.selected-a .role-label, th.role-head.selected-a .role-count { color: var(--white); }
  th.role-head.selected-b { background: var(--peach); }
  th.role-head:hover { background: var(--sage-mid); }

  th.perm-name {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--white);
    width: var(--perm-col-width);
    min-width: var(--perm-col-width);
    max-width: var(--perm-col-width);
    height: var(--row-height);
    text-align: left;
    font-weight: 400;
    padding: 0 10px 0 22px;
    border-right: 2px solid var(--deep-forest);
    border-bottom: 1px solid var(--sage-pale);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  th.perm-name .verb-tag {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 2px;
    margin-right: 7px;
    vertical-align: middle;
  }
  .verb-manage { background: var(--deep-forest); }
  .verb-view { background: var(--sage); }
  .verb-other { background: var(--mocha); }

  th.perm-name .grant-count {
    float: right;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 10px;
    color: var(--forest-mid);
    padding-left: 8px;
  }

  tbody tr:nth-child(even) th.perm-name,
  tbody tr:nth-child(even) td.cell { background: var(--sage-pale); }

  tbody tr:hover th.perm-name,
  tbody tr:hover td.cell { background: var(--sage-mid); }

  td.cell {
    padding: 0;
    height: var(--row-height);
    width: var(--col-width);
    min-width: var(--col-width);
    background: var(--white);
    border-bottom: 1px solid var(--sage-pale);
    border-left: 1px solid var(--sage-pale);
    text-align: center;
    vertical-align: middle;
  }

  td.cell .marker {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    background: var(--kelly);
  }

  td.cell.diff-a .marker { background: var(--kelly); box-shadow: 0 0 0 3px rgba(20,159,105,0.28); }
  td.cell.diff-b .marker { background: var(--peach); box-shadow: 0 0 0 3px rgba(255,157,111,0.35); }

  .empty-state { padding: 40px; color: var(--forest-mid); }

  /* ---------- instance comparison view ---------- */

  .instances-view { padding: 20px 26px 60px; }
  .instances-view table { border-collapse: collapse; margin-top: 10px; }
  .instances-view th, .instances-view td {
    border: 1px solid var(--forest-pale);
    padding: 6px 10px;
    text-align: left;
  }
  .instances-view thead th { background: var(--deep-forest); color: var(--sage); font-weight: 600; }
  .present-yes { color: var(--kelly); font-weight: 600; }
  .present-no { color: var(--forest-pale); }

  .view-title {
    margin: 0 0 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--forest-mid);
    font-weight: 600;
  }

  .compare-picker {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 10px 0 6px;
  }
  .compare-picker label { display: flex; align-items: center; gap: 6px; font-size: 12px; }
  .compare-picker select {
    background: var(--white);
    border: 1px solid var(--deep-forest);
    color: var(--deep-forest);
  }
  .compare-picker select option { color: var(--deep-forest); }
  .compare-picker .arrow { color: var(--forest-mid); }
  .compare-picker .compare-summary {
    margin-left: 8px;
    font-size: 12px;
    color: var(--forest-mid);
    font-variant-numeric: tabular-nums;
  }

  .instances-view tbody tr { cursor: pointer; }
  .instances-view tbody tr:hover td { background: var(--sage-pale); }
  .instances-view tbody tr.row-selected td { background: var(--sage-mid); font-weight: 500; }
  .count-added { color: var(--kelly); font-variant-numeric: tabular-nums; }
  .count-removed { color: #B4632F; font-variant-numeric: tabular-nums; }
  .status-identical { color: var(--forest-mid); }
  .status-differs { color: #B4632F; font-weight: 600; }
  .status-missing { color: var(--deep-forest); background: var(--mocha); font-weight: 600; }

  .catalog-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 6px; }
  .perm-list.compact li { font-size: 12px; }

  .panel-block.notice { border-left: 4px solid var(--peach); }

  .role-across-wrap { padding: 0; }

  .role-across-picker {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 12px 22px;
    background: var(--white);
    border-bottom: 1px solid var(--forest-pale);
    position: sticky;
    left: 0;
    z-index: 6;
  }
  .role-across-picker label { display: flex; align-items: center; gap: 8px; font-size: 12px; }
  .role-across-picker select {
    background: var(--white);
    border: 1px solid var(--deep-forest);
    color: var(--deep-forest);
    max-width: 380px;
  }
  .role-across-picker select option { color: var(--deep-forest); }

  th.instance-head {
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--white);
    height: 46px;
    width: 46px;
    min-width: 46px;
    border-bottom: 2px solid var(--deep-forest);
    border-left: 1px solid var(--sage-pale);
    vertical-align: bottom;
    text-align: center;
  }
  th.instance-head .instance-code {
    display: block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
  }
  th.instance-head.head-absent { background: var(--forest-pale); color: var(--forest-mid); }

  .instance-matrix td.cell { width: 46px; min-width: 46px; }
  .instance-matrix th.instance-head + th.instance-head { border-left: 1px solid var(--sage-pale); }

  td.cell-absent {
    background: repeating-linear-gradient(
      45deg,
      var(--forest-pale),
      var(--forest-pale) 3px,
      var(--white) 3px,
      var(--white) 6px
    ) !important;
  }

  tr.row-divergent th.perm-name { box-shadow: inset 4px 0 0 var(--peach); }


  /* ---------- mode switch ---------- */

  .mode-switch { margin-left: 4px; }

  .mode-switch .chip[aria-pressed="true"] {
    background: var(--sage);
    color: var(--deep-forest);
    border-color: var(--sage);
    font-weight: 600;
  }

  /* ---------- users: list ---------- */

  table.user-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
  }

  table.user-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--deep-forest);
    color: var(--sage);
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    padding: 8px 12px;
    white-space: nowrap;
  }

  table.user-table td {
    padding: 7px 12px;
    border-bottom: 1px solid var(--forest-pale);
    vertical-align: top;
  }

  tr.user-row { cursor: pointer; }
  tr.user-row:hover td { background: var(--sage-pale); }
  tr.user-row.selected-a td { background: var(--sage-mid); }

  td.user-name { font-weight: 600; color: var(--deep-forest); }
  td.user-username, td.user-email {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 11.5px;
    color: var(--forest-mid);
  }
  td.user-count { text-align: right; font-variant-numeric: tabular-nums; }

  /* ---------- badges ---------- */

  .badge-row { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }

  .badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 999px;
    white-space: nowrap;
  }

  /* Locked and unnamed-role are the two an auditor is looking for, so they carry
     the warm colours; never-signed-in and archived are context, not findings. */
  .badge-locked     { background: var(--peach);  color: var(--deep-forest); }
  .badge-unresolved { background: var(--highlighter); color: var(--deep-forest); }
  .badge-stale      { background: var(--mocha);  color: var(--deep-forest); }
  .badge-archived   { background: var(--forest-pale); color: var(--forest-mid); }

  /* ---------- users: detail panel ---------- */

  .panel-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--deep-forest);
    margin: 0 0 4px;
  }

  .panel-note {
    margin: 0 0 10px;
    font-size: 12px;
    line-height: 1.45;
    color: var(--forest-mid);
  }

  .panel-empty { padding: 20px 0; color: var(--forest-mid); line-height: 1.5; }

  .muted { color: var(--forest-mid); font-size: 11.5px; }
  .nowrap { white-space: nowrap; }

  table.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    background: var(--white);
    border-radius: 10px;
    overflow: hidden;
  }

  table.detail-table th {
    text-align: left;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--forest-mid);
    padding: 7px 9px;
    border-bottom: 1px solid var(--forest-pale);
    white-space: nowrap;
  }

  table.detail-table td {
    padding: 7px 9px;
    border-bottom: 1px solid var(--sage-pale);
    vertical-align: top;
  }

  table.detail-table tr:last-child td { border-bottom: none; }

  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
  }


/* Shown when the API cannot be reached or returns nothing. */
.boot-error {
  margin: 48px auto;
  max-width: 560px;
  padding: 24px 28px;
  border: 1px solid var(--border, #d8d8d8);
  border-radius: 8px;
  line-height: 1.5;
}
.boot-error h2 { margin: 0 0 12px; font-size: 1.1rem; }
.boot-error p  { margin: 0 0 10px; }
