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

:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-10: rgba(99,102,241,0.1);
  --accent-15: rgba(99,102,241,0.15);
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --cyan: #06b6d4;
}

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

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

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: #0b1120;
  border-right: 1px solid var(--border);
  padding: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand-logo {
  width: 32px; height: 32px; border-radius: 8px; object-fit: contain;
}
.sidebar-brand-text {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0.75rem 0.5rem; flex: 1; }
.sidebar-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.625rem 0.75rem; border-radius: 8px;
  color: var(--text-muted); font-size: 0.875rem;
  transition: all 0.15s;
}
.sidebar-link:hover { background: var(--accent-10); color: var(--text); }
.sidebar-link.active { background: var(--accent-15); color: var(--accent); }
.sidebar-link .icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-link .icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.main { flex: 1; padding: 2rem; overflow-x: hidden; }
.page-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.5rem; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.page-header .page-title { margin-bottom: 0; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  transition: border-color 0.2s, transform 0.2s;
}
.card-hover:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-title { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.card-value { font-size: 1.75rem; font-weight: 700; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }

/* Instance card */
.instance-card { cursor: default; }
.instance-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.instance-name { font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; }
.instance-meta { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; font-size: 0.8rem; }
.instance-meta-item { }
.instance-meta-label { color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; margin-bottom: 2px; }
.instance-meta-value { font-weight: 600; }
.instance-actions { display: flex; gap: 0.5rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.375rem; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 0.625rem 0.75rem;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 0.875rem;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--accent);
}
.form-textarea { min-height: 120px; resize: vertical; font-family: inherit; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }

/* API key input wrapper */
.input-with-toggle { position: relative; }
.input-with-toggle .form-input { padding-right: 3rem; }
.input-toggle-btn {
  position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0.25rem;
}
.input-toggle-btn:hover { color: var(--text); }
.input-toggle-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Color picker */
.color-picker-wrapper { display: flex; align-items: center; gap: 0.75rem; }
.color-picker-input {
  width: 48px; height: 36px; padding: 2px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg-input); cursor: pointer;
}

/* Buttons */
.btn {
  padding: 0.625rem 1.25rem; border-radius: 8px; border: none;
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
  transition: all 0.15s; display: inline-flex; align-items: center; gap: 0.5rem;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-outline {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--text); color: var(--text); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Status indicators */
.status-dot {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
}
.status-dot.connected { background: var(--green); box-shadow: 0 0 8px rgba(34,197,94,0.5); }
.status-dot.disconnected { background: var(--red); }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 0.75rem; text-align: left; border-bottom: 1px solid rgba(71,85,105,0.3);
  font-size: 0.875rem;
}
.table th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }

/* Chat */
.chat-list { max-height: 70vh; overflow-y: auto; }
.chat-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem; border-radius: 8px; cursor: pointer;
  transition: background 0.15s;
}
.chat-item:hover { background: rgba(255,255,255,0.05); }
.chat-item.active { background: var(--accent-15); }
.chat-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.875rem; flex-shrink: 0;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; max-height: 60vh; }
.chat-bubble {
  max-width: 70%; padding: 0.625rem 0.875rem; border-radius: 12px;
  font-size: 0.875rem; line-height: 1.4;
}
.chat-bubble.inbound { background: var(--bg-input); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-bubble.outbound { background: var(--accent); align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-time { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }

/* Copy button */
.copy-btn {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-muted); padding: 0.375rem 0.75rem; cursor: pointer; font-size: 0.8rem;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }

/* API docs */
.endpoint {
  border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 1rem; overflow: hidden;
}
.endpoint-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.875rem 1rem; cursor: pointer; transition: background 0.15s;
}
.endpoint-header:hover { background: rgba(255,255,255,0.03); }
.method-badge {
  padding: 0.25rem 0.625rem; border-radius: 6px; font-size: 0.75rem;
  font-weight: 700; text-transform: uppercase;
}
.method-badge.get { background: rgba(34,197,94,0.15); color: var(--green); }
.method-badge.post { background: rgba(99,102,241,0.15); color: var(--accent); }
.method-badge.put { background: rgba(245,158,11,0.15); color: var(--amber); }
.method-badge.delete { background: rgba(239,68,68,0.15); color: var(--red); }
.endpoint-body { padding: 1rem; border-top: 1px solid var(--border); display: none; }
.endpoint.open .endpoint-body { display: block; }
pre.code {
  background: #0b1120; padding: 0.875rem; border-radius: 8px;
  font-size: 0.8rem; overflow-x: auto; margin: 0.5rem 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
  line-height: 1.5;
}

