/* ==========================================================================
   PIA | Centro de Atención Plenus
   WhatsApp Light Interface & Design System (Tema Blanco - Pixel Perfect)
   ========================================================================== */

:root {
  /* WhatsApp Official Light Theme Palette */
  --wa-bg-body: #eae6df;
  --wa-bg-header: #f0f2f5;
  --wa-bg-chat: #efeae2;
  --wa-bg-panel: #ffffff;
  --wa-bg-subtle: #f7f8fa;
  
  --wa-incoming-bubble: #ffffff;
  --wa-outgoing-bubble: #d9fdd3;
  
  --wa-text-primary: #111b21;
  --wa-text-secondary: #3b4a54;
  --wa-text-muted: #667781;
  
  --wa-accent-teal: #00a884;
  --wa-accent-green: #008069;
  --wa-accent-blue: #53bdeb;
  --wa-badge-green: #25d366;
  --wa-border: #e9edef;
  --wa-border-darker: #d1d7db;
  
  /* Plenus Institutional Palette */
  --plenus-navy: #0e2439;
  --plenus-blue: #005696;
  --plenus-red: #d32f2f;
  --plenus-gold: #c6a052;
  --plenus-emerald: #10b981;
  --plenus-alert: #dc2626;
  --plenus-warning: #d97706;

  --radius-bubble: 10px;
  --radius-card: 12px;
  --shadow-bubble: 0 1px 0.5px rgba(11,20,26,.13);
  --shadow-frame: 0 20px 50px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.06);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  background: var(--wa-bg-body);
  color: var(--wa-text-primary);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  position: relative;
}

/* Background Top Banner (Classic WhatsApp Web Look) */
body::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 127px;
  background: #00a884;
  z-index: 0;
}

/* Base App Wrapper Modes */
.app-wrapper {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  position: relative;
  z-index: 1;
}

/* 1. Phone Mockup Mode (Default) */
.app-wrapper.mode-phone {
  padding: 16px;
}

.mode-phone .phone-frame {
  width: 420px;
  height: 870px;
  max-height: 96vh;
  background: #0f1418;
  border-radius: 54px;
  padding: 11px;
  box-shadow: 0 25px 70px -15px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255,255,255,0.1), 0 0 0 4px #262c32;
  position: relative;
  display: flex;
  flex-direction: column;
}

.mode-phone .phone-screen {
  width: 100%;
  height: 100%;
  background: var(--wa-bg-chat);
  border-radius: 44px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Status Bar & Dynamic Island (Inside the curved phone screen) */
.phone-statusbar {
  height: 44px;
  background: #f0f2f5;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 28px 8px 28px;
  font-size: 13px;
  font-weight: 700;
  color: #111b21;
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.status-time {
  letter-spacing: -0.2px;
  font-weight: 800;
  font-size: 13.5px;
}

.dynamic-island {
  width: 102px;
  height: 25px;
  background: #000;
  border-radius: 20px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 7px;
  z-index: 12;
}

.status-icons {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #111b21;
  font-weight: 800;
}

/* 2. WhatsApp Web Desktop Mode */
.app-wrapper.mode-web {
  padding: 24px;
}

.mode-web .phone-frame {
  width: 1180px;
  height: 840px;
  max-height: 94vh;
  background: #ffffff;
  border-radius: 12px;
  padding: 0;
  box-shadow: var(--shadow-frame);
  border: 1px solid var(--wa-border-darker);
  display: grid;
  grid-template-columns: 360px 1fr;
  overflow: hidden;
}

.mode-web .phone-statusbar,
.mode-web .dynamic-island {
  display: none;
}

.mode-web .web-sidebar {
  display: flex !important;
  flex-direction: column;
  background: #ffffff;
  border-right: 1px solid var(--wa-border);
}

.web-sidebar {
  display: none;
}

.sidebar-header {
  height: 60px;
  background: var(--wa-bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--wa-border);
}

.user-avatar-mini {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0e2439, #005696);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.sidebar-search-bar {
  padding: 8px 14px;
  border-bottom: 1px solid var(--wa-border);
  background: #ffffff;
}

.search-input-box {
  background: #f0f2f5;
  border-radius: 8px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--wa-text-secondary);
  font-size: 13px;
}

.chats-list-preview {
  flex: 1;
  overflow-y: auto;
  background: #ffffff;
}

.chat-item-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f0f2f5;
  transition: background 0.15s;
}

