/* Dashboard UI (neo-brutal) - built on `ui/static/css/common.css` */

:root {
  --admin-max-content-width: 1680px;
  --admin-border-strong: rgba(255, 255, 255, 0.22);
}

/* Keep viewport width stable when vertical scrollbar appears/disappears */
html {
  scrollbar-gutter: stable both-edges;
}

body.admin-body {
  overflow-y: scroll;
  overflow-x: hidden;
}

[data-theme="light"] {
  --admin-border-strong: rgba(0, 0, 0, 0.22);
}

/* Active nav */
.admin-nav a.active {
  background: var(--ui-surface-hover);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow-sm);
  border-radius: 0;
}

.admin-user {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ui-text-muted);
}

/* Page layout */
.admin-nav .container,
.admin-main.container {
  max-width: none;
  width: 100%;
  padding-left: 1rem;
  padding-right: 1rem;
}

.admin-main {
  width: 100%;
  max-width: none;
  min-width: 0;
  margin-left: auto;
  margin-right: auto;
  padding-top: 1.5rem;
  gap: 1.5rem;
}

.admin-main > * {
  min-width: 0;
}

.page-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1.1rem;
  padding: 0.5rem 0 0.25rem;
}

.page-title {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.page-title h1 {
  font-size: 1.25rem;
  margin: 0;
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 0.85rem;
  color: var(--ui-text-muted);
}

.page-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.field-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.cost-cache-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-sm);
}

.filter-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-cluster {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}

.filter-cluster .ui-select,
.filter-cluster .ui-input {
  min-width: 0;
}

.filter-input-date {
  width: 150px;
}

.filter-date-separator {
  color: var(--ui-text-muted);
  font-size: 0.92rem;
  font-weight: 700;
  padding: 0 0.05rem;
}

.filter-submit {
  margin-left: auto;
}

.filter-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-note {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ui-text-muted);
}

