.audit {
  max-width: 1200px;
  margin: 0 auto;
}

.audit-header {
  margin-bottom: 1.5rem;
}

.title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.intro {
  margin: 0;
  font-size: 0.875rem;
  color: #6b7280;

  code {
    padding: 0.0625rem 0.25rem;
    border-radius: 0.25rem;
    background-color: rgba(0, 0, 0, 0.05);
    font-family: ui-monospace, monospace;
    font-size: 0.875em;
  }

  a {
    color: var(--color-brand-primary-600, #2563eb);
    text-decoration: underline;
  }
}

:host-context(.dark) .intro {
  color: #9ca3af;

  code {
    background-color: rgba(255, 255, 255, 0.08);
  }
  a {
    color: var(--color-brand-primary-300, #93c5fd);
  }
}

.filters {
  padding: 1rem;
  margin-bottom: 1rem;
  background-color: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
}

:host-context(.dark) .filters {
  background-color: #111827;
  border-color: #1f2937;
}

.filters-heading {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: #6b7280;
}

:host-context(.dark) .filter-label {
  color: #9ca3af;
}

.filter input,
.filter select {
  height: 2rem;
  padding: 0 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  background-color: #ffffff;
  color: inherit;
  font-size: 0.875rem;

  &:focus-visible {
    outline: 2px solid var(--color-brand-primary-500, #2563eb);
    outline-offset: 1px;
    border-color: transparent;
  }
}

:host-context(.dark) .filter input,
:host-context(.dark) .filter select {
  background-color: #0f172a;
  border-color: #374151;
  color: #e5e7eb;
}

.filters-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.875rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  height: 2.25rem;
  padding: 0 0.875rem;
  border: 1px solid transparent;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  &:focus-visible {
    outline: 2px solid var(--color-brand-primary-500, #2563eb);
    outline-offset: 2px;
  }
}

.btn--primary {
  background-color: var(--color-brand-primary-600, #2563eb);
  color: #ffffff;

  &:hover:not(:disabled) {
    background-color: var(--color-brand-primary-700, #1d4ed8);
  }
}

.btn--secondary {
  background-color: transparent;
  border-color: #d1d5db;
  color: inherit;

  &:hover:not(:disabled) {
    background-color: rgba(0, 0, 0, 0.04);
  }
}

:host-context(.dark) .btn--secondary:hover:not(:disabled) {
  background-color: rgba(255, 255, 255, 0.06);
}

.status-bar {
  margin-bottom: 0.5rem;
  min-height: 1.25rem;
  font-size: 0.875rem;
  color: #6b7280;
}

.status-line--error {
  color: #b91c1c;
  font-weight: 500;
}

:host-context(.dark) .status-bar {
  color: #9ca3af;
}

:host-context(.dark) .status-line--error {
  color: #fca5a5;
}

.empty {
  padding: 1.5rem;
  text-align: center;
  color: #6b7280;
  background-color: #ffffff;
  border: 1px dashed #d1d5db;
  border-radius: 0.5rem;
}

:host-context(.dark) .empty {
  background-color: #111827;
  border-color: #374151;
  color: #9ca3af;
}

// Tabs above the content. WAI-ARIA pattern: `role="tablist"` on the
// container, `role="tab"` on each button, roving `tabindex` (the
// active tab is reachable via Tab, inactive ones via arrow keys
// once focus is in the list). The visual treatment is a thin
// underline on the active tab — minimal furniture, lets the panel
// content carry the eye.
.tablist {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 1rem;
}

:host-context(.dark) .tablist {
  border-bottom-color: #1f2937;
}

.tab {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0.5rem 0.75rem;
  margin-bottom: -1px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  transition:
    color 0.12s ease-out,
    border-color 0.12s ease-out;

  &:hover {
    color: var(--color-brand-primary-600, #1d4ed8);
  }

  &:focus-visible {
    outline: 2px solid var(--color-brand-primary-500, #2563eb);
    outline-offset: 2px;
    border-radius: 0.125rem;
  }
}

:host-context(.dark) .tab {
  color: #9ca3af;

  &:hover {
    color: var(--color-brand-primary-300, #93c5fd);
  }
}

.tab--active {
  color: var(--color-brand-primary-600, #1d4ed8);
  border-bottom-color: var(--color-brand-primary-600, #1d4ed8);
  font-weight: 600;
}

:host-context(.dark) .tab--active {
  color: var(--color-brand-primary-300, #93c5fd);
  border-bottom-color: var(--color-brand-primary-300, #93c5fd);
}

.tab-panel {
  // No box-styling — the panel inherits the page's surface.
  // `[hidden]` is set imperatively when the tab isn't active.
}

// Charts panel container. Same surface tokens as `.filters` so the
// chart stack reads as one related block.
.charts {
  margin: 0 0 1rem;
  padding: 1rem;
  background-color: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
}

:host-context(.dark) .charts {
  background-color: #111827;
  border-color: #1f2937;
}

.charts-heading {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: #1f2937;

  :where(.dark) & {
    color: #f3f4f6;
  }
}

.charts-note {
  margin: 0.25rem 0 1rem;
  font-size: 0.75rem;
  color: #6b7280;

  :where(.dark) & {
    color: #9ca3af;
  }
}

.charts-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));

  @media (max-width: 800px) {
    grid-template-columns: 1fr;
  }
}

// Grid items default to `min-width: auto`, which prevents the column
// from shrinking below the intrinsic width of its content. Without
// the override, Plot's fixed-width SVG could push the column wider
// than 1fr, busting the layout and forcing a horizontal scrollbar.
.chart-tile {
  min-width: 0;
}

// The stacked-bar chart carries a legend and benefits from the
// full width; flag it via a modifier and span both columns.
.chart-tile--wide {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow-x: auto;
  background-color: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
}

:host-context(.dark) .table-wrap {
  background-color: #111827;
  border-color: #1f2937;
}

.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;

  th,
  td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: top;
  }

  th {
    font-weight: 600;
    background-color: #f9fafb;
    position: sticky;
    top: 0;
  }
}

:host-context(.dark) .audit-table {
  th,
  td {
    border-bottom-color: #1f2937;
  }

  th {
    background-color: #1f2937;
  }
}

.cell-timestamp {
  white-space: nowrap;
}

.cell-event,
.cell-trace,
.actor-hash,
.subject {
  font-family: ui-monospace, monospace;
}

.cell-trace,
.actor-hash,
.subject {
  word-break: break-all;
  font-size: 0.75rem;
}

.actor-hash {
  color: #1f2937;
}

.subject {
  color: #6b7280;
  margin-top: 0.125rem;
}

:host-context(.dark) .actor-hash {
  color: #e5e7eb;
}

:host-context(.dark) .subject {
  color: #9ca3af;
}

// The clickable variant of `.actor-hash` (rendered as a <button> so
// keyboard activation works) reuses the inline-hash typography but
// strips the native button chrome and surfaces a subtle hover
// affordance. Filter pivot per the same row's actor.
.actor-hash--clickable {
  display: inline;
  padding: 0;
  margin: 0;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
  text-decoration: underline dotted transparent;
  text-underline-offset: 2px;
  transition:
    color 0.12s ease-out,
    text-decoration-color 0.12s ease-out;

  &:hover {
    color: var(--color-brand-primary-600, #1d4ed8);
    text-decoration-color: currentColor;
  }

  &:focus-visible {
    outline: 2px solid var(--color-brand-primary-500, #2563eb);
    outline-offset: 2px;
    border-radius: 0.125rem;
  }
}

:host-context(.dark) .actor-hash--clickable {
  &:hover {
    color: var(--color-brand-primary-300, #93c5fd);
  }
}

// Trace-id deep-link into Jaeger. Same hash typography as the actor
// cell (already inherited via `.cell-trace`), plus a brand-coloured
// underline so investigators read it as "follow this".
.trace-link {
  color: var(--color-brand-primary-600, #1d4ed8);
  text-decoration: underline;
  text-underline-offset: 2px;

  &:hover {
    text-decoration-thickness: 2px;
  }

  &:focus-visible {
    outline: 2px solid var(--color-brand-primary-500, #2563eb);
    outline-offset: 2px;
    border-radius: 0.125rem;
  }
}

:host-context(.dark) .trace-link {
  color: var(--color-brand-primary-300, #93c5fd);
}

.aud-badge,
.outcome-badge {
  display: inline-block;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-right: 0.25rem;
}

.aud-badge {
  background-color: rgba(0, 0, 0, 0.06);
  color: #1f2937;
}

.outcome-badge--success {
  background-color: rgba(34, 197, 94, 0.18);
  color: #166534;
}

.outcome-badge--failure {
  background-color: rgba(239, 68, 68, 0.18);
  color: #991b1b;
}

.outcome-badge--denied {
  background-color: rgba(234, 179, 8, 0.22);
  color: #854d0e;
}

:host-context(.dark) {
  .aud-badge {
    background-color: rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
  }
  .outcome-badge--success {
    background-color: rgba(34, 197, 94, 0.22);
    color: #86efac;
  }
  .outcome-badge--failure {
    background-color: rgba(239, 68, 68, 0.22);
    color: #fecaca;
  }
  .outcome-badge--denied {
    background-color: rgba(234, 179, 8, 0.22);
    color: #fde68a;
  }
}

.cell-payload {
  details {
    cursor: pointer;
  }

  summary {
    color: var(--color-brand-primary-600, #2563eb);
    font-size: 0.75rem;
  }

  pre {
    margin: 0.25rem 0 0;
    padding: 0.5rem;
    background-color: rgba(0, 0, 0, 0.04);
    border-radius: 0.25rem;
    font-size: 0.6875rem;
    font-family: ui-monospace, monospace;
    word-break: break-all;
  }
}

:host-context(.dark) .cell-payload {
  summary {
    color: var(--color-brand-primary-300, #93c5fd);
  }

  pre {
    background-color: rgba(255, 255, 255, 0.05);
  }
}

.dim {
  color: #9ca3af;
}

.pagination {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.75rem;
}
