@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ═══════════════════════════════
   DESIGN TOKENS
═══════════════════════════════ */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #0f1628;
  --bg-card: #131c35;
  --bg-card-hover: #182040;
  --bg-input: #0d1526;
  --bg-modal: #111827;

  --accent-primary: #3b82f6;
  --accent-secondary: #6366f1;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --accent-info: #06b6d4;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --border-color: rgba(59, 130, 246, 0.15);
  --border-color-hover: rgba(59, 130, 246, 0.4);

  --glow-blue: 0 0 20px rgba(59, 130, 246, 0.3);
  --glow-green: 0 0 20px rgba(16, 185, 129, 0.3);
  --glow-red: 0 0 20px rgba(239, 68, 68, 0.3);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-modal: 0 20px 60px rgba(0, 0, 0, 0.6);

  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);

  --sidebar-width: 260px;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; outline: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; outline: none; border: none; }
img { max-width: 100%; }
ul { list-style: none; }

/* ═══════════════════════════════
   SCROLLBAR
═══════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-color-hover); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }

/* ═══════════════════════════════
   LAYOUT
═══════════════════════════════ */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: var(--transition-slow);
}

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

/* ═══════════════════════════════
   SIDEBAR
═══════════════════════════════ */
.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; gap: 12px;
}

.sidebar-logo .logo-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: var(--glow-blue);
  flex-shrink: 0;
}

.sidebar-logo .logo-text { font-weight: 700; font-size: 16px; }
.sidebar-logo .logo-sub { font-size: 11px; color: var(--text-secondary); }

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

.nav-section { margin-bottom: 24px; }
.nav-section-title {
  font-size: 10px; font-weight: 600; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--text-muted);
  padding: 0 8px 8px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-md);
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
  transition: var(--transition); cursor: pointer; margin-bottom: 2px;
  position: relative;
}

.nav-item:hover {
  background: rgba(59, 130, 246, 0.08);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; border-radius: 0 2px 2px 0;
  background: var(--accent-primary);
}

.nav-item .nav-icon { font-size: 18px; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--accent-danger);
  color: white; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: var(--radius-full);
}

.sidebar-user {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex; align-items: center; gap: 10px;
}

.user-avatar {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-secondary); text-transform: capitalize; }

.btn-logout {
  color: var(--text-muted); font-size: 18px; padding: 4px;
  border-radius: var(--radius-sm); transition: var(--transition);
}
.btn-logout:hover { color: var(--accent-danger); background: rgba(239, 68, 68, 0.1); }

/* ═══════════════════════════════
   TOPBAR
═══════════════════════════════ */
.topbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}

.topbar-title { font-size: 20px; font-weight: 700; }
.topbar-subtitle { font-size: 13px; color: var(--text-secondary); }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* ═══════════════════════════════
   CONTENT AREA
═══════════════════════════════ */
.content-area { flex: 1; padding: 24px; overflow-y: auto; }
.page { display: none; }
.page.active { display: block; }

/* ═══════════════════════════════
   CARDS
═══════════════════════════════ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-card);
  transition: var(--transition);
}

.card:hover { border-color: var(--border-color-hover); }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.card-title { font-size: 16px; font-weight: 700; }
.card-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

/* ═══════════════════════════════
   STATS GRID
═══════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; flex-direction: column; gap: 8px;
  transition: var(--transition);
  cursor: default;
}

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

.stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; margin-bottom: 4px;
}

.stat-icon.blue { background: rgba(59, 130, 246, 0.15); }
.stat-icon.green { background: rgba(16, 185, 129, 0.15); }
.stat-icon.yellow { background: rgba(245, 158, 11, 0.15); }
.stat-icon.red { background: rgba(239, 68, 68, 0.15); }

.stat-value { font-size: 28px; font-weight: 800; }
.stat-label { font-size: 13px; color: var(--text-secondary); }

/* ═══════════════════════════════
   INSTANCE CARDS GRID
═══════════════════════════════ */
.instances-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.instance-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.instance-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent-primary);
  opacity: 0;
  transition: var(--transition);
}

.instance-card:hover {
  border-color: var(--border-color-hover);
  transform: translateY(-3px);
  box-shadow: var(--shadow-card);
}
.instance-card:hover::before { opacity: 1; }

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

.instance-name { font-size: 16px; font-weight: 700; }
.instance-host { font-size: 12px; color: var(--text-muted); margin-top: 2px; word-break: break-all; }

.instance-status {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}

