/* ============================================================
   Admin-only styles for the dev/staging event-log review UI.
   Loaded in addition to /style.css from admin.html. Everything
   in this file is admin-page-specific; main-app styles live in
   /style.css so the admin can be removed by simply dropping
   the <link rel="stylesheet" href="/admin.css"> reference.
   ============================================================ */


/* Sessions list ---------------------------------------------- */

.admin-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin: 16px 0 24px;
}

.admin-filters label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.admin-filters input[type="text"],
.admin-filters input[type="datetime-local"] {
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.admin-sessions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-sessions-table th,
.admin-sessions-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.admin-sessions-table th {
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-muted);
  position: sticky;
  top: 0;
}

.admin-sessions-table tbody tr {
  cursor: pointer;
}

.admin-sessions-table tbody tr:hover {
  background: var(--surface-muted);
}

.admin-sessions-table .col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.admin-pagination button {
  font: inherit;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.admin-pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}


/* Error chip ------------------------------------------------- */

.error-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(220, 38, 38, 0.12);
  color: #b91c1c;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

[data-theme="dark"] .error-chip {
  background: rgba(248, 113, 113, 0.18);
  color: #fca5a5;
}

.muted {
  color: var(--text-muted);
}


/* Session detail timeline ------------------------------------ */

.event-timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
}

.event-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.event-card.event-error {
  border-color: rgba(220, 38, 38, 0.45);
  background: rgba(220, 38, 38, 0.04);
}

[data-theme="dark"] .event-card.event-error {
  background: rgba(248, 113, 113, 0.06);
}

.event-summary {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.event-summary:hover {
  background: var(--surface-muted);
}

/* Existing one-line header row inside the summary card. */
.event-summary-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

/* Multi-line preview block shown below the header. Each line is a
   label : value pair so the eye picks out the field name and content
   independently. Hidden when no preview lines apply (e.g. the auth
   events). */
.event-summary-preview {
  margin-top: 6px;
  padding: 4px 0 2px 10px;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
  /* Allow text selection in the preview so reviewers can copy values
     out without expanding the row. The header row above keeps
     user-select: none via the parent. */
  user-select: text;
}
.event-summary-preview:empty {
  display: none;
}

.event-preview-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 12px;
  color: var(--text);
}

