/* ============================================================
   v690: Änderungsprotokoll als schlichte Liste – eine Zeile je Änderung
   (Wann | Wer | Element | Feld | Vorher | Nachher). Farben aus den App-Tokens (hell und dunkel).
   Alles unter #view-auditlog gekapselt.
   ============================================================ */
html body[data-app-view="auditlog"]:not(#_) .app-layout { width: 100%; max-width: none; margin: 0; padding: 0 24px; display: block; }
html body[data-app-view="auditlog"]:not(#_) .app-layout > main { width: 100%; max-width: none; margin: 0; padding: 0; }
html body[data-app-view="auditlog"]:not(#_) .elementarten-nav { display: none !important; }

#view-auditlog {
  --ap-flaeche: var(--bg-elevated, #ffffff);
  --ap-kopf: color-mix(in srgb, var(--text) 4%, var(--bg-elevated, #ffffff));
  --ap-linie: var(--border);
  --ap-linie-fein: color-mix(in srgb, var(--border) 65%, transparent);
  --ap-text: var(--text);
  --ap-leise: var(--text-muted, #68717d);
  --ap-auto: #8a63d2;
  --ap-rand: 16px;
  --ap-spalten: 136px minmax(140px, .9fr) minmax(180px, 1.3fr) minmax(200px, 1.6fr) minmax(110px, .9fr) minmax(110px, .9fr);
  width: 100%;
  max-width: none;
}

/* Kopf und Filter nutzen die volle Breite. */
#view-auditlog .audit-filter-panel,
#view-auditlog .audit-panel { max-width: none; }
#view-auditlog .audit-panel { border: 0; background: transparent; padding: 0; }

/* Aktionsleiste: gleiches 4er-Raster wie die Filter, alle Knöpfe gleich hoch. */
#view-auditlog .audit-filter-aktionen {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
  margin-top: 16px;
}
#view-auditlog .audit-filter-aktionen > * { min-width: 0; }
/* Alle Filterfelder beginnen auf derselben Höhe (Suche stand bisher höher als Benutzer/Projekt). */
#view-auditlog .audit-filter-grid { align-items: start; }
#view-auditlog .audit-filter-grid > label { align-self: start; justify-content: flex-start; margin: 0; }
#view-auditlog .audit-bereinigen-btn {
  background: color-mix(in srgb, var(--bad) 7%, var(--bg-elevated, #ffffff));
  color: color-mix(in srgb, var(--bad) 78%, var(--text));
}
#view-auditlog .audit-filter-aktionen button { width: 100%; height: 46px; min-height: 46px; margin: 0; padding: 0 16px; }
#view-auditlog #btnAuditZuruecksetzen { grid-column: 1; }
#view-auditlog .ap-export { grid-column: 2; }
#view-auditlog #btnAuditBereinigen { grid-column: 3; }
#view-auditlog #btnAuditAktualisieren { grid-column: 4; }

.ap-export { position: relative; }
.ap-export-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.ap-export-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; flex: none; transition: transform .15s ease; }
.ap-export-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.ap-export-menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  width: max(100%, 340px);
  padding: 6px;
  border: 1px solid var(--ap-linie);
  border-radius: 12px;
  background: var(--ap-flaeche);
  box-shadow: 0 12px 32px rgba(16, 24, 40, .16);
  display: grid;
  gap: 2px;
}
.ap-export-menu[hidden] { display: none; }
#view-auditlog .ap-export-menu button {
  height: auto;
  min-height: 0;
  display: grid;
  gap: 2px;
  justify-items: start;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ap-text);
  font: inherit;
  cursor: pointer;
}
#view-auditlog .ap-export-menu button:hover,
#view-auditlog .ap-export-menu button:focus-visible { background: color-mix(in srgb, var(--accent) 9%, var(--ap-flaeche)); outline: none; }
.ap-export-menu strong { font-size: 14px; }
.ap-export-menu span { font-size: 12.5px; color: var(--ap-leise); }

/* ---------------------------------------------------------- Liste */
.ap-tabelle {
  border: 1px solid var(--ap-linie);
  border-radius: 12px;
  background: var(--ap-flaeche);
  overflow: clip; /* nicht „hidden“: sonst bleibt die Kopfzeile nicht stehen */
}
.ap-zeile {
  display: grid;
  grid-template-columns: var(--ap-spalten);
  gap: 0 16px;
  align-items: center;
  height: 38px;
  padding: 0 var(--ap-rand);
  border-bottom: 1px solid var(--ap-linie-fein);
  font-size: 14px;
  color: var(--ap-text);
}
.ap-zeile:last-child { border-bottom: 0; }
.ap-zeile:not(.ap-kopf):hover { background: color-mix(in srgb, var(--accent) 5%, var(--ap-flaeche)); }
.ap-zeile > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ap-kopf {
  position: sticky;
  top: var(--ap-kopf-oben, 0px);
  z-index: 2;
  height: 34px;
  background: var(--ap-kopf);
  border-bottom: 1px solid var(--ap-linie);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ap-leise);
}
.ap-wann { color: var(--ap-leise); font-variant-numeric: tabular-nums; }
.ap-wer { font-weight: 600; }
.ap-automatik { color: var(--ap-auto); font-weight: 500; }
.ap-typ { color: var(--ap-leise); font-size: 12.5px; }
.ap-vorher { color: var(--ap-leise); }
.ap-nachher { font-weight: 600; }
.ap-leise { color: var(--ap-leise); font-weight: 400; }
.ap-kursiv { font-style: italic; }

/* ---------------------------------------------------------- schmale Fenster */
@media (max-width: 1100px) {
  #view-auditlog { --ap-spalten: 128px minmax(110px, .8fr) minmax(150px, 1.2fr) minmax(160px, 1.4fr) minmax(80px, .7fr) minmax(80px, .7fr); }
}

@media (max-width: 860px) {
  html body[data-app-view="auditlog"]:not(#_) .app-layout { padding: 0 12px; }
  #view-auditlog { --ap-rand: 14px; }
  #view-auditlog .audit-filter-aktionen { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #view-auditlog .audit-filter-aktionen button { font-size: 14px; padding: 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* Filter und Knöpfe bleiben auch am Handy im selben 2er-Raster. */
  #view-auditlog .audit-filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #view-auditlog .audit-filter-span-2 { grid-column: 1 / -1; }
  #view-auditlog #btnAuditZuruecksetzen,
  #view-auditlog #btnAuditBereinigen { grid-column: 1; }
  #view-auditlog .ap-export,
  #view-auditlog #btnAuditAktualisieren { grid-column: 2; }
  .ap-export-menu { left: auto; right: 0; width: min(340px, calc(100vw - 32px)); }

  /* Je Änderung drei kurze Zeilen: Wann · Wer / Element – Feld / Vorher → Nachher. */
  .ap-kopf { display: none; }
  .ap-zeile {
    height: auto;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "wann wer" "element element" "feld feld" "vorher nachher";
    gap: 2px 12px;
    padding: 10px var(--ap-rand);
  }
  .ap-wann { grid-area: wann; font-size: 12.5px; }
  .ap-wer { grid-area: wer; font-size: 12.5px; text-align: right; }
  .ap-element { grid-area: element; }
  .ap-feld { grid-area: feld; font-weight: 600; }
  .ap-vorher { grid-area: vorher; }
  .ap-vorher::before { content: var(--t-vorher, "vorher: "); font-size: 12px; }
  .ap-nachher { grid-area: nachher; }
  .ap-nachher::before { content: var(--t-nachher, "nachher: "); font-size: 12px; color: var(--ap-leise); font-weight: 400; }
}
