/* Sidekick Agent Evaluation — component styles on the Toge Design System.
 * Token values live in toge-tokens.css (hand-extracted from
 * toge-ds-components/src/style.css, light mode). No build step.
 * Class names (sc-*) are app contracts — tests and app.js depend on them.
 */

* { box-sizing: border-box; }

/* ── Motion ──────────────────────────────────────────────────────────────── */
@keyframes sc-fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes sc-pulse   { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.8); } }
@keyframes sc-spin    { to { transform: rotate(360deg); } }
@keyframes sc-shake   { 0%,100% { transform: none; } 20%,60% { transform: translateX(-5px); } 40%,80% { transform: translateX(5px); } }
@keyframes sc-blink   { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }
@keyframes sc-line-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes sc-bar-grow { from { width: 0; } }

.sc-enter { animation: sc-fade-up 0.35s ease-out both; }
.sc-shake { animation: sc-shake 0.4s var(--easing); }

/* htmx swap transitions (vendored htmx 1.9.12 adds these classes during swaps) */
#dataset-panel.htmx-swapping, #run-panel.htmx-swapping { opacity: 0; transition: opacity 100ms var(--easing); }
#dataset-panel.htmx-added, #run-panel.htmx-added { animation: sc-fade-up 250ms ease-out both; }

@media (prefers-reduced-motion: reduce) {
  .sc-enter, .sc-shake, .sc-live-dot, .sc-spinner, .sc-log__cursor, .sc-log__line,
  .sc-tile, #dataset-panel.htmx-added, #run-panel.htmx-added { animation: none !important; }
  #dataset-panel.htmx-swapping, #run-panel.htmx-swapping { transition: none !important; opacity: 1 !important; }
  .sc-bar__fill { animation: none !important; transition: none !important; }
}

/* ── Focus (toge ring: brand @ 45% over a white halo) ────────────────────── */
:focus-visible { outline: 2px solid color-mix(in srgb, var(--brand) 65%, transparent); outline-offset: 1px; }
.sc-btn:focus-visible, .sc-input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 1px var(--surface-white), 0 0 0 4px color-mix(in srgb, var(--brand) 45%, transparent);
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.sc-body {
  margin: 0;
  min-height: 100dvh;
  background: var(--page-gradient), var(--surface);
  background-attachment: fixed;
  color: var(--text-strong);
  font-family: var(--font-body);
  font-size: var(--text-300);
  line-height: var(--leading-500);
}

.sc-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-weak);
}
.sc-header__brand { display: flex; align-items: center; gap: 12px; }
.sc-header__title { font-weight: 600; letter-spacing: var(--tracking-dense); }
.sc-header__user { display: flex; align-items: center; gap: 12px; }
.sc-logo-img { height: 28px; width: auto; display: inline-block; }
.sc-logo-img--large { height: 34px; }

.sc-main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }

.sc-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .sc-grid { grid-template-columns: 1fr; } }
.sc-side { display: flex; flex-direction: column; gap: 20px; }
.sc-side > .sc-card:nth-child(1) { animation-delay: 60ms; }
.sc-side > .sc-card:nth-child(2) { animation-delay: 120ms; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.sc-card {
  background: var(--surface-white);
  border: 1px solid var(--border-weak);
  border-radius: var(--radius-xl);
  box-shadow: 0 1px 2px rgba(38, 43, 43, 0.06);
  padding: 24px;
  transition: box-shadow var(--duration) var(--easing);
}
.sc-card:hover { box-shadow: 0 4px 12px rgba(38, 43, 43, 0.08); }
.sc-card--wide { max-width: none; }
.sc-card__title { margin: 0 0 6px; font-size: var(--text-600); font-weight: 600; letter-spacing: var(--tracking-dense); }
.sc-card__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sc-card__head .sc-card__title { margin: 0; font-size: var(--text-500); }
.sc-muted { color: var(--text-supporting); line-height: var(--leading-500); }
.sc-error { color: var(--danger-text); font-weight: 500; }

/* Section eyebrow label (toge `overline` spec) */
.sc-overline {
  margin: 0;
  font-size: var(--text-200); font-weight: 500;
  text-transform: uppercase; letter-spacing: var(--tracking-widest);
  color: var(--text-supporting);
}
.sc-overline + .sc-card__head { margin-top: 8px; }

/* Inline Phosphor icons (templates/_icons.html) */
.sc-card__title svg { vertical-align: -3px; margin-right: 7px; color: var(--text-supporting); }
.sc-btn svg { flex: none; }

/* ── Buttons / inputs ───────────────────────────────────────────────────── */
.sc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 500; font-size: var(--text-300); font-family: inherit;
  text-decoration: none; cursor: pointer;
  transition: all var(--duration) var(--easing);
}
.sc-btn:hover { box-shadow: inset 0 -2px 1px 0 rgba(0, 0, 0, 0.10); }
.sc-btn:active { transform: scale(0.98); box-shadow: inset 0 2px 1px 0 rgba(0, 0, 0, 0.15); }
.sc-btn--primary { background: var(--brand); color: var(--on-brand); }
.sc-btn--primary:hover { background: var(--brand-hover); }
.sc-btn--primary:active { background: var(--brand-pressed); }
.sc-btn--ghost { background: var(--surface-white); border-color: var(--border-weak); color: var(--text-strong); }
.sc-btn--ghost:hover { background: var(--surface-hover); }
.sc-btn--danger { background: var(--surface-white); border-color: var(--color-tomato-200); color: var(--danger-text); }
.sc-btn--danger:hover { background: var(--danger-subtle); border-color: var(--danger); }
.sc-btn--small { height: 28px; padding: 0 10px; font-size: var(--text-200); }
.sc-btn--full { width: 100%; }

