/* ----------------------------------------------------------------------------
 * asc Merkmal-Matrix — gefma-aligned visual system
 * Tokens follow the gefma brand: deep navy ink (#192052), vibrant royal-blue
 * accent (#4165FF), light-gray surfaces, Roboto type, hard-edged geometry.
 * Reads like a serious facility-management workspace — flat, structured,
 * professional, no decorative texture.
 * ------------------------------------------------------------------------- */

:root {
  /* surfaces */
  --paper:         #ededed;
  --paper-2:       #dedede;
  --paper-3:       #d2d4dc;
  --surface:       #ffffff;     /* cards, panels, login, dialog */

  /* ink */
  --ink:           #192052;     /* gefma textPrimary navy */
  --ink-soft:      #2b3158;
  --muted:         #6c6f81;
  --muted-2:       #9a9eaf;
  --line:          #c8ccd9;
  --line-strong:   #a4a9bd;

  /* accents */
  --accent:        #4165ff;     /* gefma vibrant royal blue */
  --accent-strong: #1920a0;     /* gefma deep blue */
  --accent-soft:   #dbe2ff;     /* light blue for focus rings + cell-flash */
  --warn:          #b71c1c;

  /* type */
  --font-body:    "Roboto", "Helvetica", Arial, sans-serif;
  --font-display: "Roboto", "Helvetica", Arial, sans-serif;
  --font-mono:    "Roboto Mono", ui-monospace, monospace;

  /* metrics */
  --rule-thin: 1px;
  --rule-bold: 3px;
  --radius:    0;   /* gefma uses square edges */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color .12s;
}
a:hover { color: var(--accent-strong); text-decoration-thickness: 2px; }

::selection { background: var(--accent-soft); color: var(--ink); }

/* --------- typography --------- */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.005em;
  color: var(--ink);
  margin: 0;
}
h1 { font-size: 1.85rem;  line-height: 1.2;  margin: 0 0 1.1rem; font-weight: 700; }
h2 { font-size: 1.25rem;  line-height: 1.25; margin: 1.9rem 0 .75rem; font-weight: 600; }
h3 { font-size: 1.02rem;  line-height: 1.35; margin: 1.3rem 0 .5rem;  font-weight: 600; }
p  { margin: 0 0 0.85rem; }

code, .mono { font-family: var(--font-mono); font-size: 0.9em; }
code {
  background: var(--paper-2);
  padding: 0.05rem 0.35rem;
  border-radius: var(--radius);
}
pre {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
  background: var(--paper-2);
  padding: 1rem 1.1rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  border-left: 2px solid var(--line-strong);
}
.muted { color: var(--muted); font-size: 0.85em; }

/* --------- topbar --------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.95rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--ink);
}
.brand:hover { color: var(--ink); text-decoration: none; }
.brand-mark {
  font-style: italic;
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.brand-divider {
  display: inline-block;
  width: 1px;
  height: 1.05rem;
  background: var(--line-strong);
  margin: 0 0.15rem 0 0.05rem;
  transform: translateY(0.15rem);
}
.brand-name {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink);
}

.nav {
  display: flex;
  align-items: center;
  gap: 1.85rem;
  flex: 1;
  margin-left: 1rem;
}
.nav a {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.35rem 0;
  position: relative;
}
.nav a::after {
  content: "";
  position: absolute;
  left: 0; right: 100%;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  transition: right .18s ease;
}
.nav a:hover { color: var(--ink); text-decoration: none; }
.nav a:hover::after { right: 0; }

.user {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.user-meta { display: inline-flex; align-items: center; gap: 0.55rem; }
.user-name { color: var(--ink); }
.user-role {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 0.05rem 0.42rem;
  background: var(--paper);
  border-radius: var(--radius);
}
.user form { margin: 0; }

/* --------- main --------- */

main {
  max-width: 96rem;
  margin: 0 auto;
  padding: 2rem 2rem 4.5rem;
}
section { margin: 1.75rem 0; }
section > h2 {
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.45rem;
  margin-top: 2.25rem;
}

