/* Notfallseite: ergänzt app.css. Eigener Akzentton, damit man die Seiten auseinanderhält. */
body[data-mode="nofa"] { --accent: #c2410c; --accent-ink: #ffffff; }
body[data-mode="logins"] { --accent: #0f766e; }
@media (prefers-color-scheme: dark) {
  body[data-mode="nofa"] { --accent: #ff9a62; --accent-ink: #1a0f08; }
  body[data-mode="logins"] { --accent: #5eead4; }
}
.sub-head { display: flex; align-items: center; gap: 0.5rem; margin: 1.1rem 0 0.5rem; }
.sub-head h3 { font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.sub-head .grow { flex: 1; }
.foot { padding-top: 0; font-size: 0.875rem; }
.foot a { color: var(--muted); }

.sec { margin: 0 0 1.75rem; }
.sec-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.sec-head .grow { flex: 1; }

/* Kontakte */
.contacts { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
.contact {
  display: grid; gap: 0.3rem; align-content: start; padding: 0.9rem 1rem; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: var(--radius);
  overflow-wrap: anywhere;
}
.contact.empty { border-top-color: var(--line); }
.contact .slot { font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.contact .cname { font-size: 1.125rem; line-height: 1.25; }
.contact .call { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; margin: 0.35rem 0 0.15rem; font-size: 1.125rem; font-variant-numeric: tabular-nums; }
.contact .call-plain { font-size: 1.125rem; font-weight: 600; }
.contact .mail { color: var(--ink); }
.contact .cnote { font-size: 0.9rem; color: var(--muted); white-space: pre-wrap; }
fieldset.slotset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0.75rem 0; padding: 0 0.9rem 0.4rem; }
fieldset.slotset legend { font-weight: 600; padding: 0 0.4rem; }

/* Person */
.facts { display: grid; grid-template-columns: minmax(7rem, 14rem) 1fr; gap: 0.4rem 1rem; margin: 0; padding: 0.9rem 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.facts dt { color: var(--muted); font-size: 0.9rem; }
.facts dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 30rem) { .facts { grid-template-columns: 1fr; gap: 0.1rem; } .facts dd { margin-bottom: 0.5rem; } }

/* Geheimnisse */
.chev { color: var(--muted); padding-right: 0.5rem; }
.vbody { padding: 0.25rem 1rem 0.9rem; display: grid; gap: 0.15rem; }
.vrow { display: grid; grid-template-columns: minmax(6rem, 9rem) 1fr auto; gap: 0.5rem; align-items: center; min-height: 2.25rem; }
.vlabel { color: var(--muted); font-size: 0.875rem; }
.vrow .val { overflow-wrap: anywhere; }
.vrow .val.multi { white-space: pre-wrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.95rem; }
.vtools { display: flex; }
.vtools .btn { padding: 0.25rem 0.55rem; min-height: 2rem; font-size: 0.875rem; }
@media (max-width: 30rem) { .vrow { grid-template-columns: 1fr auto; } .vlabel { grid-column: 1 / -1; margin-bottom: -0.35rem; } }


/* Zähler hinter Abschnittsüberschriften (LOGINS) */
.sec-head .count {
  display: inline-block; min-width: 1.6em; padding: 0 0.5em; border-radius: 999px; text-align: center; font-size: 0.8rem; font-weight: 700; line-height: 1.6;
  background: var(--panel); color: var(--muted); border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}

/* Notfallkarte: Link, QR-Code, Freigabe */
.cardlink { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin: 0.75rem 0; }
.cardlink input { flex: 1 1 16rem; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; }
.cardlink .btn { text-decoration: none; display: inline-flex; align-items: center; }
.qrbox { display: grid; justify-items: start; gap: 0.4rem; margin: 0.5rem 0 1rem; }
.qrbox .qr { width: 12rem; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
label.chk { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.4rem 0; min-height: 2.5rem; cursor: pointer; }
label.chk input { margin-top: 0.3rem; flex: none; width: 1.15rem; height: 1.15rem; }
.chk-text { display: grid; min-width: 0; overflow-wrap: anywhere; }

/* Ausdruck: nur das Blatt mit Kontakten und darunter dem QR-Code */
.print-sheet { display: none; }
@media print {
  body.printing > *:not(.print-sheet) { display: none !important; }
  body.printing { background: #fff; }
  body.printing .print-sheet {
    display: block; color: #000; background: #fff; font: 12pt/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    border: 2px solid #000; border-radius: 8px; padding: 12mm; max-width: 18cm; margin: 0 auto; break-inside: avoid;
  }
  .print-sheet h1 { margin: 0 0 4mm; font-size: 22pt; letter-spacing: 0.04em; text-transform: uppercase; }
  .print-sheet h2 { margin: 6mm 0 2mm; font-size: 11pt; text-transform: uppercase; letter-spacing: 0.06em; }
  .print-sheet .ps-name { margin: 0; font-size: 16pt; font-weight: 700; }
  .print-sheet .ps-contact { margin: 0 0 2mm; font-size: 13pt; }
  .print-sheet .ps-phone { display: block; font-size: 15pt; font-weight: 700; font-variant-numeric: tabular-nums; }
  .print-sheet .ps-qr { margin-top: 8mm; display: grid; justify-items: center; text-align: center; gap: 2mm; }
  .print-sheet .qr { width: 5.5cm; height: 5.5cm; }
  .print-sheet .ps-hint { margin: 0; font-weight: 700; }
  .print-sheet .ps-link { margin: 0; font-size: 8.5pt; overflow-wrap: anywhere; font-family: ui-monospace, Menlo, Consolas, monospace; }
}

/* Visitenkarten-PDF: breiter Dialog, Vorschau (immer weiße Karte, auch im Dunkelmodus), Einstellungen in zwei Spalten */
dialog.modal:has(.pdfdlg) { width: min(44rem, calc(100vw - 2rem)); }
.pdfprev { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 0.5rem 0; }
.pdfprev figure { margin: 0; flex: 1 1 14rem; max-width: 20rem; }
.pdfprev-svg { display: block; width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 1px 4px rgba(8, 14, 22, 0.18); }
.pdfprev figcaption { margin-top: 0.2rem; }
.pdfgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.75rem; }
.pdfrow { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.75rem; }
.pdfrow[hidden] { display: none; }
@media (max-width: 34rem) { .pdfgrid, .pdfrow { grid-template-columns: 1fr; } }
/* Vorschau bleibt beim Scrollen im Dialog oben stehen (nur wenn genug Platz ist) */
@media (min-width: 34rem) and (min-height: 44rem) {
  .pdfsticky { position: sticky; top: -1.25rem; z-index: 2; background: var(--panel); padding: 0.5rem 0 0.25rem; margin-top: -0.25rem; border-bottom: 1px solid var(--line); }
}

/* Arztbriefe: Zeilen Titel / Dateiname / Datum, per Griff sortierbar */
.docbox { border: 1px dashed transparent; border-radius: var(--radius); }
.docbox.over, .dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.dropzone { border: 1px dashed var(--line); border-radius: var(--radius); padding: 1rem; color: var(--muted); text-align: center; cursor: pointer; }
.docrow { display: grid; grid-template-columns: 2.25rem minmax(0, 1.4fr) minmax(0, 1fr) 9rem auto; gap: 0.5rem; align-items: center; padding: 0.35rem 0; border-bottom: 1px solid var(--line); background: var(--panel); }
.dochead { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.docrow input { width: 100%; box-sizing: border-box; min-width: 0; }
.docrow.dragging { box-shadow: 0 2px 12px rgba(8, 14, 22, 0.25); position: relative; z-index: 2; }
.docgrip { display: flex; align-items: center; justify-content: center; min-height: 2.5rem; border: 0; background: transparent; color: var(--muted); cursor: grab; touch-action: none; }
.docrow.dragging .docgrip { cursor: grabbing; }
.docname { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; padding: 0.2rem 0.3rem; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.docname:hover .docfile { text-decoration: underline; }
.docfile { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.docimg { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto 0.75rem; }
@media (max-width: 40rem) {
  .dochead { display: none; }
  .docrow { grid-template-columns: 2.25rem minmax(0, 1fr) auto; grid-template-areas: "grip title del" ". name name" ". date date"; }
  .docrow > :nth-child(1) { grid-area: grip; } .docrow > :nth-child(2) { grid-area: title; } .docrow > :nth-child(3) { grid-area: name; }
  .docrow > :nth-child(4) { grid-area: date; } .docrow > :nth-child(5) { grid-area: del; }
}

/* Medikamente */
.medrow { grid-template-columns: 2.25rem minmax(0, 1.5fr) minmax(0, 1.3fr) minmax(0, 0.8fr) minmax(0, 0.7fr) 10.5rem auto; }
.medintake { display: flex; align-items: center; justify-content: center; gap: 0.3rem; }
.medintake .dose { width: 2.6rem; padding-inline: 0.2rem; text-align: center; font-variant-numeric: tabular-nums; }
.medlabel { display: none; }
@media (max-width: 40rem) {
  .medrow { grid-template-columns: 2.25rem minmax(0, 1fr) minmax(0, 1fr) auto; grid-template-areas: "grip name name del" ". sub sub sub" ". mg cnt cnt" ". dose dose dose"; }
  .medrow > :nth-child(1) { grid-area: grip; } .medrow > :nth-child(2) { grid-area: name; } .medrow > :nth-child(3) { grid-area: sub; }
  .medrow > :nth-child(4) { grid-area: mg; } .medrow > :nth-child(5) { grid-area: cnt; } .medrow > :nth-child(6) { grid-area: dose; justify-content: flex-start; flex-wrap: wrap; } .medrow > :nth-child(7) { grid-area: del; }
  .medlabel { display: inline; margin-left: 0.4rem; }
}

/* Medikamente: 4. Einnahme (zur Nacht) und Detailzeile */
.medrow { grid-template-columns: 2.25rem minmax(0, 1.5fr) minmax(0, 1.3fr) minmax(0, 0.8fr) minmax(0, 0.7fr) 13.5rem auto; }
.meddetails { grid-column: 2 / -1; font-size: 0.875rem; }
.meddetails summary { cursor: pointer; color: var(--muted); }
.meddgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0.4rem; margin-top: 0.35rem; }
@media (max-width: 40rem) {
  .medrow { grid-template-areas: "grip name name del" ". sub sub sub" ". mg cnt cnt" ". dose dose dose" ". det det det"; }
  .medrow > .meddetails { grid-area: det; }
}

/* Medikationsplan: Knopfzeile und Druckblatt */
.sec-head { flex-wrap: wrap; }
.medactions { margin: 0 0 0.6rem; }
@media print {
  body.printing .print-sheet.medplan { border: 0; border-radius: 0; padding: 0; max-width: none; break-inside: auto; }
  .print-sheet.medplan table { width: 100%; border-collapse: collapse; font-size: 8pt; margin: 4mm 0; }
  .print-sheet.medplan th { text-align: left; background: #e5e7eb; padding: 1.5mm; border-bottom: 1px solid #000; }
  .print-sheet.medplan td { padding: 1.5mm; border-bottom: 1px solid #999; vertical-align: top; overflow-wrap: anywhere; }
  .print-sheet.medplan td.dose { text-align: center; font-weight: 700; font-size: 10pt; }
  .print-sheet.medplan td.strong { font-weight: 700; }
  .print-sheet.medplan tr { break-inside: avoid; }
  .print-sheet.medplan h1 { text-transform: none; font-size: 18pt; }
}

/* Medikamente: zweizeilige Zeile auf jeder Breite (die Seite ist nur 40rem breit, eine Zeile wäre zu eng) */
.medrow.dochead { display: none; }
.medrow {
  grid-template-columns: 2.25rem minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  grid-template-areas: "grip name name sub del" ". mg cnt dose dose" ". det det det det";
  row-gap: 0.4rem;
}
.medrow > :nth-child(1) { grid-area: grip; } .medrow > :nth-child(2) { grid-area: name; } .medrow > :nth-child(3) { grid-area: sub; }
.medrow > :nth-child(4) { grid-area: mg; } .medrow > :nth-child(5) { grid-area: cnt; }
.medrow > :nth-child(6) { grid-area: dose; justify-content: flex-start; flex-wrap: wrap; }
.medrow > :nth-child(7) { grid-area: del; }
.medrow > .meddetails { grid-area: det; }
.medlabel { display: inline; margin-left: 0.3rem; }
@media (max-width: 34rem) {
  .medrow { grid-template-columns: 2.25rem minmax(0, 1fr) minmax(0, 1fr) auto; grid-template-areas: "grip name name del" ". sub sub sub" ". mg cnt cnt" ". dose dose dose" ". det det det"; }
}

/* Wiederherstellungscodes und eigene Felder bei Logins */
.extrarow { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-bottom: 0.4rem; }
.extrarow input[type="text"] { flex: 1 1 8rem; min-width: 0; }
.extrasec { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.875rem; color: var(--muted); white-space: nowrap; }
.extras + select { margin-top: 0.1rem; }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.codelist { margin: 0.5rem 0; }
.codeitem { grid-template-columns: auto 1fr auto; }
.codeused { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.875rem; color: var(--muted); white-space: nowrap; }
.val.code-used { text-decoration: line-through; opacity: 0.65; }
.val.codes-empty { color: var(--muted); }
@media (max-width: 30rem) { .codeitem { grid-template-columns: 1fr auto; } .codeitem .codeused { grid-column: 1 / -1; } }

/* E-Mail-Alias (HME): Einstellungen mit Reitern und Testergebnis (hme-settings-ui.js) */
.hme-settings .tabs { margin: 1rem 0 0.75rem; }
.hme-settings .tab { flex: 1 1 0; text-align: center; }
.hme-settings [role=tabpanel][hidden] { display: none; }
.hme-dot { color: var(--ok); font-weight: 700; }
.hme-test { margin: 0.75rem 0; }
.hme-test:empty { display: none; }
.hme-verdict { font-weight: 600; margin: 0 0 0.4rem; }
.hme-verdict.ok { color: var(--ok); }
.hme-verdict.bad { color: var(--danger); }
.hme-step { display: grid; grid-template-columns: 1.4rem 1fr; gap: 0.4rem; padding: 0.3rem 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.hme-step .hme-mark { font-weight: 700; }
.hme-step.ok .hme-mark { color: var(--ok); }
.hme-step.bad .hme-mark { color: var(--danger); }
.hme-settings .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.hme-settings .error:empty { display: none; }
