:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --text: #192435;
  --muted: #5f6f84;
  --line: #d4deeb;
  --primary: #1766d0;
  --primary-soft: #e7f0ff;
  --danger: #b42318;
  --shadow: 0 10px 35px rgba(23, 48, 82, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top right, #dcecff, var(--bg) 35%), var(--bg);
  color: var(--text);
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(420px, 100%);
  padding: 28px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-bottom: 8px;
}

.muted {
  color: var(--muted);
  margin-top: 6px;
}

.stack {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.stack.compact {
  gap: 8px;
  margin-top: 10px;
}

input,
select,
textarea,
button {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 14px;
  font-family: inherit;
}

input,
select,
textarea {
  padding: 10px 12px;
  background: #fff;
}

textarea {
  min-height: 430px;
  resize: vertical;
  line-height: 1.45;
}

button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}

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

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

.hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

code {
  background: #f2f5fa;
  padding: 2px 6px;
  border-radius: 6px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-top: 18px;
  border-bottom: 2px solid var(--line);
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border-radius: 0;
}

.auth-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.auth-error {
  margin-top: 14px;
  color: var(--danger);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.app {
  width: min(1240px, 100%);
  display: grid;
  gap: 16px;
}

.topbar {
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.content-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
}

aside.panel {
  padding: 16px;
}

.metric {
  border-radius: 12px;
  padding: 14px;
  background: var(--primary-soft);
  border: 1px solid #c9dcff;
  margin-bottom: 10px;
}

.metric-label {
  font-size: 12px;
  color: var(--muted);
}

.metric-value {
  display: block;
  margin-top: 4px;
  font-size: 32px;
  font-weight: 700;
}

.employee-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
}

.employee-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  margin-top: 7px;
  background: #fbfdff;
}

.agent-panel {
  padding: 16px;
  display: grid;
  gap: 0;
}

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

.agent-header select {
  width: auto;
  min-width: 200px;
}

.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--line);
  margin-bottom: 16px;
}

.tab-btn {
  flex: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 8px 16px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  border-radius: 0;
  width: auto;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-btn:hover:not(.active) {
  color: var(--text);
}

.tab-content {
  display: none;
}

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

.editor-panel {
  padding: 16px;
  display: grid;
  gap: 12px;
}

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

.editor-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor-controls select {
  min-width: 180px;
}

.editor-footer {
  display: flex;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 440px;
  background: #10233f;
  color: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.toast.error {
  background: var(--danger);
}

/* Employee selection */
.employee-list li {
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.employee-list li:hover {
  background: var(--primary-soft);
}

.employee-list li.selected {
  background: var(--primary-soft);
  border-color: var(--primary);
}

/* Skills */
.skills-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.skill-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #fbfdff;
}

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

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-left: 8px;
}

.catalog-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #fbfdff;
}

.catalog-item-info {
  flex: 1;
}

.catalog-item-info .muted {
  font-size: 12px;
  margin-top: 2px;
}

/* Models */
.models-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.models-section h4 {
  margin: 0 0 4px;
}

/* Connections */
.connection-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-top: 10px;
}

.connection-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.connection-card-header h4 {
  margin: 0;
  text-transform: capitalize;
}

.conn-status {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.conn-status.connected {
  color: #16a34a;
}

/* API key status */
.apikeys-status {
  margin-bottom: 10px;
}

.apikey-status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  padding: 4px 0;
}

.apikey-status-item .key-name {
  font-weight: 600;
  color: var(--text);
}

.apikey-status-item .key-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
}

.apikey-status-item .key-badge.set {
  background: #dcfce7;
  color: #16a34a;
}

.apikey-status-item .key-badge.unset {
  background: #fef2f2;
  color: var(--danger);
}

/* Small button variant */
button.small {
  width: auto;
  padding: 6px 12px;
  font-size: 12px;
}

@media (max-width: 980px) {
  .page {
    padding: 12px;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .editor-header {
    flex-direction: column;
    align-items: stretch;
  }

  .editor-controls {
    flex-wrap: wrap;
  }

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

  .agent-header {
    flex-direction: column;
    align-items: stretch;
  }

  .agent-header select {
    width: 100%;
    min-width: 0;
  }

  .tab-btn {
    padding: 8px 10px;
    font-size: 12px;
  }
}
