*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.is-loading { visibility: hidden; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }
.muted { color: var(--text-muted); margin: 0; }
.eyebrow { margin: 0 0 6px; color: var(--accent-strong); font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }

/* Logo (Bodyline): zwei Masken, damit die Farben dem Thema folgen */
.logo { position: relative; display: inline-block; flex: none; width: 30px; aspect-ratio: 256 / 244; }
.logo::before, .logo::after {
  content: ""; position: absolute; inset: 0;
  -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat;
}
.logo::before { --m: url("/assets/img/logo-tool.png"); background: var(--logo-tool); }
.logo::after { --m: url("/assets/img/logo-accent.png"); background: var(--logo-accent); }
.logo--large { width: 64px; }

/* Buttons & Felder */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s;
}
.button--primary { background: var(--accent); color: var(--on-accent); width: 100%; }
.button--primary:hover { background: var(--accent-strong); }
.button--primary:disabled { opacity: .6; cursor: progress; }
.button--ghost { background: transparent; color: var(--text); border-color: var(--border); height: 34px; }
.button--ghost:hover { background: var(--surface-hover); }
.icon-button {
  height: 34px; min-width: 34px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.icon-button svg { display: block; }
.icon-button:hover { color: var(--text); background: var(--surface-hover); }
.link { background: none; border: 0; padding: 0; color: var(--text-muted); font: inherit; font-size: 12px; cursor: pointer; }
.link:hover { color: var(--accent-strong); }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--text-muted); }
.field input {
  height: 42px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px;
}
.field input:focus { border-color: var(--accent); outline: none; box-shadow: var(--focus); }
.message { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--error-soft); color: var(--error); font-size: 13px; }
.hint { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-strong); font-size: 13px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border);
  font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--text-muted);
}

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; background: var(--login-bg); }
.login-panel { width: min(920px, 100%); display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: center; }
.login-heading { font-size: 36px; line-height: 1.15; margin: 4px 0 12px; }
.login-lead { margin: 0; color: var(--text-muted); max-width: 38ch; font-size: 15px; }
.login-intro .logo { margin-bottom: 22px; }
.login-card {
  display: grid; gap: 16px; padding: 28px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lift);
}
.card-title { font-size: 18px; }
.login-foot { display: flex; justify-content: space-between; }