/* --------- form controls --------- */

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 500;
  padding: 0 1.15rem;
  min-height: 2.4rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background .12s, color .12s, border-color .12s;
}
button:hover, .button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
  text-decoration: none;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--ink);
}
button.ghost:hover {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

input:not([type]),
input[type=text], input[type=email], input[type=number], input[type=password], input[type=search],
select, textarea, input[type=file] {
  font-family: var(--font-body);
  font-size: 0.94rem;
  line-height: 1.4;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0.5rem 0.7rem;
  min-height: 2.4rem;
  width: 100%;
  transition: border-color .12s, box-shadow .12s, background .12s;
}
input[type=number] { -moz-appearance: textfield; }
input::placeholder { color: var(--muted-2); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%236c6f81' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M1.5 1.5 L6 6.5 L10.5 1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 10px 7px;
  padding-right: 2rem;
}
select:focus {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%234165ff' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M1.5 1.5 L6 6.5 L10.5 1.5'/></svg>");
}

input[type=file] {
  padding: 0.45rem 0.5rem;
  background: var(--surface);
  cursor: pointer;
}
input[type=file]::file-selector-button {
  font: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.45rem 1rem;
  margin-right: 0.85rem;
  cursor: pointer;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 500;
  border-radius: var(--radius);
}
input[type=file]::file-selector-button:hover { background: var(--accent-strong); }

input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  width: 3rem;
  height: 2rem;
  padding: 2px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  cursor: pointer;
  border-radius: var(--radius);
  vertical-align: middle;
  transition: border-color .12s, box-shadow .12s;
}
input[type="color"]:hover { border-color: var(--accent); }
input[type="color"]:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 0; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 0; }
.grid input[type="color"] { width: 3rem; height: 1.85rem; }

label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

/* checkbox: hollow square ↔ filled accent square with white check */
input[type=checkbox] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  border: 1.5px solid var(--ink-soft);
  background: var(--surface);
  cursor: pointer;
  position: relative;
  border-radius: var(--radius);
  vertical-align: middle;
  transition: background .1s, border-color .1s, box-shadow .1s;
}
input[type=checkbox]:hover { border-color: var(--accent); }
input[type=checkbox]:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
input[type=checkbox]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type=checkbox]:checked::after {
  content: "";
  position: absolute;
  inset: 0;
  background-color: #fff;
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M3.5 8.4 L6.6 11.4 L12.7 4.7' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  -webkit-mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M3.5 8.4 L6.6 11.4 L12.7 4.7' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  mask-size: 100% 100%;
  mask-repeat: no-repeat;
}

/* --------- login --------- */

.login {
  max-width: 28rem;
  margin: 5rem auto 4rem;
  padding: 2.5rem 2.5rem 2.25rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  position: relative;
}
.login::before {
  content: "";
  position: absolute;
  top: -1px; left: -1px; right: -1px;
  height: 4px;
  background: var(--accent);
}
.login h1 { font-size: 2rem; margin: 0 0 0.4rem; }
.login p { color: var(--muted); margin-bottom: 1.75rem; }
.login form { display: flex; flex-direction: column; gap: 1rem; }
.login label {
  flex-direction: column; align-items: flex-start; gap: 0.4rem;
  font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.login label input { width: 100%; }
.login button { padding: 0.6rem 1.2rem; }
.login-error {
  background: #fde6e6;
  border-left: 3px solid var(--warn);
  padding: 0.6rem 0.85rem;
  margin: 0 0 1.1rem;
  color: var(--warn);
  font-size: 0.92rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
.login-identity {
  background: var(--paper);
  border-left: 3px solid var(--accent);
  padding: 0.65rem 0.85rem;
  margin: 0.4rem 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.login-identity strong { font-family: var(--font-mono); font-size: 0.95rem; color: var(--ink); }
.login-identity .muted { font-size: 0.85rem; }
.login-hint { margin-top: 1.1rem; font-size: 0.8rem; }

/* --------- filter bar --------- */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.05rem;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  margin-bottom: 1.5rem;
}
.filter-bar input[name=q] {
  width: 22rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236c6f81' stroke-width='1.5' stroke-linecap='round'><circle cx='7' cy='7' r='4.5'/><path d='m10.5 10.5 3 3'/></svg>");
  background-repeat: no-repeat;
  background-position: 0.65rem center;
  background-size: 14px 14px;
  padding-left: 2.1rem;
}
.filter-bar select { width: auto; min-width: 12rem; background-color: var(--surface); }
.filter-bar input[name=q] { background-color: var(--surface); }
.filter-bar label {
  gap: 0.45rem; font-size: 0.85rem; color: var(--ink-soft);
  text-transform: none; letter-spacing: 0; font-weight: 400;
}
.filter-bar button { margin-left: auto; }

/* --------- UC legend --------- */

.uc-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0;
  margin: 0 0 1.5rem;
}
.uc-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.32rem 0.75rem 0.32rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--ink-soft);
  border-radius: var(--radius);
}
.uc-pill::before {
  content: "";
  width: 9px;
  height: 9px;
  background: var(--uc-color, var(--accent));
  border-radius: 50%;
  display: inline-block;
}

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

