/* Posteingang – Erscheinungsbild
   Kühles Briefpapier, Königsblau als Tinte, Status als Stempel. Eine Schrift: Atkinson Hyperlegible. */

@font-face { font-family: 'Atkinson'; font-weight: 400; font-display: swap;
  src: url('vendor/fonts/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Atkinson'; font-weight: 700; font-display: swap;
  src: url('vendor/fonts/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Atkinson'; font-weight: 400; font-display: swap;
  src: url('vendor/fonts/atkinson-hyperlegible-latin-ext-400-normal.woff2') format('woff2');
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Atkinson'; font-weight: 700; font-display: swap;
  src: url('vendor/fonts/atkinson-hyperlegible-latin-ext-700-normal.woff2') format('woff2');
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  --papier: #F2F4F6;
  --blatt: #FFFFFF;
  --blatt-2: #F7F8FA;
  --tinte: #17202B;
  --tinte-2: #566271;
  --tinte-3: #8A94A1;
  --linie: #D8DDE3;
  --aktion: #2446C8;
  --aktion-hell: #E7ECFB;
  --st-neu: #2446C8;
  --st-bearb: #A85F00;
  --st-wv: #7638BF;
  --st-erledigt: #1D7444;
  --st-verworfen: #7D848C;
  --warnung: #B42318;
  --warnung-hell: #FDECEA;
  --radius: 10px;
  --radius-klein: 6px;
  --schatten: 0 1px 2px rgba(23, 32, 43, .06), 0 6px 18px rgba(23, 32, 43, .06);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --papier: #12161C; --blatt: #1A2029; --blatt-2: #202733; --tinte: #E6EAF0; --tinte-2: #A3ADBA;
    --tinte-3: #737E8C; --linie: #2E3743; --aktion: #7B96FF; --aktion-hell: #222C4A;
    --st-neu: #7B96FF; --st-bearb: #F0A543; --st-wv: #B48AF0; --st-erledigt: #56C48A; --st-verworfen: #8A9199;
    --warnung: #FF7A6E; --warnung-hell: #3A1E1C; --schatten: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--papier); color: var(--tinte);
  font: 400 16px/1.45 'Atkinson', -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--aktion); }
:focus-visible { outline: 3px solid var(--aktion); outline-offset: 2px; border-radius: 4px; }
.versteckt { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Grundlayout ---------- */
.rahmen { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); }
.spalte, .inhalt { min-width: 0; }
html, body { overflow-x: hidden; }
.kopf {
  position: sticky; top: 0; z-index: 20; background: var(--papier);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; gap: 10px; align-items: center;
}
.kopf h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.01em; flex: 1; }
.inhalt { padding: 0 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); max-width: 860px; width: 100%; margin: 0 auto; }

.nav {
  position: fixed; inset: auto 0 0 0; z-index: 30; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--blatt); border-top: 1px solid var(--linie);
  display: grid; grid-template-columns: repeat(4, 1fr); align-items: center;
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none;
  color: var(--tinte-2); font-size: 12px; padding: 6px 0; position: relative;
}
.nav a[aria-current="page"] { color: var(--aktion); font-weight: 700; }
.nav svg { width: 24px; height: 24px; }
.nav .scan-knopf {
  width: 58px; height: 58px; margin-top: -26px; border-radius: 50%; background: var(--aktion); color: #fff;
  display: grid; place-items: center; box-shadow: 0 6px 16px rgba(36, 70, 200, .35); border: 4px solid var(--papier);
}
.nav .scan-knopf svg { width: 26px; height: 26px; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warnung); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.nav .badge { position: absolute; top: 2px; left: calc(50% + 6px); }

/* Desktop: Seitenleiste + Liste + Detail */
@media (min-width: 1000px) {
  .rahmen { grid-template-columns: 232px minmax(360px, 440px) minmax(0, 1fr); height: 100dvh; overflow: hidden; }
  .nav {
    position: static; height: auto; grid-template-columns: 1fr; align-content: start; gap: 2px;
    border-top: 0; border-right: 1px solid var(--linie); padding: 18px 12px; overflow-y: auto;
  }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 9px 12px; border-radius: 8px; }
  .nav a:hover { background: var(--blatt-2); }
  .nav a[aria-current="page"] { background: var(--aktion-hell); }
  .nav .scan-knopf-link { padding: 0; }
  .nav .scan-knopf-link:hover { background: none; }
  .nav .scan-knopf { width: 100%; height: 44px; margin: 0 0 14px; border-radius: 10px; border: 0; box-shadow: none;
    display: flex; justify-content: center; gap: 8px; color: #fff; font-weight: 700; }
  .nav .scan-knopf svg { width: 20px; height: 20px; }
  .nav .badge { position: static; margin-left: auto; }
  .nav .marke { display: block; font-weight: 700; font-size: 18px; padding: 4px 12px 16px; }
  .nav .nav-trenner { display: block; border-top: 1px solid var(--linie); margin: 12px 4px; }
  .nav .nav-mandant { font-size: 14px; padding: 6px 12px; }
  .spalte { overflow-y: auto; height: 100dvh; }
  .spalte-liste { border-right: 1px solid var(--linie); }
  .spalte-liste .inhalt, .spalte-detail .inhalt { padding-bottom: 32px; }
  .nur-mobil { display: none !important; }
}
@media (max-width: 999.98px) {
  .nav .marke, .nav .nav-trenner, #nav-mandanten, .nur-desktop { display: none !important; }
  .spalte-detail.leer { display: none; }
}

