:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-border: #d7dbe0;
  --color-text: #1f2733;
  --color-text-muted: #5b6673;
  --color-primary: #1d4e7a;
  --color-primary-dark: #143a5c;
  --color-green-bg: #e3f2e6;
  --color-green-text: #1e6b34;
  --color-amber-bg: #fdf1de;
  --color-amber-text: #8a5a12;
  --color-grey-bg: #eceef1;
  --color-grey-text: #4a5360;
  --focus-ring: #1d4e7a;
  --radius: 6px;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
}

a {
  color: var(--color-primary);
}

.site-header {
  background: var(--color-primary-dark);
  color: #ffffff;
  padding: 1.25rem 1rem;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
}

.site-header h1 {
  margin: 0 0 0.25rem 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.header-sep {
  color: #b9c8d6;
}

.subtitle {
  margin: 0;
  font-size: 0.9rem;
  color: #cfd9e3;
}

.health-strip {
  max-width: 1100px;
  margin: 0.75rem auto 0 auto;
  padding: 0 1rem;
}

.health-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pill {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--color-border);
}

.pill-green {
  background: var(--color-green-bg);
  color: var(--color-green-text);
  border-color: #b7dcc0;
}

.pill-grey {
  background: var(--color-grey-bg);
  color: var(--color-grey-text);
}

.health-note {
  margin: 0.5rem 0 0 0;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  max-width: 60ch;
}

.tabs {
  max-width: 1100px;
  margin: 1rem auto 0 auto;
  padding: 0 1rem;
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--color-border);
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  margin-bottom: -2px;
}

.tab-btn.active {
  color: var(--color-primary-dark);
  border-bottom-color: var(--color-primary);
}

.tab-btn:focus-visible,
.btn:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.tab-panels {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

.panel h2 {
  font-size: 1.1rem;
  margin-top: 0;
}

.qc-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.field-row-inline {
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
}

.field-row-actions {
  margin-top: 0.5rem;
}

.field-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.field-disabled-note {
  font-weight: 400;
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.field-row input[type="number"] {
  width: 6rem;
}

input,
textarea {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--color-text);
}

textarea {
  resize: vertical;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

.btn {
  border: 1px solid var(--color-border);
  background: #fff;
  color: var(--color-text);
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary-dark);
}

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

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

.inline-error {
  background: #fbe6e6;
  border: 1px solid #e3a9a9;
  color: #7a2020;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin: 0.75rem 0;
}

.summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  font-size: 0.88rem;
}

.summary-bar strong {
  display: block;
  font-size: 1.15rem;
}

.qc-results {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.record-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

.record-card h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.98rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.chip {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--color-amber-bg);
  color: var(--color-amber-text);
  border: 1px solid #f0d6a4;
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
}

table.grounding-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 480px;
}

table.grounding-table th,
table.grounding-table td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-green {
  background: var(--color-green-bg);
  color: var(--color-green-text);
}

.badge-amber {
  background: var(--color-amber-bg);
  color: var(--color-amber-text);
}

.badge-grey {
  background: var(--color-grey-bg);
  color: var(--color-grey-text);
}

.hitl-queue,
.hitl-history {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.hitl-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.hitl-item-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: baseline;
  margin-bottom: 0.5rem;
  font-size: 0.88rem;
}

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

.candidate-empty-note {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.5rem 0;
}

.candidate-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
}

.spinner {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 0.4rem;
  vertical-align: middle;
}

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

.history-table-wrap {
  overflow-x: auto;
}

table.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 480px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

table.history-table th,
table.history-table td {
  padding: 0.35rem 0.55rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}

.dashboard-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.85rem;
  overflow-x: auto;
}

.chart-card h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
}

.chart-unavailable {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-style: italic;
  padding: 1rem 0;
}

.chart-svg-wrap {
  overflow-x: auto;
}

.done-tag {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-green-text);
}

@media (max-width: 480px) {
  .field-row-inline {
    flex-direction: column;
    align-items: stretch;
  }

  table.grounding-table {
    min-width: 0;
  }

  table.grounding-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  table.grounding-table tr {
    display: block;
    margin-bottom: 0.6rem;
    border-bottom: 2px solid var(--color-border);
  }

  table.grounding-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.3rem 0;
    border-bottom: 1px dashed var(--color-border);
    text-align: right;
    white-space: normal;
    word-break: break-word;
  }

  table.grounding-table td:last-child {
    border-bottom: none;
  }

  table.grounding-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: left;
    flex: 0 0 auto;
  }
}

/* demo mode additions */
.demo-banner {
  background: #fef3c7;
  color: #78350f;
  border-bottom: 1px solid #f59e0b;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  text-align: center;
}
.demo-note {
  color: #78350f;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}