.sc-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sc-field__label { font-size: var(--text-300); color: var(--text-base); font-weight: 500; }
.sc-input {
  height: 36px; padding: 6px 12px;
  border: 1px solid var(--border-weak); border-radius: var(--radius-sm);
  font-size: var(--text-300); font-family: inherit; color: var(--text-strong);
  background: var(--surface-white);
  transition: border-color var(--duration) var(--easing), box-shadow var(--duration) var(--easing);
}
.sc-input::placeholder { color: var(--text-weak); }
.sc-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.sc-textarea { height: auto; min-height: 96px; font-family: var(--font-mono); font-size: 13px; line-height: var(--leading-500); resize: vertical; }

/* ── Spinner / loading (wired to htmx-indicator) ─────────────────────────── */
.sc-spinner {
  width: 16px; height: 16px; flex: none;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: sc-spin 0.7s linear infinite;
}
.sc-spinner--inline { border-color: var(--border-weak); border-top-color: var(--brand); vertical-align: -2px; display: inline-block; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }

.sc-live-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
  background: currentColor; margin-right: 2px;
  animation: sc-pulse 1.2s var(--easing) infinite;
}

/* ── Form composition ───────────────────────────────────────────────────── */
.sc-form { display: flex; flex-direction: column; gap: 16px; margin-top: 14px; }
.sc-form__row { display: flex; gap: 14px; }
.sc-form__row .sc-field { flex: 1; }
.sc-form__row .sc-field--narrow { flex: 0 0 130px; }
.sc-advanced { border: 1px solid var(--border-weak); border-radius: var(--radius-md); padding: 10px 14px; }
.sc-advanced summary { cursor: pointer; color: var(--text-supporting); font-weight: 500; }
.sc-advanced .sc-table { margin-top: 10px; }

/* ── Judge toggle ───────────────────────────────────────────────────────── */
.sc-judge { border: 1px solid var(--border-weak); border-radius: var(--radius-md); padding: 14px; background: var(--surface); }
.sc-switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.sc-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.sc-switch__track {
  width: 42px; height: 24px; flex: none; border-radius: 999px;
  background: var(--control); position: relative; transition: background var(--duration) var(--easing);
}
.sc-switch__track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform var(--duration) var(--easing);
}
.sc-switch:hover .sc-switch__track { background: var(--control-hover); }
.sc-switch input:checked + .sc-switch__track { background: var(--brand); }
.sc-switch input:checked + .sc-switch__track::after { transform: translateX(18px); }
.sc-switch input:focus-visible + .sc-switch__track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 45%, transparent); }
.sc-switch__label { font-weight: 500; }
.sc-judge__prompt { display: none; margin-top: 12px; }
.sc-judge__prompt.is-open { display: block; animation: sc-fade-up 0.25s ease-out both; }

