:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --primary: #0369a1;
  --primary-hover: #075985;
  --focus: #2563eb;
  --ok-bg: #dcfce7;
  --ok-fg: #166534;
  --info-bg: #e0f2fe;
  --info-fg: #075985;
  --warn-bg: #fef3c7;
  --warn-fg: #92400e;
  --danger-bg: #fee2e2;
  --danger-fg: #991b1b;
  --muted-bg: #e2e8f0;
  --muted-fg: #334155;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem;
}

.site-header {
  background: #0f172a;
  color: #f8fafc;
  padding: 1.25rem 0;
  margin-bottom: 1.25rem;
}

.site-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0;
  color: #cbd5e1;
  font-size: 0.95rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

h2 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
}

.card-header h2 {
  margin: 0;
}

h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

h4 {
  margin: 0.75rem 0 0.25rem;
  font-size: 0.9rem;
}

.section-note,
.muted-text,
.hint {
  color: var(--muted);
  font-size: 0.875rem;
}

.section-note {
  margin: 0 0 0.75rem;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.conn-form {
  display: grid;
  gap: 0.75rem;
}

.field {
  display: grid;
  gap: 0.25rem;
}

.field label {
  font-weight: 600;
  font-size: 0.9rem;
}

input[type="text"],
input[type="url"],
input[type="password"],
input[type="number"] {
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
}

.key-row {
  display: flex;
  gap: 0.5rem;
}

.key-row input {
  flex: 1;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

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

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

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

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

.btn-secondary:hover:not(:disabled) {
  background: #f1f5f9;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.chip-ok {
  background: var(--ok-bg);
  color: var(--ok-fg);
}

.chip-info {
  background: var(--info-bg);
  color: var(--info-fg);
}

.chip-warn {
  background: var(--warn-bg);
  color: var(--warn-fg);
}

.chip-danger {
  background: var(--danger-bg);
  color: var(--danger-fg);
}

.chip-muted {
  background: var(--muted-bg);
  color: var(--muted-fg);
}

.inline-error {
  margin: 0;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  background: var(--danger-bg);
  color: var(--danger-fg);
  font-size: 0.875rem;
  font-weight: 500;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.product-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.5rem;
}

.product-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.product-title {
  margin: 0;
  font-weight: 600;
}

.product-price {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.cart-box {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

.cart-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.cart-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.cart-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.cart-item-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cart-qty {
  width: 4.5rem !important;
}

.order-results {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.4rem;
}

.order-result-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid var(--border);
  font-size: 0.875rem;
}

.scenario-list {
  display: grid;
  gap: 0.65rem;
}

.scenario-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

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

.burst-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.burst-input {
  width: 5rem !important;
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.85rem;
  font-size: 0.9rem;
}

.notice-info {
  background: var(--info-bg);
  color: var(--info-fg);
}

.notice-warn {
  background: var(--warn-bg);
  color: var(--warn-fg);
  border: 1px solid #f59e0b;
}

.spinner {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  margin-top: 0.2rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}

.inspector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.subpanel {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  min-width: 0;
}

.last-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.header-dl,
.tally-dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.85rem;
}

.header-dl dt,
.tally-dl dt {
  color: var(--muted);
  font-weight: 600;
}

.header-dl dd,
.tally-dl dd {
  margin: 0;
  word-break: break-word;
}

.body-pre {
  margin: 0;
  padding: 0.6rem;
  background: #0f172a;
  color: #f8fafc;
  border-radius: 6px;
  font-size: 0.8rem;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.table-scroll {
  width: 100%;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.825rem;
  min-width: 560px;
}

.history-table th,
.history-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.history-table th {
  background: #f1f5f9;
  position: sticky;
  top: 0;
}

.site-footer {
  padding: 1rem 0 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
