/* 双色球 Agent — 暖色工作台 UI（设计 token + 布局；不依赖 Tailwind） */
:root {
  --bg: #faf7f2;
  --surface: #fffcf8;
  --surface-elevated: #ffffff;
  --border: #e8e0d6;
  --text: #2c2825;
  --muted: #6b6560;
  --accent: #c8102e;
  --accent-hover: #a50d26;
  --accent-gold: #a67c00;
  --accent-gold-soft: rgba(166, 124, 0, 0.12);
  --danger: #b91c1c;
  --success: #15803d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(44, 40, 37, 0.06);
  --shadow-md: 0 4px 12px rgba(44, 40, 37, 0.08);
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --header-h: 56px;
  --focus-ring: 0 0 0 3px rgba(200, 16, 46, 0.25);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ----- App shell ----- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.site-header__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-header__left {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.site-brand {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.site-brand__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.site-brand__sub {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
}

.site-nav a {
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.site-nav a:hover {
  background: var(--accent-gold-soft);
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  background: transparent;
  color: var(--accent);
  box-shadow: inset 0 -2px 0 rgba(200, 16, 46, 0.9);
}

@media (max-width: 639px) {
  .site-header__inner {
    padding: 0 0.65rem;
    gap: 0.5rem;
  }

  .site-header__left {
    gap: 0.35rem;
  }

  .site-brand__title {
    font-size: 0.92rem;
  }

  .site-brand__sub {
    font-size: 0.64rem;
  }

  .site-nav {
    gap: 0.2rem;
  }

  .site-nav a {
    font-size: 0.78rem;
    padding: 0.24rem 0.38rem;
  }

  .header-actions {
    gap: 0.3rem;
  }

  .fab-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 0.42rem;
    border-radius: 7px;
  }
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.app-main--narrow {
  max-width: 520px;
}

.app-main--predict {
  max-width: 1120px;
  padding-top: 0.8rem;
}

.site-footer {
  margin-top: auto;
  padding: 1rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 700;
  font-family: inherit;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn--secondary {
  background: var(--surface-elevated);
  border-color: var(--border);
  color: var(--text);
}

.btn--secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn--ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.btn--ghost:hover:not(:disabled) {
  color: var(--accent);
  background: var(--accent-gold-soft);
}

.btn--icon {
  padding: 0;
  min-width: 2.25rem;
  min-height: 2.25rem;
  gap: 0;
  line-height: 1;
}

.btn--icon svg {
  flex-shrink: 0;
  display: block;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toolbar--floating {
  display: none;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.fab-btn {
  min-width: 36px;
  height: 34px;
  padding: 0 0.62rem;
  border-radius: 8px;
  border: 1px solid rgba(232, 224, 214, 0.92);
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(44, 40, 37, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease;
  position: relative;
}

.fab-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(44, 40, 37, 0.12);
}

a.fab-btn:hover {
  text-decoration: none;
}

.fab-btn:active {
  transform: translateY(0) scale(0.96);
}

.fab-btn::after {
  display: none;
}

.fab-btn__icon {
  font-size: 0.88rem;
  line-height: 1;
  transition: transform 0.2s ease;
}

.fab-btn__icon-svg {
  width: 0.96rem;
  height: 0.96rem;
  display: block;
}

.fab-btn__text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.fab-btn--primary {
  background: var(--accent);
  border-color: #b90f2d;
  color: #fff;
  box-shadow: 0 2px 6px rgba(200, 16, 46, 0.24);
}

.fab-btn--primary:hover {
  background: var(--accent-hover);
}

.fab-btn--primary.is-running {
  background: linear-gradient(160deg, #b52424 0%, #981b1b 100%);
  border-color: #8d1919;
  animation: fab-pulse 1.25s ease-in-out infinite;
}

.fab-btn--primary.is-running .fab-btn__icon {
  transform: rotate(90deg);
}

.fab-btn--drawer:hover {
  color: var(--accent);
  border-color: rgba(200, 16, 46, 0.28);
  background: rgba(200, 16, 46, 0.04);
}

.fab-btn--drawer .fab-btn__icon {
  color: var(--accent);
}

.fab-btn--drawer:hover .fab-btn__icon {
  color: var(--accent-hover);
}

@keyframes fab-pulse {
  0%,
  100% {
    box-shadow:
      0 8px 18px rgba(185, 28, 28, 0.2),
      0 0 0 0 rgba(185, 28, 28, 0.28);
  }
  60% {
    box-shadow:
      0 10px 20px rgba(185, 28, 28, 0.26),
      0 0 0 8px rgba(185, 28, 28, 0);
  }
}

@keyframes fab-enter {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toolbar--stack {
  flex-direction: column;
  align-items: flex-start;
}

.dashboard-kpi {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "latest"
    "neural"
    "pending"
    "compare";
  gap: 0.75rem;
  margin-bottom: 1.1rem;
  position: relative;
}

.dashboard-layout::before {
  content: none;
}

.dashboard-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  box-shadow: var(--shadow);
  padding: 0.85rem 0.9rem;
}

.dashboard-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}

.dashboard-panel__label {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.dashboard-panel--latest {
  grid-area: latest;
  margin-top: 0;
  border-radius: 14px;
  border-color: rgba(200, 16, 46, 0.14);
  background:
    linear-gradient(180deg, rgba(200, 16, 46, 0.05) 0%, rgba(255, 255, 255, 0.96) 62%),
    var(--surface-elevated);
  box-shadow:
    0 6px 14px rgba(200, 16, 46, 0.08),
    0 2px 6px rgba(44, 40, 37, 0.05);
}

.dashboard-panel--latest .dashboard-panel__label {
  color: #8f1027;
  font-weight: 700;
}

.dashboard-panel--compare {
  grid-area: compare;
}

.dashboard-panel--pending {
  grid-area: pending;
}

.dashboard-panel--neural {
  grid-area: neural;
}

.dashboard-kpi__card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem;
  background: var(--surface-elevated);
  box-shadow: var(--shadow);
}

.dashboard-kpi__label {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.dashboard-kpi__value {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.25;
}

.dashboard-kpi__value--small {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

.predict-dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.85rem;
  margin-bottom: 0.9rem;
}

.panel-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  box-shadow: var(--shadow);
  padding: 0.9rem;
}

.panel-card__head {
  margin-bottom: 0.75rem;
}

.panel-card__head h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
}

.panel-card__head p {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.panel-card__hint {
  margin: 0.6rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.trend-panel {
  min-height: 240px;
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.trend-title {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
}

.trend-text {
  margin: 0 0 0.6rem;
  font-size: 0.84rem;
  color: var(--text);
}

.trend-explain {
  margin: 0.45rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.mini-bars {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.mini-bar-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.mini-bar-label {
  width: 3rem;
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
}

.mini-bar-fill {
  display: inline-flex;
  align-items: center;
  min-height: 1.2rem;
  border-radius: 8px;
  padding: 0 0.45rem;
  font-size: 0.72rem;
  color: #fff;
  background: linear-gradient(90deg, #c8102e, #2563eb);
}

.chart-surface {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0.45rem;
  min-height: 130px;
}

.chart-svg {
  width: 100%;
  height: 120px;
  display: block;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line--avg {
  stroke: #2563eb;
  stroke-dasharray: 5 4;
}

.chart-caption {
  margin: 0.3rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.stack-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.25rem;
}

.stack-label {
  width: 2rem;
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.stack-bar {
  display: flex;
  height: 0.72rem;
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  background: #efe7dc;
}

.stack-seg {
  display: inline-block;
}

.stack-seg--0 { background: #c8102e; }
.stack-seg--1 { background: #a67c00; }
.stack-seg--2 { background: #2563eb; }

.comparison-grid {
  margin-top: 0.1rem;
}

.btn--predict {
  min-width: 10rem;
}

.result-status-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid rgba(200, 16, 46, 0.25);
  background: rgba(200, 16, 46, 0.08);
}

.result-summary {
  margin: 0 0 0.7rem;
  font-size: 0.84rem;
  color: var(--text);
}

.result-timestamp {
  margin: 0.7rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ----- Predict layout ----- */
.predict-run {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.predict-run--stream {
  margin-top: 0.25rem;
}

.stream-errors {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid rgba(185, 28, 28, 0.35);
  background: rgba(185, 28, 28, 0.06);
  font-size: 0.8125rem;
  color: var(--danger);
}

.stream-empty {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
  font-size: 0.8125rem;
  color: var(--muted);
  background: var(--surface);
}

.stream-error-line + .stream-error-line {
  margin-top: 0.35rem;
}

.model-stream {
  min-width: 0;
}

.chat-transcript {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  max-height: none;
  overflow: visible;
  scroll-margin-top: calc(var(--header-h) + 8px);
}

.chat-assistant-text {
  margin: 0 0 0.75rem;
}

.chat-prediction {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-elevated);
}

.chat-transcript > .chat-tools {
  margin-bottom: 0.75rem;
}

.chat-transcript > .chat-assistant-text:last-child,
.chat-transcript > .chat-tools:last-child {
  margin-bottom: 0;
}

.tools-inline {
  margin-top: 0.65rem;
  padding-top: 0.1rem;
}

.tools-inline.hidden {
  display: none;
}

.tools-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.875rem;
}

.status-bar__state {
  font-weight: 700;
  color: var(--text);
}

.status-bar__state.is-idle {
  color: var(--muted);
  font-weight: 600;
}

.status-bar__state.is-error {
  color: var(--danger);
}

.status-bar__state.is-success {
  color: var(--success);
}

.status-bar__meta {
  font-size: 0.8125rem;
  color: var(--muted);
}

.status-hint {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8125rem;
}

.status-hint__state {
  font-weight: 700;
  color: var(--text);
}

.status-hint__state.is-idle {
  color: var(--muted);
  font-weight: 600;
}

.status-hint__state.is-error {
  color: var(--danger);
}

.status-hint__state.is-success {
  color: var(--success);
}

.status-hint__meta {
  color: var(--muted);
}

.reasoning-text {
  margin: 0;
  padding: 0;
  max-height: none;
  overflow: visible;
  white-space: normal;
  word-break: break-word;
  font-size: 0.8125rem;
  line-height: 1.65;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--text);
}

.reasoning-text.streaming {
  color: var(--text);
}

.markdown-content p,
.markdown-content ul,
.markdown-content blockquote,
.markdown-content pre,
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6,
.markdown-content hr,
.markdown-content table {
  margin: 0 0 0.5rem;
}

.markdown-content p:last-child,
.markdown-content ul:last-child,
.markdown-content blockquote:last-child,
.markdown-content pre:last-child,
.markdown-content h1:last-child,
.markdown-content h2:last-child,
.markdown-content h3:last-child,
.markdown-content h4:last-child,
.markdown-content h5:last-child,
.markdown-content h6:last-child,
.markdown-content hr:last-child,
.markdown-content table:last-child {
  margin-bottom: 0;
}

.markdown-content ul {
  padding-left: 1.1rem;
}

.markdown-content code {
  padding: 0.08rem 0.3rem;
  border-radius: 6px;
  background: rgba(166, 124, 0, 0.14);
  font-family: "Consolas", "SFMono-Regular", "Courier New", monospace;
  font-size: 0.76rem;
}

.markdown-content pre {
  overflow-x: auto;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
}

.markdown-content pre code {
  padding: 0;
  background: transparent;
}

.markdown-content blockquote {
  margin-left: 0;
  padding-left: 0.6rem;
  border-left: 3px solid var(--accent-gold);
  color: var(--muted);
}

.markdown-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.65rem 0;
}

.markdown-content .md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  line-height: 1.5;
}

.markdown-content .md-table th,
.markdown-content .md-table td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.5rem;
  vertical-align: top;
}

.markdown-content .md-table th {
  background: var(--accent-gold-soft);
  font-weight: 700;
  color: var(--text);
}

.markdown-content .md-table td code {
  font-size: 0.74rem;
}

.tool-call {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.tool-call__title {
  margin: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.83rem;
  font-weight: 800;
  line-height: 1.45;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-elevated);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.tool-call__body {
  margin: 0.3rem 0 0.5rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(166, 124, 0, 0.08);
  overflow-x: auto;
}

.tool-call__title::-webkit-details-marker {
  display: none;
}

.tool-call__title::before {
  content: "▸";
  display: inline-block;
  margin-right: 0.35rem;
  color: var(--accent-gold);
  transition: transform 0.15s ease;
}

.tool-call[open] .tool-call__title::before {
  transform: rotate(90deg);
}

.tool-call__title:hover {
  border-color: rgba(200, 16, 46, 0.4);
  background: rgba(200, 16, 46, 0.05);
}

.tool-call:not([open]) .tool-call__body {
  display: none;
}

.tool-call--flat {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-elevated);
  padding: 0.4rem 0.5rem;
}

.tool-call--flat .tool-call__title {
  padding: 0;
  cursor: default;
  border: none;
  border-radius: 0;
  background: transparent;
}

.tool-call--flat .tool-call__title::before {
  display: none;
}

.tool-call.tool-call--flat .tool-call__body {
  margin: 0.3rem 0 0;
  padding: 0.45rem 0.5rem;
  border-left: 2px solid var(--accent-gold);
  border-radius: 0;
}

.tool-call--flat .tool-call__title:hover {
  border-color: transparent;
  background: transparent;
}

.tool-call.tool-call--flat .tool-call__body {
  display: block;
}

.tool-call__line {
  margin: 0;
  font-size: 0.775rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.tool-call__line + .tool-call__line {
  margin-top: 0.2rem;
}

.tool-call__line--result {
  color: var(--text);
}

/* Markdown 表格等块级元素需 normal，避免继承 .tool-call__line 的 pre-wrap */
.tool-call__line.markdown-content {
  white-space: normal;
}

.tool-round {
  margin-bottom: 0.45rem;
}

.result-dock {
  display: block;
  margin-top: 0.5rem;
  padding: 0.9rem;
  background: linear-gradient(180deg, var(--surface-elevated) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.result-dock.is-empty {
  padding: 0.9rem;
  font-size: 0.8125rem;
  color: var(--muted);
  box-shadow: var(--shadow);
  background: var(--surface);
}

.result-dock__title {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-gold);
  margin: 0 0 0.5rem;
}

.balls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.prediction-list {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
}

.prediction-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0.5rem 0.55rem;
}

.prediction-row--button {
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.prediction-row--button:hover {
  border-color: rgba(200, 16, 46, 0.35);
  background: #fff;
}

.prediction-row--button:focus-visible {
  box-shadow: var(--focus-ring);
}

.prediction-row__meta {
  margin: 0 0 0.4rem;
}

.prediction-row__meta--inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.prediction-row__balls-inline {
  gap: 0.45rem;
}

.prediction-row__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.result-status-tag.is-hit {
  color: #0f766e;
  border-color: rgba(15, 118, 110, 0.3);
  background: rgba(15, 118, 110, 0.1);
}

.result-status-tag.is-miss {
  color: #9a3412;
  border-color: rgba(154, 52, 18, 0.28);
  background: rgba(154, 52, 18, 0.1);
}

.dashboard-panel--pending .prediction-list {
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.dashboard-panel--compare .prediction-list {
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.ball {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.ball.red {
  background: var(--accent);
}

.ball.blue {
  background: #2563eb;
}

.ball.matched {
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.95),
    0 0 0 4px var(--accent-gold),
    0 0 8px rgba(166, 124, 0, 0.35);
  filter: brightness(1.03);
}

.ball-separator {
  color: var(--accent-gold);
  font-weight: 800;
}

/* Spinner */
.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: var(--accent-gold);
  border-radius: 999px;
  animation: spin 0.75s linear infinite;
}

.loading .spinner {
  display: inline-block;
}

.loading .btn-text {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ----- History ----- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  padding: 0.55rem 0.35rem;
  margin-bottom: 0.85rem;
  border: 1px solid rgba(166, 124, 0, 0.24);
  border-radius: 12px;
  background:
    radial-gradient(circle at 10% -26%, rgba(166, 124, 0, 0.18), transparent 50%),
    radial-gradient(circle at 92% 120%, rgba(200, 16, 46, 0.1), transparent 44%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(252, 248, 242, 0.92) 100%),
    var(--surface-elevated);
  position: relative;
  overflow: hidden;
  box-shadow:
    0 6px 16px rgba(44, 40, 37, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.kpi-row.kpi-row--compact-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi-row.kpi-row--compact-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kpi-row::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    rgba(166, 124, 0, 0) 0%,
    rgba(166, 124, 0, 0.52) 34%,
    rgba(200, 16, 46, 0.55) 68%,
    rgba(200, 16, 46, 0) 100%
  );
}

.kpi-item {
  min-width: 0;
  padding: 0.55rem 0.35rem;
  text-align: center;
  position: relative;
}

.kpi-item + .kpi-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18%;
  bottom: 18%;
  width: 1px;
  background: linear-gradient(
    180deg,
    rgba(166, 124, 0, 0.06) 0%,
    rgba(166, 124, 0, 0.25) 48%,
    rgba(166, 124, 0, 0.06) 100%
  );
}

.kpi-item__val {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.06;
  letter-spacing: 0.01em;
  text-shadow: 0 0 12px rgba(200, 16, 46, 0.14);
}

.kpi-item__val--gold {
  color: var(--accent-gold);
}

.kpi-item__lbl {
  margin-top: 0.24rem;
  font-size: 0.69rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  white-space: nowrap;
  line-height: 1.25;
  opacity: 0.9;
}

.kpi-item__val--draws-db {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  line-height: 1.08;
}

.kpi-item__draw-line {
  font-size: clamp(0.85rem, 3.1vw, 1.35rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(200, 16, 46, 0.14);
}

.kpi-item__draw-sub {
  font-size: clamp(0.52rem, 1.85vw, 0.69rem);
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.kpi-row.kpi-row--draws-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0;
  align-items: stretch;
}

.kpi-row__cluster--draws-left {
  display: flex;
  min-width: 0;
  width: 100%;
  align-items: stretch;
}

.kpi-row__cluster--draws-left > .kpi-item {
  flex: 1 1 0;
  min-width: 0;
}

.kpi-row__cluster--draws-right {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(11.5rem, 32vw);
  min-width: 7.5rem;
  align-self: stretch;
  border-left: 1px solid rgba(166, 124, 0, 0.22);
  background: linear-gradient(180deg, rgba(166, 124, 0, 0.05) 0%, transparent 48%);
}

.kpi-row__cluster--draws-right .kpi-item {
  min-width: 0;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  background: var(--surface);
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.data-table tbody tr:hover {
  background: var(--accent-gold-soft);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}

.badge--pending {
  border: 1px dashed var(--border);
  color: var(--muted);
  font-weight: 600;
}

.badge--none {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
}

.badge--prize {
  border: 1px solid rgba(166, 124, 0, 0.35);
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
}

.badge--reflection-queue {
  border: 1px dashed rgba(200, 16, 46, 0.45);
  color: var(--accent);
  font-weight: 600;
}

.badge--reflection-running {
  border: 1px solid rgba(200, 16, 46, 0.4);
  background: rgba(200, 16, 46, 0.08);
  color: var(--accent);
  font-weight: 600;
}

.badge--reflection-ok {
  border: 1px solid rgba(34, 139, 34, 0.35);
  background: rgba(34, 139, 34, 0.08);
  color: #1f6b1f;
}

.ball--sm {
  width: 28px;
  height: 28px;
  font-size: 0.7rem;
}

.history-mobile-cards {
  display: none;
  flex-direction: column;
  gap: 0.65rem;
}

.history-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  background: var(--surface-elevated);
  box-shadow: var(--shadow);
}

.history-card:hover {
  border-color: rgba(200, 16, 46, 0.25);
}

.infinite-scroll-foot {
  margin-top: 0.75rem;
  min-height: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.infinite-scroll-sentinel {
  width: 100%;
  height: 1px;
  pointer-events: none;
}

.infinite-scroll-status {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 767px) {
  .kpi-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    padding: 0.35rem 0.1rem;
    overflow: hidden;
  }

  .kpi-row.kpi-row--compact-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .kpi-row.kpi-row--compact-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-row.kpi-row--draws-split {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .kpi-row__cluster--draws-left {
    display: flex;
  }

  .kpi-row__cluster--draws-left > .kpi-item {
    flex: 1 1 0;
    min-width: 0;
  }

  .kpi-row__cluster--draws-right {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(10.5rem, 40vw);
    min-width: 6.25rem;
  }

  .kpi-item {
    padding: 0.42rem 0.12rem;
  }

  .kpi-item__val {
    font-size: clamp(0.94rem, 3.9vw, 1.08rem);
    line-height: 1.02;
  }

  .kpi-item__lbl {
    font-size: clamp(0.53rem, 2.15vw, 0.6rem);
    letter-spacing: 0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .kpi-item + .kpi-item::before {
    top: 25%;
    bottom: 25%;
  }

  .dashboard-kpi {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .dashboard-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "latest"
      "neural"
      "pending"
      "compare";
    gap: 0.65rem;
  }

  .app-main--predict {
    padding-top: 0.6rem;
  }

  .dashboard-layout::before {
    content: none;
  }

  .dashboard-panel--latest {
    margin-top: 0;
    border-radius: 12px;
  }

  .dashboard-panel {
    padding: 0.75rem;
  }

  .dashboard-kpi__card {
    padding: 0.7rem 0.75rem;
  }

  .dashboard-kpi__value {
    font-size: 1rem;
  }

  .dashboard-kpi__value--small {
    font-size: 0.84rem;
  }

  .dashboard-panel--pending .prediction-list,
  .dashboard-panel--compare .prediction-list {
    max-height: none;
  }

  .predict-dashboard {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }

  .trend-grid {
    grid-template-columns: 1fr;
  }

  .panel-card {
    padding: 0.75rem;
  }

  .btn--predict {
    width: 100%;
  }

  .header-actions {
    gap: 0.3rem;
  }

  .fab-btn {
    min-width: 32px;
    height: 32px;
  }

  .fab-btn__icon {
    font-size: 0.92rem;
  }

  .fab-btn::after {
    display: none;
  }

  .ball {
    width: 34px;
    height: 34px;
    font-size: 0.8rem;
  }

  .chat-transcript {
    max-height: min(56vh, 560px);
  }

  .table-wrap {
    display: none;
  }

  .history-mobile-cards {
    display: flex;
  }
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pagination.is-hidden {
  display: none;
}

.skeleton-block {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.alert {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-top: 0.75rem;
}

.alert--error {
  background: rgba(185, 28, 28, 0.08);
  border: 1px solid rgba(185, 28, 28, 0.25);
  color: var(--danger);
}

.alert--success {
  background: rgba(21, 128, 61, 0.08);
  border: 1px solid rgba(21, 128, 61, 0.25);
  color: var(--success);
}

/* ----- Drawer ----- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  visibility: hidden;
}

.drawer.is-open {
  pointer-events: auto;
  visibility: visible;
}

body.drawer-open {
  overflow: hidden;
  padding-right: var(--drawer-scrollbar-compensation, 0);
}

.drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(44, 40, 37, 0.45);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.drawer.is-open .drawer__backdrop {
  opacity: 1;
}

.drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(100%, 520px);
  max-width: 100vw;
  background: var(--surface-elevated);
  box-shadow: -8px 0 24px rgba(44, 40, 37, 0.12);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
}

.drawer.is-open .drawer__panel {
  transform: translateX(0);
}

.drawer__head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  height: var(--header-h);
  padding: 0 0.85rem;
  border-bottom: 1px solid var(--border);
}

.drawer__head h2 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.2;
  font-weight: 800;
  color: var(--accent);
}

.drawer__head .btn {
  height: 2rem;
  padding: 0 0.4rem;
  min-height: 0;
  border-radius: 7px;
  font-size: 0.95rem;
  line-height: 1;
}

.drawer__head time,
.drawer__head .sub {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
}

.drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem 1rem;
  min-height: 0;
}

.drawer-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin: 0 -1rem 0.75rem;
  padding: 0 0.5rem;
}

.drawer-tab {
  padding: 0.5rem 0.65rem;
  font-size: 0.8125rem;
  font-weight: 700;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.drawer-tab:hover {
  color: var(--accent);
}

.drawer-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.drawer-panel {
  display: none;
}

.drawer-panel.is-active {
  display: block;
}

.step-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--surface);
  font-size: 0.8125rem;
}

.step-card__round {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

/* ----- Setup ----- */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.field input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  font-family: inherit;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.field input:disabled {
  opacity: 0.6;
  background: var(--surface);
}

.form-section {
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.hidden {
  display: none !important;
}

.link-inline {
  font-weight: 600;
}

/* ----- Memory ----- */
.app-main--memory {
  max-width: 52rem;
}

.memory-toolbar {
  margin-bottom: 0.65rem;
}

.memory-file-tabs-shell {
  flex: 1;
  min-width: 0;
}

.memory-file-tabs-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.memory-file-tabs {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 0.15rem;
  padding: 0 0.15rem 0 0;
  min-height: 2.35rem;
}

.memory-file-tab {
  flex: 0 0 auto;
  max-width: none;
  padding: 0.45rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  border-radius: 8px 8px 0 0;
}

.memory-file-tab:hover {
  color: var(--accent);
  background: rgba(200, 16, 46, 0.06);
}

.memory-file-tab:focus-visible {
  outline: none;
  border-bottom-color: transparent;
  box-shadow: var(--focus-ring);
}

.memory-file-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(200, 16, 46, 0.08);
}

.memory-panel {
  position: relative;
  border: 1px solid rgba(166, 124, 0, 0.22);
  border-radius: 12px;
  background: var(--surface-elevated);
  padding: 1rem 1.1rem;
  padding-top: 0.85rem;
  min-height: 12rem;
  box-shadow:
    0 4px 14px rgba(44, 40, 37, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.memory-panel__refresh {
  position: absolute;
  top: 0.55rem;
  right: 0.5rem;
  z-index: 2;
  border-radius: 9px;
  color: var(--muted);
}

.memory-panel__refresh:hover:not(:disabled) {
  color: var(--accent);
  background: rgba(200, 16, 46, 0.08);
}

.memory-panel__refresh:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.memory-panel__content {
  padding-right: 2.5rem;
  padding-top: 0.15rem;
}

.memory-panel .markdown-content {
  font-size: 0.875rem;
  line-height: 1.55;
}

.memory-empty {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0;
}
