:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body.drawer-open {
  overflow: hidden;
}

.topbar {
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.top-actions,
.graph-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

button.ghost {
  background: #fff;
}

button:hover {
  border-color: #cbd5e1;
}

.search-bar {
  padding: 14px 22px;
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 12px;
  align-items: center;
}

.search-bar label {
  font-weight: 600;
}

.search-bar input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

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

.active-filters {
  margin: 0 22px 12px;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #ffffff;
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.active-filters.show {
  display: flex;
}

.filter-chip {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.75rem;
  cursor: pointer;
}

.filter-chip:hover {
  background: #e2e8f0;
}

.reset-filters-btn {
  border: 1px solid #fecaca;
  background: #fff1f2;
  color: #b91c1c;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.75rem;
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 14px;
  padding: 0 22px 22px;
  min-height: calc(100vh - 120px);
}

.filters {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  overflow: auto;
}

.filter-group {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
  background: #fdfefe;
}

.filter-group summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.93rem;
}

.filter-search {
  margin: 8px 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.check-list {
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: #fff;
}

.check-list label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  padding: 3px 0;
}

.badge {
  color: var(--muted);
  font-size: 0.75rem;
}

.text-filter {
  margin-top: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.content {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  min-width: 0;
}

.tabs {
  display: flex;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.tab-view {
  display: none;
  height: calc(100vh - 240px);
}

.tab-view.active {
  display: block;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  height: calc(100% - 44px);
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #edf2f7;
  text-align: left;
  vertical-align: top;
  padding: 7px 8px;
  max-width: 380px;
  white-space: normal;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 5;
  cursor: pointer;
  user-select: none;
}

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

td a:hover {
  text-decoration: underline;
}

.truncated-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 4.2em;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1e40af;
  font-size: 0.72rem;
  border: 1px solid #bfdbfe;
}

button.pill {
  cursor: pointer;
  font: inherit;
  line-height: 1.2;
}

button.pill.is-clickable:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

.profile-link {
  border: 0;
  background: transparent;
  color: #0f172a;
  font: inherit;
  font-weight: 600;
  text-align: left;
  padding: 0;
  cursor: pointer;
}

.profile-link:hover {
  color: #1d4ed8;
  text-decoration: underline;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
}

.graph-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 10px;
  height: calc(100% - 52px);
}

#network {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.detail-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  overflow: auto;
  background: #fcfcfd;
  font-size: 0.85rem;
}

.detail-panel h3 {
  margin-top: 0;
}

.detail-row {
  margin-bottom: 8px;
}

.detail-row strong {
  display: block;
  margin-bottom: 3px;
}

.profile-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.profile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(560px, 96vw);
  background: #ffffff;
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 28px rgba(15, 23, 42, 0.18);
  transform: translateX(102%);
  transition: transform 0.24s ease;
  z-index: 31;
  display: flex;
  flex-direction: column;
}

.profile-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.profile-drawer.open {
  transform: translateX(0);
}

.profile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.profile-header h3 {
  margin: 0;
}

.profile-actions {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.profile-content {
  overflow: auto;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.profile-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fcfcfd;
}

.profile-card h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.chat-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  height: calc(100% - 2px);
}

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.chat-messages {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  padding: 10px;
  overflow: auto;
  min-height: 260px;
}

.chat-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-msg {
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}

.chat-msg.user {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.chat-msg.assistant {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.chat-msg-header {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.chat-msg-body {
  white-space: normal;
  line-height: 1.45;
  font-size: 0.9rem;
}

.chat-msg-body .md-p {
  margin: 0 0 8px;
}

.chat-msg-body .md-list {
  margin: 0 0 8px 18px;
  padding: 0;
}

.chat-msg-body .md-spacer {
  height: 4px;
}

.chat-msg-body code {
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 4px;
  padding: 1px 4px;
}

.chat-block {
  margin-top: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.chat-block summary {
  cursor: pointer;
  font-weight: 600;
}

.chat-block ol {
  margin: 8px 0 0 18px;
  padding: 0;
}

.chat-block li {
  margin-bottom: 3px;
}

.transparency-list {
  margin: 8px 0 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
}

.transparency-list code {
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  padding: 2px 4px;
  display: inline-block;
  margin-top: 4px;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.chat-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  resize: vertical;
  min-height: 78px;
  font-family: inherit;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.45);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-overlay.open {
  display: flex;
}

.auth-card {
  width: min(420px, 96vw);
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 16px;
  display: grid;
  gap: 10px;
}

.auth-card h3 {
  margin: 0;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
}

.auth-card input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.auth-error {
  min-height: 18px;
  color: #b91c1c !important;
  font-size: 0.82rem;
}

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

  .graph-layout {
    grid-template-columns: 1fr;
  }

  .search-bar {
    grid-template-columns: 1fr;
  }

  .stats {
    text-align: left;
  }

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

  .chat-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}
