/* KI-Sicht – Oberfläche
   Keine externen Schriften oder CDNs: alles läuft lokal auf dem eigenen Server. */

:root {
    --paper:   #F4F6F3;
    --surface: #FFFFFF;
    --ink:     #1B2430;
    --muted:   #66716B;
    --line:    #DDE2DC;          /* rein zeichnerische Trennlinien */
    --line-2:  #EDF0EC;
    --field:   #767C77;          /* Rahmen von Bedienelementen, 4,27:1 */
    --present: #1F6F5C;
    --gap:     #8A6800;          /* gemessen 5,17:1 gegen Weiß */
    --alert:   #A33A3A;
    --focus:   #2F5AA8;

    --sp: 4px;
    --radius: 3px;
    --shadow: 0 1px 2px rgba(27, 36, 48, .06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-variant-numeric: tabular-nums;
}

a { color: var(--focus); }
a:hover { color: var(--ink); }

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

/* ---------- Gerüst ---------- */

.shell { display: flex; min-height: 100vh; }

.rail {
    width: 208px;
    flex: 0 0 208px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 20px 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.rail-brand {
    padding: 0 18px 18px;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -.01em;
}
.rail-brand span { display: block; font-size: 12px; font-weight: 400; color: var(--muted); margin-top: 2px; }

.rail-nav { display: flex; flex-direction: column; }
.rail-nav a {
    padding: 8px 18px;
    color: var(--ink);
    text-decoration: none;
    font-size: 14px;
    border-left: 3px solid transparent;
}
.rail-nav a:hover { background: var(--line-2); }
.rail-nav a[aria-current="page"] {
    border-left-color: var(--present);
    font-weight: 600;
    background: var(--line-2);
}

.rail-foot {
    padding: 16px 18px 0;
    margin-top: 20px;
    border-top: 1px solid var(--line-2);
    font-size: 12px;
    color: var(--muted);
}

.main { flex: 1; min-width: 0; padding: 24px 28px 64px; max-width: 1180px; }

.page-head {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 20px;
}
.page-head h1 { font-size: 22px; margin: 0; font-weight: 600; letter-spacing: -.015em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- Karten ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 18px;
}
.card > h2 {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 14px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
}
.card > h2 small { font-weight: 400; color: var(--muted); font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 > .card { margin-bottom: 0; }

/* ---------- Anteilsband (Hero) ---------- */

.share {
    display: flex;
    height: 68px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--line);
}
.share-seg {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 10px;
    color: #fff;
    min-width: 0;
    font-size: 12px;
    line-height: 1.25;
}
.share-seg b { font-size: 15px; font-weight: 600; }
.share-seg span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: .85;
}
.share-seg.is-own { box-shadow: inset 0 -4px 0 rgba(255, 255, 255, .55); }
.share-legend { margin-top: 10px; font-size: 12px; color: var(--muted); }

/* ---------- Kennzahlen ---------- */

.kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 18px;
}
.kpi { background: var(--surface); padding: 14px 16px; }
.kpi dt { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.kpi dd { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.kpi dd small { font-size: 14px; font-weight: 400; color: var(--muted); }
.delta { font-size: 12px; margin-top: 4px; }
.delta.up { color: var(--present); }
.delta.down { color: var(--alert); }
.delta.flat { color: var(--muted); }

/* ---------- Präsenzmatrix ---------- */

.matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
.matrix th, .matrix td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--line-2); }
.matrix thead th {
    font-weight: 500;
    color: var(--muted);
    font-size: 12px;
    vertical-align: bottom;
    border-bottom: 1px solid var(--line);
}
.matrix td.q { max-width: 380px; }
.matrix td.q span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.matrix td.q em { font-style: normal; color: var(--muted); font-size: 12px; }
.matrix .cell { text-align: center; width: 62px; }

