/* Security Admin: page-specific styles on top of /shared/ui.css (tokens only; CSP allows no inline styles). */
.sa { padding: 12px var(--gutter) 24px; max-width: 1400px; width: 100%; margin: 0 auto; box-sizing: border-box; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 0 12px; overflow-x: auto; scrollbar-width: none; }
.tabs [role=tab] { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; font: 600 1rem var(--f-body); cursor: pointer; color: var(--muted); min-height: 40px; white-space: nowrap; }
.tabs [role=tab][aria-selected=true] { border-bottom-color: var(--accent); color: var(--ink); }

/* list left, details right */
.split { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 16px; align-items: start; }
.split.wide { grid-template-columns: 1fr; }
.split.wide .dcol { display: none; }
.lcol { display: flex; flex-direction: column; gap: 8px; min-width: 0; position: sticky; top: 8px; }
.lcol .scope { margin: 0; }
.lwrap { max-height: calc(100vh - 230px); }
.split.wide .lwrap { max-height: none; }
.lcol .lsearch[hidden] { display: none; }
.rt tbody tr.sel { background: var(--accent-soft); }
.rt tbody tr.noclick { cursor: default; }
.rt td.warn { color: var(--danger); font-weight: 700; }
.rt td.muted { color: var(--muted); }
.dcol { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.dcol .empty .spinner { margin: 0 auto; }

.dhead { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-start; justify-content: space-between; }
.dhead h2 { margin: 0; font: 700 1.5rem var(--f-display); }
.dhead p { margin: 2px 0 0; }
.dhead .acts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.back { display: none; align-self: flex-start; }

.card h3 { margin: 0; font: 700 1.1rem var(--f-display); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card .tw.inner { max-height: 420px; margin-top: 8px; }
.notes .lbl { font-weight: 600; margin-right: 6px; }
.notes .pre { white-space: pre-wrap; }
.notes p { margin: 4px 0; }
.note-edit, .sa-dlg form { display: flex; flex-direction: column; gap: 10px; }
.note-edit textarea { width: 100%; box-sizing: border-box; font: inherit; resize: vertical; }
.dlg-act { display: flex; justify-content: flex-end; gap: 8px; }

/* permission grid */
.rt.acl th.pc, .rt.acl td.pc { text-align: center; width: 36px; padding-left: 4px; padding-right: 4px; }
.rt.acl abbr { text-decoration: none; cursor: help; }
.rt.acl td.pc input { width: 20px; height: 20px; margin: 0; cursor: pointer; }
.rt.acl tbody tr { cursor: default; }
.rt.acl tr.saving { opacity: .55; }

/* pickers */
.picker { position: relative; margin: 4px 0; }
.picker input, .picker select { width: 100%; box-sizing: border-box; }
.pick-list { position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 320px; overflow: auto; }
.pick-list button { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; font: inherit; color: var(--ink); cursor: pointer; min-height: 40px; }
.pick-list button:hover, .pick-list button:focus { background: var(--surface-2); }
.pick-list p { margin: 0; padding: 10px 12px; }

.chips-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips-list li { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 4px 4px 12px; }
.chips-list li.muted { padding-right: 12px; }
.chips-list a { color: inherit; text-decoration: none; font-weight: 600; }
.chips-list .x { background: none; border: 0; color: var(--muted); font-size: 1.1rem; width: 32px; height: 32px; border-radius: 999px; cursor: pointer; }
.chips-list .x:hover { background: var(--danger-soft); color: var(--danger); }

.branch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 12px; margin-top: 6px; }

.refs { background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 14px; }
.refs ul { margin: 6px 0 0; padding-left: 18px; }
.refs p { margin: 0; }

.sa-dlg { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); padding: 20px; width: min(520px, calc(100% - 32px)); }
.sa-dlg::backdrop { background: rgba(0,0,0,.45); }
.sa-dlg h2 { margin: 0; font: 700 1.3rem var(--f-display); }
.sa-dlg label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.sa-dlg .err[hidden], .sa-dlg .refs[hidden] { display: none; }