.event-preview-label {
  color: var(--text-subtle);
  flex-shrink: 0;
  min-width: 84px;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

.event-preview-value {
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  flex: 1;
}

.event-preview-metric {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.event-preview-success {
  color: #15803d;
  font-weight: 500;
}

.event-preview-warning {
  color: #c2410c;
  font-weight: 500;
}

[data-theme="dark"] .event-preview-success { color: #4ade80; }
[data-theme="dark"] .event-preview-warning { color: #fb923c; }

.event-kind {
  font-weight: 600;
  font-variant: small-caps;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  min-width: 80px;
  color: var(--text-muted);
}

.event-kind.kind-error {
  color: #b91c1c;
}

[data-theme="dark"] .event-kind.kind-error {
  color: #fca5a5;
}

.event-endpoint {
  font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace);
}

.event-status {
  font-variant-numeric: tabular-nums;
}

.event-status.status-2xx { color: #15803d; }
.event-status.status-4xx { color: #c2410c; }
.event-status.status-5xx { color: #b91c1c; }

[data-theme="dark"] .event-status.status-2xx { color: #4ade80; }
[data-theme="dark"] .event-status.status-4xx { color: #fb923c; }
[data-theme="dark"] .event-status.status-5xx { color: #fca5a5; }

.event-meta {
  color: var(--text-muted);
  font-size: 12px;
}

.event-body {
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Inner pre blocks (in the pertinent fields' text panels, in the
   key-value section, in the full-payload dump). Shared whitespace +
   font + word-break rules so they all render the same. */
.event-body pre {
  margin: 0;
  font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* "Pertinent fields" — the middle expansion state. Formatted summary
   of the most useful per-kind content (user_message, summary,
   parameters, tool input, etc.) without the infrastructure noise. */
.event-pertinent {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.event-pertinent-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.event-pertinent-heading {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Plain-text panels (user_message, system prompt, summary, ...).
   The pre wrapper preserves newlines from the data (see the
   ``unescapeJsonEscapes`` step in session-detail.js). */
.event-pertinent-text {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 480px;
  overflow-y: auto;
}

/* Key-value mini-table for /score and /monte-carlo style responses. */
.event-pertinent-kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 18px;
  margin: 0;
  padding: 10px 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.event-pertinent-kv dt {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}
.event-pertinent-kv dd {
  margin: 0;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* Structured-data panels (parameters, scenarios, peers, tool input).
   Reuses the JSON colour palette by inheriting from .event-body so
   the same hljs-* CSS selectors apply. */
.event-pertinent-json {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 480px;
  overflow: auto;
}

/* Web-search result list / clarification queries. */
.event-pertinent-list {
  margin: 0;
  padding: 4px 4px 4px 26px;
  font-size: 12px;
  line-height: 1.6;
}
.event-pertinent-list a {
  color: var(--text);
  text-decoration: underline;
}
.event-pertinent-list a:hover {
  color: var(--accent, var(--text));
}

/* "Show full request/response" toggle row. Lives between the
   pertinent section and the raw JSON dump; clicking flips the dump
   on/off without affecting the parent card's collapse state. */
.event-full-toggle-wrap {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}
.event-full-toggle {
  font-size: 12px;
  padding: 4px 10px;
}

/* The raw JSON dump itself. Same look as the pre panels above. */
.event-full {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}


/* JSON-payload token colours --------------------------------- */
/*
   The payload renderer in session-detail.js emits HTML with these
   class names (`hljs-attr` for keys, `hljs-string` for string values,
   etc.) so the existing CSS keeps working without a class rename.
   The names are borrowed from highlight.js's JSON grammar — we used
   that library briefly but dropped it because its token output is
   single-line per value, which doesn't render newlines inside string
   values literally. The custom renderer preserves those newlines, so
   a logged user_message with `\n` separators shows multi-line in the
   admin UI.

   The two-palette light/dark approach below uses CSS variables and a
   `[data-theme="dark"]` selector — no external stylesheet juggling,
   so theme switching is instant.
*/

/* Light palette (default). */
.event-body .hljs-attr     { color: #b45309; }   /* JSON keys: amber */
.event-body .hljs-string   { color: #15803d; }   /* String values: green */
.event-body .hljs-number   { color: #1d4ed8; }   /* Numbers: blue */
.event-body .hljs-literal  { color: #7c3aed; }   /* true / false / null: purple */
.event-body .hljs-punctuation { color: var(--text-subtle); }

/* Dark palette: brighter / cooler so contrast holds on the dark
   surface. Same class names; selector specificity scoped via the
   data-theme attribute on <html>. */
[data-theme="dark"] .event-body .hljs-attr     { color: #fbbf24; }
[data-theme="dark"] .event-body .hljs-string   { color: #86efac; }
[data-theme="dark"] .event-body .hljs-number   { color: #93c5fd; }
[data-theme="dark"] .event-body .hljs-literal  { color: #c4b5fd; }
[data-theme="dark"] .event-body .hljs-punctuation { color: var(--text-subtle); }


/* Session-detail header ------------------------------------- */

.admin-session-header {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 24px;
  font-size: 13px;
  margin-top: 16px;
}

.admin-session-header dt {
  color: var(--text-muted);
}

.admin-session-header dd {
  margin: 0;
  font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace);
}

.admin-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
}

.admin-error {
  margin: 24px 0;
  padding: 14px 18px;
  border: 1px solid rgba(220, 38, 38, 0.45);
  border-radius: 8px;
  background: rgba(220, 38, 38, 0.04);
  color: #b91c1c;
}

[data-theme="dark"] .admin-error {
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.06);
}