.matrix-tree {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

details.klasse {
  border-bottom: 1px solid var(--line);
  margin: 0;
  padding-left: 0;
  border-left: none;
}
details.klasse > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.65rem 0.85rem 0.65rem 0.5rem;
  display: flex;
  align-items: flex-start;     /* head + meta top-aligned (meta wraps to multiple lines) */
  flex-wrap: nowrap;           /* meta MUST sit next to the head, items wrap inside meta */
  column-gap: 1rem;
  row-gap: .15rem;
  user-select: none;
  transition: background .1s;
  position: relative;
}
details.klasse > summary::-webkit-details-marker { display: none; }
details.klasse > summary::marker { content: ''; }
details.klasse > summary:hover { background: var(--paper); }
details.klasse > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  margin-left: 0.5rem;
  margin-right: 0.25rem;
  margin-top: .45rem;           /* visually align with the first line of the klasse name */
  align-self: flex-start;
  transition: transform .15s ease;
  flex-shrink: 0;
}
details.klasse[open] > summary::before { transform: rotate(90deg); border-left-color: var(--accent); }
details.klasse > summary strong {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--accent);
  letter-spacing: 0;
  white-space: nowrap;
}
details.klasse > summary > .muted {
  margin-left: auto;
  margin-right: 0.5rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

details.klasse details.klasse {
  margin-left: 1.5rem;
  border-bottom: none;
  border-top: 1px dashed var(--line);
}
details.klasse details.klasse > summary { padding: 0.5rem 0.75rem 0.5rem 0; }
details.klasse details.klasse > summary strong { color: var(--ink); }

.abgek {
  font-style: normal;
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--warn);
  border: 1px solid var(--warn);
  padding: 0.05rem 0.4rem;
  font-weight: 500;
}

/* subtree mark indicators on closed/open klasse rows */
.subtree-marks {
  display: inline-flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}
.subtree-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  padding: 0.08rem 0.5rem;
  border: 1px solid var(--uc-color);
  color: var(--ink);
  background: var(--surface);
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-radius: var(--radius);
}
.subtree-mark strong {
  font-weight: 700;
  color: var(--uc-color);
  font-family: var(--font-body);
  font-size: 0.78rem;
}
.uc-edge {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  width: 4px;
  pointer-events: none;
}
.uc-edge .seg { flex: 1; min-height: 4px; }

/* --------- merkmale table (per Klasse) --------- */

.merkmale {
  width: calc(100% - 1.75rem);
  border-collapse: collapse;
  margin: 0.4rem 0 1rem 1.75rem;
  font-size: 0.92rem;
  background: var(--surface);
  border: 1px solid var(--line);
}
.merkmale thead th {
  background: var(--paper) !important;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--line-strong);
  text-align: left;
  vertical-align: bottom;
}
.merkmale thead th:not(:first-child) {
  text-align: center;
  width: 4.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--ink);
  border-bottom: var(--rule-bold) solid var(--uc-color, var(--accent)) !important;
  position: relative;
  padding-bottom: 0.5rem;
}
.merkmale tbody td {
  padding: 0.45rem 0.8rem;
  border-bottom: 1px solid var(--paper);
  vertical-align: middle;
}
.merkmale tbody tr:last-child td { border-bottom: none; }
.merkmale tbody tr:hover td { background: var(--paper); }
.merkmale tbody td.cell {
  text-align: center;
  width: 4.5rem;
  border-left: 1px solid var(--paper);
}
.merkmale .unit {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 0.78rem;
  margin-left: 0.45rem;
  letter-spacing: 0;
}

