:root {
  --bg: #0c0e14;
  --bg-elev: #12151f;
  --border: rgba(255, 255, 255, 0.06);
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #7c9cff;
  --accent-dim: rgba(124, 156, 255, 0.15);
  --danger: #ff6b8a;
  --ok: #5bd39c;
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

body.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(124, 156, 255, 0.14), transparent),
    radial-gradient(ellipse 60% 50% at 80% 90%, rgba(91, 211, 156, 0.08), transparent),
    var(--bg);
}

.glass {
  background: linear-gradient(145deg, rgba(22, 26, 36, 0.92), rgba(14, 16, 22, 0.88));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

.auth-card {
  width: min(400px, 92vw);
  padding: 2rem;
}

.brand {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.75rem;
}
.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: #0a0c12;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}
.hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 1rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.input,
.textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
.textarea.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
}
.input:focus,
.textarea:focus {
  outline: none;
  border-color: rgba(124, 156, 255, 0.45);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1.1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  font-size: 0.92rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: linear-gradient(135deg, #6b8cff, #8b7cff);
  color: #0a0c12;
  box-shadow: 0 8px 24px rgba(107, 140, 255, 0.35);
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}
.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.alert-error {
  background: rgba(255, 107, 138, 0.12);
  border: 1px solid rgba(255, 107, 138, 0.35);
  color: #ffb4c4;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* Dashboard layout */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 1.25rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-right: 1px solid var(--border);
  background: rgba(10, 12, 18, 0.95);
}
.sidebar-brand {
  padding: 0.35rem 0.65rem;
  margin-bottom: 0.75rem;
}
.brand-text {
  font-weight: 700;
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.nav-item {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.nav-logout {
  margin-top: auto;
  text-decoration: none;
  text-align: center;
  padding: 0.5rem;
}

.main {
  padding: 1.5rem 2rem 3rem;
  max-width: 1200px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.topbar h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}
.pill {
  font-size: 0.78rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

.grid-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.metric-card {
  padding: 1.1rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(18, 21, 31, 0.85);
}
.metric-card .val {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.metric-card .lbl {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.field label {
  font-size: 0.78rem;
  color: var(--muted);
}

.branch-rows {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.branch-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 0.65rem;
  align-items: end;
}
@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
  }
  .branch-row {
    grid-template-columns: 1fr;
  }
}

.dialogs-split {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 1rem;
  min-height: 420px;
}
.dialogs-list-wrap {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.dialogs-toolbar {
  padding: 0.65rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
}
.dialogs-ul {
  list-style: none;
  margin: 0;
  padding: 0.35rem;
  overflow-y: auto;
  max-height: 60vh;
}
.dialogs-ul li button {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  font-size: 0.88rem;
}
.dialogs-ul li button:hover,
.dialogs-ul li button.active {
  background: rgba(124, 156, 255, 0.12);
}
.dlg-meta {
  font-size: 0.72rem;
  color: var(--muted);
}
.dlg-title {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
}
.dlg-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  margin-bottom: 0.2rem;
}
.dlg-id {
  font-size: 0.72rem;
}
.dialog-detail {
  padding: 1rem;
  overflow-y: auto;
  max-height: 70vh;
  font-size: 0.82rem;
  line-height: 1.55;
}
.msg {
  margin-bottom: 0.85rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.msg.user {
  border-left: 3px solid var(--accent);
}
.msg.assistant {
  border-left: 3px solid var(--ok);
}
.role-tag {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.35rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.msg-ts {
  font-size: 0.65rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

code {
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
}

.hidden {
  display: none !important;
}

.kb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.65rem;
  margin-bottom: 1rem;
}
.kb-label {
  font-size: 0.85rem;
  color: var(--muted);
}
.kb-select {
  min-width: 12rem;
}
.kb-editor {
  margin-bottom: 1rem;
}
.kb-block-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.65rem 0;
}
.kb-hint-inline {
  margin-top: 0;
  margin-bottom: 0.75rem;
}
.kb-json-wrap {
  margin-top: 1rem;
}
.kb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.kb-table th,
.kb-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.5rem;
  vertical-align: top;
  text-align: left;
}
.kb-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kb-key {
  white-space: nowrap;
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kb-cell {
  width: 100%;
  min-width: 12rem;
  font-size: 0.82rem;
  resize: vertical;
}
.kb-actions {
  white-space: nowrap;
}
.kb-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
}
.kb-badge-emb {
  background: rgba(139, 147, 167, 0.2);
  color: var(--muted);
}
.kb-badge-ov {
  background: var(--accent-dim);
  color: var(--accent);
}
.kb-intents .kb-int-kw {
  width: 100%;
  min-width: 10rem;
}

.kb-cards {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.kb-card {
  padding: 1rem;
  border-radius: var(--radius);
}
.kb-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.65rem;
}
.kb-card-key {
  font-weight: 600;
  font-size: 0.88rem;
}
.kb-card-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.kb-card-ta {
  width: 100%;
  font-size: 0.82rem;
  resize: vertical;
}
.kb-mini-label {
  display: block;
  font-size: 0.72rem;
  margin: 0.35rem 0 0.2rem 0;
}
.kb-intent-card .kb-int-kw {
  margin-bottom: 0.5rem;
}

.bc-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.65rem;
  margin-bottom: 1rem;
}
.bc-filter {
  flex: 1;
  min-width: 12rem;
}
.bc-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: none;
}
.bc-card {
  padding: 1rem;
  border-radius: var(--radius);
}
.bc-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.bc-key {
  font-weight: 600;
  font-size: 0.85rem;
  word-break: break-all;
}
.bc-ta {
  width: 100%;
  font-size: 0.82rem;
  resize: vertical;
}
