:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #243044;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --text-muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 8px;
  --font: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SF Mono", "Fira Code", "Consolas", monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(100%, 360px);
}

.login-panel {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-panel h1 {
  margin-bottom: 6px;
  font-size: 1.25rem;
}

.login-panel p {
  margin-bottom: 20px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.login-panel .btn {
  width: 100%;
}

.login-error {
  margin-bottom: 14px;
  padding: 8px 10px;
  border: 1px solid rgba(239, 68, 68, 0.45);
  border-radius: var(--radius);
  color: #fecaca;
  background: rgba(239, 68, 68, 0.12);
  font-size: 0.875rem;
}

/* Full-height app shell (test page only; the admin page scrolls normally) */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Test page: three tracks so the tabs sit dead center regardless of side widths */
.app-shell .header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
}

.app-shell .header h1 {
  justify-self: start;
}

.app-shell .header .tabs {
  justify-self: center;
}

.app-shell .header-nav {
  justify-self: end;
}

.header h1 {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

/* Grid header places it in the last track; auto margin would double up */
.app-shell .header-nav {
  margin-left: 0;
}

.header-nav a {
  font-size: 0.875rem;
}

.logout-form {
  display: contents;
}

.user-chip {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  align-self: stretch;
  min-width: 0;
}

.tab {
  padding: 0 18px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Layout */
.main-layout {
  display: grid;
  grid-template-columns: 560px 560px minmax(420px, 1fr);
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--border);
  --panel-bg: var(--bg);
  background: var(--panel-bg);
}

.panel:last-child {
  border-right: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px;
  overscroll-behavior: contain;
}

.panel-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
}

.section-divider {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 22px 0 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.select-all {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.select-all:hover {
  color: var(--text);
}

.select-all input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}
/* Form */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
}

.form-group textarea {
  font-family: var(--mono);
  font-size: 0.8125rem;
  min-height: 120px;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Checkbox list */
.check-list {
  list-style: none;
}

.check-list li {
  margin-bottom: 6px;
}

.check-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s;
}

.check-list label:hover {
  background: var(--surface-hover);
}

.check-list input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* Model row: checkbox + name + inline rename controls */
.model-item {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 6px;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.model-item:hover {
  background: var(--surface-hover);
}

.model-item > label {
  flex: 1;
  min-width: 0;
}

.model-item > label:hover {
  background: transparent;
}

.model-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-item.renamed .model-name {
  color: var(--warning);
}

.alias-tag {
  font-size: 0.6875rem;
  color: var(--warning);
  background: rgba(245, 158, 11, 0.15);
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  cursor: help;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1;
  padding: 5px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.model-item:hover .icon-btn,
.model-item.renamed .icon-btn,
.model-item.editing .icon-btn {
  opacity: 1;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--border);
}

.model-item.editing {
  gap: 4px;
  padding: 4px 6px 4px 10px;
  background: var(--surface-hover);
}

.model-name-input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
}

.model-name-input:focus {
  outline: none;
}

/* Test case list */
.group-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.group-filter:empty {
  display: none;
}

.group-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.group-chip:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.group-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.chip-count {
  font-size: 0.6875rem;
  opacity: 0.75;
}

.group-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.16);
  color: var(--accent);
  font-size: 0.6875rem;
  white-space: nowrap;
}

.case-list {
  list-style: none;
}

.case-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  border: 1px solid transparent;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, border-color 0.15s;
}

.case-item .case-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-item .case-open {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  padding: 4px 6px;
  opacity: 0;
  white-space: nowrap;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.case-item:hover .case-open {
  opacity: 1;
}

.case-item .case-open:hover {
  color: var(--text);
  background: var(--border);
}

.case-item:hover {
  background: var(--surface-hover);
}

.case-item.active {
  background: var(--surface-hover);
}

.case-item.selected .case-open {
  color: var(--text-muted);
}

.case-item input[type="checkbox"] {
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* Case detail */
.detail-section {
  margin-bottom: 20px;
}

.detail-section h3 {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.detail-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.curl-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: var(--mono);
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 320px;
  overflow-y: auto;
}

.validation-list {
  list-style: none;
}

.validation-list li {
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--radius);
  margin-bottom: 6px;
  font-size: 0.8125rem;
  font-family: var(--mono);
}

.validation-list .desc {
  font-family: var(--font);
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 2px;
}

/* Run bar */
.run-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.run-hint,
#run-status {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
}

