@layer basis, bausteine, seiten;

:root {
  color-scheme: light dark;
  --hg: light-dark(#f4f5f7, #0f1217);
  --flaeche: light-dark(#ffffff, #171b22);
  --flaeche-2: light-dark(#f8f9fb, #1d222b);
  --text: light-dark(#151a22, #e7eaf0);
  --leise: light-dark(#5a6372, #9ba4b4);
  --linie: light-dark(#dfe3e9, #2b323d);
  --primaer: light-dark(#1f4a96, #8db0ff);
  --primaer-hover: light-dark(#183c7c, #a9c3ff);
  --primaer-text: light-dark(#ffffff, #0d1424);
  --primaer-zart: light-dark(#edf2fb, #1b2538);
  --gut: light-dark(#1d6b45, #6fd6a0);
  --gut-zart: light-dark(#e8f5ee, #15291f);
  --warn: light-dark(#8a5a00, #f0c46a);
  --warn-zart: light-dark(#fdf4e1, #2b2414);
  --fehler: light-dark(#b42318, #ff8f85);
  --fehler-zart: light-dark(#fdeceb, #2e1816);
  --radius: 10px;
  --schatten: 0 1px 2px rgb(0 0 0 / .05), 0 2px 8px rgb(0 0 0 / .04);
  --schrift: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@layer basis {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; scroll-padding-block-start: 5rem; }
  body {
    margin: 0;
    font: 1rem/1.55 var(--schrift);
    color: var(--text);
    background: var(--hg);
    min-block-size: 100dvh;
    display: flex;
    flex-direction: column;
    hyphens: manual;
    overflow-wrap: break-word;
  }
  h1, h2, h3 { line-height: 1.25; text-wrap: balance; margin: 0 0 .5em; }
  h1 { font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2rem); letter-spacing: -.01em; }
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1.05rem; margin-block-start: 1.2em; }
  p { margin: 0 0 .8em; text-wrap: pretty; }
  a { color: var(--primaer); text-underline-offset: 3px; }
  a:hover { color: var(--primaer-hover); }
  img { max-inline-size: 100%; display: block; }
  :focus-visible { outline: 3px solid color-mix(in srgb, var(--primaer) 55%, transparent); outline-offset: 2px; }
  [hidden] { display: none !important; }
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
}

@layer bausteine {
  /* Kopfzeile */
  .kopf {
    position: sticky; inset-block-start: 0; z-index: 10;
    background: color-mix(in srgb, var(--flaeche) 92%, transparent);
    backdrop-filter: blur(8px);
    border-block-end: 1px solid var(--linie);
  }
  .kopf-innen {
    max-inline-size: 72rem; margin-inline: auto; padding: .75rem 1rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    min-block-size: 4rem;
  }
  .marke {
    display: inline-flex; align-items: center; gap: .55rem;
    font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none;
  }
  .marke-zeichen { inline-size: 1.75rem; block-size: 1.75rem; }
  .menue-knopf {
    display: inline-flex; align-items: center; gap: .4rem;
    font: inherit; font-weight: 600; color: var(--text);
    background: var(--flaeche-2); border: 1px solid var(--linie); border-radius: var(--radius);
    padding: .5rem .8rem; cursor: pointer;
  }
  .nav {
    margin: 0; inset: 4.25rem .75rem auto auto; inline-size: min(18rem, calc(100vw - 1.5rem));
    padding: .5rem; border: 1px solid var(--linie); border-radius: var(--radius);
    background: var(--flaeche); color: var(--text); box-shadow: 0 10px 30px rgb(0 0 0 / .15);
    &:popover-open { display: flex; flex-direction: column; gap: .15rem; }
    a, .nav-abmelden {
      display: block; padding: .7rem .8rem; border-radius: 8px; text-decoration: none;
      color: var(--text); font: inherit; font-weight: 500; text-align: start;
      background: none; border: 0; inline-size: 100%; cursor: pointer;
    }
    a:hover, .nav-abmelden:hover { background: var(--flaeche-2); }
    a[aria-current="page"] { background: var(--primaer-zart); color: var(--primaer); font-weight: 600; }
    form { margin: 0; border-block-start: 1px solid var(--linie); padding-block-start: .15rem; }
  }
  @media (min-width: 56rem) {
    .menue-knopf { display: none; }
    .nav, .nav:popover-open {
      display: flex; flex-direction: row; align-items: center; gap: .25rem;
      position: static; inset: auto; inline-size: auto; padding: 0; border: 0; box-shadow: none; background: none; overflow: visible;
      a, .nav-abmelden { padding: .5rem .75rem; inline-size: auto; }
      form { border: 0; padding: 0; }
    }
  }
  .nav-gast { display: flex; align-items: center; gap: 1rem; a:not(.knopf) { font-weight: 500; } }

  .inhalt { flex: 1; inline-size: 100%; max-inline-size: 72rem; margin-inline: auto; padding: 1.25rem 1rem 3rem; }
  .fuss { text-align: center; padding: 1.5rem 1rem; color: var(--leise); font-size: .85rem; }

  /* Karten und Raster */
  .karte {
    background: var(--flaeche); border: 1px solid var(--linie); border-radius: 14px;
    padding: 1.25rem; margin: 0 0 1rem; box-shadow: var(--schatten); min-inline-size: 0;
  }
  fieldset.karte { padding-block-start: 1rem; }
  legend { font-weight: 700; font-size: 1.15rem; padding: 0; float: inline-start; inline-size: 100%; margin-block-end: .6rem; }
  legend + * { clear: both; }
  .karte.schmal { max-inline-size: 28rem; margin: 2rem auto; }
  .raster { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); margin-block-end: 1rem; .karte { margin: 0; } }
  .seitenkopf {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; margin-block-end: 1rem;
    h1, p { margin: 0; }
  }
  .zurueck { margin: 0 0 .5rem; font-size: .95rem; a::before { content: "‹ "; } }

  /* Knöpfe */
  .knopf {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-block-size: 2.75rem; padding: .6rem 1.1rem;
    font: inherit; font-weight: 600; line-height: 1.2; text-align: center; text-decoration: none;
    color: var(--primaer-text); background: var(--primaer); border: 1px solid var(--primaer);
    border-radius: var(--radius); cursor: pointer; transition: background .15s, border-color .15s;
    &:hover { background: var(--primaer-hover); border-color: var(--primaer-hover); color: var(--primaer-text); }
    &:disabled { opacity: .6; cursor: progress; }
    &.zweit { background: var(--flaeche); color: var(--text); border-color: var(--linie); &:hover { background: var(--flaeche-2); border-color: var(--leise); } }
    &.gefahr { background: var(--flaeche); color: var(--fehler); border-color: color-mix(in srgb, var(--fehler) 40%, var(--linie)); &:hover { background: var(--fehler-zart); } }
    &.klein { min-block-size: 2.35rem; padding: .4rem .8rem; font-size: .92rem; }
    &.voll { inline-size: 100%; }
  }
  .knopfreihe {
    display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(min(9.5rem, 100%), 1fr));
    form { margin: 0; }
  }
  @media (min-width: 40rem) { .knopfreihe { display: flex; flex-wrap: wrap; } }
  .symbol {
    display: inline-grid; place-items: center; inline-size: 2.25rem; block-size: 2.25rem;
    border: 1px solid var(--linie); border-radius: 8px; background: var(--flaeche); color: var(--leise); cursor: pointer;
    &:hover { color: var(--text); background: var(--flaeche-2); }
    &.gefahr:hover { color: var(--fehler); background: var(--fehler-zart); }
  }

  /* Formulare */
  .formular { display: grid; gap: .9rem; margin-block-end: .9rem; }
  @media (min-width: 40rem) { .formular > .knopf:not(.voll) { justify-self: start; } }
  label { display: grid; gap: .3rem; font-weight: 600; font-size: .95rem; }
  label small, .klein:not(.knopf) { font-weight: 400; font-size: .85rem; color: var(--leise); }
  input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea {
    inline-size: 100%; font: inherit; font-weight: 400; font-size: 1rem; color: var(--text);
    background: var(--flaeche); border: 1px solid var(--linie); border-radius: 8px;
    padding: .62rem .75rem; min-block-size: 2.75rem;
    &:hover { border-color: color-mix(in srgb, var(--leise) 60%, var(--linie)); }
    &:focus { border-color: var(--primaer); outline: 3px solid color-mix(in srgb, var(--primaer) 22%, transparent); outline-offset: 0; }
    &[aria-busy="true"] { background: var(--flaeche-2); color: var(--leise); }
  }
  input[type="file"] { font: inherit; font-weight: 400; font-size: .92rem; max-inline-size: 100%; }
  textarea { resize: vertical; line-height: 1.5; field-sizing: content; min-block-size: 5.5rem; max-block-size: 70vh; }
  textarea.brief { min-block-size: 20rem; }
  .kontrolle { display: flex; align-items: center; gap: .5rem; font-weight: 500; input { inline-size: 1.15rem; block-size: 1.15rem; } }
  /* Zweispaltig, sobald der Platz in der Karte reicht (Container Query auf die Karte). */
  .karte, .eintrag { container-type: inline-size; }
  .felder { display: grid; gap: .85rem; grid-template-columns: minmax(0, 1fr); }
  @container (min-width: 36rem) {
    .felder { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .felder > .breit { grid-column: 1 / -1; }
  }
  /* minmax(0, …) und min-inline-size: 0, sonst drücken Datums- und Monatsfelder das Raster über die Bildschirmbreite. */
  .felder-paar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; align-items: start; }
  label, input, select, textarea { min-inline-size: 0; }
  .editor .karte > textarea { margin-block-end: .5rem; }

  /* Lebenslauf-Editor */
  .person { display: grid; gap: 1.25rem; }
  @media (min-width: 60rem) { .person { grid-template-columns: 1fr 13rem; } }
  .foto-feld { display: grid; gap: .6rem; align-content: start; }
  .foto-vorschau, .foto-leer { inline-size: 9rem; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 8px; border: 1px solid var(--linie); }
  .foto-leer { display: grid; place-items: center; color: var(--leise); font-size: .9rem; background: var(--flaeche-2); }
  .liste { display: grid; gap: .8rem; margin-block-end: .8rem; &:empty { display: none; } }
  .eintrag { border: 1px solid var(--linie); border-radius: 12px; padding: 1rem; background: var(--flaeche-2); }
  .eintrag-kopf { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-block-end: .7rem; }
  .eintrag-knoepfe { display: flex; gap: .35rem; }
  .eintrag:first-child [data-hoch], .eintrag:last-child [data-runter] { visibility: hidden; }

  .ki-zeile { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .8rem; margin-block: .7rem .2rem; }
  .ki-status { font-size: .9rem; color: var(--leise); }
  .ki-status button { font: inherit; color: var(--primaer); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
  .ki-status.fehler { color: var(--fehler); }
  .laeuft::before {
    content: ""; display: inline-block; inline-size: .9em; block-size: .9em; margin-inline-end: .45em; vertical-align: -.1em;
    border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: drehen .8s linear infinite;
  }
  @keyframes drehen { to { rotate: 1turn; } }

  .ueberarbeiten { border-block-start: 1px solid var(--linie); padding-block-start: 1rem; margin-block-start: 1rem; display: grid; gap: .6rem; }
  .klein-reihe { grid-template-columns: repeat(auto-fit, minmax(min(7rem, 100%), 1fr)); }

  .leiste {
    position: sticky; inset-block-end: 0; z-index: 5;
    display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .6rem;
    padding: .75rem 1rem; margin-inline: -1rem; margin-block: 0 1rem;
    background: color-mix(in srgb, var(--hg) 90%, transparent); backdrop-filter: blur(8px);
    border-block-start: 1px solid var(--linie);
    > span { margin-inline-end: auto; }
  }
  @media (max-width: 39.99rem) {
    .leiste { display: grid; grid-template-columns: 1fr 1fr; > span { grid-column: 1 / -1; } > .knopf:last-child:nth-child(odd) { grid-column: 1 / -1; } }
  }

  /* Hinweise, Status, Listen */
  .hinweis { padding: .8rem 1rem; border-radius: var(--radius); margin-block-end: 1rem; border: 1px solid; }
  .hinweis-ok { background: var(--gut-zart); color: var(--gut); border-color: color-mix(in srgb, var(--gut) 30%, transparent); }
  .hinweis-fehler { background: var(--fehler-zart); color: var(--fehler); border-color: color-mix(in srgb, var(--fehler) 30%, transparent); }
  .hinweis-info { background: var(--primaer-zart); color: var(--text); border-color: color-mix(in srgb, var(--primaer) 25%, transparent); }
  .leise { color: var(--leise); }
  .mittig { text-align: center; }
  .gross { font-size: 1.1rem; }

  .status {
    display: inline-block; padding: .15rem .55rem; border-radius: 6px; font-size: .82rem; font-weight: 600; white-space: nowrap;
    background: var(--flaeche-2); color: var(--leise); border: 1px solid var(--linie);
    &.gross { font-size: .95rem; padding: .3rem .7rem; }
  }
  .status-versendet { background: var(--primaer-zart); color: var(--primaer); border-color: transparent; }
  .status-gespraech { background: var(--warn-zart); color: var(--warn); border-color: transparent; }
  .status-zusage { background: var(--gut-zart); color: var(--gut); border-color: transparent; }
  .status-absage { background: var(--fehler-zart); color: var(--fehler); border-color: transparent; }

  .zeilen {
    list-style: none; margin: 0 0 .8rem; padding: 0;
    li { border-block-end: 1px solid var(--linie); &:last-child { border: 0; } }
    li > a, li > span:first-child:not(:only-child), li:has(> span) {
      display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .3rem 1rem;
      padding: .8rem .25rem; color: var(--text); text-decoration: none;
    }
    li > a:hover { background: var(--flaeche-2); }
  }
  .zeile-haupt { display: grid; min-inline-size: 0; }
  .zeile-neben { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; form { margin: 0; } }
  .nutzerliste { margin-block: 1.25rem; }
  .zahlen {
    list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem;
    a { display: flex; align-items: center; gap: .7rem; padding: .45rem .5rem; border-radius: 8px; text-decoration: none; color: var(--text); &:hover { background: var(--flaeche-2); } }
    strong { min-inline-size: 2ch; text-align: end; font-size: 1.1rem; }
  }
  .fortschritt {
    display: flex; align-items: center; gap: .8rem; margin-block-end: .6rem; font-weight: 600;
    progress { flex: 1; block-size: .6rem; appearance: none; border: 0; border-radius: 99px; background: var(--flaeche-2); overflow: hidden; accent-color: var(--primaer); }
    progress::-webkit-progress-bar { background: var(--flaeche-2); }
    progress::-webkit-progress-value { background: var(--primaer); border-radius: 99px; }
    progress::-moz-progress-bar { background: var(--primaer); }
  }
  .filter { margin-block-end: 1rem; max-inline-size: 20rem; }
  .text { ul { padding-inline-start: 1.2rem; margin: 0 0 .8em; } li { margin-block-end: .25em; } }
  .analyse { margin-block-start: 1rem; padding: 1rem; border-radius: 12px; background: var(--primaer-zart); border: 1px solid color-mix(in srgb, var(--primaer) 20%, transparent); }
  .gefahrzone h2 { font-size: 1.05rem; }

  /* Dialog */
  .dialog {
    inline-size: min(30rem, calc(100vw - 2rem)); padding: 1.25rem; border: 1px solid var(--linie); border-radius: 14px;
    background: var(--flaeche); color: var(--text); box-shadow: 0 20px 50px rgb(0 0 0 / .25);
    &::backdrop { background: rgb(10 15 25 / .45); }
    h2 { margin: 0; }
  }
}

@layer seiten {
  .start {
    display: grid; gap: 2rem; align-items: center; padding-block: 1.5rem 2.5rem;
    h1 { font-size: clamp(1.9rem, 1.3rem + 2.6vw, 3rem); max-inline-size: 18ch; }
    .gross { max-inline-size: 38rem; color: var(--leise); margin-block-end: 1.5rem; }
    .knopfreihe { max-inline-size: 26rem; }
  }
  @media (min-width: 60rem) { .start { grid-template-columns: 1.1fr .9fr; } }
  .blatt {
    background: #fff; color: #1b1f27; border: 1px solid var(--linie); border-radius: 6px;
    padding: 1.6rem 1.5rem; font-size: .92rem; line-height: 1.6; box-shadow: 0 12px 32px rgb(0 0 0 / .1);
    rotate: -1deg;
  }
  .blatt-betreff { font-weight: 700; }
  .blatt-leise { color: #8a909b; }
  .start-beispiel { margin: 0; }
  .schritte {
    display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr));
    > div { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 14px; padding: 1.25rem; }
    h2 { font-size: 1.1rem; }
    p { color: var(--leise); margin: 0; }
  }
}
