:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e8eef7;
  --muted: #9aa8bc;
  --accent: #3d8bfd;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --bad: #f87171;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(circle at top, #172033, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

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

.subtitle {
  margin: 0;
  color: var(--muted);
}

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

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1724;
  color: var(--text);
  font: inherit;
}

input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  border-color: var(--accent);
}

.history-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.history-row select {
  flex: 1;
  min-width: 220px;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1724;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.history-row select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  border-color: var(--accent);
}

.btn-secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

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

.actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.25rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.status-text {
  color: var(--muted);
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.status-item {
  padding: 0.75rem;
  border-radius: 8px;
  background: #111927;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.status-item .label {
  color: var(--muted);
  display: block;
  margin-bottom: 0.2rem;
}

.status-item .value.ok { color: var(--ok); }
.status-item .value.bad { color: var(--bad); }
.status-item .value.warn { color: var(--warn); }

.error-list {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
  color: var(--bad);
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.5rem 1rem;
  margin: 0;
}

.device-grid dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.device-grid dd {
  margin: 0 0 0.5rem;
  font-family: var(--mono);
  font-size: 0.9rem;
}

.checklist {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
}

.checklist li::before {
  content: '✗ ';
  color: var(--bad);
}

.checklist li.on::before {
  content: '✓ ';
  color: var(--ok);
}

.profile-row {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.4rem;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.uri-cell {
  display: flex;
  gap: 0.35rem;
  align-items: flex-start;
}

.uri-cell code {
  font-family: var(--mono);
  font-size: 0.78rem;
  word-break: break-all;
  flex: 1;
}

.copy-btn {
  background: #243044;
  color: var(--text);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  flex-shrink: 0;
}

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

details summary {
  cursor: pointer;
  color: var(--muted);
}

pre {
  margin: 0.75rem 0 0;
  padding: 0.75rem;
  background: #0f1724;
  border-radius: 8px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  max-height: 420px;
}

/* Device classification */
.device-classification {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  background: #111927;
}

.device-classification .dc-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.device-classification .dc-type {
  font-weight: 600;
  text-transform: capitalize;
}

.device-classification .dc-confidence {
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 500;
}

.device-classification .dc-confidence.high {
  background: color-mix(in srgb, var(--ok) 20%, transparent);
  color: var(--ok);
  border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent);
}

.device-classification .dc-confidence.medium {
  background: color-mix(in srgb, var(--warn) 20%, transparent);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
}

.device-classification .dc-confidence.low {
  background: color-mix(in srgb, var(--muted) 15%, transparent);
  color: var(--muted);
  border: 1px solid color-mix(in srgb, var(--muted) 30%, transparent);
}

.device-classification .dc-note {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 0.35rem;
}

.device-classification .dc-reasons {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--text);
}

.device-classification .dc-reasons li {
  margin-bottom: 0.2rem;
}

/* Tabs */
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.tab-bar .tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 0.45rem 0.85rem;
  font-size: 0.88rem;
  font-weight: 500;
}

.tab-bar .tab.active {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface);
  border-radius: 8px 8px 0 0;
}

.tab-panel {
  margin-top: 0.5rem;
}

/* Diagnostics */
.diag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem 1rem;
  margin: 0;
}

.diag-grid dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.diag-grid dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.88rem;
}

.endpoint-list, .service-list, .structured-errors {
  list-style: none;
  padding: 0;
  margin: 0;
}

.endpoint-item, .service-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #243044;
  color: var(--muted);
}

.badge-success, .badge.badge-success { background: color-mix(in srgb, var(--ok) 25%, transparent); color: var(--ok); }
.badge-error, .badge.badge-error { background: color-mix(in srgb, var(--bad) 25%, transparent); color: var(--bad); }
.badge-warn, .badge.badge-warn { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); }

.service-item.status-supported .badge { color: var(--ok); }
.service-item.status-not_supported .badge { color: var(--muted); }
.service-item.status-advertised_unavailable .badge { color: var(--warn); }

.profile-details {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.profile-card {
  padding: 0.65rem 0.85rem;
  background: #111927;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.88rem;
}

.profile-card ul {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.confidence {
  font-size: 0.75rem;
  margin-left: 0.35rem;
  color: var(--muted);
}

.unknown-list .unknown-item {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: #111927;
  border-radius: 6px;
  font-size: 0.85rem;
}

.structured-error {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.structured-error .hint {
  color: var(--warn);
  font-size: 0.82rem;
  margin-top: 0.25rem;
}

.error-diag {
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

/* Developer */
.advanced-disclosure summary {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.advanced-content h3 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1rem;
}

.dev-actions {
  margin: 0.75rem 0;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.timeline-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111927;
  padding: 0.35rem 0.65rem;
}

.timeline-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  list-style: none;
}

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

.timeline-label { flex: 1; font-family: var(--mono); font-size: 0.85rem; }
.timeline-ms { color: var(--muted); font-size: 0.82rem; }

.exchange-detail h4 {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.9rem;
}

.code-block {
  position: relative;
  margin: 0.5rem 0;
}

.code-block .copy-btn {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 1;
}

.code-block pre, .parsed-item pre, .norm-section pre {
  margin: 0;
  padding: 0.75rem;
  background: #0f1724;
  border-radius: 8px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.75rem;
  max-height: 360px;
  white-space: pre-wrap;
  word-break: break-word;
}

.fault-block {
  color: var(--bad);
  padding: 0.5rem;
  background: color-mix(in srgb, var(--bad) 10%, transparent);
  border-radius: 6px;
  margin: 0.5rem 0;
}

.parsed-item, .norm-section {
  margin-bottom: 0.5rem;
}

.derived-ok { color: var(--ok); }

.raw-json-details {
  margin-top: 1.5rem;
}