.concurrency-select {
  width: auto;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
}

/* Results */
#results-panel {
  --panel-bg: var(--surface);
}

#results-panel .panel-head {
  gap: 16px;
}

#results-panel .panel-head .summary-bar {
  margin-bottom: 0;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.result-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 10px;
}

.result-card.pass {
  border-left: 3px solid var(--success);
}

.result-card.fail {
  border-left: 3px solid var(--danger);
}

.result-card.skipped {
  border-left: 3px solid var(--text-muted);
  opacity: 0.92;
}

.result-matrix-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.result-matrix-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.result-matrix-title {
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.matrix-export-btn {
  flex-shrink: 0;
}

.result-matrix-scroll {
  overflow-x: auto;
}

.result-matrix {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.result-matrix th,
.result-matrix td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.result-matrix thead th {
  color: var(--text-muted);
  background: var(--surface);
  font-weight: 600;
}

.result-matrix .matrix-case-col,
.result-matrix .matrix-case-name {
  position: sticky;
  left: 0;
  z-index: 1;
  max-width: 260px;
  min-width: 180px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-matrix .matrix-case-col {
  z-index: 2;
}

.result-matrix .matrix-case-name {
  background: var(--bg);
  font-weight: 500;
}

.matrix-cell.pass {
  color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}

.matrix-cell.fail {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.matrix-cell.missing {
  color: var(--text-muted);
  background: rgba(139, 156, 179, 0.08);
}

.matrix-cell.skipped {
  color: var(--text-muted);
  background: rgba(139, 156, 179, 0.12);
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.result-title {
  font-weight: 600;
  font-size: 0.9375rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.pass {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.badge.fail {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.badge.pending {
  background: rgba(139, 156, 179, 0.15);
  color: var(--text-muted);
}

.badge.skipped {
  background: rgba(139, 156, 179, 0.15);
  color: var(--text-muted);
}

/* Placeholder cards shown while a run is in flight */
.result-card.pending {
  border-left: 3px solid var(--border);
  animation: pulse 1.4s ease-in-out infinite;
}

.result-card.pending .result-header {
  margin-bottom: 0;
}

.result-card.pending .result-title {
  color: var(--text-muted);
  font-weight: 500;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.85;
  }
}

.running-indicator {
  display: inline-flex;
  align-items: center;
  color: var(--accent);
}

.running-indicator .loading {
  border-color: rgba(59, 130, 246, 0.25);
  border-top-color: var(--accent);
}

.result-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.validation-result {
  font-size: 0.8125rem;
  padding: 4px 0;
  font-family: var(--mono);
}

.validation-result.pass {
  color: var(--success);
}

.validation-result.fail {
  color: var(--danger);
}

.response-preview {
  margin-top: 8px;
  padding: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.75rem;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.response-full {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.response-full summary {
  cursor: pointer;
  user-select: none;
}

.response-preview-full {
  max-height: 520px;
}

#results-panel .response-preview {
  background: var(--surface-hover);
}

.summary-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 0.875rem;
  flex-wrap: wrap;
}

.summary-bar .pass-count {
  color: var(--success);
}

.summary-bar .fail-count {
  color: var(--danger);
}

.loading {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

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

.empty-state {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
  padding: 32px 16px;
}

/* Admin page */
.admin-container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
}

.admin-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-tab {
  appearance: none;
  padding: 12px 18px;
  min-height: 44px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.admin-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.admin-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 0;
}

.admin-panel[hidden] {
  display: none;
}

.admin-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.admin-section h2 {
  font-size: 1.125rem;
  margin-bottom: 4px;
}

.admin-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0;
}

.admin-inline-control {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 380px;
  margin-bottom: 14px;
}

.admin-inline-control label {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.admin-inline-control select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
}

.admin-case-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  min-height: 20px;
  margin-bottom: 8px;
}

.admin-filter-summary {
  color: var(--text-muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.admin-group-filter {
  margin-bottom: 12px;
}

.syntax-hint {
  margin: 0 0 10px;
  line-height: 1.8;
}

.syntax-hint code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text);
}

.muted {
  color: var(--text-muted);
}

.admin-table .empty-state {
  padding: 20px 0;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.admin-table th,
.admin-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.admin-table tr:hover td {
  background: var(--surface-hover);
}

.admin-actions {
  white-space: nowrap;
}

.admin-actions .btn {
  white-space: nowrap;
}

.admin-actions .btn + .btn {
  margin-left: 8px;
}

.sort-input {
  width: 72px;
  padding: 5px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
}

.sort-input:focus {
  outline: none;
  border-color: var(--accent);
}

.sort-input:disabled {
  opacity: 0.6;
}

.cases-admin-table {
  table-layout: fixed;
  min-width: 980px;
}

.cases-admin-table th:nth-child(1),
.cases-admin-table td:nth-child(1) {
  width: 24%;
}

.cases-admin-table th:nth-child(2),
.cases-admin-table td:nth-child(2) {
  width: 16%;
}

.cases-admin-table th:nth-child(3),
.cases-admin-table td:nth-child(3) {
  width: auto;
}

.cases-admin-table th:nth-child(4),
.cases-admin-table td:nth-child(4) {
  width: 18%;
}

.cases-admin-table th:nth-child(5),
.cases-admin-table td:nth-child(5) {
  width: 96px;
}

.cases-admin-table th:nth-child(6),
.cases-admin-table td:nth-child(6) {
  width: 90px;
}

.cases-admin-table th:nth-child(7),
.cases-admin-table td:nth-child(7) {
  width: 180px;
}

.model-patterns {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.8125rem;
}

.monitors-admin-table {
  min-width: 1100px;
}

.monitor-name-cell {
  font-weight: 600;
}

.monitor-sub-cell {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.monitor-url-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.8125rem;
}

.monitor-status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(139, 156, 179, 0.16);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.monitor-status.running {
  color: var(--accent);
  background: rgba(59, 130, 246, 0.16);
}

.monitor-status.passed {
  color: var(--success);
  background: rgba(34, 197, 94, 0.14);
}

.monitor-status.failed,
.monitor-status.error {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.14);
}

.monitor-status.disabled {
  color: var(--text-muted);
  background: rgba(139, 156, 179, 0.1);
}

.monitor-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 14px;
}

.monitor-enabled {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  margin-top: 20px;
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
}

.monitor-enabled input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.monitor-pickers {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 14px;
  margin-top: 6px;
}

.monitor-picker {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}

.monitor-picker-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.monitor-picker-head label {
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
}

.monitor-check-list {
  max-height: 260px;
  overflow-y: auto;
  padding: 8px;
}

.monitor-check-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  border-radius: 6px;
  color: var(--text);
  font-size: 0.8125rem;
  cursor: pointer;
}

.monitor-check-item:hover {
  background: var(--surface-hover);
}

.monitor-check-item input {
  width: 15px;
  height: 15px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.monitor-check-item span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.monitor-check-item small {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.6875rem;
}

@media (max-width: 760px) {
  .admin-container {
    padding: 14px 12px 24px;
  }

  .admin-tabs {
    overflow-x: auto;
    scrollbar-width: thin;
    margin: 0 -12px 14px;
    padding: 0 12px;
  }

  .admin-tab {
    flex: 0 0 auto;
    min-height: 42px;
    padding: 10px 14px;
  }

  .admin-section-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .admin-section {
    padding: 14px;
  }

  .admin-inline-control {
    max-width: none;
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }

  .monitor-form-grid,
  .monitor-pickers {
    grid-template-columns: 1fr;
  }
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8125rem;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: min(100%, 640px);
  max-width: 640px;
  max-height: min(90vh, 900px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal h3 {
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.validation-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) 150px minmax(0, 1.1fr) minmax(0, 1fr) auto auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

.validation-row[data-mode="raw"] {
  grid-template-columns: minmax(0, 2.6fr) minmax(0, 1fr) auto auto;
  align-items: stretch;
}

.validation-row input,
.validation-row select,
.validation-row textarea {
  width: 100%;
  min-width: 0;
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.8125rem;
  font-family: inherit;
}

.validation-row .val-left,
.validation-row .val-right,
.validation-row .val-expr {
  font-family: var(--mono);
}

.validation-row textarea.val-expr {
  min-height: 66px;
  line-height: 1.45;
  resize: vertical;
}

.validation-row select {
  font-family: var(--mono);
  cursor: pointer;
}

.validation-row input:focus,
.validation-row select:focus,
.validation-row textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.validation-row input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.validation-row .btn {
  padding: 6px 9px;
  font-size: 0.8125rem;
}

.validation-row[data-mode="raw"] .btn {
  align-self: start;
}

.validation-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* History modal */
.modal-lg {
  max-width: 760px;
}

.modal-xl {
  max-width: 1000px;
}

#history-modal .modal-xl {
  width: min(96vw, 1440px);
  max-width: 1440px;
  height: min(88vh, 960px);
  display: flex;
  flex-direction: column;
}

#history-modal .modal-header,
#history-modal .history-filters,
#history-modal #history-summary {
  flex-shrink: 0;
}

#history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin-bottom: 0;
}

.history-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.history-filters label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.history-filters input[type="checkbox"] {
  accent-color: var(--accent);
}

.history-filters .history-batch-input {
  min-width: 220px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.history-filters .concurrency-select {
  padding: 6px 10px;
}

.history-item {
  padding: 0 16px 0;
}

.history-item[open] {
  padding-bottom: 12px;
}

/* Batch grouping */
.batch-id {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.18);
  color: var(--accent);
  white-space: nowrap;
}

.batch-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: var(--bg);
  overflow: hidden;
}

.batch-item.pass {
  border-left: 3px solid var(--success);
}

.batch-item.fail {
  border-left: 3px solid var(--danger);
}

.batch-summary-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
}

.batch-summary-row::-webkit-details-marker {
  display: none;
}

.batch-summary-row:hover {
  background: var(--surface-hover);
}

.batch-models {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.batch-counts {
  display: flex;
  gap: 10px;
  font-size: 0.8125rem;
  white-space: nowrap;
}

.batch-body {
  padding: 4px 14px 12px;
}

.result-url {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-summary-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  cursor: pointer;
  list-style: none;
}

.history-summary-row::-webkit-details-marker {
  display: none;
}

.history-summary-row .result-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
}

.history-time {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.history-provider {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.history-item .response-preview {
  max-height: 200px;
}

.tabs-admin {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tabs-admin button {
  padding: 8px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
}

.tabs-admin button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

@media (max-width: 1600px) {
  .main-layout {
    grid-template-columns: 460px 460px minmax(0, 1fr);
  }
}

@media (max-width: 1280px) {
  .main-layout {
    grid-template-columns: 380px 360px minmax(0, 1fr);
  }
}

@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 300px 300px minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .app-shell {
    height: auto;
    min-height: 100svh;
    overflow: visible;
    padding-bottom: 112px;
  }

  .header {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 12px;
    min-height: 0;
  }

  .app-shell .header {
    display: grid;
    grid-template-columns: 1fr;
  }

  .app-shell .header h1,
  .app-shell .header .tabs,
  .app-shell .header-nav {
    justify-self: stretch;
  }

  .header h1 {
    white-space: normal;
    line-height: 1.25;
  }

  .header-nav {
    width: 100%;
    gap: 8px;
    flex-wrap: wrap;
    margin-left: 0;
  }

  .header-nav a,
  .user-chip,
  .header-nav .btn {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
  }

  .header-nav a {
    padding: 6px 0;
  }

  .tabs {
    align-self: auto;
    margin: 0 -12px;
    padding: 0 12px;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .tab {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0 14px;
  }

  .main-layout {
    grid-template-columns: 1fr;
    flex: initial;
    min-height: auto;
  }

  .panel {
    min-height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .panel-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--panel-bg);
  }

  .panel-body {
    max-height: none;
    overflow: visible;
    padding: 12px;
  }

  #results-panel {
    order: 9;
  }

  .run-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
    box-shadow: 0 -10px 24px rgba(0, 0, 0, 0.28);
  }

  .run-bar .btn {
    flex: 1 1 116px;
  }

  .concurrency-select {
    flex: 0 0 auto;
    min-height: 42px;
  }

  .run-hint,
  #run-status {
    flex: 1 0 100%;
    font-size: 0.8125rem;
  }

  .case-item {
    min-height: 44px;
    padding: 10px;
  }

  .case-item .case-open {
    opacity: 1;
  }

  .icon-btn {
    opacity: 1;
    min-width: 32px;
    min-height: 32px;
  }

  .result-card {
    padding: 12px;
  }

  .result-header,
  .result-matrix-head,
  .batch-summary-row,
  .history-summary-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .result-title {
    flex: 1 1 220px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .batch-id,
  .history-time,
  .history-provider,
  .batch-counts {
    white-space: normal;
  }

  .batch-models {
    flex-basis: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .history-filters {
    align-items: stretch;
    gap: 8px;
  }

  .history-filters label,
  .history-filters .history-batch-input,
  .history-filters .concurrency-select,
  .history-filters .btn {
    width: 100%;
  }

  .modal-overlay {
    align-items: stretch;
    padding: 10px;
  }

  .modal {
    width: 100%;
    max-width: none;
    max-height: calc(100svh - 20px);
    padding: 16px;
    border-radius: 10px;
  }

  #history-modal .modal-xl {
    width: 100%;
    height: calc(100svh - 20px);
    max-width: none;
    max-height: calc(100svh - 20px);
  }

  .modal-header {
    gap: 12px;
    align-items: flex-start;
  }

  .modal-actions {
    position: sticky;
    bottom: -16px;
    margin: 18px -16px -16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  .modal-actions .btn {
    flex: 1 1 0;
  }

  .validation-row,
  .validation-row[data-mode="raw"] {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.02);
  }

  .validation-row .btn {
    min-height: 36px;
  }

  .validation-actions .btn {
    flex: 1 1 140px;
  }
}

@media (max-width: 520px) {
  .login-page {
    padding: 16px;
    align-items: start;
  }

  .login-panel {
    padding: 20px;
  }

  .btn {
    min-height: 42px;
    padding: 9px 14px;
  }

  .btn-sm {
    min-height: 34px;
    padding: 5px 10px;
  }

  .panel-head {
    padding: 10px 12px;
  }

  .group-filter {
    flex-wrap: nowrap;
    margin: 0 -12px 12px;
    padding: 0 12px 12px;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .group-chip {
    flex: 0 0 auto;
    min-height: 34px;
  }

  .model-item {
    min-height: 44px;
  }

  .model-name-input {
    min-height: 36px;
  }

  .case-item {
    flex-wrap: wrap;
  }

  .case-item .case-name {
    flex-basis: calc(100% - 32px);
  }

  .case-item .group-tag {
    margin-left: 24px;
  }

  .result-matrix {
    min-width: 460px;
    font-size: 0.75rem;
  }

  .result-matrix th,
  .result-matrix td {
    padding: 8px;
  }

  .result-matrix .matrix-case-col,
  .result-matrix .matrix-case-name {
    min-width: 140px;
    max-width: 180px;
  }

  .admin-table {
    min-width: 560px;
  }

  .cases-admin-table {
    min-width: 900px;
  }

  .syntax-hint {
    max-height: 180px;
    overflow: auto;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
  }
}
