:root {
    --border: #dfe5ec;
    --error: #c50f1f;
    --warning: #bc4b09;
    --accent: #1767ad;
    --navy: #0f3a57;
    --surface: #f6f9fc;
    --page: #eef3f8;
    /* Height of the test system banner. */
    --banner: 0px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; color: #1f2933; background: var(--page); }
a { color: var(--accent); }
h2 { margin: 0 0 4px; font-size: 24px; color: var(--navy); }
h3 { margin: 16px 0 8px; }
h4 { margin: 4px 0 8px; font-size: 14px; }
.center { display: flex; justify-content: center; align-items: center; min-height: 80vh; }
.login-card { width: 400px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login-form { display: flex; flex-direction: column; gap: 10px; }

.frame { display: flex; min-height: calc(100vh - var(--banner)); }
.sidebar { width: 230px; flex: none; position: sticky; top: var(--banner); height: calc(100vh - var(--banner)); display: flex; flex-direction: column; gap: 24px;
    padding: 16px; background: linear-gradient(180deg, #0f3a57 0%, #14506f 60%, #17607f 100%); }
.brand { background: #fff; border-radius: 14px; padding: 14px 12px; display: flex; justify-content: center; }
.brand img { display: block; width: 100%; height: auto; }
.sidebar nav, .sidebar .user { display: flex; flex-direction: column; gap: 6px; }
.sidebar nav { flex: 1; }
.nav-link { display: block; padding: 10px 12px; border-radius: 8px; text-decoration: none; color: #fff; font-size: 14px; border: 0; background: none;
    text-align: left; font: inherit; cursor: pointer; border-left: 3px solid transparent; }
.nav-link:hover { background: rgba(255, 255, 255, .08); }
.nav-link.active { background: rgba(255, 255, 255, .14); border-left-color: #7fb6e6; font-weight: 600; }
.content { flex: 1; min-width: 0; padding: 20px 24px; background: var(--page); }
.card { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 16px 20px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(15, 58, 87, .04); }

.page-head, .sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.subline { color: #616161; margin-top: 2px; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.buttons a { text-decoration: none; }
.chip { display: inline-block; margin: 4px 6px 0 0; padding: 2px 8px; border: 1px solid var(--border); border-radius: 12px; background: #fff; text-decoration: none; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips .chip { margin: 0; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; background: var(--surface); }
.chip-remove { border: 0; background: none; padding: 0 2px; cursor: pointer; color: #616161; font-size: 14px; line-height: 1; }
.chip-remove:hover { color: var(--error); }
.chips .choice { width: auto; min-width: 150px; flex: 1; }
.date-input { display: flex; gap: 4px; align-items: center; position: relative; }
.date-input .thaw-input { flex: 1; min-width: 0; }
.date-button { border: 1px solid var(--border); background: #fff; border-radius: 4px; height: 32px; width: 32px; cursor: pointer; flex: none; }
/* Only its calendar is used (opened by the button). */
.date-picker { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.settings-tabs { margin: 8px 0 12px; }
.entity-edit { display: flex; flex-direction: column; gap: 8px; min-width: 460px; }

.filter { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; background: #fff; padding: 12px; border: 1px solid var(--border); border-radius: 14px; margin-bottom: 12px; }
.filter .field { min-width: 180px; }
.filter .field.fulltext { flex: 1 0 100%; }
.count { color: #616161; margin: 4px 0; }
/* No nested scroll area: columns wrap to fit the page. */
.table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); }
.table th, .table td { padding: 6px 8px; border-bottom: 1px solid #ececec; text-align: left; overflow-wrap: anywhere; }
.table th { background: var(--surface); font-weight: 600; position: sticky; top: 0; }
.table td.note-cell { white-space: normal; color: var(--warning); }
.clickable { cursor: pointer; }
.clickable:hover { background: #ebf3fc; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin: 16px 0; }
.tile { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px; text-decoration: none; color: inherit; }
.tile .number { font-size: 28px; font-weight: 700; color: var(--accent); }
.quick-search { display: flex; gap: 8px; max-width: 600px; }
.quick-search > :first-child { flex: 1; }

.inline-fields { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.computed { display: flex; gap: 20px; flex-wrap: wrap; color: #424242; background: var(--surface); padding: 6px 10px; border-radius: 4px; margin-bottom: 8px; }
.group { margin: 6px 0; }
/* At most one level of indentation; wrappers (optional, variant, list) do not indent. */
.group .group:not(.optional, .variant, .list) { border-left: 3px solid #e6e6e6; padding-left: 10px; }
.group .group:not(.optional, .variant, .list) .group { border-left: 0; padding-left: 0; }
/* Klient columns are narrow: no indentation at all. */
.sb-cell .group { border-left: 0 !important; padding-left: 0 !important; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 14px; margin-bottom: 6px; }
/* Label, input and issues share rows across the fields of a grid row: a wrapping label does not shift its input. */
.field { display: flex; flex-direction: column; gap: 3px; }
.grid > .field { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 3px; align-content: start; min-width: 0; }
/* A taller control in the row (e.g. a referencable entity) must not stretch the inputs next to it. */
.grid > .field > label + * { align-self: start; min-width: 0; }
.grid > .field > label { align-self: end; }
.grid > .field-bool > :first-child { grid-row: 2; align-self: center; }
.field-issues:empty { display: none; }
.field > label { font-size: 12px; color: #616161; }
.field.show .value { padding: 2px 0; min-height: 20px; white-space: pre-wrap; }
.value.empty, .empty { color: #9e9e9e; font-style: italic; }
.field-bool { justify-content: flex-end; }
/* Field markers only while the issue list is open. */
.issues-open .field-error .thaw-input, .issues-open .field-error .thaw-textarea, .issues-open .field-error .choice select { outline: 2px solid var(--error); border-radius: 4px; }
.issues-open .field-warning .thaw-input, .issues-open .field-warning .choice select { outline: 2px solid var(--warning); border-radius: 4px; }
.issue { font-size: 12px; }
.issue.error { color: var(--error); }
.issue.warning { color: var(--warning); }
.list-entry { border: 1px dashed var(--border); border-radius: 6px; padding: 6px 10px; margin: 6px 0; }
.list-head { display: flex; justify-content: space-between; align-items: center; color: #616161; font-size: 12px; }

.suggest { position: relative; }
.suggestions { list-style: none; margin: 0; padding: 0; position: absolute; z-index: 5; background: #fff; width: 100%; box-shadow: 0 4px 12px rgba(0,0,0,.15); border-radius: 4px; }
.suggestions button, .entity-hits button { width: 100%; text-align: left; border: 0; background: none; padding: 6px 10px; cursor: pointer; font: inherit; }
.suggestions button:hover, .entity-hits button:hover { background: #ebf3fc; }
.suggest .thaw-input { width: 100%; }

.entity { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.entity-text { flex: 1; min-width: 120px; padding: 4px 0; }
.entity-picker { display: flex; flex-direction: column; gap: 8px; min-width: 420px; }
.entity-hits { list-style: none; padding: 0; margin: 0; max-height: 240px; overflow-y: auto; border: 1px solid #ececec; border-radius: 4px; }
.entity-new { border-top: 1px solid var(--border); padding-top: 8px; display: flex; flex-direction: column; gap: 8px; }

.noted { margin: 4px 0; }
.link-small { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; font-size: 12px; }
.note-box { border: 1px solid var(--warning); background: #fff8f0; border-radius: 6px; padding: 8px 12px; }
.note-head { display: flex; justify-content: space-between; align-items: center; }
.hint { color: #616161; font-size: 12px; margin: 4px 0; }

.remove-box { border: 1px solid var(--warning); background: #fff8f0; border-radius: 6px; padding: 10px 14px; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.transfer-box { display: flex; flex-direction: column; gap: 8px; min-width: 320px; }

.save-bar { flex: none; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; margin-top: 8px; display: flex; flex-direction: column; gap: 4px; transition: box-shadow .2s; }
.save-bar.flash { box-shadow: 0 0 0 3px var(--error); }
.issue-summary { border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: #616161; text-align: left; cursor: pointer; display: flex; gap: 6px; }
.issue-summary.error { color: var(--error); }
.issue-summary.warning { color: var(--warning); }
.save-bar .issues { margin: 0; padding-left: 34px; max-height: 76px; overflow-y: auto; font-size: 13px; }
.issue-link { border: 0; background: none; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.issue-link:hover { text-decoration: underline; }
.jumped { outline: 3px solid #7fb6e6; outline-offset: 2px; border-radius: 4px; }
.issues li.error { color: var(--error); }
.issues li.warning { color: var(--warning); }
.confirm-text { color: var(--warning); font-weight: 600; }
.invitation-link { display: block; word-break: break-all; background: #fff; padding: 6px; border: 1px solid var(--border); margin-top: 4px; user-select: all; }
.choice { position: relative; display: inline-flex; width: 100%; }
.choice select { width: 100%; height: 32px; padding: 0 28px 0 10px; font: inherit; border: 1px solid var(--border); border-bottom-color: #616161; border-radius: 4px; background: #fff; appearance: none; cursor: pointer; }
.choice::after { content: "▾"; position: absolute; right: 10px; top: 6px; pointer-events: none; color: #616161; }

/* Klientenstammblatt: header and issue list stay in place; index and sheet are separate scroll containers. */
.sheet-page { height: calc(100vh - 40px - var(--banner)); display: flex; flex-direction: column; }
.sheet-head { flex: none; display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.sheet-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.title-row { display: flex; align-items: center; gap: 12px; }
.title-row h2 { margin: 0; }
.sheet-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; }
.sb-index { margin: 0; display: flex; flex-direction: column; gap: 2px; padding: 12px; overflow-y: auto; }
.sb-index a { color: #1f2933; text-decoration: none; padding: 5px 8px; border-radius: 6px; font-size: 13px; }
.sb-index a:hover { background: var(--surface); color: var(--accent); }
.sb-index a.active { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.sheet-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.sheet-body { flex: 1; min-height: 0; overflow: auto; }
/* Klient columns have one width; the rest of the row stays blank. */
.sheet-body > .sb-section { min-width: calc(222px + var(--cols) * 260px + 140px); }
.sb-section { padding: 14px 16px; }
.sb-title { margin: 0 0 10px; padding: 10px 14px; border-radius: 8px; color: #fff; font-size: 17px; background: linear-gradient(90deg, #0f3a57, #1767ad); }
.sb-grid { display: grid; grid-template-columns: 180px repeat(var(--cols), 250px) minmax(140px, 1fr); column-gap: 10px; align-items: stretch; }
.sb-grid > * { padding: 7px 0; border-bottom: 1px solid #eef1f5; min-width: 0; }
.sb-label { grid-column: 1; font-weight: 700; color: #1f2933; padding-top: 12px; overflow-wrap: break-word; hyphens: auto; }
.sb-wide { grid-column: 2 / -1; }
/* Single shared fields get the width of two Klient columns, not the whole row. */
.sb-wide > .sb-cell > div > .field, .sb-wide > .sb-cell > div > .variant > .field, .sb-wide > .sb-cell > div > .noted { max-width: 510px; }
.sb-filler { display: flex; align-items: center; padding-left: 10px; }
/* Main tab: room for exactly two Klienten, filling the width. */
.sb-grid.main-tab { grid-template-columns: 180px repeat(2, minmax(250px, 1fr)); }
/* Klient columns of the other tab. */
.tab-col { display: contents; }
.tab-hidden { display: none !important; }
.sb-tabs { display: flex; gap: 4px; margin-top: 10px; }
.sb-tab { border: 1px solid var(--border); border-bottom-width: 3px; background: #fff; border-radius: 8px 8px 0 0; padding: 6px 14px; font: inherit; cursor: pointer; color: #4a5866; }
.sb-tab.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; background: var(--surface); }
/* Help of a row: shown on hover or focus. */
.help { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 6px; border-radius: 50%;
    background: #e3edf7; color: var(--accent); font-size: 11px; font-weight: 700; cursor: help; vertical-align: 1px; }
.help-text { display: none; position: absolute; z-index: 30; left: 22px; top: -6px; width: 340px; padding: 8px 10px; border-radius: 8px; background: #1f2933; color: #fff;
    font-size: 12px; font-weight: 400; line-height: 1.45; white-space: normal; hyphens: manual; box-shadow: 0 4px 14px rgba(0, 0, 0, .2); }
.help:hover .help-text, .help:focus .help-text { display: block; }
.person-support { display: grid; grid-template-columns: minmax(200px, 280px) minmax(0, 360px); gap: 4px 16px; align-items: start; padding: 4px 0; }
.person-support + .person-support { border-top: 1px dashed var(--border); }
.person-name { display: flex; flex-direction: column; padding-top: 6px; }
.person-name .hint { margin: 0; }
.sb-colhead { text-align: center; font-size: 12px; color: #4a5866; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sb-colhead strong { font-size: 13px; color: #1f2933; }
.sb-cell .field > label:empty { display: none; }
.sb-cell .grid, .sb-wide .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.computed-cell { padding-top: 12px; color: #4a5866; font-weight: 600; }
.derived { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 16px; margin: 0; max-width: 420px; }
.derived dt { font-weight: 400; }
.derived dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.user-field { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 32px; }
.shv-ansatz { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.test-banner { position: sticky; top: 0; z-index: 20; height: 36px; line-height: 20px; background: var(--error); color: #fff; font-weight: 700; text-align: center; padding: 8px 16px; }
/* thaw keeps message bars on one line; long texts must wrap instead of being cut off. */
.thaw-message-bar { white-space: normal; }
.thaw-message-bar-body { min-width: 0; overflow-wrap: anywhere; padding-top: 8px; padding-bottom: 8px; }
/* thaw's provider paints its own background; one page colour for the whole window (only the app root: dialogs
   are moved to <body> in providers of their own). */
.app-root { background: var(--page); min-height: 100vh; }
/* Grundbedarf SHV as in the former form (comparison). */
.shv-b { max-width: 900px; display: flex; flex-direction: column; gap: 10px; }
.shv-b .hint { margin: 0; }
.shv-block { border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 14px; background: #fff; }
.shv-block.wg { border-left-color: #c9a227; }
.shv-block.kq { border-left-color: #8e6cc7; background: #fcfbff; }
.shv-b .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
/* Shown on demand: laid out like the other fields of the grid. */
.shv-opt > .field { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 3px; align-content: start; min-width: 0; }
.shv-opt > .field > label { align-self: end; }
.shv-out { min-height: 32px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; background: #eef5fc; font-weight: 600; font-variant-numeric: tabular-nums; }
.shv-inline { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.shv-inline label { font-weight: 600; }
.shv-inline .shv-out { min-width: 160px; }