/* QR Code */
.qr-container {
  width: 240px; height: 240px; background: white; border-radius: 12px;
  padding: 16px; margin: 1rem auto; display: flex; align-items: center; justify-content: center;
}
.qr-container img { width: 100%; height: 100%; object-fit: contain; }

/* Alerts */
.alert {
  padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.875rem;
  margin-bottom: 1rem;
}
.alert-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--green); }
.alert-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--red); }
.alert-info { background: rgba(99,102,241,0.1); border: 1px solid rgba(99,102,241,0.3); color: var(--accent); }

/* Login page */
.login-container {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
}
.login-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 2.5rem; width: 100%; max-width: 400px;
}
.login-logo { display: block; max-width: 48px; max-height: 48px; margin: 0 auto 1rem; border-radius: 8px; }
.login-title { font-size: 1.5rem; font-weight: 700; text-align: center; margin-bottom: 0.5rem; }
.login-subtitle { color: var(--text-muted); text-align: center; margin-bottom: 2rem; font-size: 0.875rem; }

/* Toast notifications */
#toast-container {
  position: fixed; top: 1rem; right: 1rem; z-index: 9999;
  display: flex; flex-direction: column; gap: 0.5rem;
  pointer-events: none;
}
.toast {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.75rem 1rem;
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.875rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transform: translateX(120%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 360px;
  pointer-events: auto;
}
.toast.show { transform: translateX(0); }
.toast-success { border-color: var(--green); }
.toast-success .toast-icon { color: var(--green); }
.toast-error { border-color: var(--red); }
.toast-error .toast-icon { color: var(--red); }
.toast-info { border-color: var(--accent); }
.toast-info .toast-icon { color: var(--accent); }
.toast-icon { flex-shrink: 0; width: 18px; height: 18px; }
.toast-icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--border) 50%, var(--bg-input) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}
.skeleton-line { height: 1rem; margin-bottom: 0.75rem; }
.skeleton-line:nth-child(2) { width: 80%; }
.skeleton-line:nth-child(3) { width: 60%; }
.skeleton-card { height: 120px; margin-bottom: 1rem; }
.skeleton-circle { width: 40px; height: 40px; border-radius: 50%; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s;
}
.modal-content {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  animation: slideUp 0.3s;
}
.modal-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.5rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Empty state */
.empty-state {
  text-align: center; padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 1rem; opacity: 0.4; stroke: currentColor; fill: none; }
.empty-state p { margin-bottom: 1rem; }

/* Badge */
.badge {
  display: inline-flex; align-items: center;
  padding: 0.2rem 0.5rem; border-radius: 9999px;
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
}
.badge-green { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-red { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-accent { background: var(--accent-15); color: var(--accent); }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { padding: 1rem; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .instance-meta { grid-template-columns: repeat(2, 1fr); }
  .mobile-nav {
    display: flex; gap: 4px; overflow-x: auto; padding: 0.5rem;
    background: #0b1120; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
  }
  .mobile-nav a {
    flex-shrink: 0; padding: 0.5rem 0.75rem; border-radius: 6px;
    color: var(--text-muted); font-size: 0.8rem; display: flex; align-items: center; gap: 0.375rem;
  }
  .mobile-nav a.active { background: var(--accent-15); color: var(--accent); }
}
@media (min-width: 769px) {
  .mobile-nav { display: none; }
}

/* Utilities */
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-accent { color: var(--accent); }
.text-amber { color: var(--amber); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.7rem; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-05 { gap: 0.375rem; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none; }
.w-full { width: 100%; }
