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

body {
  margin: 0;
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1a1a1a;
  background: #eef0f2;
}

.page-header {
  background: #1e293b;
  color: #f8fafc;
  padding: 1.25rem 1.5rem;
  border-bottom: 3px solid #3b82f6;
}

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

.subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: #94a3b8;
}

.dashboard {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.grid-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 768px) {
  .grid-top {
    grid-template-columns: 1fr;
  }
}

.card {
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 1rem 1.15rem;
}

.card h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
}

.card h3.subsection-title {
  margin: 1rem 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #334155;
}

.card-meta {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  color: #64748b;
}

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

.card-header-row h2 {
  margin: 0;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.status-label {
  color: #64748b;
}

.mono {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.8rem;
}

.kv-list {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  font-size: 0.85rem;
}

.kv-list dt {
  margin: 0;
  color: #64748b;
  font-weight: 500;
}

.kv-list dd {
  margin: 0;
  font-family: ui-monospace, Consolas, monospace;
  word-break: break-word;
}

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

.badge-ok {
  background: #dcfce7;
  color: #166534;
}

.badge-warn {
  background: #fef9c3;
  color: #854d0e;
}

.badge-error {
  background: #fee2e2;
  color: #991b1b;
}

.badge-disconnected {
  background: #f1f5f9;
  color: #475569;
}

.badge-connected {
  background: #dcfce7;
  color: #166534;
}

.badge-reconnecting {
  background: #fef9c3;
  color: #854d0e;
}

.subscribe-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}

.subscribe-form label {
  font-weight: 500;
  color: #475569;
}

.subscribe-form input[type="text"] {
  width: 7rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.9rem;
  text-transform: uppercase;
}

.subscribe-form button,
.chat-form button,
.btn {
  padding: 0.4rem 0.85rem;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  background: #f1f5f9;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.subscribe-form button:hover,
.chat-form button:hover:not(:disabled),
.btn-primary:hover {
  background: #e2e8f0;
}

.btn-primary {
  display: inline-block;
  text-decoration: none;
  color: inherit;
  background: #3b82f6;
  border-color: #2563eb;
  color: #fff;
}

.btn-primary:hover {
  background: #2563eb;
  color: #fff;
}

.form-error {
  margin: 0.5rem 0 0;
  color: #b91c1c;
  font-size: 0.8rem;
}

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

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

th,
td {
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

th {
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
}

.empty-cell {
  text-align: center;
  color: #94a3b8;
  font-style: italic;
}

.btn-remove {
  padding: 0.2rem 0.5rem;
  border: 1px solid #fca5a5;
  border-radius: 3px;
  background: #fff;
  color: #b91c1c;
  font-size: 0.75rem;
  cursor: pointer;
}

.btn-remove:hover {
  background: #fee2e2;
}

.status-live {
  color: #166534;
  font-weight: 500;
}

.status-waiting {
  color: #854d0e;
}

.status-stale {
  color: #94a3b8;
}

.chat-history {
  min-height: 10rem;
  max-height: 18rem;
  overflow-y: auto;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.chat-line {
  margin-bottom: 0.65rem;
}

.chat-line-user .chat-role {
  color: #1d4ed8;
}

.chat-line-assistant .chat-role {
  color: #047857;
}

.chat-role {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 0.15rem;
}

.chat-content {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.chat-form textarea {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

.chat-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-loading {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: #64748b;
}

#docs-card p {
  margin: 0 0 0.75rem;
  color: #475569;
  font-size: 0.85rem;
}

.activity-log {
  max-height: 14rem;
  overflow-y: auto;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.78rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 0.5rem 0;
}

.activity-entry {
  display: grid;
  grid-template-columns: 5.5rem 5.5rem 1fr;
  gap: 0.5rem;
  padding: 0.25rem 0.65rem;
  border-bottom: 1px solid #f1f5f9;
}

.activity-entry:last-child {
  border-bottom: none;
}

.activity-ts {
  color: #64748b;
}

.activity-type {
  color: #475569;
  text-transform: lowercase;
}

.activity-summary {
  color: #1e293b;
  word-break: break-word;
}

.activity-warn .activity-summary {
  color: #854d0e;
}

.activity-error .activity-summary {
  color: #991b1b;
}

.arch-diagram {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.75rem 0;
}

.arch-node {
  padding: 0.4rem 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #f8fafc;
  font-size: 0.8rem;
  font-weight: 500;
  text-align: center;
  min-width: 6rem;
}

.arch-node-top {
  background: #1e293b;
  color: #f8fafc;
  border-color: #1e293b;
}

.arch-node-main {
  background: #3b82f6;
  color: #fff;
  border-color: #2563eb;
  min-width: 8rem;
}

.arch-node-sub {
  font-size: 0.75rem;
  min-width: 5rem;
}

.arch-node-ext {
  background: #fef9c3;
  border-color: #fde047;
  font-size: 0.75rem;
}

.arch-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.arch-connector {
  width: 2px;
  height: 1rem;
  background: #94a3b8;
}

.arch-connector-split {
  height: 0.75rem;
}

@media (max-width: 768px) {
  .activity-entry {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .arch-row {
    flex-direction: column;
    align-items: center;
  }
}
