@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,400;1,600&family=JetBrains+Mono:wght@400;500;600;700;800&display=swap');

:root {
  --bg-main: #F4F7F6;
  --bg-card: #FFFFFF;
  --bg-input: #FFFFFF;
  --text-main: #1E293B;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --primary: #57C785; /* Fresh WhatsApp Emerald */
  --primary-hover: #45B371;
  --primary-light: #E8F8F0;
  --primary-dark: #1F7344;
  --accent: #6366F1;
  --accent-light: #EEF2FF;
  --danger: #EF4444;
  --danger-light: #FEF2F2;
  --warning: #F59E0B;
  --warning-light: #FFFBEB;
  --border: #E2E8F0;
  --border-focus: #57C785;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 4px 18px -2px rgba(0, 0, 0, 0.05), 0 2px 6px -1px rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 10px -2px rgba(0, 0, 0, 0.03);
}

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

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
}

/* Ensure FontAwesome font family is never overridden */
.fa, .fas, .far, .fab, .fa-solid, .fa-regular, .fa-brands, [class^="fa-"], [class*=" fa-"] {
  font-family: var(--fa-style-family, "Font Awesome 6 Free");
}
.fa-brands, .fab {
  font-family: "Font Awesome 6 Brands" !important;
}
.fa-solid, .fas {
  font-family: "Font Awesome 6 Free" !important;
  font-weight: 900;
}
.fa-regular, .far {
  font-family: "Font Awesome 6 Free" !important;
  font-weight: 400;
}

header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 6px rgba(0,0,0,0.03);
}

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

.logo-badge {
  background: linear-gradient(135deg, #57C785, #3EA86C);
  color: #FFFFFF;
  font-weight: 800;
  font-size: 1.15rem;
  padding: 6px 14px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(87, 199, 133, 0.35);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.4px;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.main-container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.75rem 2rem;
  width: 100%;
  flex: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
  align-items: stretch;
}

.stat-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  min-height: 140px;
}

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

.stat-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}

.stat-icon {
  font-size: 1rem;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-val {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-main);
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.2;
  margin: 4px 0;
}

.stat-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-footer {
  margin-top: 0.5rem;
  padding-top: 0.4rem;
  border-top: 1px dashed #E2E8F0;
  font-size: 0.74rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #FFFFFF;
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 0.6rem 1.2rem;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

.btn:hover {
  background: #F8FAFC;
  border-color: #CBD5E1;
  color: var(--text-main);
}

.btn-primary {
  background: #57C785;
  color: #FFFFFF;
  border-color: #57C785;
  box-shadow: 0 2px 10px rgba(87, 199, 133, 0.3);
}

.btn-primary:hover {
  background: #45B371;
  border-color: #45B371;
  color: #FFFFFF;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(87, 199, 133, 0.4);
}

.btn-accent {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.25);
}

.btn-accent:hover {
  background: #4F46E5;
  color: #FFFFFF;
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
  border-radius: 7px;
}

.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.5rem;
}

.client-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  position: relative;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.client-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px -6px rgba(0, 0, 0, 0.08), 0 4px 8px -4px rgba(0, 0, 0, 0.04);
  border-color: #10B981;
}

.client-card .btn {
  box-shadow: none;
  margin: 0;
  line-height: 1.2;
}

.client-card .btn:hover {
  transform: translateY(-1px);
}

.client-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.client-name {
  font-size: 1.18rem;
  font-weight: 800;
  color: var(--text-main);
}

.client-id-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: #F1F5F9;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
}

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

.status-connected {
  background: #E8F8F0;
  color: #1F7344;
  border: 1px solid rgba(87, 199, 133, 0.4);
}

.status-scan_needed {
  background: #FFFBEB;
  color: #B45309;
  border: 1px solid #FDE68A;
}

.status-disconnected {
  background: #FEF2F2;
  color: #DC2626;
  border: 1px solid #FECACA;
}

.client-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 1.25rem;
}

.client-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 1.1rem;
}

/* Modal styles */
.modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(5px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.active {
  display: flex;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 650px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.85rem;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-main);
}

.modal-close {
  background: #F1F5F9;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.modal-close:hover {
  background: #E2E8F0;
  color: var(--text-main);
}

.form-group {
  margin-bottom: 1.2rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid #CBD5E1;
  color: var(--text-main);
  border-radius: 9px;
  padding: 0.65rem 0.95rem;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: #57C785;
  box-shadow: 0 0 0 3px rgba(87, 199, 133, 0.2);
}

.form-textarea {
  min-height: 110px;
  resize: vertical;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 5px;
  font-weight: 500;
}

/* QR Scanner Container */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}

.qr-box {
  background: #FFFFFF;
  padding: 16px;
  border-radius: 14px;
  margin: 1.5rem 0;
  display: inline-block;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.qr-box img {
  display: block;
  max-width: 250px;
  height: auto;
}

.qr-instructions {
  max-width: 450px;
  text-align: left;
  background: #F8FAFC;
  border: 1px solid var(--border);
  padding: 1.1rem 1.35rem;
  border-radius: 12px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.post-item-card {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  margin-bottom: 0.85rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.post-item-card:hover {
  border-color: rgba(87, 199, 133, 0.5);
  box-shadow: var(--shadow-md);
}

.post-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.ad-tag-badge {
  background: #E8F8F0;
  color: #1F7344;
  border: 1px solid rgba(87, 199, 133, 0.35);
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
}

@media (max-width: 992px) {
  .main-container {
    padding: 1.25rem 1rem;
  }
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.75rem;
  }
}

@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
  .clients-grid {
    grid-template-columns: 1fr;
  }
}
