/* ==========================================================
   GRUPO RICA - MULTIPLICA TU FUERZA (QR ENCUESTA / BUZÓN)
   Mobile-First High-End Styling & Real-Time Sync
   ========================================================== */

:root {
  --primary-blue: #002d72;
  --rica-blue: #0047ba;
  --accent-cyan: #00b4d8;
  --accent-cyan-glow: rgba(0, 180, 216, 0.4);
  --rica-red: #e61c24;
  --rica-red-hover: #c41219;
  --whatsapp-green: #25d366;
  --whatsapp-green-hover: #20ba5a;
  
  --bg-dark: #020b1f;
  --card-bg: rgba(7, 24, 56, 0.72);
  --card-border: rgba(255, 255, 255, 0.14);
  --card-border-focus: rgba(0, 180, 216, 0.6);
  
  --text-main: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.78);
  --text-muted: rgba(255, 255, 255, 0.52);
  
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 9999px;
  
  --shadow-card: 0 16px 36px -8px rgba(0, 0, 0, 0.5), 0 0 25px rgba(0, 180, 216, 0.12);
  --shadow-btn: 0 8px 24px -4px rgba(37, 211, 102, 0.45);
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Background Atmosphere */
.background-wrapper {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  filter: brightness(0.92) contrast(1.08);
  transform: scale(1.02);
}

.bg-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(2, 11, 31, 0.45) 0%,
    rgba(2, 11, 31, 0.65) 40%,
    rgba(2, 11, 31, 0.92) 100%
  );
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.ambient-glow {
  position: absolute;
  bottom: 5%;
  right: -20%;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 180, 216, 0.18) 0%, rgba(0, 45, 114, 0) 70%);
  filter: blur(40px);
}

/* App Container */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 16px) + 16px) 20px calc(env(safe-area-inset-bottom, 16px) + 16px) 20px;
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Header Section */
.header-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 20px;
}

.logo-container {
  width: 100%;
  max-width: 240px;
  margin-bottom: 12px;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.45));
  transition: transform 0.25s ease;
  user-select: none;
  cursor: pointer;
}

.logo-container:active {
  transform: scale(0.97);
}

.main-logo {
  width: 100%;
  height: auto;
  max-height: 135px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: rgba(0, 180, 216, 0.15);
  border: 1px solid rgba(0, 180, 216, 0.35);
  color: #72e2ff;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.pulse-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #00e5ff;
  box-shadow: 0 0 10px #00e5ff;
  animation: pulseDot 2s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.6; }
}

.main-heading {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: #ffffff;
  margin-bottom: 8px;
  text-wrap: balance;
}

.sub-heading {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.45;
  max-width: 360px;
  text-wrap: balance;
}

/* Main Form Card */
.form-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}

.form-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-cyan), transparent);
}

.input-group {
  margin-bottom: 20px;
}

.input-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.char-counter {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease;
}