/* ── Run panel / live log ───────────────────────────────────────────────── */
.sc-run-panel { margin-top: 20px; }
.sc-run { border-top: 1px solid var(--border-weak); padding-top: 16px; margin-top: 6px; }
.sc-run__head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.sc-run__hint { display: flex; align-items: center; gap: 8px; font-size: var(--text-300); }
.sc-run__subtitle { margin: 22px 0 8px; font-size: var(--text-400); font-weight: 600; }
.sc-log {
  background: var(--surface-inverted); color: #d7f7c8;
  border-radius: var(--radius-md); padding: 14px;
  font-family: var(--font-mono); font-size: 12.8px; line-height: 1.55;
  max-height: 280px; overflow: auto; white-space: pre-wrap;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.25);
}
.sc-log__cursor { animation: sc-blink 1.1s step-end infinite; color: var(--color-kangkong-400); }
.sc-log__line { animation: sc-line-in 0.25s ease-out both; }

/* ── Badges / pills / chips (toge badge spec: 6px radius, label-xs) ─────── */
.sc-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 6px; border-radius: 6px;
  font-size: var(--text-200); font-weight: 500; text-transform: uppercase; letter-spacing: var(--tracking-wide);
}
.sc-badge--queued     { background: var(--neutral); color: var(--neutral-text); }
.sc-badge--running    { background: var(--pending-status); color: var(--pending-text); }
.sc-badge--done       { background: var(--success-status); color: var(--success-text); }
.sc-badge--error      { background: var(--danger-status); color: var(--danger-text); }
.sc-badge--cancelled  { background: var(--neutral); color: var(--neutral-text); }
.sc-badge--cancelling { background: var(--pending-status); color: var(--pending-text); }

.sc-run__cancel { margin-left: auto; }

.sc-env-pill {
  padding: 2px 8px; border-radius: 6px;
  font-size: var(--text-200); font-weight: 500; letter-spacing: var(--tracking-wide);
}
.sc-env-pill--qa   { background: var(--brand-subtle); color: var(--brand-text); border: 1px solid var(--color-kangkong-200); }
.sc-env-pill--prod { background: var(--danger-subtle); color: var(--danger-text); border: 1px solid var(--color-tomato-200); }

.sc-chip {
  display: inline-block; padding: 2px 6px; border-radius: 6px;
  font-size: var(--text-200); font-weight: 500;
}
.sc-chip--pass { background: var(--success-status); color: var(--success-text); }
.sc-chip--fail { background: var(--danger-status); color: var(--danger-text); }
.sc-chip--mid  { background: var(--caution-status); color: var(--caution-text); }
.sc-chip--tool { background: var(--accent-subtle); color: var(--accent-text); border: 1px solid var(--color-wintermelon-200); }

/* ── Dataset preview ────────────────────────────────────────────────────── */
.sc-dataset { border-top: 1px solid var(--border-weak); padding-top: 16px; margin-top: 18px; }
.sc-dataset__scroll { max-height: 360px; margin: 12px 0 4px; }
.sc-dataset__search {
  display: flex; align-items: center; gap: 12px; margin-top: 12px;
}
.sc-dataset__search .sc-input { flex: 1; max-width: 420px; }
.sc-dataset__search .sc-search { flex: 1; max-width: 420px; }
.sc-dataset__search .sc-search .sc-input { width: 100%; max-width: none; }
.sc-dataset__search [data-filter-count] { font-size: var(--text-300); white-space: nowrap; }
.sc-search { position: relative; }
.sc-search > svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-weak); pointer-events: none;
}
.sc-search .sc-input { padding-left: 32px; }
mark.sc-mark {
  background: var(--pending-subtle); color: var(--pending-text);
  border-radius: 3px; padding: 0 1px;
}
.sc-dataset input[type="checkbox"] { accent-color: var(--brand); width: 15px; height: 15px; }
.sc-field--button { justify-content: flex-end; }

/* ── Metric tiles + bar charts ──────────────────────────────────────────── */
.sc-tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px; margin: 14px 0 6px;
}
.sc-tile {
  border: 1px solid var(--border-weak); border-radius: var(--radius-lg);
  padding: 14px 16px; background: var(--surface-white);
  display: flex; flex-direction: column; gap: 6px;
  animation: sc-fade-up 0.35s ease-out both;
}
.sc-tile__name { font-size: var(--text-200); color: var(--text-supporting); font-weight: 500; text-transform: capitalize;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-tile__value { font-size: var(--text-700); font-weight: 600; letter-spacing: var(--tracking-denser); font-variant-numeric: tabular-nums; }
.sc-tile__value.is-good { color: var(--success-text); }
.sc-tile__value.is-mid  { color: var(--caution-text); }
.sc-tile__value.is-bad  { color: var(--danger-text); }
.sc-bar { display: block; height: 7px; border-radius: 999px; background: var(--surface-adaptive); overflow: hidden; }
.sc-bar__fill {
  display: block; height: 100%; border-radius: 999px;
  background: var(--success); width: 0;
  animation: sc-bar-grow 700ms cubic-bezier(0.22, 1, 0.36, 1);
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.sc-bar__fill.is-good { background: var(--success); }
.sc-bar__fill.is-mid  { background: var(--caution); }
.sc-bar__fill.is-bad  { background: var(--danger); }

.sc-mini-metric {
  display: inline-block; margin-right: 8px; padding: 1px 8px;
  border: 1px solid var(--border-weak); border-radius: 6px;
  font-size: var(--text-200); color: var(--text-supporting); text-transform: capitalize;
}
.sc-mini-metric strong { color: var(--text-strong); font-weight: 600; }
.sc-mini-metric strong.is-good { color: var(--success-text); }
.sc-mini-metric strong.is-mid  { color: var(--caution-text); }
.sc-mini-metric strong.is-bad  { color: var(--danger-text); }

/* ── Tables ─────────────────────────────────────────────────────────────── */
table.sc-table { width: 100%; border-collapse: collapse; font-size: var(--text-300); }
table.sc-table th, table.sc-table td {
  text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border-weak);
  vertical-align: top;
}
table.sc-table th { color: var(--text-supporting); font-weight: 500; font-size: var(--text-200); }
table.sc-table tbody tr { transition: background var(--duration) var(--easing); }
table.sc-table tbody tr:hover { background: var(--surface-hover); }
.sc-table-scroll { overflow: auto; max-height: 480px; border: 1px solid var(--border-weak); border-radius: var(--radius-md); }
.sc-table--sticky thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-white); box-shadow: 0 1px 0 var(--border-weak); }
.sc-cell { display: inline-block; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* ── History lists ──────────────────────────────────────────────────────── */
.sc-history { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 10px; }
.sc-history__item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 10px; border: 1px solid transparent; border-radius: var(--radius-md);
  transition: background var(--duration) var(--easing), border-color var(--duration) var(--easing);
}
.sc-history__item:hover { background: var(--surface-hover); border-color: var(--border-weak); }
.sc-history__meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: var(--text-300); }
.sc-history__meta a { color: var(--text-strong); text-decoration: none; }
.sc-history__meta a:hover { color: var(--brand-text); }
.sc-history__metrics { margin-top: 3px; }

/* ── Login ──────────────────────────────────────────────────────────────── */
.sc-login-body {
  margin: 0; min-height: 100dvh; position: relative; overflow: hidden;
  background: var(--page-gradient), var(--surface); background-attachment: fixed;
  font-family: var(--font-body); font-size: var(--text-300); line-height: var(--leading-500);
  color: var(--text-strong);
}
.sc-login-wrap {
  position: relative; z-index: 1; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.sc-login-card {
  width: 100%; max-width: 460px; background: var(--surface-white);
  border: 1px solid var(--border-weak); border-radius: var(--radius-xl);
  box-shadow: 0 8px 24px rgba(38, 43, 43, 0.10); padding: 32px;
}
.sc-login-card__logo { display: flex; align-items: center; gap: 10px; font-weight: 600; margin-bottom: 18px; }
.sc-login-title { margin: 0 0 4px; font-size: var(--text-700); font-weight: 600; letter-spacing: var(--tracking-dense); }
.sc-login-form { display: flex; flex-direction: column; gap: 14px; }
.sc-login-foot { margin-top: 20px; color: var(--text-weak); font-size: var(--text-200); text-align: center; }

.sc-env-choices { display: flex; gap: 12px; }
.sc-env-choice {
  flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 12px; border: 1px solid var(--border-weak); border-radius: var(--radius-md); cursor: pointer;
  font-weight: 500; background: var(--surface-white);
  transition: all var(--duration) var(--easing);
}
.sc-env-choice:hover { background: var(--surface-hover); border-color: var(--border-base-hover); }
.sc-env-choice:has(input:checked) { border-color: var(--brand); background: var(--brand-subtle); box-shadow: 0 0 0 1px var(--brand); }
.sc-env-choice input { accent-color: var(--brand); }