/* phones and tablets: one column; the list hides while a record is open */
@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .lcol { position: static; }
  .lwrap { max-height: none; }
  .split.has-sel .lcol { display: none; }
  .split:not(.has-sel):not(.wide) .dcol { display: none; }
  .back { display: inline-flex; }
}

/* permission cells: checkbox with a label that only shows on phones */
.pcl { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 32px; min-height: 32px; cursor: pointer; }
.pcl > span { display: none; }
.rt.acl td.pc.ro { color: var(--muted); }
.rt.acl td.pc.ro.on { color: var(--brand-2); font-weight: 700; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--brand-2); padding: 6px 0; min-height: 32px; }
.branch-grid.dim { opacity: .55; }

@media (max-width: 600px) {
  /* permission grid: one card per form/role, the six permissions as labelled tiles in a 3x2 grid */
  .card .tw.inner { max-height: none; overflow: visible; border: 0; background: none; }
  .rt.acl thead { display: none; }
  .rt.acl, .rt.acl tbody { display: block; }
  .rt.acl tr { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .rt.acl td { border: 0; padding: 0; }
  .rt.acl td:not(.pc) { grid-column: 1 / -1; }
  .rt.acl td.num { text-align: left; color: var(--muted); font-size: .85rem; }
  .rt.acl td.num::before { content: "Members: "; }
  .rt.acl td.pc { width: auto; }
  .pcl { width: 100%; justify-content: flex-start; min-height: 44px; padding: 0 10px; box-sizing: border-box; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); }
  .pcl > span { display: inline; font-size: .9rem; }
  .rt.acl td.pc.ro .pcl { cursor: default; }
  .rt.acl td.pc.ro.on .pcl { border-color: var(--brand-2); }

  /* audit: each change as a card */
  .split.wide .lwrap { border: 0; background: none; overflow: visible; }
  .split.wide .rt thead { display: none; }
  .split.wide .rt, .split.wide .rt tbody { display: block; }
  .split.wide .rt tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; padding: 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
  .split.wide .rt td { border: 0; padding: 0; }
  .split.wide .rt td[data-l="What"], .split.wide .rt td[data-l="Item"], .split.wide .rt td[data-l="Change"] { grid-column: 1 / -1; }
  .split.wide .rt td[data-l="When"], .split.wide .rt td[data-l="Who"] { color: var(--muted); font-size: .85rem; }
  .split.wide .rt td[data-l="Who"] { text-align: right; }

  .dhead h2 { font-size: 1.3rem; }
  .rt td.num .btn.link { min-height: 40px; }
}

/* Apps tab */
.apps { display: flex; flex-direction: column; gap: 12px; }
.app-pills { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.app-pills .pill-btn { white-space: nowrap; min-height: 40px; }
.app-pills .cnt { opacity: .7; font-weight: 500; margin-left: 4px; }
#appBody { display: flex; flex-direction: column; gap: 12px; }
.app-intro h2 { margin: 0 0 4px; font: 700 1.4rem var(--f-display); }
.app-intro p { margin: 4px 0; }
.steps { margin: 6px 0; padding-left: 22px; }
.steps li { margin: 4px 0; }
.appq { width: 100%; box-sizing: border-box; font-size: 1rem; padding: 10px 14px; border-radius: 10px; }
.area h3 { margin: 8px 0 6px; font: 700 1.1rem var(--f-display); color: var(--muted); text-transform: none; }
.aform details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 8px; }
.aform summary { cursor: pointer; padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-height: 24px; }
.aform summary a { margin-left: auto; }
.aform details[open] summary { border-bottom: 1px solid var(--line); }
.rt.meaning { font-size: .92rem; }
.rt.meaning tbody tr { cursor: default; }
.rt.meaning td:nth-child(2) { min-width: 240px; }
.rchip { display: inline-block; margin: 2px 4px 2px 0; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); color: var(--ink); text-decoration: none; font-size: .85rem; white-space: nowrap; }
.rchip small { color: var(--muted); margin-left: 2px; }
.rchip:hover { border-color: var(--brand-2); }
.mean-form { display: flex; flex-direction: column; gap: 6px; }
.mean-form textarea { width: 100%; box-sizing: border-box; font: inherit; }
.danger-link { color: var(--danger) !important; }
details.legend { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 12px; margin: 6px 0; }
details.legend summary { cursor: pointer; font-weight: 600; }
.lg-app { margin-top: 6px; }
.lg-app dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 4px 0 0; }
.lg-app dt { font-weight: 600; }
.lg-app dd { margin: 0; }

