/* ─── Xiaozhi MCP Dashboard — Custom Styles ─────────────────────────────── */

@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@300;400;500&display=swap");

/* ─── CSS Variables ──────────────────────────────────────────────────────── */
:root {
  --bg: #0c0d10;
  --bg-surface: #13151a;
  --bg-card: #191c23;
  --bg-card-hover: #1f2330;
  --border: rgba(255, 255, 255, 0.07);
  --border-active: rgba(245, 158, 11, 0.4);
  --text-primary: #f0f2f5;
  --text-secondary: #8b909e;
  --text-muted: #545a6b;
  --accent: #f59e0b;
  --accent-dim: rgba(245, 158, 11, 0.12);
  --accent-glow: rgba(245, 158, 11, 0.3);
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.12);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.12);
  --blue: #6366f1;
  --blue-dim: rgba(99, 102, 241, 0.12);
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-accent: 0 0 30px rgba(245, 158, 11, 0.15);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Visibility (MUST be first, overrides everything) ───────────────────── */
.hidden { display: none !important; }

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

html { scroll-behavior: smooth; }

body {
  font-family: "DM Sans", sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(245, 158, 11, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(99, 102, 241, 0.04) 0%, transparent 50%);
}

/* ─── Typography ─────────────────────────────────────────────────────────── */
.mono { font-family: "DM Mono", monospace; }

/* ─── Noise Texture Overlay ──────────────────────────────────────────────── */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ─── Page ───────────────────────────────────────────────────────────────── */
#app { position: relative; z-index: 1; }

/* ─── Auth Screen ────────────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 40px;
  box-shadow: var(--shadow);
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.auth-logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--accent), #d97706);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.auth-logo-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.auth-logo-text span { color: var(--accent); }

.auth-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

/* ─── Form Elements ──────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}

.field input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.field input:focus {
  border-color: var(--border-active);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

.field input::placeholder { color: var(--text-muted); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  letter-spacing: 0.1px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #d97706);
  color: #0c0d10;
  width: 100%;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.2);
}

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

.btn-ghost:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Auth Links ─────────────────────────────────────────────────────────── */
.auth-links {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.auth-link {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  transition: color var(--transition);
  padding: 2px;
}

.auth-link span { color: var(--accent); font-weight: 500; }
.auth-link:hover { color: var(--text-primary); }

/* ─── Dashboard Layout ───────────────────────────────────────────────────── */
.dashboard { min-height: 100vh; display: flex; flex-direction: column; }

/* ─── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(12, 13, 16, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
}

.topbar-logo-icon {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, var(--accent), #d97706);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #0c0d10;
}

.topbar-logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.topbar-logo-text span { color: var(--accent); }

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.4s ease;
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 6px var(--green), 0 0 14px rgba(16, 185, 129, 0.3);
  animation: pulse 2s infinite;
}

.status-dot.disconnected { background: var(--text-muted); }

.topbar-spacer { flex: 1; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

/* ─── Main Content ───────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 32px 28px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

/* ─── Section Header ─────────────────────────────────────────────────────── */
.section-header {
  margin-bottom: 20px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.section-desc {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ─── Connect Panel ──────────────────────────────────────────────────────── */
.connect-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 28px;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.connect-panel .field {
  flex: 1;
  min-width: 220px;
  margin-bottom: 0;
}

.connect-actions { display: flex; gap: 10px; flex-shrink: 0; }

/* ─── Tools Grid ─────────────────────────────────────────────────────────── */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

@media (max-width: 680px) {
  .tools-grid { grid-template-columns: 1fr; }
  .connect-panel { flex-direction: column; }
  .connect-actions { width: 100%; }
  .connect-actions .btn { flex: 1; }
  .topbar { padding: 0 16px; }
  .main-content { padding: 20px 16px; }
}

/* ─── Tool Card ──────────────────────────────────────────────────────────── */
.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.tool-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 60%, rgba(245, 158, 11, 0.03));
  pointer-events: none;
}

.tool-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.tool-card.enabled {
  border-color: var(--border-active);
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.08), var(--shadow-accent);
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.tool-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.tool-icon.search { background: var(--blue-dim); color: #818cf8; }
.tool-icon.telegram { background: rgba(14, 165, 233, 0.12); color: #38bdf8; }
.tool-icon.currency { background: var(--green-dim); color: #34d399; }
.tool-icon.wiki { background: rgba(168, 85, 247, 0.12); color: #c084fc; }

.tool-info { flex: 1; min-width: 0; }

.tool-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* ─── Toggle Switch ──────────────────────────────────────────────────────── */
.toggle-wrap { flex-shrink: 0; }

.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 22px;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all var(--transition);
}

.toggle input:checked + .toggle-slider { background: var(--accent-dim); }
.toggle input:checked + .toggle-slider::before {
  background: var(--accent);
  transform: translateX(18px);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ─── Tool Extra Fields ──────────────────────────────────────────────────── */
.tool-extra {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-extra.hidden { display: none; }

.tool-extra .field { margin-bottom: 0; }

.tool-extra .btn {
  align-self: flex-start;
  padding: 8px 16px;
  font-size: 13px;
}

/* ─── Stats Strip ────────────────────────────────────────────────────────── */
.stats-strip {
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-chip i { font-size: 12px; color: var(--text-muted); }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
}

.modal-close:hover { background: rgba(255, 255, 255, 0.1); color: var(--text-primary); }

/* ─── API Keys Panel ─────────────────────────────────────────────────────── */
.apikeys-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 28px;
}

/* ─── Toast Notifications ────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  max-width: 340px;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid transparent;
}

.toast.success {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.25);
  color: #6ee7b7;
}

.toast.error {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

.toast.info {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
}

.toast-icon { font-size: 14px; flex-shrink: 0; }
.toast-dismiss { animation: fadeOut 0.25s ease forwards; }

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

/* ─── Spinner ────────────────────────────────────────────────────────────── */
.fa-spinner { animation: spin 0.8s linear infinite; }

/* ─── Keyframes ──────────────────────────────────────────────────────────── */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(12px); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 4px var(--green), 0 0 10px rgba(16, 185, 129, 0.2); }
  50%       { box-shadow: 0 0 8px var(--green), 0 0 20px rgba(16, 185, 129, 0.4); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ─── Message Boxes ──────────────────────────────────────────────────────── */
.msg-box {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.msg-box.success { background: var(--green-dim); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.2); }
.msg-box.error   { background: var(--red-dim);   color: #f87171; border: 1px solid rgba(239, 68, 68, 0.2); }
.msg-box.info    { background: var(--blue-dim);  color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.2); }
.msg-box.hidden  { display: none; }

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }