/* Theme: light by default, dark when the system asks for it, or when the user picks it
   (static/theme.js stores the choice in localStorage as board.theme = light | dark).
   Token names are shared by every part of the page: change values, not names. */
:root {
  color-scheme: light;
  --bg: #f2f4f7;
  --col: #e7ecf2;
  --col-back: #dce3eb;
  --card: #ffffff;
  --text: #1d2733;
  --muted: #66737f;
  --line: #c4cfdb;
  --chip: #e3eaf2;
  --track: #d6dee7;
  --backlog: #8a97a6;
  --working: #2f80ed;
  --amber: #e8a317;
  --blocked: #e5534b;
  --done: #2e9b64;
  --danger: #c2413a;
  --warn: #b56a00;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 40, .08);
  --prio-low: #9aa5b1;
  --prio-normal: #2f80ed;
  --prio-high: #e0792b;
  --prio-urgent: #c2413a;
  --done-bg: #e6f6ee;
  --done-line: #9fd3b8;
  --done-text: #2f6b50;
  --blk-a: #ffffff;
  --blk-b: #f9d2cb;
  --blk-line: #d9655a;
  --reason-bg: #ffffff;
  --reason-text: #9b2c24;
  --tag-1: #c2413a; /* bug, always red */
  --tag-2: #2e9b64;
  --tag-3: #8e44ad;
  --tag-4: #2f80ed;
  --tag-5: #14937c;
  --tag-6: #b56a00;
  --av-1: #3f72af;
  --av-2: #e4572e;
  --av-3: #29a19c;
  --av-4: #b16cea;
  --av-5: #b98500;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121a22;
    --col: #1c2732;
    --col-back: #26323f;
    --card: #2b3a4a;
    --text: #eef3f8;
    --muted: #b0c0cf;
    --line: #5a6f85;
    --chip: #3d4f62;
    --track: #43566a;
    --working: #5aa0ff;
    --amber: #f0b35a;
    --blocked: #ff8a80;
    --done: #4fc38a;
    --danger: #ff8a80;
    --warn: #f0b35a;
    --shadow: 0 2px 6px rgba(0, 0, 0, .35);
    --prio-low: #7d8c9c;
    --prio-normal: #5aa0ff;
    --prio-high: #ff9d5c;
    --prio-urgent: #ff6b61;
    --done-bg: #1d3b2e;
    --done-line: #3f8a68;
    --done-text: #a6e6c6;
    --blk-a: #2e3d4e;
    --blk-b: #7a332e;
    --blk-line: #ff8a80;
    --reason-bg: #16202a;
    --reason-text: #ffc2bb;
    --tag-1: #ff8a80;
    --tag-2: #6fd39c;
    --tag-3: #c39bef;
    --tag-4: #7fb4ff;
    --tag-5: #5fd6bf;
    --tag-6: #f0b35a;
    --av-1: #5a8fcc;
    --av-2: #ff8a65;
    --av-3: #4fc0b8;
    --av-4: #c58cf2;
    --av-5: #e0b34a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121a22;
  --col: #1c2732;
  --col-back: #26323f;
  --card: #2b3a4a;
  --text: #eef3f8;
  --muted: #b0c0cf;
  --line: #5a6f85;
  --chip: #3d4f62;
  --track: #43566a;
  --working: #5aa0ff;
  --amber: #f0b35a;
  --blocked: #ff8a80;
  --done: #4fc38a;
  --danger: #ff8a80;
  --warn: #f0b35a;
  --shadow: 0 2px 6px rgba(0, 0, 0, .35);
  --prio-low: #7d8c9c;
  --prio-normal: #5aa0ff;
  --prio-high: #ff9d5c;
  --prio-urgent: #ff6b61;
  --done-bg: #1d3b2e;
  --done-line: #3f8a68;
  --done-text: #a6e6c6;
  --blk-a: #2e3d4e;
  --blk-b: #7a332e;
  --blk-line: #ff8a80;
  --reason-bg: #16202a;
  --reason-text: #ffc2bb;
  --tag-1: #ff8a80;
  --tag-2: #6fd39c;
  --tag-3: #c39bef;
  --tag-4: #7fb4ff;
  --tag-5: #5fd6bf;
  --tag-6: #f0b35a;
  --av-1: #5a8fcc;
  --av-2: #ff8a65;
  --av-3: #4fc0b8;
  --av-4: #c58cf2;
  --av-5: #e0b34a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }
.error:empty { display: none; }
.ok { color: var(--done); font-size: 13px; }
.ok:empty { display: none; }
.warn { color: var(--warn); font-weight: 600; }
code { font-size: 12px; background: var(--chip); padding: 1px 5px; border-radius: 4px; }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--card);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.status { color: var(--muted); font-size: 12px; }
.status.error { color: var(--danger); }
.who { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.who .name { font-weight: 700; margin-right: 4px; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; border-radius: 50%; overflow: hidden;
  background: var(--line); color: var(--muted); font-size: 12px; font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 72px; height: 72px; font-size: 26px; }
.avatar-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.theme-btn { font-size: 12px; padding: 5px 10px; }

/* Controls */
input, textarea, select {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 36px; }
button {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 12px;
  white-space: nowrap;
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--working); border-color: var(--working); color: #fff; }
button.danger { color: var(--danger); }
button.link-danger { border: 0; background: none; color: var(--danger); padding: 0 4px; font-size: 12px; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.check { display: flex; align-items: center; gap: 6px; font-weight: 500; color: var(--text); }
label.check input { width: auto; }
.linkish { display: inline; color: var(--working); cursor: pointer; text-decoration: underline; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; }
legend { font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 4px; }
.checks { display: grid; gap: 4px; max-height: 220px; overflow: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Login */
.login {
  max-width: 360px; margin: 12vh auto 0; padding: 22px; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px;
}
.login h2 { margin: 0 0 14px; font-size: 18px; }
.login form { display: grid; gap: 12px; }
.links { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; font-size: 13px; }
.links a { color: var(--working); }

/* Board */
main { padding: 16px 20px; }
.toolbar { display: grid; gap: 10px; margin-bottom: 14px; }
.add { display: grid; grid-template-columns: minmax(200px, 1fr) auto; gap: 8px; }
.filters { display: grid; grid-template-columns: minmax(130px, 1fr) 2fr repeat(4, minmax(120px, 1fr)) auto; gap: 8px; }
.board {
  display: grid; grid-template-columns: repeat(4, minmax(230px, 1fr)); gap: 12px;
  align-items: start; overflow-x: auto;
}
.column {
  background: var(--col); border-radius: 12px; padding: 10px; min-height: 240px;
  border-top: 4px solid var(--c);
}
.col-backlog { --c: var(--backlog); background: var(--col-back); }
.col-working { --c: var(--amber); }
.col-blocked { --c: var(--blocked); }
.col-done { --c: var(--done); }
.column.over { outline: 2px dashed var(--c); outline-offset: -4px; }
.column h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin: 4px 4px 10px;
  display: flex; justify-content: space-between; color: var(--muted);
}
.column h2 .count { color: var(--text); font-weight: 700; }
.card {
  position: relative;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
  border-left: 5px solid var(--prio-normal); box-shadow: var(--shadow);
}
.card.prio-low { border-left-color: var(--prio-low); }
.card.prio-normal { border-left-color: var(--prio-normal); }
.card.prio-high { border-left-color: var(--prio-high); }
.card.prio-urgent { border-left-color: var(--prio-urgent); }
.card:hover { filter: brightness(1.04); box-shadow: 0 4px 14px rgba(0, 0, 0, .14); }
.card .title { font-weight: 700; margin-bottom: 4px; word-break: break-word; }
.card .desc { color: var(--muted); font-size: 13px; word-break: break-word; }
/* Blocked: diagonal stripes; the reason sits in its own box so it stays readable */
.card.is-blocked {
  background: repeating-linear-gradient(135deg, var(--blk-a) 0 9px, var(--blk-b) 9px 18px);
  border-color: var(--blk-line);
}
.card .reason {
  margin-top: 6px; font-size: 12px; padding: 4px 8px; border-radius: 6px;
  background: var(--reason-bg); color: var(--reason-text); border: 1px dashed var(--blk-line);
}
/* Done: green card, struck title */
.card.is-done { background: var(--done-bg); border-color: var(--done-line); }
.card.is-done .title { color: var(--done-text); text-decoration: line-through; text-decoration-color: var(--done-line); }
.card .meta {
  margin-top: 8px; font-size: 11px; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card .meta .who-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.card .meta .counts { display: flex; gap: 6px; white-space: nowrap; }
.empty { color: var(--muted); font-size: 13px; padding: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 1px 8px;
  border-radius: 999px; background: var(--chip); color: var(--text); white-space: nowrap;
}
/* Tags: colour from a small palette, picked by the lowercased name (see tagSlot in app.js) */
.chip.tag-1, .chip.tag-2, .chip.tag-3, .chip.tag-4, .chip.tag-5, .chip.tag-6 {
  font-weight: 600;
}
.chip.tag-1 { color: var(--tag-1); background: color-mix(in srgb, var(--tag-1) 18%, transparent); }
.chip.tag-2 { color: var(--tag-2); background: color-mix(in srgb, var(--tag-2) 18%, transparent); }
.chip.tag-3 { color: var(--tag-3); background: color-mix(in srgb, var(--tag-3) 18%, transparent); }
.chip.tag-4 { color: var(--tag-4); background: color-mix(in srgb, var(--tag-4) 18%, transparent); }
.chip.tag-5 { color: var(--tag-5); background: color-mix(in srgb, var(--tag-5) 18%, transparent); }
.chip.tag-6 { color: var(--tag-6); background: color-mix(in srgb, var(--tag-6) 18%, transparent); }
.chip.epic { background: color-mix(in srgb, var(--working) 22%, transparent); }
.chip.prio-high { background: color-mix(in srgb, var(--prio-high) 24%, transparent); }
.chip.prio-urgent { background: color-mix(in srgb, var(--prio-urgent) 25%, transparent); }
.chip.prio-low { opacity: .75; }
/* Small initials avatar on the card footer; colour from the name */
.av {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 22px; height: 22px; border-radius: 50%; color: #fff;
  font-size: 9.5px; font-weight: 700; letter-spacing: .02em;
  border: 2px solid var(--card);
}
.av-1 { background: var(--av-1); }
.av-2 { background: var(--av-2); }
.av-3 { background: var(--av-3); }
.av-4 { background: var(--av-4); }
.av-5 { background: var(--av-5); }
.chip-x { border: 0; background: none; padding: 0 2px; font-size: 13px; line-height: 1; color: var(--muted); }
.notes-flag { color: var(--working); font-weight: 700; }

/* Dialogs */
dialog {
  width: min(680px, calc(100% - 24px)); border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--text); padding: 18px;
}
dialog.wide { width: min(1080px, calc(100% - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.item-form { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; }
.item-main, .item-side { display: grid; gap: 12px; align-content: start; }
.item-side h3, .editor h3, .tab h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.field { display: grid; gap: 4px; }
.field .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.dialog-actions { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 14px; text-align: center;
  color: var(--muted); font-size: 13px;
}
.dropzone.over { border-color: var(--working); color: var(--text); }
.attachments { display: grid; gap: 8px; margin-top: 8px; }
.attachment { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
.attachment img { max-width: 100%; max-height: 140px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.attachment .file { word-break: break-all; }
.attachment .muted { grid-column: 1 / 2; }
.attachment button { grid-row: 1; grid-column: 2; }
.comments { display: grid; gap: 8px; max-height: 260px; overflow: auto; }
.comment { border-left: 3px solid var(--line); padding-left: 8px; }
.comment .body { white-space: pre-wrap; word-break: break-word; }
.comment-form { display: grid; gap: 6px; margin-top: 8px; }
.comment-form button { justify-self: end; }
.activity { display: grid; gap: 4px; font-size: 12px; color: var(--muted); max-height: 220px; overflow: auto; margin-top: 6px; }

/* Admin */
.tabs { display: flex; gap: 6px; margin: 6px 0 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--working); }
.row-tools { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin: 8px 0; flex-wrap: wrap; }
.row-tools input[type="search"] { max-width: 360px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.table tr.off td { color: var(--muted); }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--col); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; color: var(--working); margin-left: 6px; }
.list { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 6px; }
.list li { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.list li:hover { background: var(--col); }
.list li.selected { border-color: var(--working); }
.editor { display: grid; gap: 10px; margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.projects { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.bar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; width: 90px; }
.bar span { display: block; height: 100%; background: var(--done); }
.token-result { margin-top: 12px; display: grid; gap: 8px; }
.token-result input { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.row-tools input#tokenValue { flex: 1; }

@media (max-width: 900px) {
  .board { grid-template-columns: repeat(4, minmax(240px, 1fr)); }
  .item-form, .projects { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .add { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- header user menu */
.topbar .who { position: relative; }
.userbox { position: relative; }
.userbtn {
  display: inline-flex; align-items: center; gap: 8px; max-width: 220px;
  background: transparent; border-color: transparent; padding: 3px 8px 3px 3px; border-radius: 999px;
}
.userbtn .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbtn .caret { color: var(--muted); font-size: 11px; }
.userbtn:hover, .userbtn[aria-expanded="true"] { background: var(--col); }
/* The menu sits directly under the trigger with its own padding, so the pointer never leaves the hover area. */
.usermenu {
  display: none; position: absolute; right: 0; top: 100%; min-width: 180px; z-index: 20;
  padding-top: 6px;
}
.usermenu > button {
  display: block; width: 100%; text-align: left; border-radius: 0; font-weight: 500;
  background: var(--card); border: 1px solid var(--line); border-bottom: 0; padding: 9px 12px;
}
.usermenu > button:first-child { border-radius: 8px 8px 0 0; }
.usermenu > button:last-child { border-bottom: 1px solid var(--line); border-radius: 0 0 8px 8px; }
.usermenu > button:hover, .usermenu > button:focus-visible { background: var(--col); }
.usermenu.open { display: block; }
@media (hover: hover) {
  .userbox:hover .usermenu { display: block; }
}
.userbox:has(:focus-visible) .usermenu { display: block; }

/* ---------------------------------------------------------------- admin shell */
dialog.admin { width: min(1180px, calc(100% - 24px)); padding: 0; max-height: calc(100vh - 24px); overflow: hidden; }
dialog.admin[open] { display: flex; flex-direction: column; }
.admin-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 20px 12px; border-bottom: 1px solid var(--line);
}
.admin-head h2 { margin: 0 0 2px; font-size: 19px; }
.admin-head p { margin: 0; }
.admin-body { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 0; flex: 1; }
.admin-nav {
  border-right: 1px solid var(--line); padding: 12px 8px; background: var(--panel);
  display: flex; flex-direction: column; gap: 2px; overflow: auto;
}
.admin-nav .nav-group {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  padding: 12px 10px 4px; font-weight: 700;
}
.admin-nav .nav-group:first-child { padding-top: 4px; }
.admin-nav button {
  text-align: left; border: 0; background: transparent; border-radius: 8px; padding: 7px 10px;
  color: var(--text); font-weight: 500;
}
.admin-nav button:hover { background: var(--col); }
.admin-nav button[aria-selected="true"] { background: var(--col-back); color: var(--text); font-weight: 700; box-shadow: inset 3px 0 0 var(--working); }
.admin-main { padding: 14px 20px 18px; overflow: auto; min-width: 0; }
.section-head { margin-bottom: 10px; }
.section-head h3 { margin: 0 0 2px; font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.section-head p { margin: 0; }
.term { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0; text-transform: none; font-family: ui-monospace, Menlo, monospace; }
.strong + .chip, .strong + .tag { margin-left: 6px; }
#usersBody td:nth-child(3), #usersBody td:nth-child(4) { white-space: nowrap; }
.subhead { font-size: 13px; margin: 18px 0 6px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.subsection { margin-top: 6px; }
.subsection h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.pane { min-width: 0; }
.pane.detail { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--panel); position: sticky; top: 0; }
.empty-detail { color: var(--muted); font-size: 13px; padding: 26px 8px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.table-wrap .table { border: 0; }
.table tr.selected td { background: var(--col-back); }
.strong { font-weight: 650; }
.block { display: block; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-tools label.inline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.row-tools label.inline select { width: auto; min-width: 200px; }
.table tr.dirty td { background: color-mix(in srgb, var(--amber) 12%, transparent); }
.tag { color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-left: 6px; font-size: 10.5px; font-weight: 600; }

/* ---------------------------------------------------------------- chips and permission marks */
.chip.role { background: var(--col-back); color: var(--text); font-weight: 600; border: 1px solid var(--line); }
.chip.via { background: transparent; color: var(--text); border: 1px dashed var(--muted); }
.chip.super { background: color-mix(in srgb, var(--working) 22%, transparent); color: var(--text); font-weight: 600; }
.chip.danger { background: color-mix(in srgb, var(--danger) 22%, transparent); color: var(--text); }
.chip.warn { background: color-mix(in srgb, var(--warn) 24%, transparent); color: var(--text); }
.chip.ok { background: color-mix(in srgb, var(--done) 22%, transparent); color: var(--text); }
.perm-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.perm { font-size: 10.5px; border-radius: 4px; padding: 0 6px; background: var(--track); color: var(--text); }
.access-list { display: grid; gap: 8px; }
.access-row {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card);
}
.access-name { font-weight: 650; }
.access-roles { display: flex; flex-wrap: wrap; gap: 4px; }
.access-row .perm-chips { margin-top: 2px; }

/* ---------------------------------------------------------------- oikeusmatriisi */
.matrix { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.matrix th, .matrix td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.matrix thead th { position: sticky; top: 0; background: var(--panel); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: center; z-index: 1; }
.matrix thead th:first-child, .matrix tbody td:first-child { text-align: left; }
.matrix th.perm-col code { font-size: 11.5px; color: var(--text); text-transform: none; letter-spacing: 0; display: block; }
.matrix th.perm-col .muted { text-transform: none; letter-spacing: 0; font-size: 11px; font-weight: 400; }
.matrix td.perm-cell { text-align: center; }
.matrix td.perm-cell input { width: 18px; height: 18px; accent-color: var(--done); cursor: pointer; margin: 2px; }
.matrix td.perm-cell input:disabled { cursor: default; }
.matrix tbody tr:last-child td { border-bottom: 0; }
.matrix .role-name { min-width: 240px; }
.matrix .role-name input { margin-bottom: 4px; }
.matrix .note { display: block; margin-top: 4px; font-size: 11.5px; color: var(--muted); }
.matrix tr.draft td { background: color-mix(in srgb, var(--working) 8%, transparent); }
.matrix td .link-danger { font-size: 12px; }
.savebar {
  position: sticky; bottom: 0; margin-top: 10px; padding: 10px 12px; display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); flex-wrap: wrap;
}
.savebar > span:first-child { font-size: 13px; color: var(--text); }

@media (max-width: 900px) {
  .admin-body { grid-template-columns: 1fr; }
  .admin-nav { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); }
  .admin-nav .nav-group { width: 100%; padding: 6px 4px 0; }
  .split { grid-template-columns: 1fr; }
  .pane.detail { position: static; }
  .userbtn .name { display: none; }
}