@media (max-width: 600px) {
  .rt.meaning thead { display: none; }
  .rt.meaning, .rt.meaning tbody { display: block; }
  .rt.meaning tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .rt.meaning td { display: block; border: 0; padding: 2px 0; min-width: 0 !important; }
  .rt.meaning td[data-l="Roles with it"] { margin-top: 4px; }
  .aform summary a { margin-left: 0; }
  .card .tw.inner .rt:not(.acl):not(.meaning) td[data-l] { white-space: normal; }
  .lg-app dl { grid-template-columns: 1fr; }
  .lg-app dd { margin-bottom: 4px; }
}

@media (max-width: 600px) {
  /* cleanup tables: each row a block with labels */
  .rt.stack thead { display: none; }
  .rt.stack, .rt.stack tbody { display: block; }
  .rt.stack tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .rt.stack td { border: 0; padding: 0; text-align: left !important; }
  .rt.stack td:first-child { grid-column: 1 / -1; }
  .rt.stack td[data-l]:not(:first-child)::before { content: attr(data-l) ": "; color: var(--muted); font-size: .85rem; }
  .rt.stack td[data-l="Recommendation"]::before { content: ""; }
}

/* pick dialog, copy access */
.pick-list.inline { position: static; box-shadow: none; max-height: 50vh; min-height: 120px; }
.sa-dlg.wide { width: min(640px, calc(100% - 32px)); }
.sa-dlg input[type=search] { width: 100%; box-sizing: border-box; font-size: 1rem; padding: 10px 12px; }
.copy-from { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.copy-from .lbl { color: var(--muted); }
.radios { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 12px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.radios legend { font-weight: 600; padding: 0 4px; }
.radios .toggle, .sa-dlg .toggle { font-weight: 400; flex-direction: row; min-height: 32px; }
.copy-plan { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 12px; min-height: 24px; }
.copy-plan:empty { display: none; }
.copy-plan p { margin: 4px 0; }
.rchip.add { border-color: var(--brand-2); }
.rchip.rem { border-color: var(--danger); color: var(--danger); text-decoration: line-through; }

/* letters (R E C D X P) */
.letters { font-family: ui-monospace, Consolas, monospace; white-space: nowrap; letter-spacing: .05em; }
.letters > * { display: inline-block; width: 1.2em; text-align: center; }
.letters .off { color: var(--muted); opacity: .5; }
.letters .only { background: var(--accent-soft); border-radius: 4px; font-weight: 700; }

/* compare */
.card.hide-same tr.same { display: none; }
.rt.cmp tbody tr { cursor: default; }
.cmp-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.cmp-col h4 { margin: 0 0 6px; font: 700 1rem var(--f-display); }
.cmp-col ul { margin: 0; padding-left: 18px; max-height: 260px; overflow: auto; }
.cmp-col li { margin: 2px 0; }
.cmp-dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; }
.cmp-dl dt { font-weight: 600; }
.cmp-dl dd { margin: 0; }
.rt.people tbody tr { cursor: default; }

@media (max-width: 600px) {
  .cmp-cols { grid-template-columns: 1fr; }
  .cmp-dl { grid-template-columns: 1fr; }
  .cmp-dl dd { margin-bottom: 6px; }
  .rt.cmp th, .rt.cmp td { padding: 6px 4px; }
  .rt.cmp td:first-child { word-break: break-word; }
}

.rt tr.inactive td { opacity: .75; }
.rt tr.inactive b a { text-decoration: line-through; }
.warn-t { color: var(--danger); font-weight: 700; }