.cell-truncate {
  display: inline-block;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.failure-hotspot-table {
  min-width: 1120px;
  table-layout: auto;
}

.failure-hotspot-table th,
.failure-hotspot-table td {
  overflow-wrap: normal;
  word-break: normal;
}

.failure-hotspot-error {
  max-width: 12rem;
}

.failure-detail-table {
  min-width: 1520px;
  table-layout: fixed;
}

.failure-detail-table th,
.failure-detail-table td {
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.failure-col-time {
  width: 11rem;
}

.failure-col-stage {
  width: 10rem;
}

.failure-col-provider-model {
  width: 11rem;
}

.failure-col-persona-mode {
  width: 13rem;
}

.failure-col-source {
  width: 11rem;
}

.failure-col-error {
  width: 16rem;
}

.failure-col-handling-status {
  width: 10rem;
}

.failure-col-handling-detail {
  width: 15rem;
}

.failure-col-ids {
  width: 19rem;
}

.failure-detail-error-kind {
  display: block;
  max-width: 100%;
}

.failure-detail-error-message {
  display: block;
  max-width: 100%;
}

.failure-detail-handling {
  display: block;
  max-width: 100%;
}

.failure-detail-row.is-hidden {
  display: none;
}

.failure-detail-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.failure-detail-pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.failure-detail-source {
  min-width: 0;
}

.failure-detail-source code {
  display: block;
  max-width: 100%;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  margin-bottom: 0.25rem;
}

.failure-detail-provider-model,
.failure-detail-persona-mode,
.failure-detail-handling-status-cell,
.failure-detail-handling-detail-cell,
.failure-detail-error-cell {
  min-width: 0;
}

.failure-detail-provider-model {
  min-width: 0;
}

.failure-detail-persona-mode {
  min-width: 0;
}

.failure-detail-request-source {
  min-width: 0;
  max-width: 100%;
}

.failure-detail-error-cell {
  min-width: 0;
  max-width: 100%;
}

.failure-detail-handling-status-cell,
.failure-detail-handling-detail-cell {
  min-width: 0;
  max-width: 100%;
}

.failure-detail-error-cell > div,
.failure-detail-handling-status-cell > div,
.failure-detail-handling-detail-cell > div {
  margin-bottom: 0.2rem;
}

.failure-detail-error-cell > div:last-child,
.failure-detail-handling-status-cell > div:last-child,
.failure-detail-handling-detail-cell > div:last-child {
  margin-bottom: 0;
}

.failure-hotspot-code {
  white-space: nowrap;
  min-width: 5.5rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ui-input,
.ui-select {
  appearance: none;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-sm);
  color: var(--ui-text);
  font-family: var(--ui-font-family);
  font-size: var(--ui-font-size-sm);
  padding: 0.55rem 0.7rem;
  transition: border-color var(--ui-transition-fast), box-shadow var(--ui-transition-fast);
}

.ui-input:focus,
.ui-select:focus {
  outline: none;
  border-color: var(--ui-border-active);
  box-shadow: var(--ui-shadow-md);
}

.ui-chip {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  background: var(--ui-surface-raised);
  color: var(--ui-text-muted);
  font-size: var(--ui-font-size-xs);
}

.ui-chip.is-stale {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
}

/* Auth */
.auth-wrapper {
  min-height: calc(100vh - 52px);
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.auth-card {
  width: min(460px, 100%);
  padding: 1.5rem;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.auth-title {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
}

.auth-title h1 {
  margin: 0;
  font-size: 1.25rem;
}

.auth-subtitle {
  color: var(--ui-text-muted);
  font-size: 0.85rem;
}

.auth-note {
  margin-top: 1rem;
  padding: 0.75rem 0.9rem;
  border: 1px dashed var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface-hover);
  color: var(--ui-text-muted);
  font-size: 0.82rem;
  text-align: center;
}

/* Cards / sections */
.section {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.dashboard-shell {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.dashboard-shell[data-dashboard-page="funnel"] {
  gap: 0.75rem;
}

.dashboard-shell[data-dashboard-page="retention"] {
  gap: 0.75rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.funnel-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

.section-header h2 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.funnel-page-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.funnel-toolbar {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  column-gap: 1.25rem;
  row-gap: 0.5rem;
}

.funnel-title-group,
.funnel-controls-group,
.funnel-status-line {
  min-width: 0;
}

.funnel-controls-group {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: flex-end;
  gap: 0.75rem;
}

.funnel-status-line {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-top: -0.1rem;
}

.funnel-status-text {
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--ui-text-muted);
}

.funnel-status-text.is-stale {
  color: var(--ui-warning);
}

.funnel-control-block {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.funnel-control-label {
  font-size: 0.68rem;
  line-height: 1;
  color: var(--ui-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.dashboard-shell[data-dashboard-page="funnel"] .table-scroll {
  overflow-x: visible;
}

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

.section-note {
  color: var(--ui-text-muted);
  font-size: 0.8rem;
}

.tooltip-inline {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 0.25rem;
}

.tooltip-trigger {
  width: 1rem;
  height: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  background: var(--ui-surface-raised);
  color: var(--ui-text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  cursor: help;
  padding: 0;
}

.tooltip-trigger:hover,
.tooltip-trigger:focus-visible {
  color: var(--ui-text);
  border-color: var(--ui-border-active);
  outline: none;
}

.floating-tooltip {
  position: fixed;
  z-index: 1000;
  display: none;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface);
  color: var(--ui-text);
  box-shadow: var(--ui-shadow-md);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.45;
  white-space: normal;
  word-break: keep-all;
}

.floating-tooltip.is-visible {
  display: block;
}

.floating-tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 0.6rem;
  height: 0.6rem;
  margin-left: -0.3rem;
  background: var(--ui-surface);
  transform: rotate(45deg);
  border-right: 1px solid var(--ui-border);
  border-bottom: 1px solid var(--ui-border);
}

.floating-tooltip[data-placement="top"]::after {
  bottom: -0.34rem;
}

.floating-tooltip[data-placement="bottom"]::after {
  top: -0.34rem;
  transform: rotate(225deg);
}

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
}

.kpi-grid > * {
  min-width: 0;
}

.kpi-card {
  background: var(--ui-surface);
  border: 1px solid var(--admin-border-strong);
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-md);
  padding: 1.15rem 1.2rem;
  position: relative;
  overflow: hidden;
}

.kpi-card__label {
  font-size: 0.75rem;
  color: var(--ui-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 0.35rem;
}

.kpi-card__value {
  font-size: 1.8rem;
  font-weight: 800;
  margin: 0;
}

.kpi-card__hint {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--ui-text-muted);
}

.kpi-accent {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 3px rgba(99, 102, 241, 0.35);
}

/* Charts */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.chart-grid > * {
  min-width: 0;
}

.chart-card {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-md);
  padding: 1.1rem 1.15rem 1rem;
}

.chart-grid--focus {
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

.chart-card--focus {
  min-height: 360px;
}

.chart-card h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  color: var(--ui-text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chart-card__meta {
  margin: 0 0 0.9rem;
  color: var(--ui-text-muted);
  font-size: 0.78rem;
}

.chart-card canvas {
  width: 100% !important;
  height: 280px !important;
}

/* Tables */
.table-scroll {
  overflow: auto;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-md);
  scrollbar-gutter: stable both-edges;
}

.table-scroll table {
  min-width: 980px;
  width: 100%;
  table-layout: fixed;
  margin: 0;
}

.model-breakdown-table {
  min-width: 1720px !important;
  table-layout: auto !important;
}

.model-breakdown-table th,
.model-breakdown-table td {
  overflow-wrap: normal !important;
  word-break: keep-all !important;
  white-space: nowrap;
  vertical-align: middle;
}

.model-breakdown-table .model-breakdown-label,
.model-breakdown-table .model-breakdown-cache {
  white-space: normal;
}

/* Inline scroll wrapper for smaller tables inside cards (prevents page overflow) */
.table-scroll-inline {
  overflow: auto;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  scrollbar-gutter: stable both-edges;
}

.table-scroll-inline table {
  min-width: 860px;
  width: 100%;
  table-layout: fixed;
  margin: 0;
}

/* Prevent long text/components from stretching table width unpredictably */
.admin-main .ui-table td,
.admin-main .ui-table th {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.metrics-table td,
.metrics-table th {
  white-space: nowrap;
}

/* Daily metrics has many columns; keep clear column boundaries and avoid text overlap */
#daily-metrics-table {
  min-width: 1120px;
  table-layout: auto;
}

#daily-metrics-table th,
#daily-metrics-table td {
  overflow-wrap: normal;
  word-break: normal;
  border-right: 1px solid var(--ui-border);
}

#daily-metrics-table th:last-child,
#daily-metrics-table td:last-child {
  border-right: none;
}

#daily-metrics-table th:first-child,
#daily-metrics-table td:first-child {
  min-width: 118px;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--ui-surface);
}

#daily-metrics-table th:nth-child(2),
#daily-metrics-table td:nth-child(2) {
  min-width: 92px;
}

