/* MailDesk – Stylesheet (Grundlage aus RAK/FormDesk). */
:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #eef2f1; --text: #17201e; --muted: #5b6764; --line: #d7dfdc;
  --brand: #1d6f63; --brand-2: #155a50; --brand-soft: #e0f1ee; --focus: #2563eb;
  --ok: #157a3d; --ok-soft: #e3f4ea; --warn: #9a6200; --warn-soft: #fff4dc; --err: #b42318; --err-soft: #fdecea; --info-soft: #e8f0fe;
  --radius: 10px; --row: 32px; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101514; --surface: #182120; --surface-2: #1f2a28; --text: #e7eeec; --muted: #9db0ab; --line: #2f3d3a;
    --brand: #5cc4b2; --brand-2: #7fd3c4; --brand-soft: #15302b; --focus: #7aa7ff;
    --ok: #4cc27a; --ok-soft: #173426; --warn: #e3a93b; --warn-soft: #3a2e14; --err: #ff7b6b; --err-soft: #3d1d19; --info-soft: #1b2840;
    --shadow: 0 1px 2px rgb(0 0 0 / .4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 var(--font); background: var(--bg); color: var(--text); }
a { color: var(--brand); }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.boot { padding: 2rem; color: var(--muted); }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem; z-index: 99; }
.skip:focus { left: .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Kopf und Navigation ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; padding-top: max(.5rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand-ver { font-weight: 500; font-size: .72rem; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: .05rem .45rem; font-variant-numeric: tabular-nums; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { display: flex; align-items: center; gap: .35rem; padding: .45rem .7rem; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-short { display: none; }
.user { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.user-name { color: var(--muted); max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px) {
  .top { padding-left: .75rem; padding-right: .75rem; }
  .user-name { display: none; }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line);
    justify-content: space-around; padding: .25rem .25rem max(.25rem, env(safe-area-inset-bottom)); gap: 0; }
  .nav a { flex-direction: column; gap: 0; font-size: .7rem; padding: .3rem .4rem; min-width: 56px; }
  .nav-ic { font-size: 1.2rem; }
  .nav-long { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .nav-short { display: block; white-space: nowrap; }
  .nav a { min-width: 0; flex: 1; }
  main { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
}

/* ---------- Seiten ---------- */
main { outline: none; }
.page { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page.narrow { max-width: 760px; }
.page.wide { max-width: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty.err h2 { color: var(--err); }
.banner { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.err { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 30%, transparent); }
.banner.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.banner.info { background: var(--info-soft); }

/* ---------- Schaltflächen und Eingaben ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 40px; padding: .45rem .9rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; touch-action: manipulation; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 32px; padding: .25rem .6rem; font-size: .9rem; }
.btn.icon { min-width: 40px; padding: .3rem; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.in { width: 100%; min-height: 40px; padding: .45rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit;
  font-size: 16px; /* verhindert Zoom auf dem iPhone */ }
.in:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.in[readonly], .in:disabled { background: var(--surface-2); }
.in.sm { min-height: 32px; padding: .2rem .4rem; font-size: 14px; width: auto; }
textarea.in { resize: vertical; min-height: 80px; }
select.in { appearance: auto; }
.in.num { text-align: right; font-variant-numeric: tabular-nums; }
.in.calc { display: flex; align-items: center; justify-content: flex-end; font-weight: 600; background: var(--surface-2); font-variant-numeric: tabular-nums; }
.in-group { display: flex; align-items: stretch; }
.in-group > .in { border-top-right-radius: 0; border-bottom-right-radius: 0; flex: 1; min-width: 0; }
.in-group > .btn, .in-group > .in-unit { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.in-unit { display: flex; align-items: center; padding: 0 .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--muted); }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.field > .hint { font-size: .8rem; color: var(--muted); }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 180px; }
.check { display: flex; gap: .5rem; align-items: flex-start; cursor: pointer; padding: .3rem 0; }
.check input { width: 20px; height: 20px; margin: .1rem 0 0; flex: none; accent-color: var(--brand); }
.protect-opts { border: 1px solid var(--line, #ccc); border-radius: 8px; padding: .4rem .8rem .6rem; margin: .8rem 0 0; }
.protect-opts legend { padding: 0 .3rem; }
.choice { display: flex; flex-wrap: wrap; gap: .25rem 1rem; padding: .3rem 0; }
.choice-item { display: flex; gap: .4rem; align-items: center; cursor: pointer; min-height: 32px; }
.choice-item input { width: 18px; height: 18px; accent-color: var(--brand); }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.st-submitted { background: var(--info-soft); color: var(--focus); }
.st-approved { background: var(--ok-soft); color: var(--ok); }
.st-rejected { background: var(--err-soft); color: var(--err); }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .3rem .8rem; cursor: pointer; font: inherit; color: var(--text); min-height: 34px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- Listen ---------- */
.list { display: flex; flex-direction: column; gap: .5rem; }
.item { display: grid; grid-template-columns: 1fr auto; gap: .25rem 1rem; align-items: center; padding: .8rem 1rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); }
.item:hover { border-color: var(--brand); }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { color: var(--muted); font-size: .85rem; }
.item-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; }
table.grid { width: 100%; border-collapse: collapse; background: var(--surface); }
table.grid th, table.grid td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: .9rem; }
table.grid th { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; }
.scroll-x { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- Dialoge, Meldungen ---------- */
dialog.modal { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
dialog.modal.wide { width: min(1100px, calc(100vw - 2rem)); }
dialog.modal::backdrop { background: rgb(0 0 0 / .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 1rem; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1rem; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
.toasts { position: fixed; z-index: 1000; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; max-width: calc(100vw - 2rem); }
.toast { padding: .7rem 1rem; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); transition: opacity .3s, transform .3s; }
.toast-err { background: var(--err); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
@media (max-width: 760px) { .toasts { bottom: calc(80px + env(safe-area-inset-bottom)); left: 1rem; } }

/* ---------- Archiv (ab Etappe 4: Suche, Filter, Facetten; ab Etappe 5: Mail-Ansicht) ---------- */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
table.grid .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.muted td { color: var(--muted); }

/* ---------- Konten (Etappe 2) ---------- */
.account-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.account-head h2 { margin: 0 0 .2rem; font-size: 1.1rem; }
.account-card details { margin-top: .5rem; }
.account-card summary { cursor: pointer; font-weight: 600; padding: .25rem 0; }
table.folders .badge { font-size: .7rem; }

/* ---------- Archivieren (Etappe 3) ---------- */
.folder-picks { max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: .25rem .75rem; }
.folder-pick .badge { margin-left: .4rem; font-size: .7rem; }
.run-progress { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .8rem; margin: .5rem 0; background: var(--surface-2); }
.run-progress > * + * { margin-top: .35rem; }
.run-bar { width: 100%; height: .6rem; accent-color: var(--brand); }
.section-h { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }

/* ---------- Suche (Etappe 4) ---------- */
.search-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; max-width: 1180px; }
.search-bar .search-in { flex: 1 1 320px; min-width: 0; }
.search-bar .sort-in { flex: 0 0 auto; width: auto; }
.search-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 1.25rem; align-items: start; max-width: 1400px; }
.facets { position: sticky; top: .75rem; max-height: calc(100vh - 6rem); overflow: auto; font-size: .9rem; }
.facet { border-bottom: 1px solid var(--line); padding: .35rem 0; }
.facet > summary { cursor: pointer; font-weight: 600; padding: .3rem 0; }
.facet ul { list-style: none; margin: 0; padding: 0; }
.facet-sub { padding-left: .9rem !important; }
.facet-item { display: flex; justify-content: space-between; gap: .5rem; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px;
  padding: .3rem .45rem; font: inherit; color: var(--text); cursor: pointer; text-decoration: none; }
.facet-item:hover { background: var(--surface-2); }
.facet-item.active { background: var(--brand-soft); color: var(--brand-2); font-weight: 600; }
.facet-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet-n { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.facet-range { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; padding: .35rem .45rem; }
.facet-range .in { flex: 1 1 110px; }
.facet-more { padding: .35rem .2rem; }
.facet li.saved { display: flex; align-items: center; }
.results-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.hits { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.hit { display: block; padding: .65rem .9rem; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.hit:last-child { border-bottom: 0; }
.hit:hover, .hit:focus-visible { background: var(--surface-2); }
.hit-top { display: flex; justify-content: space-between; gap: 1rem; font-size: .88rem; }
.hit-from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hit-date { color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.hit-subj { margin: .1rem 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hit-snip { color: var(--muted); font-size: .85rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hit-meta { display: flex; gap: .75rem; font-size: .78rem; color: var(--muted); margin-top: .2rem; flex-wrap: wrap; }
.hit-meta span:not(.badge) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }
mark { background: #ffe58a; color: inherit; border-radius: 2px; padding: 0 1px; }
@media (prefers-color-scheme: dark) { mark { background: #6b5a12; } }
.dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; background: var(--brand); margin-right: .4rem; vertical-align: middle; }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 1rem 0; }
@media (max-width: 820px) {
  .search-layout { grid-template-columns: 1fr; }
  .facets { position: static; max-height: none; }
}

/* ---------- Mail (Etappe 4: Text) ---------- */
.msg-nav { margin-bottom: .5rem; }
.msg-subj { font-size: 1.3rem; margin: 0 0 .75rem; overflow-wrap: anywhere; }
.msg-head { border-collapse: collapse; font-size: .9rem; margin-bottom: 1rem; }
.msg-head th { text-align: left; color: var(--muted); font-weight: 500; padding: .15rem 1rem .15rem 0; vertical-align: top; white-space: nowrap; }
.msg-head td { padding: .15rem 0; overflow-wrap: anywhere; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: .95rem; border-top: 1px solid var(--line); padding-top: 1rem; margin: 0 0 1rem; }

/* ---------- Mail-Ansicht (Etappe 5) ---------- */
.msg-nav { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.seg { display: inline-flex; }
.seg .btn { border-radius: 0; }
.seg .btn:first-child { border-radius: 8px 0 0 8px; }
.seg .btn:last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.seg .btn[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-2); font-weight: 600; }
.msg-body { border-top: 1px solid var(--line); padding-top: .75rem; margin-bottom: 1rem; }
.msg-frame { width: 100%; height: 70vh; min-height: 300px; border: 1px solid var(--line); border-radius: 8px; background: #fff; resize: vertical; display: block; }
.msg-remote { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.msg-atts ul, .msg-thread ol { margin: 0 0 1rem; padding-left: 0; list-style: none; }
.msg-thread ol { padding-left: 1.4rem; list-style: decimal; }
.msg-thread li.current { font-weight: 600; }
.msg-atts li { display: flex; align-items: center; gap: .25rem; }
.msg-atts .att { text-align: left; }
.small-h { font-size: .95rem; margin: .75rem 0 .35rem; }
.msg-headers { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .8rem; margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.chip.tag { display: inline-flex; align-items: center; gap: .2rem; padding: .1rem .2rem .1rem .6rem; min-height: 28px; font-size: .85rem; background: var(--brand-soft); border-color: transparent; }
.chip.tag a { color: var(--brand-2); text-decoration: none; }
.tag-x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 .3rem; font: inherit; }
.tag-in { max-width: 12rem; }
