/* ===========================================
   Audit Log (projects/audit_log.html), theme v6: page head with the two
   switches, a filter row (native selects inside .filter chips, the range
   picker) and one card holding the feed. A row: chevron, time, avatar,
   actor + what + key details, category tag, result; it opens to the full
   detail. Day separators are the global .chat-date-sep (localtime.js).
   Reuses primitives.css (.page-head, .filter, .micro, .avatar, .list-foot,
   .link) and badges.css (.badge.mono.purple for "via …").
   =========================================== */

/* ---------- head + filters ---------- */
.audit-form { display: flex; flex-direction: column; gap: 14px; margin-bottom: var(--gap); }
.audit-switches { gap: 18px; }
.audit-switch { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; color: var(--label-2); }
.audit-switch > label:first-child { margin: 0; color: inherit; cursor: pointer; }
.audit-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.audit-when { margin-left: 4px; font-size: 12px; color: var(--label-3); }

/* A native select inside a .filter chip: the chip draws it, the select is bare text */
.audit-filter { position: relative; margin: 0; cursor: pointer; }
.audit-filter:hover { background: var(--fill-2); }
.audit-filter:focus-within { border-color: var(--accent); }
.audit-filter select {
    all: unset;
    field-sizing: content;
    max-width: 16ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--label-1);
    font: 500 12px var(--font);
    cursor: pointer;
}
.audit-filter select option { background: var(--surface-2); color: var(--label-1); }

/* ---------- card + feed ---------- */
.audit-card { gap: 0; padding: 15px 16px 14px; }
.audit-card-head { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; }
.audit-count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 16px; padding: 0 5px;
    border-radius: var(--r-xs); background: var(--fill-1);
    color: var(--label-2); font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.audit-hint { margin-left: auto; font-size: 12.5px; }
.audit-feed .chat-date-sep + .audit-item > .audit-row { border-top-color: transparent; }