/* Shell */
.shell { min-height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.topbar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 0 24px; height: 60px; background: var(--topbar); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.user { display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; border-radius: 10px; color: inherit; text-decoration: none; }
.user:hover, .user.is-active { background: var(--surface-hover); }
.user-text { display: grid; line-height: 1.2; }
.user-name { font-weight: 600; }
.user-title { font-size: 11px; color: var(--text-muted); }
.user-title:empty { display: none; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 700;
}
.content { width: min(1120px, 100%); margin: 0 auto; padding: 40px 24px 56px; display: grid; gap: 36px; align-content: start; }
.welcome h1 { font-size: 28px; margin-bottom: 6px; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.section-head h2 { font-size: 15px; }
.count { color: var(--text-muted); font-size: 13px; }
.footer { display: flex; justify-content: space-between; padding: 16px 24px; color: var(--text-muted); font-size: 12px; border-top: 1px solid var(--border); }
.empty { color: var(--text-muted); }

/* Navigation */
.brand { flex: 0 1 auto; }
.nav { display: flex; gap: 4px; margin-right: auto; margin-left: 24px; }
.nav-link { padding: 6px 12px; border-radius: 8px; color: var(--text-muted); text-decoration: none; font-weight: 500; }
.nav-link:hover { color: var(--text); background: var(--surface-hover); }
.nav-link.is-active { color: var(--text); background: var(--surface-2); }
.button--auto { width: auto; }
.small { font-size: 12px; }

/* Benutzerverwaltung */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head h1 { font-size: 24px; margin-bottom: 4px; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: -20px; }
.search {
  height: 38px; width: min(340px, 100%); padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.search:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-hover); }
.cell-user { display: flex; align-items: center; gap: 10px; }
.cell-user small { display: block; color: var(--text-muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.chip--all { color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); }
.status { font-size: 12px; font-weight: 600; }
.status--on { color: var(--ok); }
.status--off { color: var(--error); }

/* Dialog */
.dialog { width: min(640px, calc(100% - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lift); }
.dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog-body { display: grid; gap: 18px; padding: 24px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { font-size: 18px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field select {
  height: 42px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px;
}
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.apps-box { margin: 0; padding: 14px 16px 12px; border: 1px solid var(--border); border-radius: 10px; display: grid; gap: 10px; }
.apps-box legend { padding: 0 6px; font-weight: 600; font-size: 13px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.check {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
}
.check:has(input:checked) { border-color: var(--check-accent, var(--accent)); background: color-mix(in srgb, var(--check-accent, var(--accent)) 10%, var(--surface-2)); }
.check:has(input:disabled) { cursor: default; opacity: .75; }
.check input { width: 16px; height: 16px; accent-color: var(--check-accent, var(--accent)); }
.check small { display: block; color: var(--text-muted); font-size: 11px; }
.pw-reset summary { cursor: pointer; color: var(--text-muted); font-size: 13px; }
.pw-row { display: flex; gap: 8px; margin-top: 10px; }
.pw-row input { flex: 1; height: 38px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; }

/* Mein Konto */
.content--narrow { width: min(820px, 100%); }
.content--narrow h1 { font-size: 24px; margin-bottom: 4px; }
.account-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.account-logout { display: none !important; }
.card { display: grid; gap: 18px; padding: 24px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.card h2 { font-size: 16px; }
.card-foot { display: flex; justify-content: flex-end; }
.form-grid--3 { grid-template-columns: repeat(3, 1fr); }
.profile-head { display: flex; align-items: center; gap: 16px; }
.profile-head > div { display: grid; gap: 2px; }
.profile-head strong { font-size: 18px; }
.avatar { color: var(--accent-strong); }
.avatar--symbol { background: var(--avatar-bg, var(--accent-soft)); color: #fff; font-size: 16px; }
.avatar--xl { width: 64px; height: 64px; font-size: 22px; }
.avatar--xl.avatar--symbol { font-size: 32px; }
.symbol-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
.symbol {
  height: 46px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  font-size: 22px; cursor: pointer; display: grid; place-items: center; color: var(--text);
}
.symbol--text { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.symbol:hover { border-color: var(--accent); }
.symbol[aria-checked="true"] { border-color: var(--accent); box-shadow: var(--focus); background: var(--accent-soft); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; background: var(--sw); cursor: pointer; }
.swatch[aria-checked="true"] { border-color: var(--text); box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--sw); }
.message { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.message-close {
  flex: none; width: 26px; height: 26px; border-radius: 6px; border: 0; background: transparent;
  color: inherit; font: inherit; font-size: 13px; cursor: pointer; opacity: .75;
}
.message-close:hover { opacity: 1; background: color-mix(in srgb, currentColor 15%, transparent); }
.account-actions { display: flex; gap: 8px; align-items: center; }
.icon-button--close { display: inline-grid; place-items: center; width: 36px; height: 36px; text-decoration: none; font-size: 14px; }
.message.is-ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }

/* Kacheln */
.tiles { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.tile-link {
  --tile-accent: var(--accent);
  position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-rows: 1fr auto; gap: 14px 16px;
  min-height: 148px; padding: 18px; border-radius: 14px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: inherit; text-decoration: none; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.tile-link::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--tile-accent); }
a.tile-link:hover { transform: translateY(-2px); border-color: var(--tile-accent); box-shadow: var(--shadow-lift); }
.tile-mono {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 700; font-size: 17px; letter-spacing: .02em; color: var(--tile-accent);
  background: color-mix(in srgb, var(--tile-accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--tile-accent) 35%, transparent);
}
.tile-body { display: grid; gap: 4px; align-content: start; }
.tile-name { font-size: 16px; font-weight: 600; }
.tile-desc { color: var(--text-muted); font-size: 13px; }
.tile-meta { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; }
.tile-state { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--tile-accent); }
.tile--disabled .tile-link { cursor: default; opacity: .62; }
.tile--disabled .tile-link:hover { transform: none; border-color: var(--border); box-shadow: var(--shadow); }
.tile--disabled .tile-state { color: var(--text-muted); font-weight: 500; }

@media (max-width: 760px) {
  .login-panel { grid-template-columns: 1fr; gap: 24px; }
  .login-heading { font-size: 28px; }
  .topbar { padding: 0 16px; gap: 8px; }
  .topbar-actions { gap: 6px; }
  .user { padding: 0; }
  .user-name { display: none; }
  .content { padding: 28px 16px 40px; }
  .nav { margin-left: 8px; }
  .form-grid, .form-grid--3 { grid-template-columns: 1fr; }
  .user-text { display: none; }
  .page-head { flex-direction: column; align-items: stretch; }
}
@media (max-width: 440px) {
  .brand-name, .icon-button--lang, .topbar-actions > [data-action="logout"] { display: none; }
  .account-logout { display: inline-flex !important; }
  .nav-link { padding: 6px 8px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Kontosicherheit ---------- */
.last-login { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px; padding: 8px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); font-size: 13px; text-decoration: none; }
.last-login:hover { border-color: var(--accent); color: var(--text); }
.last-login strong { color: var(--text); font-weight: 600; }
.last-login.is-warn { border-color: color-mix(in srgb, var(--warn) 60%, transparent); }
.last-login .warn { color: var(--warn); font-weight: 600; }
.sec-prev { display: grid; gap: 4px; padding: 14px 16px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.sec-prev strong { font-size: 15px; }
.sec-prev .warn { color: var(--warn); font-weight: 600; }
h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.section-head--tight { justify-content: space-between; margin-bottom: 4px; }
.session-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.session-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; }
.session-list li small { color: var(--text-muted); display: block; }
.table-wrap--flat { box-shadow: none; }
.table--compact td, .table--compact th { padding: 8px 12px; font-size: 13px; }
.ok { color: var(--ok); font-weight: 600; } .bad { color: var(--error); font-weight: 600; }

/* ---------- Rechte ---------- */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.seg button { border: 0; background: transparent; color: var(--text-muted); font: inherit; font-weight: 500; padding: 6px 14px; border-radius: 7px; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--accent); color: var(--on-accent); }
.seg--small { margin-left: 0; }
#rights-body { display: grid; gap: 18px; }
#rights-body > .seg { justify-self: start; }
.rights-grid { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
.subjects { gap: 10px; padding: 16px; position: sticky; top: 12px; }
.subjects h2 { font-size: 13px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.subject-list { display: grid; gap: 4px; max-height: 340px; overflow: auto; }
.subject { display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; border: 1px solid transparent;
  background: transparent; color: var(--text); font: inherit; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.subject:hover { background: var(--surface-hover); }
.subject[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); }
.subject small { color: var(--text-muted); font-size: 11px; }
.search--small { height: 34px; width: 220px; }
.subjects .search--small { width: 100%; }
.add-role summary { cursor: pointer; color: var(--text-muted); font-size: 13px; }
.matrix-wrap { display: grid; gap: 12px; min-width: 0; }
.matrix-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.matrix-actions { display: flex; gap: 8px; align-items: center; }
.matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
.matrix th { position: sticky; top: 0; background: var(--surface); text-align: center; font-size: 11px; font-weight: 600; color: var(--text-muted);
  padding: 10px 6px; border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: .04em; z-index: 1; }
.matrix th:first-child { text-align: left; padding-left: 14px; }
.matrix td { padding: 6px; border-bottom: 1px solid var(--border); text-align: center; }
.matrix td:first-child { text-align: left; padding-left: 14px; }
.matrix tr.is-table td { background: var(--surface-2); font-weight: 600; }
.matrix tr.is-field td:first-child { padding-left: 40px; font-weight: 400; }
.matrix tr.is-dirty td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.matrix tr.is-override td:first-child::after { content: "persönlich"; margin-left: 8px; font-size: 10px; color: var(--accent-strong); font-weight: 600; }
.matrix input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.matrix input.inherited { opacity: .45; }
.matrix select { height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: 12px; }
.caret { border: 0; background: none; color: var(--text-muted); cursor: pointer; width: 20px; font-size: 11px; }
.obj-name small { color: var(--text-muted); font-weight: 400; margin-left: 6px; font-family: ui-monospace, monospace; font-size: 11px; }
.tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.tag--new { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.tag--secret { background: var(--surface-hover); color: var(--text-muted); }
.reset { border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: 14px; }
.reset:hover { color: var(--accent-strong); }
.full-note { padding: 24px; display: grid; gap: 6px; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.role-grid label { display: grid; gap: 4px; font-size: 12px; color: var(--text-muted); }
.role-grid select { height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; }
.gov-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
@media (max-width: 860px) {
  .rights-grid { grid-template-columns: 1fr; }
  .subjects { position: static; }
  .search--small { width: 100%; }
  .matrix-actions { width: 100%; }
  .seg--small { margin-left: 0; margin-top: 8px; }
}