/* live-sync: cell briefly highlights when another user toggles it */
@keyframes cell-flash {
  0%   { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
  100% { background: transparent;        box-shadow: inset 0 0 0 2px transparent; }
}
.merkmale td.cell-flash { animation: cell-flash 1.3s ease-out; }

/* --------- generic grid table --------- */

.grid {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.5rem;
  background: var(--surface);
}
.grid thead th {
  text-align: left;
  font-weight: 600;
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line-strong);
  border-top: 1px solid var(--line-strong);
  background: var(--paper);
}
.grid tbody td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 0.92rem;
}
.grid tbody tr:hover { background: var(--paper); }

.grid input:not([type]),
.grid input[type=text],
.grid input[type=email],
.grid input[type=number],
.grid input[type=search],
.grid select {
  background: transparent;
  border: 1px solid transparent;
  padding: 0.4rem 0.55rem;
  width: 100%;
  min-height: 2rem;
  font-size: 0.92rem;
}
.grid input:not([type]):hover,
.grid input[type=text]:hover,
.grid input[type=email]:hover,
.grid input[type=number]:hover,
.grid input[type=search]:hover,
.grid select:hover {
  border-color: var(--line);
  background: var(--surface);
}
.grid input:not([type]):focus,
.grid input[type=text]:focus,
.grid input[type=email]:focus,
.grid input[type=number]:focus,
.grid input[type=search]:focus,
.grid select:focus {
  background: var(--surface);
  border-color: var(--accent);
}
.grid input[type=number] { width: 5rem; min-width: 0; padding-right: 0.4rem; text-align: right; }
.grid input[type=checkbox] { margin: 0; }

.grid thead th:last-child,
.grid tbody td:last-child { text-align: right; }
.grid td > button { padding: 0.4rem 0.95rem; font-size: 0.7rem; }

.grid td.row-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  align-items: center;
}

/* --------- grid form (the "new <thing>" forms) --------- */

.grid-form {
  display: grid;
  gap: 1rem 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  background: var(--surface);
  padding: 1.4rem 1.5rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  align-items: end;
}
.grid-form > label {
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
}
.grid-form > label input,
.grid-form > label select {
  width: 100%;
  font-size: 0.94rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
}
.grid-form > button { align-self: end; }

/* --------- page header / lede --------- */

.page-header {
  margin: 0 0 1.75rem;
  padding-bottom: 1.4rem;
  border-bottom: 1px solid var(--line);
}
.page-header h1 { margin: 0 0 0.55rem; }
.lede {
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
  max-width: 60rem;
  margin: 0;
}

/* --------- panels --------- */

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
  gap: 1.5rem;
  margin: 1.75rem 0 0;
  align-items: stretch;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 1.6rem 1.6rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: relative;
  margin: 0;
  transition: border-color .15s;
}
.panel::before {
  content: "";
  position: absolute;
  top: -1px; left: -1px; bottom: -1px;
  width: 3px;
  background: var(--accent);
}
.panel--soft { background: var(--paper-2); }
.panel:hover { border-color: var(--line-strong); }

.panel__head { display: flex; flex-direction: column; gap: 0.4rem; }
.panel__head h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  border-bottom: none;
  padding-bottom: 0;
}
.panel__head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
  max-width: 38rem;
}

.op-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 0;
}
.op-form .field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
}
.op-form .field > span { display: block; }
.op-form .field > input,
.op-form .field > select {
  font-size: 0.94rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
}
.op-form__actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 0.25rem;
}
.panel > .op-form__actions { padding-top: 0; }

/* --------- import report --------- */