.audit-row {
    display: grid;
    grid-template-columns: 16px 72px 24px minmax(0, 1fr) auto 64px;
    gap: 12px;
    align-items: center;
    padding: 10px 6px;
    border-top: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    cursor: pointer;
}
.audit-feed.is-dated .audit-row { grid-template-columns: 16px 112px 24px minmax(0, 1fr) auto 64px; }
.audit-item:first-child > .audit-row { border-top-color: transparent; }
.audit-row.no-detail { cursor: default; }
.audit-row:hover { background: var(--hover-tint); }
.audit-row.is-open { background: var(--fill-1); }
.audit-toggle {
    display: grid; place-items: center;
    width: 16px; height: 16px; margin: 0; padding: 0;
    border: 0; background: none; color: var(--label-3); cursor: pointer;
}
.audit-toggle svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; transform: rotate(-90deg); transition: transform var(--dur-fast); }
.audit-row.is-open .audit-toggle { color: var(--label-1); }
.audit-row.is-open .audit-toggle svg { transform: none; }
.audit-time { font-size: 13px; color: var(--label-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.audit-row > img.avatar { object-fit: cover; }

.audit-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.audit-line { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 13.5px; }
.audit-who { font-weight: 500; color: var(--label-1); }
a.audit-who:hover { color: var(--accent-text); }
.audit-who.is-ai { color: var(--ai); }
.audit-what { color: var(--label-1); }
.audit-line .badge { text-transform: none; }
.audit-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.audit-kv {
    display: inline-flex; align-items: center; gap: 4px;
    max-width: 100%; height: 19px; padding: 0 6px;
    border-radius: var(--r-xs); background: var(--fill-1);
    color: var(--label-3); font-size: 12px; white-space: nowrap; overflow: hidden;
}
.audit-kv b { color: var(--label-1); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.audit-kv a { color: var(--accent-text); }
.audit-kv-more { background: none; padding: 0 2px; }

.audit-cat {
    display: inline-flex; align-items: center; height: 20px; padding: 0 7px;
    border: 1px solid var(--hairline); border-radius: var(--r-sm);
    color: var(--label-2); font-size: 11.5px; white-space: nowrap;
}
.audit-res { text-align: right; font-size: 12px; white-space: nowrap; }
.audit-err { color: var(--red); font-weight: 500; }
.audit-warn { color: var(--amber); font-weight: 500; }

/* ---------- the opened detail ---------- */
.audit-expand {
    display: grid;
    gap: 12px;
    margin: 2px 6px 12px 34px;
    padding: 12px 14px;
    border: 1px solid var(--hairline);
    border-radius: var(--r-md);
    background: var(--bg);
    min-width: 0;
}
.audit-expand[hidden] { display: none; }
.audit-expand .micro { display: block; margin-bottom: 6px; }
.audit-dl { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 6px 12px; margin: 0; font-size: 13px; }
.audit-dl:empty { display: none; }
.audit-dl dt { color: var(--label-3); font-weight: 400; }
.audit-dl dd { margin: 0; color: var(--label-1); overflow-wrap: anywhere; }
.audit-dl dd a { color: var(--accent-text); }
.audit-expand pre {
    margin: 0;
    padding: 10px 12px;
    max-height: 22rem;
    overflow: auto;
    border: 1px solid var(--hairline);
    border-radius: var(--r-sm);
    background: var(--surface-1);
    color: var(--label-2);
    font: 400 12.5px/1.6 var(--font-mono);
}
.audit-diff { white-space: pre; }
.audit-expand .diff-add { color: var(--green); }
.audit-expand .diff-del { color: var(--red); }
.audit-expand .diff-hunk { color: var(--label-3); }
.audit-result.is-failed { border-color: transparent; background: var(--red-tint); color: var(--red); }

/* Rule changes: rule · field · before → after */
.audit-changes {
    display: grid;
    grid-template-columns: minmax(120px, max-content) minmax(70px, max-content) minmax(60px, max-content) 18px minmax(0, 1fr);
    gap: 6px 14px;
    align-items: baseline;
    font: 400 12.5px var(--font-mono);
}
.audit-changes .micro { margin: 0; }
.audit-changes .rule-name { color: var(--label-1); font: 500 13px var(--font); }
.audit-changes .field-name { color: var(--label-3); }
.audit-changes .diff-del { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--red) 50%, transparent); }

.audit-msg { max-width: 44rem; }

.audit-foot {
    display: flex; align-items: center; flex-wrap: wrap; gap: 12px;
    padding-top: 10px; border-top: 1px solid var(--hairline);
    font-size: 12.5px; color: var(--label-3);
}
/* An AI app's change: Undo at the end of the footer. */
.audit-undo { margin: 0 0 0 auto; }

/* ---------- footer, empty ---------- */
.audit-card .list-foot { margin-top: 4px; }
.audit-pagination { display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: var(--label-2); }
.audit-pagination .page-link { color: var(--accent-text); font-weight: 500; }
.audit-empty { margin: 0; padding: 28px 0 18px; border-top: 1px solid var(--hairline); text-align: center; color: var(--label-3); font-size: 13px; }

/* ---------- phones ---------- */
@media (max-width: 768px) {
    .audit-switches { margin-left: 0; }
    .audit-row,
    .audit-feed.is-dated .audit-row { grid-template-columns: 16px minmax(0, 1fr) auto; gap: 4px 10px; }
    .audit-row > .avatar { display: none; }
    .audit-time { grid-column: 2; grid-row: 1; font-size: 12px; }
    .audit-main { grid-column: 2 / -1; grid-row: 2; }
    .audit-cat { grid-column: 3; grid-row: 1; justify-self: end; }
    .audit-res { grid-column: 3; grid-row: 1; }
    .audit-res:empty { display: none; }
    .audit-row:has(.audit-res:not(:empty)) .audit-cat { display: none; }
    .audit-toggle { grid-row: 1; }
    .audit-expand { margin-left: 6px; }
    .audit-dl { grid-template-columns: 1fr; gap: 2px; }
    .audit-dl dd { margin-bottom: 6px; }
}