#daily-metrics-table thead th:first-child {
  z-index: 3;
}

#daily-metrics-table th:not(:first-child),
#daily-metrics-table td:not(:first-child) {
  text-align: right;
}

.metrics-table tr.is-latest td {
  background: rgba(99, 102, 241, 0.12);
}

#initial-funnel-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

#initial-funnel-table th,
#initial-funnel-table td {
  white-space: normal;
  border-right: 1px solid var(--ui-border);
  text-align: center;
  vertical-align: middle;
}

#initial-funnel-table th:last-child,
#initial-funnel-table td:last-child {
  border-right: none;
}

#initial-funnel-table th:first-child,
#initial-funnel-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  min-width: 96px;
  width: 96px;
  background: var(--ui-surface);
}

#initial-funnel-table th:not(:first-child),
#initial-funnel-table td:not(:first-child) {
  min-width: 0;
  width: auto;
}

#initial-funnel-table thead th:first-child {
  z-index: 3;
}

#initial-funnel-table tbody tr.is-latest td {
  background: var(--ui-surface);
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.35);
}

#retention-grid-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

#retention-grid-table th,
#retention-grid-table td {
  white-space: normal;
  border-right: 1px solid var(--ui-border);
  text-align: center;
  vertical-align: middle;
}

#retention-grid-table th:last-child,
#retention-grid-table td:last-child {
  border-right: none;
}