.dot {
    display: inline-block;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    line-height: 22px;
    text-align: center;
    font-size: 11px;
    color: #fff;
}
.dot.none { background: var(--line-2); color: var(--muted); border: 1px solid var(--field); }
.dot.low  { background: #8A6A2A; }   /* weiße Ziffer, 5,03:1 */
.dot.mid  { background: #3F7A63; }   /* weiße Ziffer, 5,03:1 */
.dot.high { background: var(--present); }
.dot.na   { background: transparent; color: var(--line); }

/* ---------- Tabellen ---------- */

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); text-align: left; }
.table th { font-size: 12px; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--line); }
.table td.num, .table th.num { text-align: right; }
.table tr:last-child td { border-bottom: 0; }
.table .own td { background: #F2F8F5; font-weight: 600; }

.bar-cell { position: relative; min-width: 120px; }
.bar-cell i {
    display: block;
    height: 6px;
    background: var(--present);
    border-radius: 2px;
}
/* Der Balken ist nie die einzige Aussage: daneben steht immer der Zahlenwert.
   Deshalb genügt hier eine gut erkennbare, aber zurückhaltende Fläche. */

.tag {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--field);
    border-radius: 2px;
    font-size: 11px;
    color: var(--muted);
    background: var(--paper);
}
.tag.own { border-color: var(--present); color: var(--present); }
.tag.err { border-color: var(--alert); color: var(--alert); }

/* ---------- Formulare ---------- */

label { display: block; font-size: 13px; margin-bottom: 4px; color: var(--muted); }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=file], select, textarea {
    width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--field);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
}
textarea { min-height: 76px; resize: vertical; line-height: 1.45; }

.field { margin-bottom: 12px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 160px; }

.btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: #fff;
    border-radius: var(--radius);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: #2C3846; color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--field); }
.btn.ghost:hover { background: var(--line-2); color: var(--ink); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.danger { border-color: var(--alert); background: transparent; color: var(--alert); }
.btn.danger:hover { background: var(--alert); color: #fff; }

.inline-form { display: inline; }

.notice {
    padding: 10px 14px;
    border-left: 3px solid var(--present);
    background: var(--surface);
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-bottom: 16px;
    font-size: 14px;
}
.notice.error { border-left-color: var(--alert); }

.empty {
    padding: 28px 20px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}
.empty p { margin: 0 0 14px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters select, .filters input { width: auto; }

.answer-text {
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 14px;
    max-width: 72ch;
}
.answer-text mark { background: #DCEFE6; padding: 0 2px; border-radius: 2px; }

/* ---------- Login ---------- */

.login-wrap {
    max-width: 340px;
    margin: 12vh auto;
    padding: 0 16px;
}
.login-wrap h1 { font-size: 20px; margin: 0 0 4px; }
.login-wrap p.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

/* ---------- Mobil ---------- */

@media (max-width: 860px) {
    .shell { flex-direction: column; }
    .rail {
        width: auto;
        flex: none;
        height: auto;
        position: static;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 14px 0 0;
    }
    .rail-brand { padding: 0 16px 10px; }
    .rail-nav { flex-direction: row; overflow-x: auto; padding: 0 10px; }
    .rail-nav a { border-left: 0; border-bottom: 3px solid transparent; white-space: nowrap; }
    .rail-nav a[aria-current="page"] { border-left-color: transparent; border-bottom-color: var(--present); }
    .rail-foot { display: none; }
    .main { padding: 18px 16px 48px; }
    .kpis { grid-template-columns: 1fr 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .matrix td.q { max-width: 180px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* ---------- Hinweise, Konto, Budget ---------- */

.badge {
    display: inline-block;
    min-width: 17px;
    padding: 0 5px;
    background: var(--gap);
    color: #fff;
    border-radius: 9px;
    font-size: 11px;
    line-height: 17px;
    text-align: center;
}

.alerts { margin-bottom: 18px; }
.alert-item {
    display: flex;
    gap: 12px;
    align-items: baseline;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3px solid var(--gap);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 12px 16px;
    margin-bottom: 8px;
}
.alert-item.alert { border-left-color: var(--alert); }
.alert-item.info  { border-left-color: var(--present); }
.alert-item div { flex: 1; min-width: 0; }
.alert-item strong { font-size: 14px; font-weight: 600; }
.alert-item p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.totp-setup { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.totp-setup > div:last-child { flex: 1 1 260px; }

.qr-box {
    width: 196px;
    height: 196px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 4px;
}
.qr-box svg { display: block; max-width: 100%; height: auto; }

.codes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
}
.codes code {
    display: block;
    padding: 7px 10px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 14px;
    letter-spacing: .05em;
    text-align: center;
}

.meter {
    height: 8px;
    background: var(--line-2);
    border: 1px solid var(--line);
    border-radius: 4px;
    overflow: hidden;
    min-width: 90px;
}
.meter i { display: block; height: 100%; background: var(--present); }
.meter.warn i { background: var(--gap); }
.meter.over i { background: var(--alert); }

details summary { cursor: pointer; }

@media (max-width: 860px) {
    .totp-setup { flex-direction: column; }
}

/* ---------- Bereiche ---------- */

.ws-switch { padding: 0 18px 14px; }
.ws-switch label { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.ws-switch select { font-size: 13px; padding: 5px 7px; }
.ws-single {
    display: block;
    font-size: 13px;
    font-weight: 600;
    padding: 5px 0;
    border-top: 1px solid var(--line-2);
    border-bottom: 1px solid var(--line-2);
}

.swatch {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: baseline;
}

.small.up { color: var(--present); }
.small.down { color: var(--alert); }

@media (max-width: 860px) {
    .ws-switch { padding: 0 16px 10px; }
}

/* ---------- System und Auftritt ---------- */

.rail-logo { display: block; max-width: 150px; max-height: 46px; margin-bottom: 4px; }

.sub-head {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin: 18px 0 4px;
}
.card > .sub-head:first-of-type { margin-top: 0; }

.pill {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--present);
}
.pill.warn { background: var(--gap); }
.pill.fail { background: var(--alert); }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.logo-preview {
    max-width: 180px;
    max-height: 60px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 6px;
    background: #fff;
}

/* ==========================================================================
   Barrierefreiheit nach WCAG 2.2 und Feinschliff für kleine Bildschirme
   ========================================================================== */

/* Sprungmarke: erst beim Tastaturfokus sichtbar (2.4.1) */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    background: var(--ink);
    color: #fff;
    padding: 10px 16px;
    border-radius: 0 0 var(--radius) 0;
    text-decoration: none;
}
.skip-link:focus {
    left: 0;
}

/* Fokus bleibt immer sichtbar und wird nicht verdeckt (2.4.11, 2.4.13) */
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 2px;
    scroll-margin: 90px;
}
.main:focus { outline: none; }

/* Mindestgröße für Bedienelemente: 24 CSS-Pixel (2.5.8), auf Touch mehr */
.btn,
button,
select,
input[type=checkbox],
input[type=radio] {
    min-height: 24px;
}
.btn.small {
    min-height: 32px;
    padding: 6px 11px;
}
input[type=checkbox],
input[type=radio] {
    width: 18px;
    height: 18px;
    accent-color: var(--present);
    vertical-align: -3px;
    margin-right: 4px;
}
label input[type=checkbox],
label input[type=radio] { margin-right: 6px; }

/* Zusammenhängende Bedienelemente brauchen Abstand, sonst trifft man daneben */
.inline-form + .inline-form,
.btn + .btn { margin-left: 4px; }

/* Beschriftungen sind anklickbar und deutlich vom Feld getrennt */
label { cursor: pointer; }
.field label + .small { display: block; margin-top: 3px; }

/* Tabellen laufen auf schmalen Geräten nicht über den Rand hinaus */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-scroll:focus-visible { outline-offset: 0; }

/* Hilfe-Navigation */
.help-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 18px;
}
.help-nav a {
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    font-size: 13.5px;
    min-height: 32px;
}
.help-nav a:hover { background: var(--line-2); }
.help-nav a[aria-current="page"] {
    border-color: var(--present);
    background: #F2F8F5;
    font-weight: 600;
}

.help-text { max-width: 68ch; font-size: 14.5px; line-height: 1.6; }
.help-list { max-width: 68ch; font-size: 14.5px; line-height: 1.6; padding-left: 20px; }
.help-list li { margin-bottom: 7px; }
.help-dl { max-width: 68ch; font-size: 14.5px; }
.help-dl dt { font-weight: 600; margin-top: 14px; }
.help-dl dd { margin: 3px 0 0; color: var(--muted); line-height: 1.6; }

/* Stärkerer Kontrast, wenn das Gerät danach fragt */
@media (prefers-contrast: more) {
    :root {
        --muted: #39423C;
        --line: #8D948F;
        --line-2: #C1C9C3;
        --field: #4A514C;
    }
    .table th { color: var(--ink); }
    .tag { color: var(--ink); }
}

/* ---------- Kleine Bildschirme ---------- */

@media (max-width: 700px) {
    body { font-size: 15.5px; }

    .main { padding: 16px 14px 56px; }

    .page-head { gap: 10px; }
    .page-head h1 { font-size: 20px; }

    .card { padding: 15px 14px; }

    /* Kennzahlen zweispaltig, damit die Zahl lesbar groß bleibt */
    .kpis { grid-template-columns: 1fr 1fr; }
    .kpi dd { font-size: 23px; }

    /* Anteilsband hochkant: nebeneinander wäre nichts mehr lesbar */
    .share { flex-direction: column; height: auto; }
    .share-seg {
        flex: none !important;
        min-height: 34px;
        flex-direction: row;
        align-items: baseline;
        gap: 8px;
        padding: 7px 12px;
    }
    .share-seg.is-own { box-shadow: inset 4px 0 0 rgba(255, 255, 255, .6); }
    .share-seg span { opacity: 1; }

    /* Tabellen scrollen seitwärts statt zu zerbrechen */
    .table, .matrix { font-size: 13.5px; }
    .table th, .table td { padding: 9px 8px; }
    .matrix td.q { max-width: 150px; }

    /* Bedienelemente in Tabellenzeilen untereinander, nicht gequetscht */
    .table td .inline-form { display: block; margin: 4px 0 0; }
    .table td .inline-form + .inline-form { margin-left: 0; }
    .table td .btn.small { display: block; width: 100%; text-align: center; }

    .field-row { gap: 0; }
    .field-row > .field { flex: 1 1 100%; }

    .filters { width: 100%; }
    .filters select, .filters input { flex: 1 1 auto; min-width: 0; }

    .codes { grid-template-columns: 1fr 1fr; }
    .help-nav a { flex: 1 1 auto; text-align: center; }
    .rail-logo { max-height: 38px; }
}

@media (max-width: 420px) {
    .kpis { grid-template-columns: 1fr; }
    .codes { grid-template-columns: 1fr; }
}

/* Auf Zeigegeräten mit grober Auflösung größere Trefferflächen (2.5.8) */
@media (pointer: coarse) {
    .btn, button, select, .help-nav a, .rail-nav a { min-height: 44px; }
    .btn.small { min-height: 38px; }
    input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
    .rail-nav a { display: flex; align-items: center; }
}

/* Druckausgabe: Menü weg, Inhalt volle Breite */
@media print {
    .rail, .filters, .btn, .skip-link, .alerts { display: none !important; }
    .main { max-width: none; padding: 0; }
    .card { break-inside: avoid; border-color: #999; }
}

/* Genauigkeitsangabe neben der Kennzahl */
.kpi dd .ci {
    font-size: 13px;
    font-weight: 400;
    color: var(--muted);
    margin-left: 3px;
    white-space: nowrap;
}
