/* ============================================
   WhatsApp Dashboard — Design System
   ============================================ */

/* CSS Custom Properties */
:root {
  /* Color Palette — WhatsApp-inspired with premium dark theme */
  --primary: #25D366;
  --primary-hover: #1ebe5a;
  --primary-glow: rgba(37, 211, 102, 0.25);
  --primary-subtle: rgba(37, 211, 102, 0.08);

  --bg-deep: #0a0e17;
  --bg-base: #0f1623;
  --bg-surface: #151d2e;
  --bg-elevated: #1a2540;
  --bg-card: rgba(21, 29, 46, 0.65);
  --bg-hover: rgba(37, 211, 102, 0.06);

  --text-primary: #e8edf5;
  --text-secondary: #8b95a8;
  --text-muted: #5a6478;
  --text-inverse: #0a0e17;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-focus: rgba(37, 211, 102, 0.5);

  --success: #25D366;
  --warning: #f5a623;
  --danger: #e74c6f;
  --info: #4da6ff;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 40px rgba(37, 211, 102, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============ Animated Background ============ */
.bg-decoration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.bg-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.4;
  animation: float 20s ease-in-out infinite;
}

.bg-blob-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(37, 211, 102, 0.15) 0%, transparent 70%);
  top: -200px;
  right: -150px;
  animation-delay: 0s;
}

.bg-blob-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(77, 166, 255, 0.1) 0%, transparent 70%);
  bottom: -150px;
  left: -100px;
  animation-delay: -7s;
}

.bg-blob-3 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(37, 211, 102, 0.08) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -14s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -30px) scale(1.05); }
  50% { transform: translate(-20px, 20px) scale(0.95); }
  75% { transform: translate(15px, 15px) scale(1.02); }
}

/* ============ App Layout ============ */
#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ Header ============ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(15, 22, 35, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.logo-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), #128C46);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 16px rgba(37, 211, 102, 0.3);
}

.logo-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.logo-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Connection Badge */
.connection-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.8rem;
  font-weight: 500;
  transition: var(--transition);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px var(--primary-glow);
  animation: pulse-dot 2s infinite;
}

.status-dot.connecting {
  background: var(--warning);
  animation: pulse-dot 1s infinite;
}

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

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

.status-text {
  color: var(--text-secondary);
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: var(--transition);
}

.btn:hover::after {
  opacity: 1;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #128C46);
  color: white;
  box-shadow: 0 4px 16px rgba(37, 211, 102, 0.25);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(37, 211, 102, 0.35);
}

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

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

.btn-full {
  width: 100%;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-elevated);
  color: var(--danger);
  border-color: rgba(231, 76, 111, 0.3);
}

/* ============ Main Content ============ */
.app-main {
  flex: 1;
  padding: 32px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ============ Glass Card ============ */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

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

/* ============ QR Section ============ */
.qr-section {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 180px);
  animation: fadeInUp 0.6s ease-out;
}

.qr-card {
  width: 100%;
  max-width: 440px;
  padding: 40px;
  text-align: center;
}

.qr-card-header {
  margin-bottom: 32px;
}

.qr-icon {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-xl);
  background: var(--primary-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: var(--primary);
}

.qr-icon.pulse {
  animation: pulse-icon 3s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%, 100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.2); }
  50% { box-shadow: 0 0 0 20px rgba(37, 211, 102, 0); }
}

.qr-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.qr-description {
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.6;
}

.qr-description strong {
  color: var(--primary);
}

.qr-container {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 0 auto;
  width: fit-content;
  min-width: 280px;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
}

.qr-placeholder p {
  font-size: 0.85rem;
}

.qr-image {
  width: 260px;
  height: 260px;
  border-radius: 8px;
  animation: fadeIn 0.4s ease-out;
}

.qr-footer {
  margin-top: 20px;
}

.qr-attempt {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-default);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============ Dashboard Section ============ */
.dashboard-section {
  animation: fadeInUp 0.5s ease-out;
}

/* User Card */
.user-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  margin-bottom: 24px;
}

.user-avatar {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary), #128C46);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

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

.user-info h3 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-info p {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-badge {
  padding: 6px 14px;
  background: var(--primary-subtle);
  color: var(--primary);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
  border: 1px solid rgba(37, 211, 102, 0.15);
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

/* Panel */
.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.panel-header h3 svg {
  color: var(--primary);
}

.badge {
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 24px;
  text-align: center;
}

.panel-body {
  padding: 24px;
  flex: 1;
}

/* ============ Form ============ */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  display: flex;
}

.input-wrapper input {
  padding-left: 42px;
}

input[type="text"],
textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-base);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition);
  resize: vertical;
}

input[type="text"]::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

input[type="text"]:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}

.input-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Send Result */
.send-result {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  animation: fadeIn 0.3s ease-out;
}

.send-result.success {
  background: rgba(37, 211, 102, 0.1);
  border: 1px solid rgba(37, 211, 102, 0.2);
  color: var(--success);
}

.send-result.error {
  background: rgba(231, 76, 111, 0.1);
  border: 1px solid rgba(231, 76, 111, 0.2);
  color: var(--danger);
}

/* ============ Message List ============ */
.message-list {
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message-list::-webkit-scrollbar {
  width: 5px;
}

.message-list::-webkit-scrollbar-track {
  background: transparent;
}

.message-list::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 10px;
}

.message-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  transition: var(--transition);
  animation: slideInRight 0.3s ease-out;
}

.message-item:hover {
  background: var(--bg-hover);
}

.message-item.from-me {
  border-left: 3px solid var(--primary);
}

.message-item.from-other {
  border-left: 3px solid var(--info);
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.msg-content {
  flex: 1;
  min-width: 0;
}

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

.msg-sender {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 8px;
}

.msg-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  word-break: break-word;
  line-height: 1.5;
}

.msg-type-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state svg {
  opacity: 0.3;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 0.85rem;
}

/* ============ Toast Notifications ============ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  color: var(--text-primary);
  animation: slideInUp 0.4s ease-out;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  max-width: 380px;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--danger);
}

.toast.info {
  border-left: 3px solid var(--info);
}

.toast.warning {
  border-left: 3px solid var(--warning);
}

.toast-exit {
  animation: slideOutRight 0.3s ease-in forwards;
}

/* ============ Animations ============ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

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

@keyframes slideOutRight {
  to {
    opacity: 0;
    transform: translateX(100px);
  }
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .app-header {
    padding: 12px 16px;
  }

  .logo-text h1 {
    font-size: 1rem;
  }

  .app-main {
    padding: 16px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .qr-card {
    padding: 24px;
  }

  .qr-container {
    min-width: 240px;
    min-height: 240px;
  }

  .qr-image {
    width: 220px;
    height: 220px;
  }

  .user-card {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .logo-subtitle,
  .connection-badge .status-text {
    display: none;
  }

  .connection-badge {
    padding: 8px 10px;
  }
}
