/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --black:       #000000;
  --lime:        #b6e23b;
  --lime-dim:    #96bb2a;
  --white:       #ffffff;
  --aqua-gray:   #e6e7e8;
  --mid-gray:    #a6a8ab;
  --surface:     #111111;
  --card:        #1a1a1a;
  --border:      #2a2a2a;
  --border-lite: #333333;
  --danger:      #ff4d4d;
  --sidebar-w:   240px;
  --radius:      8px;
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--black);
  color: var(--white);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--lime); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
}

.login-logo {
  display: block;
  width: 180px;
  margin: 0 auto 32px;
}

.login-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--white);
  text-align: center;
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--mid-gray);
  text-align: center;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--aqua-gray);
  margin-bottom: 6px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.form-input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border-lite);
  border-radius: var(--radius);
  color: var(--white);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
  font-family: var(--font);
}

.form-input:focus {
  border-color: var(--lime);
}

.form-input::placeholder {
  color: var(--mid-gray);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, background 0.15s;
  font-family: var(--font);
  text-decoration: none;
}

.btn-primary {
  background: var(--lime);
  color: var(--black);
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

.btn-primary:hover { background: var(--lime-dim); text-decoration: none; }

.btn-secondary {
  background: var(--card);
  color: var(--white);
  border: 1px solid var(--border-lite);
}

.btn-secondary:hover { background: var(--border); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--mid-gray);
  padding: 8px 12px;
}

.btn-ghost:hover { color: var(--white); background: var(--card); text-decoration: none; }

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.error-msg {
  background: rgba(255, 77, 77, 0.1);
  border: 1px solid rgba(255, 77, 77, 0.3);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── App layout ────────────────────────────────────────────────────────────── */
.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo img {
  width: 140px;
  display: block;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section {
  padding: 0 12px;
  margin-bottom: 4px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--mid-gray);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 12px 8px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--mid-gray);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  margin-bottom: 2px;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--card);
  color: var(--white);
  text-decoration: none;
}

.nav-link.active {
  background: rgba(182, 226, 59, 0.12);
  color: var(--lime);
}

.nav-link svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-link.active svg, .nav-link:hover svg {
  opacity: 1;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--card);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--lime);
  color: var(--black);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-email {
  font-size: 11px;
  color: var(--mid-gray);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--mid-gray);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.12s;
}

.logout-btn:hover { color: var(--danger); }

/* Main content */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--white);
  flex: 1;
}

.content {
  padding: 28px;
  flex: 1;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

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

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
}

/* ── Stats ─────────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--mid-gray);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--white);
  line-height: 1;
}

.stat-sub {
  font-size: 11px;
  color: var(--mid-gray);
  margin-top: 4px;
}

/* ── Client grid ───────────────────────────────────────────────────────────── */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.client-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.15s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.client-card:hover {
  border-color: var(--lime);
  text-decoration: none;
  color: inherit;
}

.client-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.client-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--white);
}

.client-channel {
  font-size: 11px;
  color: var(--mid-gray);
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green  { background: rgba(182, 226, 59, 0.15); color: var(--lime); }
.badge-yellow { background: rgba(255, 200, 50, 0.15); color: #ffc832; }
.badge-gray   { background: var(--card); color: var(--mid-gray); }
.badge-red    { background: rgba(255, 77, 77, 0.15); color: var(--danger); }

.client-meta {
  font-size: 12px;
  color: var(--mid-gray);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.client-meta span { display: flex; align-items: center; gap: 5px; }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--mid-gray);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--white);
  margin-bottom: 6px;
}

.empty-text {
  font-size: 13px;
  margin-bottom: 20px;
}

/* ── Section header ────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
}

/* ── Divider ───────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}

/* ── Testing console ───────────────────────────────────────────────────────── */
.test-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  height: calc(100vh - 65px);
  overflow: hidden;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-header-title { font-size: 13px; font-weight: 600; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}

.msg-user  { align-self: flex-end; align-items: flex-end; }
.msg-agent { align-self: flex-start; align-items: flex-start; }

.msg-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--mid-gray);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-user  .msg-bubble { background: var(--lime); color: var(--black); border-bottom-right-radius: 3px; }
.msg-agent .msg-bubble { background: var(--card); color: var(--white); border-bottom-left-radius: 3px; }

.msg-json {
  background: var(--black);
  border: 1px solid var(--border-lite);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--aqua-gray);
  white-space: pre;
  overflow-x: auto;
  margin-top: 6px;
}

.msg-tool {
  background: rgba(182,226,59,0.07);
  border: 1px solid rgba(182,226,59,0.2);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--lime);
  font-family: 'SF Mono', 'Fira Code', monospace;
  max-width: 100%;
  align-self: flex-start;
}

.msg-tool-label { font-weight: 700; margin-bottom: 3px; opacity: 0.7; font-size: 10px; }

.msg-error .msg-bubble {
  background: rgba(255,77,77,0.12);
  border: 1px solid rgba(255,77,77,0.3);
  color: var(--danger);
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--card);
  border-radius: 12px;
  border-bottom-left-radius: 3px;
  width: fit-content;
}

.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--mid-gray);
  animation: typingBounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border-lite);
  border-radius: 8px;
  color: var(--white);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  resize: none;
  font-family: var(--font);
  line-height: 1.4;
  max-height: 100px;
  transition: border-color .15s;
}
.chat-input:focus { border-color: var(--lime); }
.chat-input::placeholder { color: var(--mid-gray); }

.send-btn {
  width: 36px; height: 36px;
  background: var(--lime);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.send-btn:hover { background: var(--lime-dim); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Meta panel */
.meta-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.meta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.meta-card-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--mid-gray);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 10px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.meta-row:last-child { border-bottom: none; }
.meta-row-label { color: var(--mid-gray); }
.meta-row-value { font-weight: 600; color: var(--white); font-family: monospace; }
.meta-row-value.lime { color: var(--lime); }

.conv-id-box {
  background: var(--card);
  border: 1px solid var(--border-lite);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: monospace;
  font-size: 10px;
  color: var(--mid-gray);
  word-break: break-all;
  line-height: 1.5;
}

.tool-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.tool-log-item {
  background: var(--card);
  border: 1px solid var(--border-lite);
  border-left: 3px solid var(--lime);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 11px;
  font-family: monospace;
}

.tool-log-name { color: var(--lime); font-weight: 700; }
.tool-log-args { color: var(--mid-gray); margin-top: 2px; word-break: break-all; }

.no-key-banner {
  background: rgba(255,200,50,0.08);
  border: 1px solid rgba(255,200,50,0.3);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: #ffc832;
  margin-bottom: 16px;
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-lite); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--mid-gray); }