.chat-item-row.active {
  background: #f0f2f5;
}

.chat-item-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #ffffff;
  border: 1.5px solid #d1d7db;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 3px;
}

.chat-item-avatar img {
  width: 100%;
  height: auto;
  object-fit: contain;
}

.online-pip {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: var(--wa-badge-green);
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.chat-item-meta {
  flex: 1;
  min-width: 0;
}

.meta-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
}

.chat-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--wa-text-primary);
}

.chat-time {
  font-size: 11px;
  color: var(--wa-text-muted);
}

.chat-last-snippet {
  font-size: 13px;
  color: var(--wa-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 3. Fullscreen App Mode */
.app-wrapper.mode-fullscreen {
  padding: 0;
}

.mode-fullscreen .phone-frame {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

.mode-fullscreen .phone-screen {
  border-radius: 0;
}

.mode-fullscreen .phone-statusbar,
.mode-fullscreen .dynamic-island {
  display: none;
}

/* ==========================================================================
   WhatsApp Main Chat Screen Structure (Tema Blanco)
   ========================================================================== */

.chat-main-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #efeae2;
  background-image: 
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.4) 0%, transparent 80%),
    url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23000000' fill-opacity='0.035' fill-rule='evenodd'/%3E%3C/svg%3E");
  overflow: hidden;
}

/* Chat Header */
.chat-header {
  height: 60px;
  background: var(--wa-bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
  z-index: 5;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #ffffff;
  border: 1.5px solid #d1d7db;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.header-avatar img {
  width: 100%;
  height: auto;
  object-fit: contain;
}

.header-titles {
  display: flex;
  flex-direction: column;
}

.header-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.contact-name {
  font-weight: 700;
  font-size: 15.5px;
  color: var(--wa-text-primary);
  letter-spacing: -0.1px;
}

.verified-badge {
  color: var(--wa-accent-teal);
  display: flex;
  align-items: center;
}

.contact-status {
  font-size: 12px;
  color: var(--wa-accent-green);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--wa-badge-green);
  border-radius: 50%;
  animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.2); }
  100% { opacity: 1; transform: scale(1); }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon-btn {
  background: transparent;
  border: none;
  color: var(--wa-text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.header-icon-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--wa-text-primary);
}

/* Chat Messages Stream Area */
.chat-messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.chat-messages-container::-webkit-scrollbar {
  width: 5px;
}

.chat-messages-container::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 4px;
}

/* Encryption & Date Badges */
.chat-encryption-notice {
  background: #ffeecd;
  border-radius: 8px;
  padding: 8px 14px;
  margin: 2px auto 8px auto;
  max-width: 90%;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  border: 1px solid #ffd591;
}

.encryption-icon {
  font-size: 13px;
}

.encryption-text {
  font-size: 11.5px;
  color: #54656f;
  line-height: 1.4;
}

.chat-date-badge {
  align-self: center;
  background: #ffffff;
  color: var(--wa-text-muted);
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 6px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  border: 1px solid var(--wa-border);
}

/* Message Rows & Bubbles */
.message-row {
  display: flex;
  width: 100%;
}

.message-row.incoming {
  justify-content: flex-start;
}

.message-row.outgoing {
  justify-content: flex-end;
}

.bubble {
  max-width: 86%;
  padding: 8px 10px 6px 12px;
  border-radius: var(--radius-bubble);
  position: relative;
  box-shadow: var(--shadow-bubble);
  font-size: 14.2px;
  line-height: 1.45;
  color: var(--wa-text-primary);
  word-wrap: break-word;
}

.incoming-bubble {
  background: var(--wa-incoming-bubble);
  border-top-left-radius: 2px;
  border: 1px solid rgba(0,0,0,0.04);
}

.outgoing-bubble {
  background: var(--wa-outgoing-bubble);
  border-top-right-radius: 2px;
  border: 1px solid rgba(0,0,0,0.03);
}

.bubble-text {
  margin-bottom: 2px;
  color: #111b21;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
}

.bubble-time {
  font-size: 10.5px;
  color: var(--wa-text-muted);
}

.bubble-ticks {
  display: flex;
  align-items: center;
}

/* Security & Status Chips inside Bubble */
.security-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(16, 185, 129, 0.12);
  color: #065f46;
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 6px;
}

