﻿/* ─── RESET & BASE ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:    #0a0c0f;
  --bg-card:    #111418;
  --bg-card2:   #161b22;
  --bg-hover:   #1c2330;
  --border:     #21262d;
  --border-2:   #30363d;
  --text-1:     #e6edf3;
  --text-2:     #8b949e;
  --text-3:     #6e7681;
  --green-1:    #3fb950;
  --green-2:    #25D366;
  --green-glow: rgba(37, 211, 102, 0.25);
  --red-1:      #f85149;
  --red-glow:   rgba(248, 81, 73, 0.2);
  --yellow-1:   #d29922;
  --blue-1:     #58a6ff;
  --accent:     #25D366;
  --accent-dark:#128C7E;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.6);
  --transition: 0.2s ease;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-base);
  color: var(--text-1);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── HEADER ───────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10, 12, 15, 0.95);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 0 1.5rem;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }

.brand-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 16px var(--green-glow);
}

.brand-icon svg { width: 100%; height: 100%; }

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-size: 15px; font-weight: 700; color: var(--text-1); line-height: 1.2; }
.brand-sub  { font-size: 11px; color: var(--text-3); font-weight: 400; }

.header-status { display: flex; align-items: center; gap: 0.75rem; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-3);
  transition: background var(--transition);
}
.status-dot.connected { background: var(--green-1); box-shadow: 0 0 8px var(--green-glow); animation: pulse 2s infinite; }
.status-dot.error     { background: var(--red-1); }

@keyframes pulse {
  0%,100% { opacity:1; } 50% { opacity: 0.5; }
}

#connectionStatus { font-size: 12px; color: var(--text-2); }

.api-badge {
  padding: 3px 10px;
  background: rgba(37,211,102,0.1);
  border: 1px solid rgba(37,211,102,0.25);
  border-radius: 100px;
  font-size: 11px;
  color: var(--green-2);
  font-family: monospace;
}

/* ─── LAYOUT ───────────────────────────────────────────────── */
.main {
  flex: 1; display: flex;
  max-width: 1400px; width: 100%; margin: 0 auto;
  padding: 1.5rem;
  gap: 1.5rem;
}

.sidebar {
  width: 220px; flex-shrink: 0;
  display: flex; flex-direction: column;
  gap: 0.5rem;
}

.sidebar-section { display: flex; flex-direction: column; gap: 0.5rem; }

.sidebar-title {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 0 4px;
}

.sidebar-subtitle {
  font-size: 11px; font-weight: 500;
  color: var(--text-3); padding: 0 4px;
}

.instance-count {
  font-size: 24px; font-weight: 800;
  color: var(--text-1); padding: 4px;
}

.content { flex: 1; display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }

/* ─── BUTTONS ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  user-select: none;
}

.btn svg { width: 16px; height: 16px; }

.btn-full { width: 100%; }

.btn-primary {
  background: linear-gradient(135deg, var(--green-2), var(--accent-dark));
  color: #fff;
  box-shadow: 0 2px 12px var(--green-glow);
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 4px 20px var(--green-glow); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-card2);
  color: var(--text-2);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-1); border-color: var(--border-2); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-1); }

.btn-danger {
  background: rgba(248,81,73,0.1);
  color: var(--red-1);
  border-color: rgba(248,81,73,0.3);
}
.btn-danger:hover { background: rgba(248,81,73,0.2); }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 12px; }
.btn-sm svg { width: 13px; height: 13px; }

/* ─── PILLS ────────────────────────────────────────────────── */
.filter-pills { display: flex; flex-direction: column; gap: 3px; }

.pill {
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  font-size: 12px; font-weight: 500;
  cursor: pointer; border: none;
  background: transparent;
  color: var(--text-2);
  text-align: left;
  transition: all var(--transition);
}
.pill:hover    { background: var(--bg-card2); color: var(--text-1); }
.pill-active   { background: rgba(37,211,102,0.12) !important; color: var(--green-2) !important; }

/* ─── STATS ROW ────────────────────────────────────────────── */
.stats-row { display: flex; gap: 1rem; }

.stat-card {
  flex: 1; display: flex; align-items: center; gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--border-2); }

.stat-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 18px; height: 18px; }
.stat-green { background: rgba(37,211,102,0.12); color: var(--green-1); }
.stat-red   { background: rgba(248,81,73,0.12); color: var(--red-1); }
.stat-blue  { background: rgba(88,166,255,0.12); color: var(--blue-1); }

.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--text-1); line-height: 1; }
.stat-label { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ─── INSTANCE CARDS ───────────────────────────────────────── */
.instances-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.instance-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
  animation: fadeIn 0.3s ease;
}

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

