:root {
  --bg: #f5f6f8; --surface: #fff; --text: #1c2330; --muted: #5d6778; --border: #dde1e8;
  --danger: #c62828; --ok: #1b7f3b; --warn-bg: #fff4d6; --warn-text: #6b4b00;
  --radius: 8px; --side: #19212e; --side-text: #cfd6e2; --side-w: 188px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151c; --surface: #1a212c; --text: #e6eaf1; --muted: #98a2b3; --border: #2b3544;
    --warn-bg: #3a2f0f; --warn-text: #f3d98b; --side: #0c1017; }
}
* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body { margin: 0; font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); }
h1 { font-size: 1.4rem; margin: 0 0 .9rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .5rem; }

/* Layout: schmale, feststehende Navigation links */
.layout { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: .6rem .5rem 1.5rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  font-size: .875rem; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.side .brand { font-weight: 700; font-size: 1rem; color: #fff; padding: .35rem .55rem .7rem; display: block; text-decoration: none; }
.side a.nav { display: block; color: var(--side-text); text-decoration: none; padding: .3rem .55rem; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side a.nav:hover { background: rgba(255,255,255,.08); }
.side a.nav.active { background: var(--brand); color: #fff; }
.side .grp-flat { margin-bottom: .35rem; }
.side details.grp { margin-top: .15rem; }
.side details.grp > summary { list-style: none; cursor: pointer; padding: .3rem .55rem; border-radius: 6px; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .07em; font-weight: 600; color: rgba(207,214,226,.7); display: flex; justify-content: space-between; align-items: center; }
.side details.grp > summary::-webkit-details-marker { display: none; }
.side details.grp > summary::after { content: "›"; font-size: 1rem; transition: transform .15s; }
.side details.grp[open] > summary::after { transform: rotate(90deg); }
.side details.grp > summary:hover { background: rgba(255,255,255,.06); color: #fff; }
.side details.grp[open] { padding-bottom: .25rem; }
.side details.grp a.nav { padding-left: .9rem; }
.main { display: flex; flex-direction: column; min-width: 0; }
.top { display: flex; align-items: center; gap: .7rem; padding: .45rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.top form { margin: 0; }
.top .spacer { flex: 1; }
.top .whoami { white-space: nowrap; text-decoration: none; color: var(--text); }
.content { padding: 1.25rem 1.5rem 3rem; max-width: 1180px; width: 100%; }
.burger, .navtoggle { display: none; }

/* Globale Suche */
.gsearch { position: relative; flex: 0 1 380px; min-width: 0; }
.gsearch input[type=search] { width: 100%; padding: .4rem .7rem; border: 1px solid var(--border); border-radius: 99px; background: var(--bg); color: var(--text); font: inherit; }
.gsearch input[type=search]:focus { outline: 2px solid var(--brand); background: var(--surface); }
.sr { position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: 320px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 70vh; overflow-y: auto; z-index: 30; }
.sr:empty, .gsearch:not(:focus-within) .sr { display: none; }
.sr-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .5rem .8rem .15rem; font-weight: 600; }
.sr-hit { display: flex; flex-direction: column; padding: .3rem .8rem; text-decoration: none; color: var(--text); }
.sr-hit small { color: var(--muted); }
.sr-hit:hover, .sr-hit:focus { background: var(--bg); }
.sr-empty { padding: .8rem; color: var(--muted); }
.sr-all { display: block; padding: .45rem .8rem; border-top: 1px solid var(--border); font-size: .85rem; }

/* Menue "+ Neu" */
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; white-space: nowrap; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); min-width: 170px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: .3rem; z-index: 30; }
.menu-list a { display: block; padding: .35rem .7rem; border-radius: 6px; color: var(--text); text-decoration: none; }
.menu-list a:hover { background: var(--bg); }
.chip { display: inline-block; font-size: .75rem; padding: .1rem .55rem; border-radius: 99px; text-decoration: none; white-space: nowrap; }
.chip.warn { background: var(--warn-bg); color: var(--warn-text); }

/* Ladebalken oben bei jedem Seitenwechsel */
#progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100; background: linear-gradient(90deg, transparent, var(--brand), transparent);
  background-size: 40% 100%; background-repeat: no-repeat; animation: slide 1s linear infinite; pointer-events: none; }
@keyframes slide { from { background-position: -40% 0; } to { background-position: 140% 0; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(127,127,127,.05); }
.tablewrap { overflow-x: auto; }
.btn, button { display: inline-block; background: var(--brand); color: #fff; border: 0; border-radius: 6px; padding: .45rem .9rem; font: inherit; cursor: pointer; text-decoration: none; }
.btn.secondary, button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.danger, button.danger { background: var(--danger); }
.btn.link, button.link { background: none; color: var(--brand); padding: 0; border: 0; }
button.small, .btn.small { padding: .25rem .6rem; font-size: .85rem; }
.actions { display: flex; gap: .6rem; align-items: center; margin: .9rem 0; flex-wrap: wrap; }
.field { margin-bottom: .9rem; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field input[type=text], .field input[type=password], .field input[type=email], .field input[type=number], .field input[type=date], .field select, .field textarea, input.search {
  width: 100%; padding: .45rem .65rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; }
.field input:focus, .field select:focus, .field textarea:focus, input.search:focus { outline: 2px solid var(--brand); outline-offset: 0; }
.field ul { list-style: none; margin: 0; padding: 0; }
.field ul li { padding: .15rem 0; }
.field ul label { font-weight: 400; display: inline; }
.help { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.errorlist { list-style: none; margin: .25rem 0 0; padding: 0; color: var(--danger); font-size: .9rem; }
.alert { padding: .6rem .9rem; border-radius: 6px; margin-bottom: .8rem; border: 1px solid var(--border); background: var(--surface); }
.alert.success { border-color: var(--ok); } .alert.error { border-color: var(--danger); color: var(--danger); }
.alert.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.alert.success, .alert.info { animation: fadeaway .4s ease 7s forwards; }
@keyframes fadeaway { to { opacity: 0; height: 0; padding: 0; margin: 0; border-width: 0; overflow: hidden; } }
.badge { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; background: var(--border); color: var(--text); }
.badge.ok { background: var(--ok); color: #fff; } .badge.off { background: var(--danger); color: #fff; }
.muted { color: var(--muted); }
.authwrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.authcard { width: 100%; max-width: 440px; }
.authcard h1 { text-align: center; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; }
.rolebox { border: 1px solid var(--border); border-radius: 6px; padding: .6rem .8rem; margin-bottom: .6rem; }
.rolebox legend, .rolebox strong { font-weight: 600; }
.codes { font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; columns: 2; margin: .4rem 0 .8rem; }
.rc-title { margin: 0 0 .3rem; }
/* Ausdruck/PDF: nur der Block mit den Wiederherstellungscodes */
@media print {
  body:has(#recovery-print) * { visibility: hidden; }
  body:has(#recovery-print) #recovery-print, body:has(#recovery-print) #recovery-print * { visibility: visible; }
  #recovery-print { position: absolute; left: 0; top: 0; width: 100%; color: #000; }
  #recovery-print .codes { font-size: 1.3rem; line-height: 2; columns: 2; }
}
.qr svg { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 6px; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.comment { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.comment:last-of-type { border-bottom: 0; }
.mention { color: var(--brand); font-weight: 600; }
.bell { text-decoration: none; }
details summary { cursor: pointer; }

/* Arbeitsansicht: Hauptspalte (z. B. Verlauf) links, Details und Bausteine rechts */
.work { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
.work-side .cols { grid-template-columns: 1fr; }
.work-side { position: sticky; top: 4rem; }
.work .card .cols { grid-template-columns: 1fr 1fr; }
.work-side .card .cols { grid-template-columns: 1fr; }
@media (max-width: 1000px) { .work { grid-template-columns: 1fr; } .work-side { position: static; order: -1; } }

.mailframe { width: 100%; height: 520px; border: 1px solid var(--border); border-radius: 6px; background: #fff; resize: vertical; margin-top: .4rem; }
.mailview { margin-top: .4rem; }

/* Reiter (z. B. Hersteller-Konsole) und Kennzahlen */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.1rem; flex-wrap: wrap; }
.tabs a { padding: .45rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.stat { font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.steps { list-style: none; padding: 0; margin: 0; }
.steps li { display: flex; gap: .7rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.steps li:last-child { border-bottom: 0; }
.steps .num { width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--border); display: grid; place-items: center; font-size: .8rem; flex: none; }
.steps .done .num { background: var(--ok); color: #fff; }
.steps .done { color: var(--muted); }
.steps form { margin: 0 0 0 auto; }
.copybox { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; word-break: break-all; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .6rem .7rem; max-height: 7.5rem; overflow-y: auto; }

/* Schmale Fenster: Menue per Knopf ein-/ausblenden */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { display: none; position: fixed; z-index: 50; width: 78vw; max-width: 300px; box-shadow: 4px 0 24px rgba(0,0,0,.35); }
  .navtoggle:checked ~ .layout .side { display: block; }
  .burger { display: inline-block; font-size: 1.3rem; cursor: pointer; padding: 0 .3rem; }
  .top { padding: .45rem .75rem; gap: .5rem; }
  .whoami { display: none; }
  .content { padding: 1rem .85rem 3rem; }
  .cols { grid-template-columns: 1fr; }
  .gsearch { flex: 1 1 auto; }
}
@media print { .side, .top, .actions, #progress { display: none !important; } .layout { display: block; } }
