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

:root {
  --purple: #6C63FF;
  --teal: #00D4AA;
  --dark: #0D0F1A;
  --dark2: #141624;
  --dark3: #1C1F35;
  --card: #1A1D2E;
  --border: rgba(108, 99, 255, 0.18);
  --text: #E8EAF6;
  --muted: #7B7FA8;
  --success: #00D4AA;
  --danger: #FF4D6A;
  --warning: #FFB547;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,0.35);
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--dark);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
input, select, textarea { font-family: inherit; }

/* ===== LOGIN ===== */
.page-login {
  background: radial-gradient(ellipse at 60% 10%, rgba(108,99,255,0.12) 0%, transparent 60%),
              radial-gradient(ellipse at 10% 80%, rgba(0,212,170,0.08) 0%, transparent 50%),
              var(--dark);
}

.login-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.brand {
  text-align: center;
  margin-bottom: 36px;
}

.brand-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
}

.brand-icon svg { width: 56px; height: 56px; }

.brand h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.brand h1 span {
  background: linear-gradient(135deg, var(--purple), var(--teal));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand p {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

.field {
  margin-bottom: 20px;
}

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.field input, .field select {
  width: 100%;
  padding: 12px 16px;
  background: var(--dark3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9375rem;
  transition: border-color 0.2s;
  outline: none;
}

.field input:focus, .field select:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.15);
}

.field select option { background: var(--dark3); }

.btn-primary {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--purple), #5A52E0);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

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

.footer-text {
  color: var(--muted);
  font-size: 0.8125rem;
  margin-top: 24px;
}

/* ===== SPINNER ===== */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

/* ===== LAYOUT GERAL (dashboard + admin) ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--dark2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 28px 0;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 24px 28px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand svg { width: 32px; height: 32px; }

.sidebar-brand .name {
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
}

.sidebar-brand .name span {
  background: linear-gradient(135deg, var(--purple), var(--teal));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-nav {
  flex: 1;
  padding: 20px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 24px;
  color: var(--muted);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.2s;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { color: var(--text); background: rgba(108,99,255,0.08); }
.nav-item.active {
  color: var(--purple);
  background: rgba(108,99,255,0.12);
  border-left: 3px solid var(--purple);
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-user {
  padding: 20px 24px 0;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--teal));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  color: #fff;
  flex-shrink: 0;
}

.user-name { font-size: 0.875rem; font-weight: 600; }
.user-role { font-size: 0.75rem; color: var(--muted); }

.btn-logout {
  width: 100%;
  padding: 9px;
  background: rgba(255,77,106,0.1);
  border: 1px solid rgba(255,77,106,0.2);
  color: var(--danger);
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-logout:hover { background: rgba(255,77,106,0.18); }

.main-content {
  flex: 1;
  padding: 36px;
  overflow-y: auto;
  background: radial-gradient(ellipse at 80% 0%, rgba(108,99,255,0.06) 0%, transparent 50%), var(--dark);
}

.page-header { margin-bottom: 32px; }
.page-header h2 { font-size: 1.5rem; font-weight: 700; }
.page-header p { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }

/* ===== CARDS ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

/* ===== GRID CONEXÕES ===== */
.connections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.conn-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: border-color 0.2s, transform 0.2s;
  cursor: pointer;
}

.conn-card:hover {
  border-color: var(--purple);
  transform: translateY(-2px);
}

.conn-card.active-card { border-color: var(--teal); }

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

.conn-name {
  font-weight: 700;
  font-size: 1rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-connected { background: rgba(0,212,170,0.12); color: var(--success); }
.status-connecting { background: rgba(255,181,71,0.12); color: var(--warning); }
.status-disconnected { background: rgba(255,77,106,0.12); color: var(--danger); }
.status-unknown { background: rgba(123,127,168,0.12); color: var(--muted); }

.conn-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn-sm {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}

.btn-sm:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm:hover:not(:disabled) { opacity: 0.85; }

.btn-connect {
  background: linear-gradient(135deg, var(--purple), var(--teal));
  color: #fff;
}

.btn-disconnect {
  background: rgba(255,77,106,0.15);
  color: var(--danger);
  border: 1px solid rgba(255,77,106,0.25) !important;
}

.btn-refresh {
  background: rgba(108,99,255,0.12);
  color: var(--purple);
  border: 1px solid rgba(108,99,255,0.2) !important;
}

/* ===== QR CODE MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  padding: 24px;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.modal h3 { font-size: 1.125rem; font-weight: 700; margin-bottom: 8px; }
.modal p { color: var(--muted); font-size: 0.875rem; margin-bottom: 24px; }

.qr-container {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  display: inline-block;
  margin-bottom: 20px;
}

.qr-container img {
  display: block;
  width: 220px;
  height: 220px;
}

.qr-loading {
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: var(--muted);
  font-size: 0.875rem;
}

.qr-loading .spinner {
  border-color: rgba(108,99,255,0.3);
  border-top-color: var(--purple);
  width: 36px;
  height: 36px;
}

.qr-status {
  margin-bottom: 16px;
  padding: 10px;
  border-radius: 8px;
}

.countdown {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-bottom: 16px;
}

.btn-close-modal {
  background: var(--dark3);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 10px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: color 0.2s;
}

.btn-close-modal:hover { color: var(--text); }

/* ===== ADMIN TABS ===== */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--dark3);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 28px;
  width: fit-content;
}

.tab {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--muted);
  transition: all 0.2s;
}

.tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  text-align: left;
  padding: 10px 16px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(108,99,255,0.07);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(108,99,255,0.04); }

.role-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}

.role-admin { background: rgba(108,99,255,0.15); color: var(--purple); }
.role-client { background: rgba(0,212,170,0.1); color: var(--teal); }

.btn-icon {
  background: rgba(255,77,106,0.1);
  border: 1px solid rgba(255,77,106,0.2);
  color: var(--danger);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-icon:hover { background: rgba(255,77,106,0.2); }
.btn-icon svg { width: 15px; height: 15px; }

/* ===== FORM PANEL ===== */
.form-panel {
  background: var(--dark3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.form-panel h4 {
  font-size: 0.9375rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.btn-add {
  background: linear-gradient(135deg, var(--purple), #5A52E0);
  color: #fff;
  border: none;
  padding: 11px 24px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-add:hover { opacity: 0.9; }

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 16px;
}

.alert-success { background: rgba(0,212,170,0.1); color: var(--teal); border: 1px solid rgba(0,212,170,0.2); }
.alert-error { background: rgba(255,77,106,0.1); color: var(--danger); border: 1px solid rgba(255,77,106,0.2); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
}

.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; padding: 16px 0; flex-direction: row; flex-wrap: wrap; }
  .sidebar-brand { padding: 0 16px 16px; border-bottom: none; border-right: 1px solid var(--border); }
  .sidebar-nav { display: flex; padding: 0 8px; }
  .sidebar-user { padding: 8px 16px; border-top: none; border-left: 1px solid var(--border); }
  .main-content { padding: 20px 16px; }
  .login-card { padding: 32px 24px; }
}
