:root {
  --bg: oklch(97% 0.008 90);
  --surface: oklch(99% 0.005 90);
  --surface-2: oklch(96% 0.012 80);
  --surface-3: oklch(94% 0.020 80);
  --border: oklch(86% 0.010 80);
  --ink: oklch(18% 0.005 330);
  --muted: oklch(34% 0.005 330);
  --muted-2: oklch(54% 0.005 330);
  --accent: oklch(46% 0.13 330);
  --accent-hover: oklch(58% 0.16 330);
  --accent-fg: oklch(99% 0.004 330);
  --danger: oklch(38% 0.080 30);
  --display: 'Space Grotesk', 'Plus Jakarta Sans', system-ui, sans-serif;
  --body: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.history-page {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  min-height: 100vh;
}

.history-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 64px 24px;
}

@media (max-width: 640px) {
  .history-main { padding: 40px 20px; }
}

.history-back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.history-back-link:hover { color: var(--accent-hover); }

.history-title {
  margin: 12px 0 8px;
  font-family: var(--display);
  font-size: clamp(1.7rem, 4vw, 2.3rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.history-subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.history-info-box {
  margin-top: 32px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  color: var(--muted-2);
}

.history-info-box a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.history-info-box a:hover { color: var(--accent-hover); }

.hidden { display: none !important; }

.history-list {
  margin-top: 32px;
}

.run-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 16px;
  padding: 16px;
  margin-top: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.run-btn:first-of-type { margin-top: 0; }
.run-btn:hover { border-color: var(--accent); background: var(--surface-2); }

.run-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.run-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface-3);
  color: var(--accent);
  font-size: 1.1rem;
}

.run-text {
  min-width: 0;
  flex: 1;
}

.run-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 0.98rem;
}

.run-meta {
  margin-top: 2px;
  font-size: 0.8rem;
  color: var(--muted-2);
}

.run-chevron { color: var(--muted-2); }
.run-btn:hover .run-chevron { color: var(--accent); }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: oklch(18% 0.005 330 / 0.55);
  padding: 20px;
}

.viewer.is-open { display: flex; }

.viewer-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 960px;
  max-height: 90vh;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 24px;
  box-shadow: 0 24px 80px -30px oklch(20% 0 0 / 0.3);
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
}

.viewer-title {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 1rem;
}

.viewer-meta {
  font-size: 0.82rem;
  color: var(--muted-2);
  margin-top: 2px;
}

.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.history-chip:hover { background: var(--surface-3); }

.history-chip--primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
  box-shadow: inset 0 1px 0 var(--accent-hover);
}

.history-chip--primary:hover { background: var(--accent-hover); }

.history-chip--danger {
  background: var(--danger);
  color: var(--accent-fg);
  border-color: transparent;
}

.history-chip--danger:hover { background: oklch(45% 0.10 30); }

.viewer-rendered {
  flex: 1;
  overflow: auto;
  padding: 24px;
  background: var(--surface-2);
}

.viewer-raw {
  flex: 1;
  padding: 16px;
  border: 0;
  outline: none;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.55;
  resize: none;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 16px 0 8px;
  line-height: 1.25;
  font-family: var(--display);
  letter-spacing: -0.01em;
}

.markdown-body h1 { font-size: 1.5rem; }
.markdown-body h2 { font-size: 1.2rem; }
.markdown-body h3 { font-size: 1.05rem; }

.markdown-body p,
.markdown-body li {
  font-size: 0.95rem;
  line-height: 1.6;
}

.markdown-body table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.88rem;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.markdown-body th { background: oklch(92% 0.015 80); }

.markdown-body code {
  background: oklch(92% 0.015 80);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85rem;
}

.markdown-body pre {
  background: var(--ink);
  color: oklch(94% 0.012 80);
  padding: 12px;
  border-radius: 10px;
  overflow: auto;
  font-size: 0.82rem;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 6px 14px;
  color: var(--muted);
  background: var(--surface);
  border-radius: 0 8px 8px 0;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.markdown-body img { max-width: 100%; }

/* Dashboard integration */
.dashboard-body.history-page { background: var(--dash-bg); font-family: "Plus Jakarta Sans", "Inter", sans-serif; }
.dashboard-body .history-main { max-width: 1172px; padding: 46px 26px 4rem; }
.dashboard-body .history-back-link,
.dashboard-body .history-title,
.dashboard-body .history-subtitle,
.dashboard-body .history-info-box,
.dashboard-body .history-list { max-width: 820px; }
.dashboard-body .history-title { font-size: var(--dash-page-title-size); line-height: 1.12; }
.dashboard-body .history-subtitle { font-size: 1rem; }
.dashboard-body .history-info-box,
.dashboard-body .viewer-card,
.dashboard-body .run-btn { border-radius: .8rem; box-shadow: none; }
.dashboard-body .history-chip { font-size: .8rem; }

@media (max-width: 640px) {
  .dashboard-body .history-main { padding: 2rem 18px 3rem; }
}