.char-counter.limit-near { color: #ffb703; }
.char-counter.limit-reached { color: #ff4d4d; }

.textarea-wrapper {
  position: relative;
  border-radius: var(--radius-md);
  background: rgba(2, 11, 31, 0.65);
  border: 1px solid var(--card-border);
  transition: all 0.25s ease;
}

.textarea-wrapper:focus-within {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px var(--accent-cyan-glow);
  background: rgba(2, 11, 31, 0.85);
}

textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  padding: 14px 16px;
  color: #ffffff;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  min-height: 125px;
  display: block;
}

textarea::placeholder {
  color: rgba(255, 255, 255, 0.35);
  font-size: 0.94rem;
}

/* Error feedback */
.error-feedback {
  display: none;
  color: #ff6b6b;
  font-size: 0.82rem;
  font-weight: 500;
  margin-top: 6px;
  padding-left: 4px;
}

.error-feedback.visible {
  display: block;
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* Submit Button */
.submit-btn {
  width: 100%;
  position: relative;
  background: linear-gradient(135deg, var(--whatsapp-green) 0%, #1da851 100%);
  border: none;
  outline: none;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  color: #ffffff;
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.submit-btn:hover {
  background: linear-gradient(135deg, #2ae06f 0%, var(--whatsapp-green) 100%);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px -4px rgba(37, 211, 102, 0.55);
}

.submit-btn:active {
  transform: scale(0.98);
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.35);
}

.btn-content {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.whatsapp-icon {
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.btn-shine {
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.28),
    transparent
  );
  transform: skewX(-20deg);
  animation: shineLoop 4s infinite ease-in-out;
}

@keyframes shineLoop {
  0% { left: -100%; }
  35% { left: 200%; }
  100% { left: 200%; }
}

/* Success Banner */
.feedback-banner {
  background: rgba(37, 211, 102, 0.16);
  border: 1px solid rgba(37, 211, 102, 0.45);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  backdrop-filter: blur(10px);
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.feedback-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--whatsapp-green);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  flex-shrink: 0;
}

.feedback-text {
  display: flex;
  flex-direction: column;
  font-size: 0.88rem;
  line-height: 1.35;
}

.feedback-text strong { color: #a8f5c4; }
.feedback-text span { color: var(--text-secondary); font-size: 0.8rem; }

/* Footer Section */
.footer-section {
  text-align: center;
  margin-top: auto;
  padding-top: 10px;
}

.privacy-note {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 10px;
}

.admin-access {
  display: flex;
  justify-content: center;
}

.admin-lock-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  opacity: 0.65;
}

.admin-lock-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  opacity: 1;
}

/* Security PIN Dialog */
.security-dialog {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  background: #06132d;
  color: var(--text-main);
  padding: 0;
  max-width: 380px;
  width: 90vw;
  margin: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.85);
  outline: none;
}

.security-dialog::backdrop {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
}

.security-content {
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.lock-icon-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(0, 180, 216, 0.12);
  border: 1px solid rgba(0, 180, 216, 0.35);
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.security-header h3 {
  font-family: var(--font-heading);
  font-size: 1.22rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 4px;
}

.security-header p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.pin-inputs-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}

.pin-digit {
  width: 52px;
  height: 58px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  color: #ffffff;
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  outline: none;
  font-family: var(--font-heading);
  transition: all 0.2s ease;
}

.pin-digit:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px var(--accent-cyan-glow);
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.pin-status-box {
  min-height: 24px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.pin-status-box.error {
  color: #ff6b6b;
  animation: shake 0.35s ease;
}

.pin-status-box.locked {
  color: #ff4d4d;
  font-weight: 600;
}

.security-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.verify-btn {
  flex: 1.4;
  background: linear-gradient(135deg, var(--rica-blue) 0%, #002d72 100%);
  color: #ffffff;
  border: 1px solid rgba(0, 180, 216, 0.3);
}

.verify-btn:hover {
  background: linear-gradient(135deg, #0056e0 0%, var(--rica-blue) 100%);
}

.cancel-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.cancel-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Admin Dialog */
.admin-dialog {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  background: #06132d;
  color: var(--text-main);
  padding: 0;
  max-width: 620px;
  width: 92vw;
  margin: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.85);
  outline: none;
}

.admin-dialog::backdrop {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
}

.dialog-content {
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.title-with-live {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-with-live h3 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #00ff88;
  box-shadow: 0 0 8px #00ff88;
  animation: livePulse 1.8s infinite ease-in-out;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.dialog-title-group p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.2s ease;
}

.close-btn:hover {
  color: #ffffff;
}

.dialog-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
}

.stat-number {
  display: block;
  font-family: var(--font-heading);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.stat-label {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.dialog-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.action-btn {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  transition: all 0.2s ease;
}

.refresh-btn {
  background: rgba(0, 180, 216, 0.18);
  border: 1px solid rgba(0, 180, 216, 0.4);
  color: #72e2ff;
}

.refresh-btn:hover {
  background: rgba(0, 180, 216, 0.3);
}

.refresh-btn.spinning .spin-icon {
  animation: spinOnce 0.6s linear;
}

@keyframes spinOnce {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.export-btn {
  flex: 1.4;
  background: #0056b3;
  color: #ffffff;
}

.export-btn:hover {
  background: #006ce0;
}

.clear-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #ff6b6b;
  border: 1px solid rgba(255, 107, 107, 0.2);
}

.clear-btn:hover {
  background: rgba(255, 107, 107, 0.15);
}

.table-container {
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.25);
  flex: 1;
  min-height: 200px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  text-align: left;
}

.data-table th {
  background: rgba(4, 18, 48, 0.95);
  padding: 10px 12px;
  font-weight: 600;
  color: var(--accent-cyan);
  position: sticky;
  top: 0;
  z-index: 2;
  backdrop-filter: blur(8px);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  vertical-align: top;
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.data-table .empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
}

/* Small Screens */
@media (max-width: 360px) {
  .app-container { padding: 14px 12px; }
  .main-heading { font-size: 1.35rem; }
  .form-card { padding: 16px 14px; }
  .pin-digit { width: 44px; height: 50px; font-size: 1.4rem; }
  .dialog-actions { flex-wrap: wrap; }
}