.report {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: var(--rule-bold) solid var(--accent);
  padding: 1.1rem 1.4rem 1.25rem;
  margin: 1.75rem 0;
}
.report h2 { margin-top: 0; font-size: 1.1rem; }
.report ul { margin: 0; padding-left: 1.25rem; }
.report li { margin: 0.25rem 0; font-size: 0.92rem; }
.report details { margin-top: 0.85rem; }
.report summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 500;
}

/* --------- invite-link dialog --------- */

dialog.invite-dialog {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-left: 4px solid var(--accent);
  padding: 1.5rem 1.75rem 1.4rem;
  min-width: min(34rem, 90vw);
  max-width: 40rem;
  border-radius: var(--radius);
  color: var(--ink);
}
dialog.invite-dialog::backdrop {
  background: rgba(25, 32, 82, 0.55);
  backdrop-filter: blur(2px);
}
dialog.invite-dialog h2 {
  margin: 0 0 0.6rem;
  font-size: 1.2rem;
  font-weight: 600;
  border-bottom: none;
  padding-bottom: 0;
}
dialog.invite-dialog p {
  color: var(--muted);
  margin: 0 0 1rem;
  font-size: 0.9rem;
  line-height: 1.55;
}
.invite-url-wrap {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.invite-url {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--paper);
  flex: 1;
  min-width: 0;
}
.invite-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* horizontal-scroll container for any wide table; keeps natural column
   widths but constrains overflow to a scrollable strip on narrow viewports */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1.5rem;
}
.table-scroll > table { margin-bottom: 0; }
.table-scroll > .grid { min-width: 50rem; }       /* 7-col forms — keep cells legible on desktop */
@media (max-width: 60rem) { .table-scroll > .grid { min-width: 0; } }
.table-scroll > .merkmale { min-width: 32rem; }   /* 1 + N UC columns */

/* --------- responsive: tablet+phone --------- */

@media (max-width: 60rem) {
  html, body { font-size: 14px; }
  h1 { font-size: 1.5rem; line-height: 1.2; }
  h2 { font-size: 1.15rem; }

  .topbar { gap: 0.75rem; padding: 0.7rem 1rem; flex-wrap: wrap; }
  .brand-mark { font-size: 1.35rem; }
  .brand-name { font-size: 0.95rem; }
  .nav {
    gap: 0.65rem; margin-left: 0; flex-basis: 100%; order: 3;
    padding-top: 0.5rem; border-top: 1px solid var(--line);
    overflow-x: auto;
    flex-wrap: nowrap;            /* nav scrolls horizontally rather than wrapping */
    -webkit-overflow-scrolling: touch;
  }
  .nav a { white-space: nowrap; padding: 0.4rem 0; font-size: 0.72rem; }
  .user { order: 2; margin-left: auto; gap: 0.5rem; font-size: 0.78rem; }
  .user form button { padding: 0 0.85rem; min-height: 2.1rem; font-size: 0.7rem; }

  main { padding: 1.25rem 1rem 4rem; }
  .page-header { margin-bottom: 1.25rem; padding-bottom: 1rem; }
  .lede { font-size: 0.95rem; }

  /* generously-sized touch targets */
  button, .button { min-height: 2.6rem; padding: 0 1rem; }
  input:not([type]),
  input[type=text], input[type=email], input[type=number], input[type=password],
  input[type=search], input[type=file], select, textarea {
    min-height: 2.6rem;
    font-size: 16px;              /* prevent iOS Safari zoom-on-focus */
  }
  input[type=checkbox] { width: 18px; height: 18px; }

  /* filter bar collapses to a vertical stack */
  .filter-bar { flex-direction: column; align-items: stretch; gap: 0.6rem; padding: 0.75rem; }
  .filter-bar input[name=q],
  .filter-bar select { width: 100%; min-width: 0; }
  .filter-bar label { padding: 0.3rem 0; }
  .filter-bar button { margin-left: 0; width: 100%; }

  .uc-legend { gap: 0.4rem; margin-bottom: 1rem; }

  /* matrix tree summary lines: allow chips and counters to wrap */
  details.klasse > summary {
    flex-wrap: wrap;
    padding: 0.7rem 0.75rem 0.7rem 0.4rem;
    gap: 0.5rem;
  }
  details.klasse > summary > .muted { margin-left: auto; flex-shrink: 0; }
  details.klasse details.klasse { margin-left: 0.85rem; }
  .subtree-marks { gap: 0.35rem; }
  .subtree-mark { padding: 0.05rem 0.4rem; }

  /* panels and grid-form stack to one column */
  .panels { gap: 1rem; grid-template-columns: 1fr; }
  .panel { padding: 1.25rem 1.25rem 1.15rem; }
  .grid-form { grid-template-columns: 1fr; padding: 1.1rem; gap: 0.85rem; }
  .grid-form > button { width: 100%; }

  /* invite dialog: stack URL + copy button */
  dialog.invite-dialog { padding: 1.25rem 1.25rem 1.1rem; }
  .invite-url-wrap { flex-direction: column; }

  /* login card breathes a bit less */
  .login { margin: 2rem auto 3rem; padding: 1.85rem 1.5rem 1.65rem; }
  .login h1 { font-size: 1.65rem; }
}