.instance-status.connected { background: rgba(16, 185, 129, 0.15); color: var(--accent-success); }
.instance-status.disconnected { background: rgba(239, 68, 68, 0.15); color: var(--accent-danger); }
.instance-status.qrcode { background: rgba(245, 158, 11, 0.15); color: var(--accent-warning); }
.instance-status.loading { background: rgba(59, 130, 246, 0.15); color: var(--accent-primary); }
.instance-status.unknown { background: rgba(100, 116, 139, 0.15); color: var(--text-secondary); }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
}
.connected .status-dot { background: var(--accent-success); animation: pulse-green 2s infinite; }
.disconnected .status-dot { background: var(--accent-danger); }
.qrcode .status-dot { background: var(--accent-warning); animation: pulse-yellow 2s infinite; }
.loading .status-dot { background: var(--accent-primary); animation: pulse-blue 2s infinite; }
.unknown .status-dot { background: var(--text-secondary); }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}
@keyframes pulse-yellow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}
@keyframes pulse-blue {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); }
}

.instance-sessions-info {
  display: flex; gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.sessions-stat { text-align: center; flex: 1; }
.sessions-stat-value { font-size: 20px; font-weight: 800; }
.sessions-stat-label { font-size: 11px; color: var(--text-secondary); }

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

/* ═══════════════════════════════
   BUTTONS
═══════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 600;
  transition: var(--transition); cursor: pointer;
  white-space: nowrap;
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon { padding: 8px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

.btn-success {
  background: rgba(16, 185, 129, 0.15); color: var(--accent-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.btn-success:hover { background: rgba(16, 185, 129, 0.25); }

.btn-warning {
  background: rgba(245, 158, 11, 0.15); color: var(--accent-warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.btn-warning:hover { background: rgba(245, 158, 11, 0.25); }

.btn-danger {
  background: rgba(239, 68, 68, 0.15); color: var(--accent-danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

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

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ═══════════════════════════════
   FORMS
═══════════════════════════════ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 8px;
}
.form-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  transition: var(--transition);
}
.form-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.form-input::placeholder { color: var(--text-muted); }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.form-error { font-size: 12px; color: var(--accent-danger); margin-top: 6px; }

/* ═══════════════════════════════
   TABLE
═══════════════════════════════ */
.table-wrapper { overflow-x: auto; }

.table {
  width: 100%; border-collapse: collapse;
  font-size: 14px;
}

.table th {
  text-align: left; padding: 12px 16px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.5px;
  text-transform: uppercase; color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(59, 130, 246, 0.06);
  color: var(--text-secondary);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(59, 130, 246, 0.04); }
.table td strong { color: var(--text-primary); }

/* ═══════════════════════════════
   BADGES & TAGS
═══════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: 11px; font-weight: 600;
}
.badge-admin { background: rgba(139, 92, 246, 0.15); color: #a78bfa; }
.badge-manager { background: rgba(59, 130, 246, 0.15); color: var(--accent-primary); }
.badge-viewer { background: rgba(100, 116, 139, 0.15); color: var(--text-secondary); }
.badge-active { background: rgba(16, 185, 129, 0.15); color: var(--accent-success); }
.badge-inactive { background: rgba(239, 68, 68, 0.15); color: var(--accent-danger); }

/* ═══════════════════════════════
   MODAL
═══════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; visibility: hidden;
  transition: var(--transition);
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 28px;
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-modal);
  transform: scale(0.95) translateY(10px);
  transition: var(--transition);
}
.modal-overlay.active .modal { transform: scale(1) translateY(0); }

.modal-lg { max-width: 720px; }
.modal-xl { max-width: 900px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close {
  color: var(--text-muted); font-size: 20px; padding: 4px;
  border-radius: var(--radius-sm); transition: var(--transition);
}
.modal-close:hover { color: var(--text-primary); background: var(--border-color); }

.modal-footer {
  display: flex; gap: 12px; justify-content: flex-end;
  margin-top: 24px; padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

/* ═══════════════════════════════
   CHAT / MESSAGES
═══════════════════════════════ */
.chat-list { display: flex; flex-direction: column; gap: 4px; }

.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-md);
  cursor: pointer; transition: var(--transition);
  border: 1px solid transparent;
}
.chat-item:hover { background: var(--bg-card-hover); border-color: var(--border-color); }
.chat-item.active { background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.3); }

.chat-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
  overflow: hidden;
}
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }

.chat-info { flex: 1; min-width: 0; }
.chat-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-last-msg { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.chat-unread {
  background: var(--accent-primary);
  color: white; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: var(--radius-full);
  min-width: 20px; text-align: center;
}

/* Messages */
.messages-container {
  display: flex; flex-direction: column; gap: 12px;
  padding: 20px;
  flex: 1; overflow-y: auto;
}

.message-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px; line-height: 1.5;
  position: relative;
}

.message-incoming {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
}

.message-outgoing {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(99, 102, 241, 0.3));
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-lg) 4px var(--radius-lg) var(--radius-lg);
}

.message-time { font-size: 10px; color: var(--text-muted); margin-top: 4px; text-align: right; }
.message-sender { font-size: 11px; color: var(--accent-primary); font-weight: 600; margin-bottom: 4px; }

/* ═══════════════════════════════
   QR CODE DISPLAY
═══════════════════════════════ */
.qr-container {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: 24px;
}
.qr-code-img {
  width: 220px; height: 220px;
  background: white;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
  box-shadow: var(--glow-blue);
}
.qr-code-img img { width: 100%; height: 100%; }
.qr-instruction { font-size: 13px; color: var(--text-secondary); text-align: center; }

