/* Designations and access (/roles). Every class starts with roles- because module
   stylesheets load on every page. Level colours come from .lv / .lv-1..4 in app.css. */

.roles-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.roles-layout-3 { grid-template-columns: 250px minmax(0, 1fr) 330px; }
.roles-main, .roles-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
/* Keep this module's header buttons side by side whatever .page-head > div does. */
.page-head > .page-actions.roles-actions { flex-direction: row; align-items: center; gap: 8px; }
/* .pill sets display, which would otherwise show the empty "unsaved changes" badge while it is hidden. */
.roles-dirty[hidden] { display: none; }
.roles-panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }

/* Designation list (left) */
.panel.roles-list { padding: 12px 0 10px; gap: 0; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.roles-list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 0 14px 10px; border-bottom: 1px solid var(--sunk); }
.roles-list-head h2 { font-size: 16px; }
.roles-list-dept { padding: 10px 14px 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.roles-list ul { list-style: none; margin: 0; padding: 0; }
.roles-list-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; padding: 6px 14px 6px 10px; border-left: 4px solid transparent; color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 500; line-height: 1.3; }
.roles-list-item:hover { background: var(--sunk); color: var(--ink); }
.roles-list-item.is-current { background: var(--info-bg); border-left-color: var(--accent); font-weight: 700; }
.roles-list-item.is-inactive .roles-list-name { color: var(--muted); }
.roles-list-count { flex: none; font-size: 12px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.roles-list-count.is-zero { color: var(--warn); }

/* Legend */
.roles-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.roles-legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.roles-legend .lv { min-width: 0; min-height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; }

/* Overview matrix: compact chips, sticky first column */
.roles-matrix { font-size: 13px; }
.roles-matrix thead th { white-space: normal; vertical-align: bottom; min-width: 66px; max-width: 92px; font-size: 11px; line-height: 1.3; padding: 8px 4px; text-align: center; }
.roles-matrix td { padding: 3px 3px; vertical-align: middle; }
.roles-matrix .lv { display: flex; min-width: 0; width: 100%; min-height: 26px; padding: 0 4px; border-radius: 6px; font-size: 12px; white-space: nowrap; }
.roles-matrix .lv-0 { background: transparent; border-color: transparent; color: var(--muted); font-weight: 500; }
.roles-matrix .roles-matrix-name { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; min-width: 170px; max-width: 220px; padding: 6px 10px; white-space: normal; border-right: 1px solid var(--line); }
.roles-matrix thead .roles-matrix-name { background: var(--sunk); font-size: 12px; }
.roles-matrix tbody th.roles-matrix-name { display: table-cell; font-weight: 600; line-height: 1.3; }
.roles-matrix tbody th.roles-matrix-name a { color: var(--ink); text-decoration: none; display: block; }
.roles-matrix tbody th.roles-matrix-name a:hover { color: var(--accent); text-decoration: underline; }
.roles-matrix tbody th.roles-matrix-name .small { font-weight: 400; font-size: 12px; }
.roles-matrix tr.roles-matrix-dept th { position: sticky; left: 0; background: var(--bg); font-size: 12px; font-weight: 700; color: var(--muted); padding: 7px 10px; text-align: left; }
.roles-matrix tr:hover td { background: var(--sunk); }

/* One designation */
.roles-areas { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 6px; }
.roles-areas li { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; padding: 5px 6px 5px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; line-height: 1.3; }
.roles-areas .lv { flex: none; }
.roles-limits li, .roles-powers li { align-items: center; font-size: 14px; line-height: 1.35; }
.roles-limits strong { white-space: nowrap; }
.roles-powers .pill { flex: none; }
.roles-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.roles-chips a { display: inline-flex; flex-wrap: wrap; align-items: baseline; column-gap: 6px; min-height: 36px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); text-decoration: none; font-size: 14px; }
.roles-chips a:hover { border-color: var(--accent); }
.panel.roles-rules { background: var(--bg); }
.roles-rules ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; line-height: 1.5; color: var(--ink-2); }
.roles-history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.roles-history li { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--sunk); font-size: 14px; }
.roles-history li:last-child { border-bottom: 0; }