/* .grid tables collapse to stacked cards on mobile: each tr becomes a card
   with an inline label per cell (drawn from data-label). Keeps every select,
   input, and button visible on iPhone-class viewports without needing
   horizontal scroll. */
@media (max-width: 60rem) {
  .table-scroll { overflow-x: visible; margin-bottom: 1rem; }
  .grid, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
  .grid thead { display: none; }
  .grid tr {
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    margin-bottom: 0.85rem;
    padding: 0.5rem 0.85rem;
  }
  .grid tr form { display: contents; }
  .grid tbody tr:hover { background: var(--surface); }
  .grid td {
    border: none;
    padding: 0.45rem 0;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-height: 0;
    font-size: 0.93rem;
  }
  .grid td::before {
    content: attr(data-label);
    flex: 0 0 8.5rem;
    font-size: 0.66rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
  }
  .grid td > input,
  .grid td > select {
    flex: 1; min-width: 0; width: auto;
    background: var(--paper); border-color: var(--line);
  }
  .grid td > input[type=checkbox] { flex: 0 0 auto; }
  .grid td > input[type=color]   { flex: 0 0 3rem; }
  .grid td.row-actions {
    margin-top: 0.4rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--line);
    justify-content: flex-end;
    gap: 0.5rem;
  }
  .grid td.row-actions::before { display: none; }
  .grid td.row-actions > button { flex: 0 0 auto; }
}

@media (max-width: 30rem) {
  .topbar { padding: 0.6rem 0.75rem; gap: 0.5rem; }
  main { padding: 1rem 0.75rem 3rem; }
  .brand-name { display: none; }       /* keep just the 'asc' mark on phones */
  h1 { font-size: 1.3rem; }
}

