* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #222633;
  --border: #2a2e3d;
  --text: #e0e0e6;
  --text-dim: #8888a0;
  --accent: #6c8cff;
  --accent-dim: #3d5099;
  --green: #4caf7c;
  --yellow: #e0a830;
  --red: #d45050;
  --orange: #d48040;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

#header-stats {
  display: flex;
  gap: 12px;
  align-items: center;
}

.stat-badge {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.stat-badge.dim {
  color: var(--text-dim);
}

main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 16px;
  padding: 20px 24px;
  max-width: 1600px;
  margin: 0 auto;
  height: calc(100vh - 57px);
}

#instances-panel {
  grid-column: 1;
  grid-row: 1 / 3;
  overflow-y: auto;
}

#concerns-panel {
  grid-column: 2;
  grid-row: 1;
  overflow-y: auto;
}

#history-panel {
  grid-column: 2;
  grid-row: 2;
  overflow-y: auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.panel h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
}

/* Instance cards */
.instance-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s;
}

.instance-card:hover {
  border-color: var(--accent-dim);
}

.instance-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.instance-name {
  font-weight: 600;
  font-size: 14px;
}

.instance-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.status-connected {
  background: rgba(76, 175, 124, 0.15);
  color: var(--green);
}

.status-disconnected {
  background: rgba(212, 80, 80, 0.15);
  color: var(--red);
}

.instance-meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.persona-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.persona-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-dim);
  border-radius: 6px;
  padding: 10px 12px;
}

.persona-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 4px;
}

.persona-description {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.4;
}

.persona-background {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
  line-height: 1.4;
}

.persona-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.expertise-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--border);
  color: var(--text-dim);
}

/* Activity section */
.activity-section {
  margin-top: 8px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.activity-line {
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.6;
  transition: opacity 0.3s;
}

.activity-line.stale {
  opacity: 0.4;
}

.activity-icon {
  margin-right: 4px;
}

.activity-tool {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(108, 140, 255, 0.12);
  color: var(--accent);
  font-weight: 500;
  margin-right: 4px;
}

.load-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.load-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

/* Concern cards */
.concern-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.concern-card:hover {
  border-color: var(--accent-dim);
}

.concern-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.concern-id {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-dim);
}

.persona-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(108, 140, 255, 0.12);
  color: var(--accent);
  font-weight: 500;
  margin-left: 4px;
}

.concern-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.status-pending { background: rgba(224, 168, 48, 0.15); color: var(--yellow); }
.status-assigned { background: rgba(108, 140, 255, 0.15); color: var(--accent); }
.status-in_progress { background: rgba(212, 128, 64, 0.15); color: var(--orange); }
.status-responded { background: rgba(76, 175, 124, 0.15); color: var(--green); }
.status-closed { background: rgba(76, 175, 124, 0.1); color: var(--green); }
.status-failed { background: rgba(212, 80, 80, 0.15); color: var(--red); }
.status-timeout { background: rgba(212, 80, 80, 0.1); color: var(--red); }

.concern-task {
  font-size: 13px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.concern-meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  gap: 12px;
}

.concern-tags {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
}

#modal-title {
  font-size: 16px;
  margin-bottom: 16px;
}

.modal-field {
  margin-bottom: 12px;
}

.modal-field label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.modal-field .value {
  font-size: 14px;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.message-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}

.message-item.direction-request {
  border-left: 3px solid var(--accent);
}

.message-item.direction-response {
  border-left: 3px solid var(--green);
}

.message-item.direction-follow_up {
  border-left: 3px solid var(--yellow);
}

.message-direction {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.message-content {
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  #instances-panel {
    grid-column: 1;
    grid-row: auto;
  }
  #concerns-panel,
  #history-panel {
    grid-column: 1;
    grid-row: auto;
  }
}