.instance-card:hover {
  border-color: var(--border-2);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.instance-card::before {
  content: '';
  position: absolute; top:0; left:0; right:0; height:2px;
  background: linear-gradient(90deg, var(--green-2), var(--accent-dark));
  opacity: 0;
  transition: opacity var(--transition);
}
.instance-card.connected::before { opacity: 1; }
.instance-card.disconnected::before { background: linear-gradient(90deg, var(--red-1), #c0392b); opacity:0.5; }

.instance-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.75rem; }

.instance-avatar {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(37,211,102,0.2), rgba(18,140,126,0.2));
  border: 1px solid rgba(37,211,102,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: var(--green-2);
  flex-shrink: 0;
}

.instance-info { flex: 1; min-width: 0; }
.instance-name { font-size: 14px; font-weight: 600; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.instance-id   { font-size: 11px; color: var(--text-3); margin-top: 2px; font-family: monospace; }

.status-badge {
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap; flex-shrink: 0;
}
.status-open   { background: rgba(63,185,80,0.15); color: var(--green-1); border: 1px solid rgba(63,185,80,0.3); }
.status-close  { background: rgba(248,81,73,0.12); color: var(--red-1); border: 1px solid rgba(248,81,73,0.25); }
.status-connecting { background: rgba(210,153,34,0.12); color: var(--yellow-1); border: 1px solid rgba(210,153,34,0.25); }

.instance-meta { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.meta-chip {
  padding: 2px 8px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 10px; color: var(--text-3);
  font-family: monospace;
}

.instance-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ─── EMPTY / LOADING STATES ───────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4rem 2rem; text-align: center;
  flex: 1;
}
.empty-icon { margin-bottom: 1.5rem; }
.empty-icon svg { width: 80px; height: 80px; }
.empty-title { font-size: 18px; font-weight: 700; color: var(--text-1); margin-bottom: 0.5rem; }
.empty-text  { font-size: 14px; color: var(--text-2); margin-bottom: 1.5rem; max-width: 360px; }

.loading-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4rem 2rem; gap: 1rem; color: var(--text-3);
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--green-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── MODALS ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-2);
  border-radius: 16px;
  width: 480px; max-width: calc(100vw - 2rem);
  box-shadow: var(--shadow-lg);
  transform: translateY(16px);
  transition: transform var(--transition);
  max-height: 90vh; overflow-y: auto;
}
.modal-sm { width: 380px; }
.modal-overlay.open .modal { transform: none; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 700; }

.modal-close {
  width: 28px; height: 28px;
  border: none; background: var(--bg-card2);
  border-radius: 6px; cursor: pointer; color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-1); }
.modal-close svg { width: 14px; height: 14px; }

.modal-body { padding: 1.5rem; }

.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem; }

/* ─── FORMS ────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-2); }

input[type="text"], input[type="url"] {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 14px; font-family: inherit;
  padding: 0.6rem 0.9rem;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(37,211,102,0.15); }

.form-hint { font-size: 11px; color: var(--text-3); }

.form-row { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }

.form-check { display: flex; align-items: center; gap: 0.5rem; }
.form-check input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--green-2);
  cursor: pointer;
}
.form-check label { font-size: 13px; color: var(--text-2); cursor: pointer; }

/* ─── ALERTS ───────────────────────────────────────────────── */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); font-size: 13px; }
.alert-error { background: rgba(248,81,73,0.1); border: 1px solid rgba(248,81,73,0.3); color: var(--red-1); }

/* ─── QR CODE ──────────────────────────────────────────────── */
.text-center { text-align: center; }
.qr-instance-name { font-size: 13px; color: var(--text-3); margin-bottom: 1rem; font-family: monospace; }

.qr-container {
  width: 220px; height: 220px; margin: 0 auto 1rem;
  background: white; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
.qr-container img { width: 100%; height: 100%; object-fit: contain; }
.qr-container .spinner { border-top-color: #128C7E; }

.qr-instructions { font-size: 13px; color: var(--text-2); line-height: 1.8; }
.qr-status { font-size: 13px; font-weight: 600; margin-top: 0.75rem; }
.qr-status.connected { color: var(--green-1); }

/* ─── TOASTS ───────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 300; display: flex; flex-direction: column; gap: 0.5rem; }

.toast {
  padding: 0.75rem 1.25rem;
  background: var(--bg-card2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
  max-width: 300px;
}
.toast-success { border-left: 3px solid var(--green-1); color: var(--green-1); }
.toast-error   { border-left: 3px solid var(--red-1); color: var(--red-1); }
.toast-info    { border-left: 3px solid var(--blue-1); color: var(--blue-1); }

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

/* ─── RESPONSIVE ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .main { flex-direction: column; padding: 1rem; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .filter-pills { flex-direction: row; }
  .stats-row { flex-direction: column; }
  .sidebar-section { flex: 1; min-width: 0; }
}