/* Edit form */
.roles-level-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 6px; }
.roles-level-field { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 48px; padding: 4px 4px 4px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; line-height: 1.3; }
.roles-level-field.has-error { border-color: var(--bad); }
/* A level error (from the server or the browser check) goes on its own line under the area name. */
.roles-level-field { flex-wrap: wrap; }
.roles-level-field .field-error { flex-basis: 100%; margin: 0 0 4px; }
select.roles-level { flex: none; width: 128px; min-height: 38px; padding: 4px 8px; font-size: 13px; font-weight: 600; background: var(--sunk); color: var(--muted); border-color: var(--line); }
select.roles-level[data-level="1"] { background: var(--info-bg); color: var(--info); border-color: var(--line-strong); }
select.roles-level[data-level="2"] { background: var(--ok-bg); color: var(--ok); border-color: var(--line-strong); }
select.roles-level[data-level="3"] { background: var(--warn-bg); color: var(--warn); border-color: var(--line-strong); }
select.roles-level[data-level="4"] { background: var(--btn-bg); color: var(--btn-ink); border-color: var(--btn-bg); }
.roles-power-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 2px 16px; }
.roles-power-grid .check { min-height: 44px; font-size: 14px; line-height: 1.35; }
.roles-power-grid .check input { flex: none; }

/* Departments */
.roles-other-name { display: block; }
.roles-rename { display: inline-block; text-align: left; }
.roles-rename summary { list-style: none; }
.roles-rename summary::-webkit-details-marker { display: none; }
.roles-rename[open] form { margin-top: 8px; min-width: 260px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--sunk); }

/* ---------- Pictures (RolesVisuals.php) ---------- */
/* Level colours: one variable per level, used by heat cells, pips, the mix bar and swatches. */
.roles-l0 { --rl: var(--sunk-2); --rlt: var(--muted); }
.roles-l1 { --rl: var(--viz-blue); --rlt: var(--info); }
.roles-l2 { --rl: var(--viz-green); --rlt: var(--ok); }
.roles-l3 { --rl: var(--viz-amber); --rlt: var(--warn); }
.roles-l4 { --rl: var(--btn-bg); --rlt: var(--ink); }
.roles-sw { display: inline-block; flex: none; width: 14px; height: 14px; border-radius: 4px; background: var(--rl); box-shadow: inset 0 0 0 1px var(--line-strong); }

.roles-kpis { margin-bottom: 16px; }
.roles-viz-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; margin: 16px 0; }
.roles-viz-grid.roles-viz-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.roles-viz-band { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; margin-bottom: 16px; }

/* Heat map: rows are designations, columns areas; each cell fills ¼..full by level. */
.roles-hm { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.roles-hm-scroll { overflow-x: auto; padding-bottom: 4px; }
.roles-hm-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.roles-hm-row { display: flex; align-items: stretch; gap: 8px; min-width: 620px; }
.roles-hm-name { position: sticky; left: 0; z-index: 1; flex: none; width: 200px; display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 2px 8px 2px 4px; background: var(--glass-strong); color: var(--ink); text-decoration: none; font-size: 13px; line-height: 1.25; }
a.roles-hm-name:hover .roles-hm-label { color: var(--accent); text-decoration: underline; }
.roles-hm-people { flex: none; min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); font-size: 12px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.roles-hm-row.is-vacant .roles-hm-people { background: var(--warn-bg); color: var(--warn); }
.roles-hm-row.is-current .roles-hm-name { font-weight: 700; box-shadow: inset 4px 0 0 var(--accent); }
.roles-hm-cells { flex: 1 1 auto; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(24px, 1fr); gap: 3px; }
.roles-hm-cell { position: relative; height: 26px; border-radius: 5px; background: var(--sunk); overflow: hidden; }
.roles-hm-cell::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: var(--rl); }
.roles-hm-cell.roles-l1::after { height: 25%; }
.roles-hm-cell.roles-l2::after { height: 50%; }
.roles-hm-cell.roles-l3::after { height: 75%; }
.roles-hm-cell.roles-l4::after { height: 100%; }
.roles-hm-row:not(.roles-hm-head):not(.roles-hm-foot):hover .roles-hm-cell { box-shadow: inset 0 0 0 1px var(--line-strong); }
.roles-hm-head { align-items: flex-end; }
.roles-hm-head .roles-hm-name { font-size: 12px; font-weight: 600; color: var(--muted); align-self: flex-end; }
.roles-hm-col { display: flex; justify-content: center; align-items: flex-end; height: 132px; }
.roles-hm-col > span { writing-mode: vertical-rl; transform: rotate(180deg); max-height: 132px; overflow: hidden; font-size: 12px; font-weight: 600; line-height: 1.15; color: var(--ink-2); white-space: nowrap; text-overflow: ellipsis; }
.roles-hm-dept { position: sticky; left: 0; width: max-content; margin: 8px 0 3px; padding: 0 4px; font-size: 12px; font-weight: 700; color: var(--muted); scroll-margin-top: 90px; }
.roles-hm-row + .roles-hm-row { margin-top: 3px; }
.roles-hm-foot { margin-top: 10px !important; padding-top: 8px; border-top: 1px solid var(--line); }
.roles-hm-foot .roles-hm-name { font-size: 12px; font-weight: 600; color: var(--muted); }
.roles-hm-count { position: relative; display: flex; align-items: flex-end; justify-content: center; height: 34px; border-radius: 5px; background: var(--sunk); overflow: hidden; font-size: 11px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.roles-hm-count > span[aria-hidden] { position: relative; z-index: 1; padding-bottom: 2px; }
.roles-hm-count::before { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: color-mix(in srgb, var(--accent) 35%, transparent); }
.roles-hm-count.roles-q1::before { height: 25%; }
.roles-hm-count.roles-q2::before { height: 50%; }
.roles-hm-count.roles-q3::before { height: 75%; }
.roles-hm-count.roles-q4::before { height: 100%; }
.roles-hm-count.is-zero { background: var(--bad-bg); color: var(--bad); }
.roles-hm figcaption { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 16px; }
.roles-hm-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--ink-2); }
.roles-hm-legend li { display: inline-flex; align-items: center; gap: 6px; }

/* Seats: one dot per holder */
.roles-seats { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 3px; }
.roles-seat { width: 9px; height: 9px; border-radius: 50%; background: var(--viz-green); }
.roles-seat.is-empty { background: transparent; box-shadow: inset 0 0 0 2px var(--viz-amber); }
.roles-seat-more { font-size: 11px; font-weight: 700; color: var(--ok); }

/* Org tree */
.roles-tree-wrap { overflow-x: auto; }
.roles-tree-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.roles-tree, .roles-tree ul { list-style: none; margin: 0; padding: 0; }
.roles-tree ul { margin-left: 10px; padding-left: 12px; border-left: 2px solid var(--line-strong); }
.roles-tree li { position: relative; padding-top: 6px; }
.roles-tree ul > li::before { content: ''; position: absolute; left: -12px; top: 24px; width: 10px; border-top: 2px solid var(--line-strong); }
.roles-node { display: inline-grid; grid-template-columns: auto auto; align-items: center; gap: 2px 10px; min-width: 180px; max-width: 100%; padding: 6px 10px; border: 1px solid var(--line); border-left: 4px solid var(--viz-green); border-radius: 10px; background: var(--glass-strong); color: var(--ink); text-decoration: none; }
a.roles-node:hover { border-color: var(--accent); }
.roles-node.is-vacant { border-left-color: var(--viz-amber); background: color-mix(in srgb, var(--warn-bg) 60%, var(--glass-strong)); }
.roles-node.is-director { border-left-color: var(--btn-bg); }
.roles-node.is-current { box-shadow: 0 0 0 2px var(--accent); }
.roles-node-name { font-size: 14px; font-weight: 600; line-height: 1.25; }
.roles-node-dept { grid-column: 1; font-size: 12px; color: var(--muted); }
.roles-node .roles-seats { grid-column: 2; grid-row: 1 / span 2; justify-content: flex-end; max-width: 90px; }

/* Line of command */
.roles-chain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: flex-start; }
.roles-chain-step { position: relative; padding-bottom: 16px; }
.roles-chain-step:not(:last-child)::after { content: '↓'; position: absolute; left: 18px; bottom: -1px; font-size: 14px; line-height: 16px; color: var(--muted); }
.roles-chain-box { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--glass-strong); color: var(--ink); text-decoration: none; font-size: 14px; }
a.roles-chain-box:hover { border-color: var(--accent); }
.roles-chain-step.is-current .roles-chain-box { border: 2px solid var(--accent); font-weight: 700; }
.roles-chain-step.is-off .roles-chain-name { color: var(--muted); text-decoration: line-through; }
.roles-chain-step.is-current { padding-bottom: 0; }
.roles-chain-under { margin: 10px 0 6px 18px; font-size: 12px; font-weight: 700; color: var(--muted); }
.roles-chain-fan { list-style: none; margin: 0 0 0 18px; padding: 0 0 0 14px; border-left: 2px solid var(--line-strong); display: flex; flex-wrap: wrap; gap: 6px; }

/* At a glance (one designation) */
.roles-glance { gap: 12px; }
.roles-glance-seats { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.roles-glance-seats .roles-seat { width: 14px; height: 14px; }
.roles-glance-rings { display: flex; flex-wrap: wrap; gap: 12px; }
.roles-mix { display: flex; flex-direction: column; gap: 6px; }
.roles-mix-bar { display: block; border-radius: 6px; overflow: hidden; background: var(--sunk); }
.roles-mix-seg { fill: var(--rl); }
.roles-mix-key { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--ink-2); }
.roles-mix-key li { display: inline-flex; align-items: center; gap: 5px; }
.roles-mix-key li.is-zero { opacity: .55; }

/* Pips per area */
.roles-pips { display: inline-flex; align-items: center; gap: 3px; flex: none; }
.roles-pip { width: 10px; height: 18px; border-radius: 3px; background: var(--sunk-2); }
.roles-pip.is-on { background: var(--rl); }
.roles-pips-word { min-width: 70px; margin-left: 6px; font-size: 13px; font-weight: 600; color: var(--rlt); }

/* Limits */
.roles-limit-meters { display: flex; flex-direction: column; gap: 14px; }
.roles-limit-off { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* Code label on a designation's page */
.roles-code { margin: 0; display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: #FFFFFF; color: #000; }
.roles-code-qr { width: 72px; height: 72px; }
.roles-code figcaption { display: flex; flex-direction: column; gap: 2px; }
.roles-code figcaption .muted { color: #444; }
.roles-code-bars { max-width: 180px; height: auto; }

/* Edit: who the change reaches */
.panel.roles-reach { flex-direction: row; align-items: center; gap: 14px; margin-bottom: 16px; }
.roles-reach > div { display: flex; flex-direction: column; gap: 2px; }
.roles-reach .roles-seat { width: 14px; height: 14px; }

/* Find in the list */
.roles-list-find { padding: 10px 14px 4px; }
.roles-find { width: 100%; min-height: 40px; }
.roles-chips-warn a { border-color: color-mix(in srgb, var(--viz-amber) 60%, transparent); background: var(--warn-bg); }

/* Print sheet */
.roles-print { display: flex; flex-direction: column; gap: 16px; }
.roles-print-head { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.roles-print-codes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.roles-print-code { display: flex; align-items: center; gap: 8px; padding: 6px; border: 1px dashed var(--line-strong); border-radius: 8px; break-inside: avoid; }
.roles-print-qr { flex: none; width: 64px; height: 64px; background: #FFFFFF; }
.roles-print-dept { grid-column: 1 / -1; border-style: solid; background: var(--sunk); }
.roles-print-name { display: flex; flex-direction: column; gap: 1px; line-height: 1.25; min-width: 0; }

@media (max-width: 1180px) {
  .roles-layout-3 { grid-template-columns: 240px minmax(0, 1fr); }
  .roles-layout-3 .roles-side { grid-column: 2; }
}
@media (max-width: 860px) {
  .roles-viz-grid, .roles-viz-grid.roles-viz-even, .roles-viz-band { grid-template-columns: minmax(0, 1fr); }
  .roles-hm-name { width: 128px; font-size: 12px; }
  .roles-hm-row { min-width: 540px; }
  .roles-node { min-width: 0; }
  .page-head > .page-actions.roles-actions { flex-wrap: wrap; }
  .roles-layout, .roles-layout-3 { grid-template-columns: minmax(0, 1fr); }
  .roles-layout-3 .roles-side { grid-column: auto; }
  .roles-layout-3 .roles-list { order: 3; }
  .panel.roles-list { position: static; max-height: none; }
}
@media print {
  /* Paper is white whatever the screen theme: the pictures take the light tokens (a dark device would print white on white). */
  .roles-print, .roles-hm, .roles-tree-wrap, .roles-viz-band, .roles-layout, .roles-chips, .page-head {
    --ink: #1D1D1F; --ink-2: #3A3F3C; --muted: #545A56; --line: rgba(29, 29, 31, .10); --line-strong: rgba(29, 29, 31, .18);
    --sunk: rgba(29, 29, 31, .045); --sunk-2: rgba(29, 29, 31, .08); --btn-bg: #1D1D1F; --surface: #FFFFFF; --glass-strong: #FFFFFF; --bg: #FFFFFF;
    --ok: #1E7A45; --warn: #8A5A00; --info: #1F5FBF; --accent: #1F7A4D; --warn-bg: rgba(230, 160, 30, .18);
    --viz-green: #2E9B5E; --viz-amber: #E0A21A; --viz-blue: #2F6FD0; --viz-red: #D9473B;
    color: #1D1D1F;
  }
  .roles-list, .roles-side form, .roles-list-find { display: none !important; }
  .roles-hm-scroll, .roles-tree-wrap { overflow: visible; }
  .roles-hm-name, .roles-node, .roles-chain-box { background: #FFFFFF; }
  .roles-hm-cell, .roles-hm-count, .roles-sw, .roles-pip, .roles-seat, .roles-mix-bar { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .roles-print-page { break-after: page; }
  .roles-print-page:last-child { break-after: auto; }
  .roles-hm-row { min-width: 0; }
  .roles-layout, .roles-layout-3 { display: block; }
  .roles-matrix .roles-matrix-name { position: static; }
}