.status-badge-chip {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 6px;
}

.status-badge-chip.success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.status-badge-chip.warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.status-badge-chip.alert {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Rich Document / File Card in Bubble */
.bubble-file-card {
  background: #f0f2f5;
  border-radius: 8px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 0;
  border: 1px solid var(--wa-border-darker);
}

.file-icon-box {
  width: 44px;
  height: 44px;
  background: rgba(220, 38, 38, 0.12);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #dc2626;
  flex-shrink: 0;
}

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

.file-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--wa-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta {
  font-size: 11px;
  color: var(--wa-text-muted);
  margin-top: 2px;
}

.file-action-btn {
  background: var(--wa-accent-green);
  color: #ffffff;
  border: none;
  font-weight: 700;
  font-size: 11.5px;
  padding: 7px 13px;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}

.file-action-btn:hover {
  background: #00a884;
}

/* In-bubble WhatsApp Quick Reply Buttons */
.bubble-buttons-stack {
  margin-top: 8px;
  border-top: 1px solid #e9edef;
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wa-bubble-btn {
  background: #ffffff;
  border: 1px solid #e9edef;
  color: #008069;
  font-size: 13.5px;
  font-weight: 700;
  padding: 9px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.wa-bubble-btn:hover:not(:disabled) {
  background: #f0fdf4;
  border-color: #86efac;
}

.wa-bubble-btn.btn-clicked-disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
  background: #f9fafb;
}

.wa-bubble-btn.active-selection {
  opacity: 1 !important;
  color: #065f46;
  background: #d1fae5;
  border-color: #6ee7b7;
}

/* Typing Indicator Bubble */
.typing-indicator-row {
  display: flex;
  margin-top: 4px;
}

.typing-indicator-row.hidden {
  display: none;
}

.typing-bubble {
  background: #ffffff;
  padding: 8px 14px;
  border-radius: 12px;
  border-top-left-radius: 2px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-bubble);
  border: 1px solid rgba(0,0,0,0.04);
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: #8696a0;
  border-radius: 50%;
  animation: bounceDot 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes bounceDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

.typing-text {
  font-size: 12px;
  color: var(--wa-text-muted);
  font-style: italic;
}

/* ==========================================================================
   Bottom Actions & Interactive Menu Grid (100% Accessible & Visible)
   ========================================================================== */

.chat-actions-container {
  background: #f0f2f5;
  border-top: 1px solid var(--wa-border-darker);
  padding: 10px 12px;
  position: relative;
  z-index: 6;
  flex-shrink: 0;
  max-height: 240px;
  overflow-y: auto;
}

.chat-actions-container::-webkit-scrollbar {
  width: 4px;
}

.chat-actions-container::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* Action Chips Wrapper: 2-Column Responsive Grid */
.action-chips-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  width: 100%;
}

.action-chip {
  background: #ffffff;
  color: var(--wa-text-primary);
  border: 1px solid #d1d7db;
  padding: 10px 8px;
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  line-height: 1.25;
}

.action-chip:hover {
  background: #f0fdf4;
  border-color: #00a884;
  color: #008069;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 168, 132, 0.18);
}

.action-chip.full-width {
  grid-column: span 2;
}

.action-chip.chip-success {
  border-color: #86efac;
  background: #f0fdf4;
  color: #166534;
}

.action-chip.chip-warning {
  border-color: #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.action-chip.chip-secondary {
  background: #0e2439;
  border-color: #c6a052;
  color: #ffd279;
}

.action-chip.chip-secondary:hover {
  background: #173b5e;
  color: #ffffff;
}

.action-chip.chip-ghost {
  background: #ffffff;
  border-color: #e2e8f0;
  color: var(--wa-text-muted);
}

/* Interactive Text Input */
.interactive-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.wa-chat-input {
  flex: 1;
  background: #ffffff;
  border: 1px solid var(--wa-border-darker);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--wa-text-primary);
  font-size: 14px;
  outline: none;
}

.wa-chat-input:focus {
  border-color: var(--wa-accent-teal);
}

.wa-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wa-accent-green);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.15s;
}

.wa-send-btn:hover {
  background: #00a884;
}

.wa-send-btn:active {
  transform: scale(0.95);
}

/* Animations */
.animate-msg-in {
  animation: fadeInMsg 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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