#retention-grid-table th:first-child,
#retention-grid-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  min-width: 96px;
  width: 96px;
  background: var(--ui-surface);
}

#retention-grid-table th:nth-child(2),
#retention-grid-table td:nth-child(2) {
  min-width: 92px;
  width: 92px;
}

#retention-grid-table thead th:first-child {
  z-index: 3;
}

#retention-grid-table tbody tr.is-latest td {
  background: var(--ui-surface);
  box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.28);
}

.retention-cohort-cell {
  font-weight: 700;
  white-space: nowrap !important;
  font-variant-numeric: tabular-nums;
}

.retention-grid-cell {
  padding: 0.28rem 0.18rem;
  background: var(--ui-surface);
}

.retention-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.22rem;
  min-height: 54px;
  padding: 0.15rem 0.05rem;
}

.retention-cell.is-empty {
  opacity: 0.72;
}

.retention-rate {
  font-weight: 700;
  color: var(--ui-text);
  font-size: 0.8rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.retention-count {
  font-size: 0.62rem;
  color: var(--ui-text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.retention-progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #10b981 0%, #0f766e 100%);
}

.retention-placeholder {
  font-weight: 700;
  color: var(--ui-text-muted);
  font-size: 0.82rem;
}

.funnel-header-label {
  display: block;
  line-height: 1.15;
  font-size: 0.65rem;
  font-weight: 700;
  word-break: keep-all;
}

.funnel-header-line {
  display: block;
  white-space: nowrap;
}

.funnel-grid-cell {
  padding: 0.25rem 0.18rem;
  background: var(--ui-surface);
}

.funnel-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.18rem;
  min-height: 48px;
  padding: 0.1rem 0.05rem;
}

.funnel-cell.is-empty {
  opacity: 0.72;
}

.funnel-count {
  font-weight: 700;
  color: var(--ui-text);
  font-size: 0.78rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.funnel-rate {
  font-size: 0.6rem;
  color: var(--ui-text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.funnel-progress-track {
  display: block;
  width: 100%;
  height: 4px;
  margin-top: 0.35rem;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.funnel-progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #38bdf8 0%, #2563eb 100%);
}

.funnel-date-cell {
  font-weight: 700;
  white-space: nowrap !important;
  font-size: 0.72rem;
}

@media (max-width: 1400px) {
  .funnel-toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .funnel-controls-group {
    justify-content: flex-start;
  }

  .funnel-status-line {
    justify-content: flex-start;
  }
}

.admin-nav .nav-links {
  gap: 0.35rem;
}

.admin-nav .nav-links > a:not(.nav-brand) {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.45rem 0.8rem;
  border-radius: 0;
}

/* Conversation insights helpers */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 0.75rem;
}

.insights-grid > * {
  min-width: 0;
}

.section-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.fact-note {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface-raised);
  color: var(--ui-text-muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

.fact-note strong {
  color: var(--ui-text);
  margin-right: 0.35rem;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--ui-border);
}

.metric-row:last-child {
  border-bottom: none;
}

.metric-label {
  color: var(--ui-text-muted);
  font-size: 0.82rem;
}

.metric-value {
  color: var(--ui-text);
  font-weight: 700;
  font-size: 0.85rem;
}

.chart-container {
  position: relative;
  height: 320px;
}

.finding-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.finding-card__title {
  color: var(--ui-text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
}

.finding-card__metric {
  color: var(--ui-text);
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1;
}

.finding-card__metric-label {
  color: var(--ui-text-muted);
  font-size: 0.78rem;
}

.finding-card__body {
  color: var(--ui-text-muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.finding-card__action {
  color: var(--ui-text);
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
  color: var(--ui-text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.badge-primary {
  border-color: rgba(99, 102, 241, 0.45);
  color: var(--ui-text);
}

.badge-success {
  border-color: rgba(74, 222, 128, 0.45);
  color: var(--ui-text);
}

.badge-warning {
  border-color: rgba(251, 191, 36, 0.55);
  color: var(--ui-text);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--ui-border);
}

.tab {
  cursor: pointer;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  color: var(--ui-text-muted);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-family: var(--ui-font-family);
  font-size: var(--ui-font-size-sm);
  box-shadow: var(--ui-shadow-sm);
  transition: transform var(--ui-transition-fast), box-shadow var(--ui-transition-fast);
}

.tab:hover {
  transform: translate(-1px, -1px);
  box-shadow: var(--ui-shadow-md);
  color: var(--ui-text);
}

.tab.active {
  color: var(--ui-text);
  border-color: var(--ui-border-active);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Generic states */
.loading {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--ui-text-muted);
}

.loading-spinner {
  display: inline-block;
  width: 36px;
  height: 36px;
  border: 3px solid var(--ui-border);
  border-top: 3px solid var(--ui-primary);
  border-radius: 999px;
  animation: admin-spin 0.9s linear infinite;
  margin-bottom: 0.5rem;
}

@keyframes admin-spin {
  to {
    transform: rotate(360deg);
  }
}

.error-message,
.error {
  border: 1px solid var(--ui-error-border);
  background: var(--ui-error-bg);
  color: var(--ui-error);
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-sm);
  padding: 0.75rem 1rem;
}

.empty-state {
  display: grid;
  place-items: center;
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--ui-text-muted);
  border: 1px dashed var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface);
}

.compact-empty {
  min-height: 120px;
  padding: 1rem;
}

.compact-table th,
.compact-table td {
  font-size: 0.8rem;
}

.section-divider {
  border: 0;
  border-top: 1px solid var(--ui-border);
  margin: 0.75rem 0;
}

.drilldown-panel {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-sm);
}

.drilldown-panel > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.9rem 1rem;
  font-weight: 700;
  color: var(--ui-text);
}

.drilldown-panel > summary::-webkit-details-marker {
  display: none;
}

.drilldown-panel[open] > summary {
  border-bottom: 1px solid var(--ui-border);
}

.drilldown-content {
  padding: 0.75rem;
}

/* User conversation viewer */
body.user-conversations-page {
  overflow: hidden;
  scrollbar-gutter: stable both-edges;
}

@media (max-width: 960px) {
  .page-header {
    flex-direction: column;
  }

  .page-actions,
  .filter-actions {
    justify-content: flex-start;
  }

  .cost-cache-form {
    width: 100%;
  }

  .filter-toolbar {
    align-items: stretch;
  }

  .filter-cluster {
    width: 100%;
  }

  .filter-cluster--dates {
    flex-wrap: wrap;
  }

  .filter-input-date,
  .filter-cluster .ui-select {
    width: 100%;
  }

  .filter-actions .btn,
  .filter-submit {
    width: 100%;
    justify-content: center;
    margin-left: 0;
  }
}

.user-conversations-page .admin-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 0;
}

.user-conversations-shell {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0;
}

.split-view {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.split-view > * {
  min-width: 0;
}

.panel {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  padding: 1rem;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
}

.panel-header h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.panel-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
}

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

.filter-row {
  display: flex;
  gap: 0.5rem;
}

.conversation-item {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  padding: 0.75rem;
  margin: 0.6rem;
  cursor: pointer;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-sm);
  transition: transform var(--ui-transition-fast), box-shadow var(--ui-transition-fast), border-color var(--ui-transition-fast);
}

.conversation-item:hover {
  transform: translate(-1px, -1px);
  box-shadow: var(--ui-shadow-md);
  border-color: var(--ui-border-hover);
}

.conversation-item.active {
  border-color: var(--ui-border-active);
  box-shadow: var(--ui-shadow-md);
}

.conversation-header {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.conversation-avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
}

.conversation-title {
  font-weight: 700;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-meta {
  font-size: 0.78rem;
  color: var(--ui-text-muted);
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.conversation-preview {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  color: var(--ui-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pagination {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  color: var(--ui-text-muted);
  font-size: 0.85rem;
}

.pagination-buttons {
  display: flex;
  gap: 0.5rem;
}

.messages-container {
  padding: 1rem;
  background: var(--ui-bg);
}

.messages-header {
  padding: 1rem;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
}

.messages-header h3 {
  margin: 0;
  font-size: 1rem;
}

.messages-header-meta {
  margin-top: 0.4rem;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--ui-text-muted);
}

.message-item {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.message-item.user {
  flex-direction: row-reverse;
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.message-item.user .message-content {
  align-items: flex-end;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
  color: var(--ui-text-muted);
  flex-shrink: 0;
}

.message-bubble {
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-sm);
  border-radius: var(--ui-radius-md);
  padding: 0.65rem 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: min(720px, 78ch);
  font-size: 0.85rem;
}

.message-item.user .message-bubble {
  border-color: rgba(99, 102, 241, 0.6);
}

.message-item.deleted {
  opacity: 0.55;
}

.message-timestamp {
  margin-top: 0.25rem;
  font-size: 0.72rem;
  color: var(--ui-text-dim);
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

.chat-mode-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
  color: var(--ui-text);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-mode-prime {
  border-color: rgba(99, 102, 241, 0.6);
}

.chat-mode-spark {
  border-color: rgba(251, 191, 36, 0.7);
}

.chat-mode-vibe {
  border-color: rgba(56, 189, 248, 0.7);
}

.chat-mode-basic {
  border-color: rgba(74, 222, 128, 0.7);
}

.deleted-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--ui-error-border);
  background: var(--ui-error-bg);
  color: var(--ui-error);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

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

.statistics-bar > * {
  min-width: 0;
}

.stat-card {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-md);
  padding: 0.9rem 1rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--ui-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 800;
}

/* Gate detail conversation */
.gate-turn {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.gate-turn__role {
  flex: 0 0 84px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ui-text-muted);
  padding-top: 0.2rem;
}

.gate-turn__content {
  flex: 1;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-sm);
  padding: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.gate-round {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-md);
  overflow: hidden;
  background: var(--ui-surface);
}

.gate-round__header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
}

.gate-round__header h3 {
  margin: 0;
  font-size: 0.9rem;
}

.gate-round__meta {
  font-size: 0.8rem;
  color: var(--ui-text-muted);
}

.gate-round__body {
  padding: 1rem;
}

.gate-attempt-trace {
  display: block;
  max-width: 540px;
}

.gate-attempt-trace summary {
  cursor: pointer;
  color: var(--ui-text);
  font-size: 0.78rem;
  font-weight: 700;
}

.gate-attempt-trace__meta {
  margin-top: 0.35rem;
  color: var(--ui-text-muted);
  font-size: 0.76rem;
}

.gate-attempt-trace__json {
  margin: 0.45rem 0 0;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
  border-radius: var(--ui-radius-sm);
  max-height: 260px;
  overflow: auto;
  font-size: 0.72rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.gate-attempt-text {
  display: block;
  max-width: 360px;
}

.gate-attempt-text summary {
  cursor: pointer;
  color: var(--ui-text);
  font-size: 0.76rem;
  font-weight: 700;
}

.gate-attempt-text__body {
  margin-top: 0.35rem;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
  border-radius: var(--ui-radius-sm);
  padding: 0.5rem 0.6rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.75rem;
  line-height: 1.35;
}

.gate-attempt-open-btn {
  min-width: 66px;
  padding: 0.28rem 0.5rem;
  font-size: 0.74rem;
}

.gate-attempt-cell {
  display: block;
  min-width: 0;
}

.gate-attempt-preview {
  min-width: 0;
  max-width: 360px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  text-overflow: ellipsis;
  font-size: 0.75rem;
  line-height: 1.3;
}

.gate-attempt-preview--button {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ui-text);
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.gate-attempt-preview--button:hover {
  color: var(--ui-primary);
}

.gate-participant-summary {
  padding: 0.85rem 1rem;
}

.gate-participant-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.4rem 0.9rem;
}

.gate-chain-row {
  cursor: pointer;
}

.gate-chain-row td {
  transition: background-color 140ms ease;
}

.gate-chain-row:hover td {
  background: var(--ui-surface-raised);
}

.gate-chain-row.is-open td {
  background: var(--ui-surface-raised);
}

.gate-chain-detail-row > td {
  padding: 0 !important;
  border-top: none;
}

.gate-chain-detail-panel {
  padding: 0.6rem;
  background: var(--ui-surface);
  min-width: 0;
  overflow: hidden;
}

.gate-chain-convo-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.gate-chain-convo {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-sm);
  overflow: hidden;
}