/* ---------- Bausteine ---------- */
.knopf {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: var(--radius); border: 1px solid var(--linie); background: var(--blatt); cursor: pointer;
  font-weight: 700; text-decoration: none; color: var(--tinte);
}
.knopf:hover { border-color: var(--tinte-3); }
.knopf.primaer { background: var(--aktion); border-color: var(--aktion); color: #fff; }
.knopf.gross { min-height: 54px; font-size: 17px; width: 100%; }
.knopf.klein { min-height: 34px; padding: 0 10px; font-size: 14px; }
.knopf.leise { background: transparent; border-color: transparent; color: var(--aktion); }
.knopf.gefahr { color: var(--warnung); }
.knopf:disabled { opacity: .5; cursor: default; }
.knopf svg { width: 20px; height: 20px; }
.knopfreihe { display: flex; flex-wrap: wrap; gap: 8px; }

.feld { display: grid; gap: 4px; margin-bottom: 14px; }
.feld > span { font-size: 14px; color: var(--tinte-2); }
.eingabe, select.eingabe, textarea.eingabe {
  width: 100%; min-height: 44px; border: 1px solid var(--linie); border-radius: var(--radius-klein);
  background: var(--blatt); padding: 9px 12px;
}
textarea.eingabe { min-height: 80px; resize: vertical; }
.eingabe:focus { border-color: var(--aktion); outline: none; box-shadow: 0 0 0 3px var(--aktion-hell); }
.zweispaltig { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.blatt { background: var(--blatt); border: 1px solid var(--linie); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.blatt h2 { font-size: 17px; margin: 0 0 12px; }
.hinweis { color: var(--tinte-2); font-size: 14px; }
.fehlerbox { background: var(--warnung-hell); color: var(--warnung); border-radius: var(--radius-klein); padding: 10px 12px; margin: 8px 0; }

/* Filterleiste */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px;
  border-radius: 18px; border: 1px solid var(--linie); background: var(--blatt); cursor: pointer; font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--tinte); border-color: var(--tinte); color: var(--papier); font-weight: 700; }
.chip .punkt { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chip .zahl { color: var(--tinte-3); font-size: 13px; }
.chip[aria-pressed="true"] .zahl { color: inherit; opacity: .75; }

.suche { position: relative; margin-bottom: 10px; }
.suche input { padding-left: 40px; border-radius: 22px; }
.suche svg { position: absolute; left: 13px; top: 12px; width: 20px; height: 20px; color: var(--tinte-3); }

/* ---------- Briefliste ---------- */
.liste { display: grid; gap: 8px; }
.brief {
  display: grid; grid-template-columns: 54px 1fr; gap: 12px; align-items: start; text-decoration: none; color: inherit;
  background: var(--blatt); border: 1px solid var(--linie); border-left: 5px solid var(--m-farbe, var(--linie));
  border-radius: var(--radius); padding: 10px 12px 10px 10px; position: relative;
}
.brief[aria-current="true"] { outline: 2px solid var(--aktion); outline-offset: -1px; }
.brief img { width: 54px; height: 72px; object-fit: cover; object-position: top; border-radius: 4px; background: var(--blatt-2);
  border: 1px solid var(--linie); }
.brief .zeile1 { display: flex; gap: 8px; align-items: baseline; }
.brief .absender { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brief .datum { color: var(--tinte-3); font-size: 13px; white-space: nowrap; }
.brief .betreff { color: var(--tinte-2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brief .meta { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 6px; align-items: center; font-size: 13px; color: var(--tinte-2); padding-right: 100px; }
.mandant-name { font-weight: 700; color: var(--m-farbe, var(--tinte-2)); }
.frist { color: var(--warnung); font-weight: 700; }

/* Der Stempel – das eine kräftige Element */
.stempel {
  --st: var(--st-neu);
  display: inline-block; font-weight: 700; font-size: 12px; letter-spacing: .06em; line-height: 1;
  color: var(--st); border: 2px solid var(--st); border-radius: 4px; padding: 3px 6px 2px;
  box-shadow: inset 0 0 0 1.5px var(--blatt), inset 0 0 0 3px var(--st); padding: 5px 8px 4px;
  transform: rotate(-3deg); opacity: .92; white-space: nowrap;
}
.stempel[data-st="in_bearbeitung"] { --st: var(--st-bearb); }
.stempel[data-st="wiedervorlage"] { --st: var(--st-wv); }
.stempel[data-st="erledigt"] { --st: var(--st-erledigt); }
.stempel[data-st="verworfen"] { --st: var(--st-verworfen); }
.stempel.gross { font-size: 18px; padding: 8px 12px 6px; transform: rotate(-4deg); }
.brief .stempel { position: absolute; right: 10px; bottom: 10px; }
.stempel.faellig { --st: var(--warnung); }

.leer-hinweis { text-align: center; padding: 48px 16px; color: var(--tinte-2); }
.leer-hinweis strong { display: block; color: var(--tinte); font-size: 18px; margin-bottom: 6px; }

.warteschlange {
  display: flex; gap: 10px; align-items: center; background: var(--aktion-hell); color: var(--tinte);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; font-size: 14px;
}
.warteschlange .drehen { width: 18px; height: 18px; border: 2px solid var(--aktion); border-right-color: transparent; border-radius: 50%; animation: drehen 1s linear infinite; }
@keyframes drehen { to { transform: rotate(360deg); } }

/* ---------- Mandanten-Kacheln ---------- */
.kacheln { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.kachel {
  min-height: 58px; text-align: left; padding: 8px 10px 8px 14px; border-radius: var(--radius);
  background: var(--blatt); border: 1px solid var(--linie); position: relative; cursor: pointer; overflow: hidden;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.kachel::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--m-farbe, var(--linie)); }
.kachel strong { font-size: 15px; line-height: 1.2; }
.kachel small { color: var(--tinte-3); font-size: 12px; }
.kachel[aria-pressed="true"] { border-color: var(--m-farbe); box-shadow: inset 0 0 0 2px var(--m-farbe); }
.kachel[aria-pressed="true"]::after { content: "✓"; position: absolute; right: 10px; top: 8px; font-weight: 700; color: var(--m-farbe); }
.kachel.vorgeschlagen { border-style: dashed; border-color: var(--m-farbe); }

/* Vorschlag */
.vorschlag {
  border: 2px dashed var(--aktion); background: var(--aktion-hell); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
}
.vorschlag .titel { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.vorschlag .titel strong { font-size: 17px; }
.sicherheit { font-weight: 700; font-size: 14px; white-space: nowrap; }
.sicherheit.hoch { color: var(--st-erledigt); }
.sicherheit.mittel { color: var(--st-bearb); }
.sicherheit.niedrig { color: var(--warnung); }
.gruende { font-size: 13px; color: var(--tinte-2); margin: 4px 0 10px; }
.laeuft { display: flex; gap: 10px; align-items: center; color: var(--tinte-2); }

/* ---------- Detail ---------- */
.detail-kopf { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; margin: 4px 0 14px; }
.detail-kopf h2 { margin: 0; font-size: 20px; line-height: 1.25; }
.detail-kopf .hinweis { margin-top: 2px; }
.vorschau { display: grid; gap: 10px; margin-bottom: 14px; }
.vorschau img { width: 100%; border-radius: var(--radius-klein); border: 1px solid var(--linie); background: #fff; }
.vorschau iframe { width: 100%; height: 70vh; border: 1px solid var(--linie); border-radius: var(--radius-klein); background: #fff; }
.vorschau-streifen { display: flex; gap: 8px; overflow-x: auto; }
.vorschau-streifen img { width: 100%; max-width: 100%; }
.statusleiste { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.statusleiste .knopf { padding: 0 6px; font-size: 15px; line-height: 1.15; }
.statusleiste .knopf[aria-pressed="true"] { border-color: var(--st, var(--aktion)); box-shadow: inset 0 0 0 2px var(--st, var(--aktion)); color: var(--st, var(--aktion)); }
.statusleiste .knopf[data-st="in_bearbeitung"] { --st: var(--st-bearb); }
.statusleiste .knopf[data-st="wiedervorlage"] { --st: var(--st-wv); }
.statusleiste .knopf[data-st="erledigt"] { --st: var(--st-erledigt); }
.schnellwahl { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
details.aufklapp { border-top: 1px solid var(--linie); padding: 10px 0; }
details.aufklapp summary { cursor: pointer; font-weight: 700; }
.ocrtext { white-space: pre-wrap; font-size: 13px; color: var(--tinte-2); max-height: 320px; overflow: auto; background: var(--blatt-2); padding: 10px; border-radius: var(--radius-klein); }
.zeilen-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.zeilen-chips button { font-size: 13px; text-align: left; }
.historie { list-style: none; padding: 0; margin: 0; font-size: 13px; color: var(--tinte-2); }
.historie li { padding: 4px 0; border-bottom: 1px solid var(--linie); }

/* ---------- Scanner ---------- */
.scanner { position: fixed; inset: 0; z-index: 50; background: #0D1015; color: #fff; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.scanner .oben { padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; display: flex; align-items: center; gap: 10px; }
.scanner .oben strong { flex: 1; font-size: 17px; }
.scanner .knopf { background: #1F2530; border-color: #2E3743; color: #fff; }
.scanner .knopf.primaer { background: var(--aktion); border-color: var(--aktion); }
.scanner .mitte { position: relative; overflow: hidden; display: grid; place-items: center; padding: 10px; }
.scanner .unten { padding: 12px 14px calc(env(safe-area-inset-bottom) + 14px); display: grid; gap: 10px; }
.eckeditor { position: relative; touch-action: none; }
.eckeditor canvas { display: block; width: 100%; height: 100%; }
.eckeditor svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.eckeditor .griff { fill: rgba(36, 70, 200, .35); stroke: #fff; stroke-width: 2.5; cursor: grab; }
.eckeditor polygon { fill: rgba(123, 150, 255, .14); stroke: #7B96FF; stroke-width: 2.5; }
.seitenleiste { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.seitenleiste figure { margin: 0; position: relative; flex: none; }
.seitenleiste img { height: 84px; border-radius: 4px; background: #fff; display: block; }
.seitenleiste figcaption { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); border-radius: 3px; font-size: 11px; padding: 1px 4px; }
.seitenleiste .weg { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: #2E3743; color: #fff; cursor: pointer; }
.modi { display: flex; gap: 6px; justify-content: center; }
.modi .chip { background: #1F2530; border-color: #2E3743; color: #fff; }
.modi .chip[aria-pressed="true"] { background: #fff; color: #0D1015; }
.grosser-ausloeser { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: var(--aktion); margin: 0 auto; display: grid; place-items: center; cursor: pointer; color: #fff; }
.grosser-ausloeser svg { width: 30px; height: 30px; }
.scanner .start { text-align: center; padding: 24px; max-width: 420px; }
.scanner .start p { color: #AEB7C2; }

/* Ablage-Schritt nach dem Scan */
.ablage { position: fixed; inset: 0; z-index: 55; background: var(--papier); overflow-y: auto; }
.ablage .inhalt { padding-top: calc(env(safe-area-inset-top) + 12px); padding-bottom: calc(env(safe-area-inset-bottom) + 100px); }
.fuss-fix { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); background: var(--papier); border-top: 1px solid var(--linie); z-index: 56; }
.fuss-fix .inhalt-schmal { max-width: 860px; margin: 0 auto; display: flex; gap: 8px; }

/* Anmeldung */
.anmeldung { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.anmeldung form { width: 100%; max-width: 380px; }
.anmeldung h1 { font-size: 28px; margin: 0 0 4px; }
.marken-umschlag { width: 64px; height: 64px; margin-bottom: 18px; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  z-index: 100; display: grid; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
#toast div { background: var(--tinte); color: var(--papier); padding: 12px 14px; border-radius: var(--radius); box-shadow: var(--schatten); font-size: 15px; }
@media (min-width: 1000px) { #toast { bottom: 24px; } }

/* Einstellungen */
.tabelle { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabelle td, .tabelle th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--linie); vertical-align: middle; }
.tabelle th { color: var(--tinte-2); font-weight: 400; }
.farbwahl { width: 44px; height: 34px; padding: 0; border: 1px solid var(--linie); border-radius: 6px; background: none; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; background: var(--blatt-2); padding: 8px; border-radius: 6px; }
.tastenhilfe { font-size: 13px; color: var(--tinte-3); margin-top: 18px; }
kbd { font: 12px ui-monospace, Menlo, monospace; border: 1px solid var(--linie); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--blatt); }

/* Lesevorschau oben im Brief: wischen zwischen Seiten, antippen für volle Größe */
.lesen { margin: 0 0 14px; }
.lesen-streifen { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
  scrollbar-width: thin; border-radius: var(--radius-klein); }
.lesen-seite { flex: 0 0 100%; scroll-snap-align: start; display: block; background: var(--blatt-2); border: 1px solid var(--linie);
  border-radius: var(--radius-klein); overflow: hidden; min-height: 200px; }
.lesen-seite img { display: block; width: 100%; height: auto; max-height: 78vh; object-fit: contain; object-position: top; background: #fff; }
.lesen-seite.fehlt::after { content: "Vorschau nicht verfügbar – antippen öffnet das Original"; display: block; padding: 24px; color: var(--tinte-2); }
.lesen-leiste { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-top: 6px; }
@media (min-width: 1000px) { .lesen-seite img { max-height: none; } }
