:root {
  font-family: Arial, sans-serif;
  background: #f5f7fa;
  color: #1f2933;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

a {
  color: #1d4ed8;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  background: #1d4ed8;
  border: 0;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  padding: 8px 12px;
}

.button-link {
  background: #1d4ed8;
  border-radius: 6px;
  color: white;
  display: inline-block;
  padding: 8px 12px;
}

.button-link.secondary {
  background: #475569;
}

button.danger {
  background: #b42318;
}

.sidebar {
  background: #111827;
  bottom: 0;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 20px;
  left: 0;
  padding: 20px;
  position: fixed;
  top: 0;
  width: 230px;
}

.sidebar a {
  color: #e5e7eb;
}

.sidebar .brand {
  color: white;
  font-size: 22px;
  font-weight: 700;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar nav a {
  border-radius: 6px;
  padding: 10px;
}

.sidebar nav a:hover {
  background: #243044;
}

.sidebar form {
  margin-top: auto;
}

.page {
  margin-left: 230px;
  padding: 24px;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.login-box,
.panel,
.notice {
  background: white;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  padding: 20px;
}

.login-box {
  width: min(100%, 380px);
}

label {
  display: grid;
  gap: 6px;
}

input,
select,
textarea {
  border: 1px solid #bcc7d4;
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 14px;
}

.stats,
.metrics {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 18px;
}

.stats section,
.metrics article {
  background: white;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  padding: 18px;
}

.stats strong,
.metrics strong {
  display: block;
  font-size: 32px;
}

.metrics small {
  color: #5b6675;
  display: block;
  margin-top: 6px;
}

table {
  border-collapse: collapse;
  margin-top: 20px;
  width: 100%;
}

th,
td {
  background: white;
  border-bottom: 1px solid #d7dde6;
  padding: 10px;
  text-align: left;
}

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

.page-actions {
  margin-bottom: 14px;
}

.details {
  display: grid;
  gap: 8px 16px;
  grid-template-columns: max-content minmax(0, 1fr);
  margin: 12px 0;
}

.details dt {
  color: #5b6675;
}

.split-header {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.graph-layout {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) 280px;
  min-height: 420px;
}

.graph-view {
  background: #f8fafc;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  min-height: 420px;
  width: 100%;
}

.graph-edge {
  cursor: pointer;
  stroke: #94a3b8;
  stroke-opacity: 0.72;
  stroke-width: 1.5;
}

.graph-node {
  cursor: pointer;
}

.graph-node circle {
  stroke: white;
  stroke-width: 2;
}

.graph-node text {
  fill: #1f2933;
  font-size: 12px;
}

.graph-details {
  background: #f8fafc;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  overflow: auto;
  padding: 12px;
}

.graph-details small {
  display: block;
  margin: 4px 0 10px;
}

.graph-details pre {
  white-space: pre-wrap;
}

.stack {
  display: grid;
  gap: 12px;
}

.error {
  color: #b42318;
}

.muted {
  color: #5b6675;
}

.badge {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
  padding: 5px 8px;
  text-transform: uppercase;
}

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

.status-degraded,
.status-stopped,
.status-unknown {
  background: #fef3c7;
  color: #92400e;
}

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

td small {
  display: block;
  margin-top: 4px;
}

.notice.error {
  border-color: #f1b7b2;
}

code {
  background: #edf1f7;
  border-radius: 4px;
  display: inline-block;
  padding: 4px 6px;
}

.json-config {
  background: #111827;
  border-radius: 6px;
  color: #e5e7eb;
  margin: 12px 0 0;
  overflow-x: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.json-config code {
  background: transparent;
  color: inherit;
  display: block;
  padding: 0;
}

.inline-edit {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(150px, 1fr) minmax(140px, 1fr) 120px auto;
}

.chat-shell {
  display: grid;
  gap: 16px;
  grid-template-columns: 280px minmax(0, 1fr);
  height: calc(100vh - 48px);
}

.chat-list,
.chat-main {
  background: white;
  border: 1px solid #d7dde6;
  border-radius: 8px;
  min-height: 0;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  padding: 14px;
}

.conversation-list {
  display: grid;
  gap: 8px;
  overflow-y: auto;
}

.conversation-row {
  align-items: stretch;
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(0, 1fr) 34px;
}

.conversation-row.active .conversation-item {
  background: #dbeafe;
  border-color: #1d4ed8;
}

.conversation-item {
  background: #f8fafc;
  border: 1px solid #d7dde6;
  color: #1f2933;
  display: grid;
  gap: 4px;
  padding: 10px;
  text-align: left;
}

.conversation-item span {
  color: #5b6675;
  font-size: 12px;
}

.delete-chat {
  background: #f8fafc;
  border: 1px solid #d7dde6;
  color: #991b1b;
  font-size: 20px;
  line-height: 1;
  padding: 0;
}

.delete-chat:hover {
  background: #fee2e2;
}

.chat-main {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.chat-log {
  display: grid;
  gap: 14px;
  overflow-y: auto;
  padding: 18px;
}

.empty-chat {
  align-self: center;
  color: #5b6675;
  justify-self: center;
}

.chat-message {
  border: 1px solid #d7dde6;
  border-radius: 8px;
  max-width: min(100%, 900px);
  padding: 14px;
}

.chat-message.user {
  background: #edf1f7;
  justify-self: end;
}

.chat-message.assistant {
  background: white;
  justify-self: start;
}

.chat-message.assistant:has(.message-content) {
  min-width: min(100%, 360px);
}

.message-role {
  color: #5b6675;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.message-content {
  line-height: 1.55;
}

.message-content p {
  margin: 0 0 8px;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 10px 0 6px;
}

.message-content pre {
  background: #edf1f7;
  border-radius: 6px;
  margin: 10px 0;
  overflow-x: auto;
  padding: 10px;
  white-space: pre;
}

.message-content pre code {
  background: transparent;
  display: block;
  padding: 0;
}

.message-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.sources {
  border-top: 1px solid #d7dde6;
  margin-top: 12px;
  padding-top: 10px;
}

.sources div {
  background: #f8fafc;
  border-radius: 6px;
  margin-top: 8px;
  padding: 8px;
}

.sources p {
  margin: 6px 0 0;
}

.chat-form {
  align-items: end;
  border-top: 1px solid #d7dde6;
  display: grid;
  gap: 10px;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  padding: 14px;
}

.rag-toggle {
  align-items: center;
  display: flex;
  gap: 8px;
  padding-bottom: 9px;
}

.rag-toggle input {
  width: auto;
}

@media (max-width: 760px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .page {
    margin-left: 0;
  }

  .inline-edit {
    grid-template-columns: 1fr;
  }

  .chat-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chat-list,
  .chat-main {
    min-height: 320px;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }
}