/* --------- manual Merkmale: badge + add/edit forms --------- */
.badge-manual { font-size: .7rem; padding: .05rem .35rem; border-radius: .25rem; background: var(--accent); color: #fff; vertical-align: middle; margin-left: .35rem; }
.add-merkmal { margin: .4rem 0 1rem; }
.add-merkmal > summary { cursor: pointer; color: var(--accent); font-size: .85rem; }
.add-merkmal-form, .m-edit-form { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-top: .4rem; }
.m-edit { display: inline-block; margin-left: .4rem; }
.m-edit > summary { cursor: pointer; font-size: .75rem; color: var(--accent); }

.k-head { flex: 0 0 auto; }

/* --------- merkmal cell: head (bold name, fixed width) + meta side-by-side --------- */
.m-cell {
  display: flex;
  align-items: flex-start;
  column-gap: 1rem;
  row-gap: .15rem;
}
.m-head {
  flex: 0 0 14rem;
  width: 14rem;
  white-space: normal;       /* long names wrap to two lines */
  word-break: break-word;
  line-height: 1.25;
}

/* --------- always-visible meta blocks (klasse + merkmal) --------- */
.k-meta, .m-meta {
  font-size: .78rem;
  color: #666;
  display: flex;
  flex-direction: column;
  gap: .08rem;
  flex: 1 1 0;                 /* take remaining space, can shrink */
  min-width: 0;
  font-weight: 400;
}
.k-meta[hidden], .m-meta[hidden] { display: none; }
.k-meta-line, .m-meta-line {
  display: flex; flex-wrap: wrap; row-gap: .05rem; column-gap: .65rem;
}
.k-meta-item, .m-meta-item { white-space: nowrap; }
.k-meta-key, .m-meta-key { color: #aaa; margin-right: .15rem; }
.k-meta code, .m-meta code {
  font-family: "Roboto Mono", monospace;
  font-size: .72rem;
  color: #555;
  background: #f4f4f4;
  padding: 0 .25rem;
  border-radius: 2px;
}
/* Definition: own line, allow wrapping */
.k-meta-def { white-space: normal; }
.k-meta-def .k-meta-key { white-space: nowrap; }

/* Shortened-GUID: hover-tooltip shows the full UUID, click copies it */
.guid-short {
  cursor: pointer;
  transition: background .15s, color .15s;
}
.guid-short:hover { background: #e8eaf3; }
.guid-short.copied { background: #d6f5d6; color: #2d6a4f; }

/* Merkmal-Name visuell hervorheben */
.m-name {
  font-weight: 600;
  color: #1a1a1a;
}

mark { background: #ffe9b3; padding: 0 .1em; border-radius: 2px; }

.merkmale thead tr.uc-totals th {
  border-bottom: 0 !important;  /* override the colored .merkmale thead th:not(:first-child) rule */
  padding: .05rem .3rem 0;
}
.merkmale thead tr.uc-totals th.uc-total {
  text-align: right;
  font-weight: 500;
  font-size: .8rem;
  color: var(--accent, #9a4a23);
}

.merkmale td.cell { text-align: center; }
.cell-btn {
  width: 1.6rem; height: 1.6rem;
  border: 1px solid #ccc; background: transparent;
  border-radius: 3px; cursor: pointer;
  font-size: 1.1rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  color: #888;
  padding: 0;
}
.cell-btn.is-kann { color: var(--uc-color, var(--accent, #9a4a23)); }
.cell-btn.is-muss { color: var(--uc-color, var(--accent, #9a4a23)); background: rgba(154,74,35,.08); font-weight: 700; }
.cell-btn:disabled { cursor: not-allowed; opacity: .55; }

/* Details-badge — toggles the k-meta / m-meta sibling right next to the name */
.meta-toggle {
  margin-left: .4rem;
  padding: .05rem .4rem;
  border-radius: .25rem;
  border: 1px solid #ddd;
  background: transparent;
  cursor: pointer;
  font-size: .7rem;
  color: #666;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  min-height: auto;
  line-height: 1.3;
}
.meta-toggle:hover { background: #f4f4f4; color: #333; }
.meta-toggle[aria-expanded="true"] { background: #e8eaf3; color: #333; border-color: #c8ccd9; }

.aus-toggle {
  margin-left: .35rem;
  padding: .05rem .35rem;
  border-radius: .25rem;
  border: 1px solid #ddd;
  background: transparent;
  cursor: pointer;
  font-size: .75rem;
  color: #555;
}
.aus-toggle[aria-expanded="true"] .aus-chevron {
  display: inline-block;
  transform: rotate(180deg);
}
.aus-toggle .aus-marked-count {
  color: var(--accent, #9a4a23);
  margin-left: .25rem;
}
.aus-row { background: #fafafa; }
.aus-row .aus-name {
  padding-left: 1.5rem;
  font-size: .85rem;
  color: #555;
}
.aus-row .aus-prefix { color: #aaa; margin-right: .35rem; }
.aus-row .aus-code {
  font-family: "Roboto Mono", monospace;
  font-size: .75rem;
  color: #888;
  margin-left: .35rem;
}
.cell-btn:focus-visible { outline: 2px solid var(--accent, #9a4a23); outline-offset: 1px; }

/* Lazy-load placeholder for klasse merkmal-tables */
.merkmale-placeholder {
  padding: .75rem 1rem;
  color: #888;
  font-size: .85rem;
  font-style: italic;
}
.merkmale-placeholder.loading .merkmale-loading-hint::before {
  content: "⏳ ";
  font-style: normal;
}
.merkmale-placeholder.error { color: #b34; font-style: normal; }