/* ═══════════════════════════════
   SESSION CARDS INSIDE INSTANCE
═══════════════════════════════ */
.session-row {
  display: flex; align-items: center; gap: 16px;
  padding: 14px; border-radius: var(--radius-md);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  margin-bottom: 8px;
  transition: var(--transition);
}
.session-row:hover { border-color: var(--border-color-hover); }

.session-name { font-weight: 600; font-size: 15px; }
.session-phone { font-size: 13px; color: var(--text-muted); }
.session-actions { margin-left: auto; display: flex; gap: 8px; }

/* ═══════════════════════════════
   PERMISSION CHECKBOXES
═══════════════════════════════ */
.perm-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 8px;
}
.perm-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: var(--radius-md);
  background: var(--bg-input); border: 1px solid var(--border-color);
  font-size: 13px;
}
.perm-item input[type="checkbox"] {
  width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent-primary);
}

/* ═══════════════════════════════
   LOGIN PAGE
═══════════════════════════════ */
#login-page {
  min-height: 100vh;
  background: var(--bg-primary);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  position: relative; overflow: hidden;
}

#login-page::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.1) 0%, transparent 70%);
  top: -200px; left: -200px; pointer-events: none;
}
#login-page::after {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.08) 0%, transparent 70%);
  bottom: -200px; right: -200px; pointer-events: none;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 860px;
  box-shadow: var(--shadow-modal);
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  min-height: 520px;
}

.login-hero {
  min-height: 420px;
}

.login-form-panel {
  padding: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

@media (max-width: 700px) {
  .login-card {
    grid-template-columns: 1fr;
  }
  .login-hero {
    min-height: 200px;
    border-radius: 0 !important;
  }
  .login-form-panel {
    padding: 28px 24px;
  }
}

.login-logo {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 32px;
}
.login-logo .logo-icon {
  width: 52px; height: 52px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  box-shadow: var(--glow-blue);
}
.login-logo .logo-name { font-size: 22px; font-weight: 800; }
.login-logo .logo-sub { font-size: 13px; color: var(--text-secondary); }

.login-title { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.login-sub { font-size: 14px; color: var(--text-secondary); margin-bottom: 28px; }

.login-submit {
  width: 100%; padding: 13px;
  font-size: 15px; font-weight: 700;
  border-radius: var(--radius-md);
}

.login-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--accent-danger);
  padding: 10px 14px; border-radius: var(--radius-md);
  font-size: 13px; margin-bottom: 16px;
  display: none;
}
.login-error.show { display: block; }

/* ═══════════════════════════════
   LOADING STATES
═══════════════════════════════ */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }
.spinner-dark { border-color: rgba(59, 130, 246, 0.2); border-top-color: var(--accent-primary); }

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

.loading-overlay {
  display: flex; align-items: center; justify-content: center;
  padding: 60px; flex-direction: column; gap: 16px;
  color: var(--text-secondary);
}

/* ═══════════════════════════════
   SEARCH BOX
═══════════════════════════════ */
.search-box {
  position: relative;
}
.search-box .search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 16px; pointer-events: none;
}
.search-box input { padding-left: 38px; }

/* ═══════════════════════════════
   ALERT / TOAST
═══════════════════════════════ */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
  max-width: 360px;
}

.toast {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border-left: 4px solid var(--accent-primary);
  box-shadow: var(--shadow-modal);
  font-size: 14px;
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.3s ease;
}
.toast.success { border-color: var(--accent-success); }
.toast.error { border-color: var(--accent-danger); }
.toast.warning { border-color: var(--accent-warning); }

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

/* ═══════════════════════════════
   EMPTY STATE
═══════════════════════════════ */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state .empty-title { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state .empty-sub { font-size: 14px; }

/* ═══════════════════════════════
   RESPONSIVE
═══════════════════════════════ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
  .instances-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .perm-grid { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════
   ANIMATIONS
═══════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease; }

.instance-card, .stat-card, .session-row, .chat-item {
  animation: fadeIn 0.3s ease;
}

/* Gradient Text */
.gradient-text {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

/* Instance Detail Layout */
.instance-detail-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  height: calc(100vh - 130px);
}

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

.chat-panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex; flex-direction: column; gap: 10px;
}

.chat-panel-body {
  flex: 1; overflow-y: auto; padding: 8px;
}

.messages-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.messages-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; gap: 12px;
}

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

.phone-search-bar {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex; gap: 10px;
}

/* Toggle switch */
.toggle {
  position: relative; width: 44px; height: 24px;
}
.toggle input { display: none; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--text-muted); border-radius: var(--radius-full);
  cursor: pointer; transition: var(--transition);
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px;
  bottom: 3px; left: 3px;
  background: white; border-radius: 50%;
  transition: var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--accent-primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }
