:root {
  --primary-color: #4f3c8b;
  --primary-hover: #6652a6;
  --primary-active: #3f2f71;
  --primary-surface: #f3f0fb;
  --success-color: #52c41a;
  --warning-color: #faad14;
  --error-color: #f5222d;
  --info-color: #4f3c8b;
  
  --text-primary: #262626;
  --text-secondary: #595959;
  --text-tertiary: #8c8c8c;
  --text-placeholder: #bfbfbf;
  
  --bg-color: #f5f5f5;
  --bg-container: #ffffff;
  --bg-hover: #fafafa;
  
  --border-color: #d9d9d9;
  --border-light: #f0f0f0;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 24px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-color);
}

.app-shell {
  display: flex;
  height: 100vh;
}

.left-rail {
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  padding: var(--spacing-md) 0 var(--spacing-md) var(--spacing-md);
  flex-shrink: 0;
}

.nav-sidebar {
  flex: 1;
  min-height: 0;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand-panel {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
}

.brand-kicker {
  display: none;
}

.brand-panel h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--primary-color);
}

.nav-list {
  display: flex;
  flex-direction: column;
  padding: 8px;
  flex: 1;
  overflow-y: auto;
}

.nav-button {
  display: block;
  text-align: left;
  align-self: stretch;
  min-height: 36px;
  padding: 8px 12px;
  margin-bottom: 4px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-button:hover {
  background: var(--primary-surface);
  color: var(--primary-color);
}

.nav-button.is-active {
  background: var(--primary-surface);
  color: var(--primary-color);
}

.nav-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nav-empty {
  margin: 0;
  padding: 12px;
  color: var(--text-tertiary);
  font-size: 13px;
}

.main-stage {
  flex: 1;
  display: flex;
  padding: var(--spacing-md);
  gap: var(--spacing-md);
  overflow: hidden;
  min-width: 0;
}

.workspace-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.description-card {
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  padding: 15px;
  margin-bottom: 5px;
  box-shadow: 0 2px 8px rgba(31, 41, 55, .06);
}

.description-card h2 {
  margin: 0 0 8px;
  color: var(--text-strong, #374151);
  font-size: 1.15rem;
  line-height: 1.45;
}

.description-card p,
.description-content p {
  margin: 0;
  color: var(--text-muted, #4b5563);
  font-size: .95rem;
  line-height: 1.7;
  white-space: pre-line;
}

.description-content {
  color: var(--text-muted, #4b5563);
  font-size: .9rem;
  line-height: 1.55;
  white-space: pre-line;
}


.side-panel {
  width: 300px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: var(--spacing-md);
  min-width: 0;
  overflow-y: auto;
}

.surface-card,
.language-card,
.control-card,
.result-card,
.memory-card {
  background: var(--bg-container);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.surface-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.surface-card > .card-header {
  display: none;
}

.card-header {
  display: flex;
  align-items: center;
  padding: var(--spacing-md) var(--spacing-lg);
  background: linear-gradient(180deg, #fafafa 0%, #f5f5f5 100%);
  border-bottom: 1px solid var(--border-light);
  gap: var(--spacing-sm);
}

.card-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.card-header h3:first-child {
  margin-right: auto;
}

.header-action-button {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.header-action-button:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.header-action-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.benchmark-surface {
  flex: 1;
  margin: var(--spacing-md);
  padding: var(--spacing-md);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  background: #ffffff;
  overflow-y: auto;
}

.surface-stack {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--spacing-md);
}

.surface-slot {
  padding: var(--spacing-md);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.surface-slot.is-list {
  grid-column: 1 / -1;
}

.surface-label {
  margin: 0 0 var(--spacing-sm);
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 500;
}

.control-card {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.language-card {
  flex: 0 0 auto;
  padding: var(--spacing-sm);
}

.language-switcher {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}

.language-switcher select {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}

.language-switcher select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(79, 60, 139, 0.18);
}

.control-body {
  padding: var(--spacing-md);
}

.panel-stack {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.panel-stack > * {
  margin: 0;
}

.result-card {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.results-body {
  padding: var(--spacing-md);
}

.memory-card {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 118px;
  max-height: none;
}

.memory-card[hidden] {
  display: none;
}

#memoryMonitorPanel {
  padding: var(--spacing-sm);
  overflow: hidden;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  margin: 0;
}

.field[hidden] {
  display: none;
}

.field-action {
  gap: 0;
}

.field-action-wide {
  width: 100%;
}

.field-label,
.checkbox-row span {
  display: block;
  margin-bottom: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.field-input {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-primary);
  font-size: 14px;
  transition: all 0.2s ease;
}

.field-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(79, 60, 139, 0.18);
}

.select-input-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
}

.select-input-wrapper::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--text-tertiary);
  pointer-events: none;
}

.field-textarea {
  min-height: 80px;
  resize: vertical;
  padding: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin: 0;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.checkbox-row span {
  margin-bottom: 0;
  cursor: pointer;
}

.button-grid,
.button-stack {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.button-grid .action-button {
  width: 100%;
}

.action-wide {
  width: 100%;
}

.action-wide + .action-wide {
  margin-top: var(--spacing-sm);
}

.action-button {
  height: 32px;
  padding: 0 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-button:hover:not(:disabled) {
  opacity: 0.85;
}

.action-button:active:not(:disabled) {
  transform: scale(0.98);
}

.action-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.action-blue {
  background: var(--primary-color);
  color: #ffffff;
}

.action-blue:hover {
  background: var(--primary-hover);
}

.action-green {
  background: var(--success-color);
  color: #ffffff;
}

.action-gray {
  background: #f5f5f5;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.action-gray:hover {
  background: #e8e8e8;
}

.result-group {
  margin-bottom: var(--spacing-lg);
}

.result-group:last-child {
  margin-bottom: 0;
}

.results-group-label {
  margin-bottom: var(--spacing-sm);
  padding-left: var(--spacing-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.result-item {
  margin-bottom: var(--spacing-xs);
}

.result-item:last-child {
  margin-bottom: 0;
}

.metric-label-inline {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: normal;
  overflow-wrap: anywhere;
}

.metric-empty,
.empty-state {
  padding: var(--spacing-md);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  background: #fafafa;
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
}

.metric-result {
  padding: var(--spacing-md);
  border-left: 4px solid var(--success-color);
  background: #f6ffed;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.metric-result.metric-compact {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  padding: 4px var(--spacing-sm);
}

.metric-result.metric-compact .metric-value {
  font-size: 13px;
  font-weight: 600;
}

.metric-result.metric-compact .metric-value {
  margin-left: auto;
}

.metric-copy-button {
  flex-shrink: 0;
  min-width: 46px;
  padding: 2px 8px;
  border: 1px solid rgba(31, 79, 136, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: #1f4f88;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.metric-copy-button:hover {
  background: #ffffff;
  border-color: rgba(31, 79, 136, 0.28);
}

.metric-copy-button.is-copied {
  color: #1f7a36;
  border-color: rgba(31, 122, 54, 0.28);
}

.metric-copy-button.is-failed {
  color: #b42318;
  border-color: rgba(180, 35, 24, 0.28);
}

.metric-info-button {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: #ffffff;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 600;
  font-style: italic;
  cursor: help;
  transition: all 0.2s ease;
}

.metric-info-button:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.metric-result.is-warn {
  border-left-color: var(--warning-color);
  background: #fffbe6;
}

.metric-result.is-slow,
.metric-result.is-error {
  border-left-color: var(--error-color);
  background: #fff2f0;
}

.metric-result.is-neutral {
  border-left-color: var(--text-tertiary);
  background: #fafafa;
}

.metric-result.is-unknown {
  border-left-color: var(--text-tertiary);
  background: #fafafa;
}

.metric-result.is-unknown .metric-value {
  color: var(--text-tertiary);
  font-weight: 400;
}

.metric-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.metric-result.is-warn .metric-value {
  color: var(--warning-color);
}

.metric-result.is-slow .metric-value,
.metric-result.is-error .metric-value {
  color: var(--error-color);
}

.metric-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  margin-top: var(--spacing-sm);
}

.metric-meta span {
  font-size: 12px;
  color: var(--text-tertiary);
}

.metric-note {
  margin-top: var(--spacing-sm);
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.5;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  margin: 0;
}

.control-group-label {
  display: block;
  margin-bottom: var(--spacing-sm);
  padding-left: var(--spacing-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: none;
  border: none;
  padding: 0;
  cursor: default;
}

.control-group-toggle {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.control-group-toggle:hover {
  color: var(--text-secondary);
}

.control-group-toggle::before {
  content: "▶";
  font-size: 8px;
  color: var(--text-tertiary);
  transition: transform 0.2s ease;
}

.control-group-toggle[aria-expanded="true"]::before {
  transform: rotate(90deg);
}

.control-group-collapsible .button-stack,
.control-group-collapsible .button-grid {
  overflow: hidden;
  transition: all 0.2s ease;
}

.control-group-collapsible .button-stack[hidden],
.control-group-collapsible .button-grid[hidden] {
  display: none !important;
}

.runtime-box {
  margin-bottom: var(--spacing-md);
  padding: var(--spacing-md);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: #fafafa;
}

.runtime-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.runtime-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.runtime-copy {
  margin-top: var(--spacing-xs);
  font-size: 12px;
  color: var(--text-tertiary);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 500;
  background: #f5f5f5;
  color: var(--text-secondary);
}

.status-badge.status-ready {
  background: #f6ffed;
  color: var(--success-color);
}

.status-badge.status-error {
  background: #fff2f0;
  color: var(--error-color);
}

.benchmark-title-card {
  margin-bottom: var(--spacing-md);
  background: var(--bg-container);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.title-shell {
  padding: var(--spacing-lg);
}

.title-kicker {
  display: block;
  margin-bottom: var(--spacing-xs);
  font-size: 12px;
  font-weight: 500;
  color: var(--primary-color);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.benchmark-title-card h2 {
  margin: 0 0 var(--spacing-sm);
  font-size: 20px;
  font-weight: 500;
  color: var(--text-primary);
}

.title-copy {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.module-alert {
  margin: 0;
  padding: var(--spacing-md) var(--spacing-lg);
  border-top: 1px solid rgba(245, 34, 45, 0.2);
  background: #fff2f0;
  color: var(--error-color);
  font-size: 13px;
}

.module-alert.is-hidden {
  display: none;
}

/* Memory Monitor */
.memory-monitor {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: var(--spacing-xs);
  min-height: 0;
}

.memory-monitor-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  min-height: 0;
}

.memory-monitor-main {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex: 1;
  min-height: 0;
}

.memory-current {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 2px;
  width: 58px;
  flex-shrink: 0;
}

.memory-value {
  min-width: 38px;
  font-size: 18px;
  font-weight: 600;
  text-align: right;
  color: var(--text-primary);
}

.memory-unit {
  font-size: 11px;
  color: var(--text-tertiary);
}

.memory-chart-container {
  flex: 1;
  align-self: stretch;
  min-height: 44px;
  position: relative;
}

.memory-chart {
  width: 100%;
  height: 100%;
  display: block;
}

@media (max-width: 1024px) {
  html, body {
    overflow: auto;
  }

  .app-shell {
    flex-direction: column;
    min-width: 0;
  }

  .left-rail {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-sm) 0;
    gap: var(--spacing-sm);
  }

  .nav-sidebar {
    flex: none;
  }

  .brand-panel {
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .brand-panel h1 {
    display: block;
  }

  .nav-list {
    flex: none;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm);
    overflow-x: auto;
    overflow-y: hidden;
  }

  .nav-button {
    align-self: auto;
    flex: 0 0 auto;
    min-width: 0;
    margin-bottom: 0;
    font-size: 13px;
    white-space: nowrap;
  }

  .main-stage {
    flex-direction: column;
    overflow: auto;
  }

  .workspace-column,
  .side-panel {
    width: 100%;
  }

  .side-panel {
    flex-direction: column;
  }

  .control-card,
  .language-card,
  .result-card,
  .memory-card {
    flex: none;
  }

  .memory-card {
    min-height: 118px;
  }

  #memoryMonitorPanel {
    height: 72px;
    max-height: 72px;
  }

  .memory-monitor,
  .memory-monitor-content {
    height: auto;
    max-height: 56px;
  }

  .memory-monitor-main {
    flex: none;
    height: 56px;
  }

  .memory-chart-container {
    flex: 1 1 auto;
    height: 44px;
    min-height: 44px;
    max-height: 44px;
  }

  .surface-card {
    flex: none;
    max-height: min(70vh, 720px);
  }
}

@media (max-width: 768px) {
  .main-stage {
    padding: var(--spacing-sm);
    gap: var(--spacing-sm);
  }

  .workspace-column {
    width: 100%;
  }

  .side-panel {
    width: 100%;
    gap: var(--spacing-sm);
  }

  .button-grid {
    grid-template-columns: 1fr;
  }

  .benchmark-surface {
    margin: var(--spacing-sm);
    padding: var(--spacing-sm);
  }

  .surface-stack {
    grid-template-columns: minmax(0, 1fr);
  }

  .surface-card {
    max-height: 60vh;
  }
}

@media (max-width: 560px) {
  .card-header {
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .nav-button {
    font-size: 12px;
  }

  .title-shell,
  .control-body,
  .results-body,
  #memoryMonitorPanel {
    padding: var(--spacing-sm);
  }

  .header-action-button {
    padding: 0 8px;
  }
}