.gate-chain-convo__summary {
  list-style: none;
  cursor: pointer;
  padding: 0.65rem 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px solid transparent;
}

.gate-chain-convo[open] .gate-chain-convo__summary {
  border-bottom-color: var(--ui-border);
  background: var(--ui-surface-raised);
}

.gate-chain-convo__summary::-webkit-details-marker {
  display: none;
}

.gate-chain-convo__title {
  font-size: 0.82rem;
  font-weight: 700;
  white-space: normal;
  overflow-wrap: anywhere;
}

.gate-chain-convo__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
}

.gate-chain-convo__body {
  padding: 0.6rem;
}

.gate-turn-detail {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-sm);
  background: var(--ui-surface);
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.gate-turn-detail:last-child {
  margin-bottom: 0;
}

.gate-turn-detail__summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  align-items: center;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid transparent;
  font-size: 0.76rem;
}

.gate-turn-detail[open] .gate-turn-detail__summary {
  border-bottom-color: var(--ui-border);
  background: var(--ui-surface-raised);
}

.gate-turn-detail__summary::-webkit-details-marker {
  display: none;
}

.gate-turn-detail__idx {
  font-weight: 700;
  color: var(--ui-text);
}

.gate-turn-detail__stamp,
.gate-turn-detail__score,
.gate-turn-detail__bet,
.gate-turn-detail__gold {
  color: var(--ui-text-muted);
}

.gate-turn-detail__body {
  padding: 0.6rem;
  display: grid;
  gap: 0.45rem;
  min-width: 0;
}

.gate-dialog-block {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-sm);
  background: var(--ui-surface-raised);
  padding: 0.5rem 0.6rem;
}

.gate-dialog-block__label {
  font-size: 0.68rem;
  color: var(--ui-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.gate-dialog-block__content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 0.76rem;
  line-height: 1.35;
}

.gate-turn-detail__footer {
  margin-top: 0.1rem;
}

.gate-attempt-inline-text {
  max-width: 420px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.75rem;
  line-height: 1.35;
}

.gate-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
}

.gate-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
}

.gate-modal__panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(1080px, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.gate-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface-raised);
}

.gate-modal__header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.gate-modal__close {
  padding: 0.35rem 0.7rem;
}

.gate-modal__content {
  margin: 0;
  padding: 1rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.78rem;
  line-height: 1.45;
  flex: 1 1 auto;
}

body.modal-open {
  overflow: hidden;
  scrollbar-gutter: stable both-edges;
}

@media (max-width: 980px) {
  .split-view {
    grid-template-columns: 1fr;
  }
}
