/* JWLS Customer Video Call - Theme-Matched PWA Styles */

/* ── CSS Custom Properties (Default: Classic Theme) ─────────────────── */
:root {
  --primary: #1B2A4A;
  --secondary: #D4A853;
  --surface: #F8F6F0;
  --text-primary: #1B2A4A;
  --text-secondary: #666;
  --border-radius: 12px;
  --glass-bg: rgba(255,255,255,0.85);
  --glass-blur: blur(20px);
  --glass-border: rgba(255,255,255,0.3);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
  --transition: all 0.3s ease;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--surface);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Screen System ──────────────────────────────────────────────────── */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}
.screen.active { display: flex; }

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

/* ══════════════════════════════════════════════════════════════════════ */
/* JOIN SCREEN                                                          */
/* ══════════════════════════════════════════════════════════════════════ */
#join-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, color-mix(in srgb, var(--primary) 70%, black) 100%);
}

.join-container {
  text-align: center;
  width: 100%;
  max-width: 400px;
  padding: 24px;
}

.join-logo { margin-bottom: 32px; }
.logo-diamond {
  font-size: 48px;
  margin-bottom: 8px;
  animation: float 3s ease-in-out infinite;
}
.join-logo h1 {
  font-size: 32px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 4px;
}
.join-subtitle {
  color: var(--secondary);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 1px;
  margin-top: 4px;
}

.join-form {
  padding: 32px 24px;
  margin-bottom: 16px;
}
.join-form h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.join-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.join-form input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  margin-bottom: 16px;
  background: #fff;
}
.join-form input:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(212,168,83,0.15);
}

.join-form button {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.join-form button:hover { opacity: 0.9; transform: translateY(-1px); }
.join-form button:active { transform: translateY(0); }
.join-form button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ── Input Group (phone + name labels) ──────────────────────────────── */
.input-group {
  margin-bottom: 14px;
  text-align: left;
}
.input-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.phone-row {
  display: flex;
  gap: 8px;
}
.phone-row input {
  flex: 1;
  margin-bottom: 0 !important;
}
#lookup-btn {
  width: auto !important;
  padding: 14px 18px !important;
  background: var(--primary) !important;
  color: #fff !important;
  border: none;
  border-radius: 10px;
  font-size: 13px !important;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
#lookup-btn:hover { opacity: 0.85; }
#lookup-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.welcome-text {
  font-size: 13px;
  margin-top: 6px;
  font-weight: 500;
  transition: var(--transition);
}
.welcome-text.success-text { color: #2e7d32; }
.welcome-text.hidden { display: none; }

.error-text {
  color: #e53935;
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

.join-footer {
  color: rgba(255,255,255,0.5);
  font-size: 12px;
}

/* ══════════════════════════════════════════════════════════════════════ */
/* CALL SCREEN                                                          */
/* ══════════════════════════════════════════════════════════════════════ */
#call-screen {
  flex-direction: column;
  background: #000;
}

/* Header */
#call-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 20;
  position: relative;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-brand {
  font-weight: 800;
  font-size: 16px;
  color: var(--secondary);
  letter-spacing: 2px;
}
.header-timer {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  font-variant-numeric: tabular-nums;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}
.badge-good { background: #4caf50; color: #fff; }
.badge-connecting { background: #ff9800; color: #fff; }
.badge-poor { background: #f44336; color: #fff; }

.header-controls {
  display: flex;
  gap: 6px;
}

.control-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.control-btn:hover { background: rgba(255,255,255,0.25); }
.control-btn.active { background: rgba(255,255,255,0.3); color: #ff5252; }
.control-btn-end { background: #f44336; }
.control-btn-end:hover { background: #d32f2f; }

/* Video Area */
#video-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#remote-videos {
  width: 100%;
  height: 100%;
  display: grid;
  gap: 2px;
  background: #111;
}
#remote-videos.grid-1 { grid-template-columns: 1fr; }
#remote-videos.grid-2 { grid-template-columns: 1fr 1fr; }
#remote-videos.grid-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.remote-video-wrapper {
  position: relative;
  overflow: hidden;
  background: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
}
.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Local PiP */
#local-pip {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 120px;
  height: 160px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.3);
  box-shadow: var(--shadow-lg);
  z-index: 15;
  background: #222;
}
#local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

/* Waiting Overlay */
#waiting-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  z-index: 10;
}
.waiting-content {
  text-align: center;
  color: #fff;
}
.waiting-pulse {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--secondary);
  margin: 0 auto 16px;
  animation: pulse 1.5s ease-in-out infinite;
}
.waiting-content p {
  font-size: 14px;
  color: rgba(255,255,255,0.7);
}

/* ── Product Card ───────────────────────────────────────────────────── */
.product-card {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 25;
  margin: 12px;
  padding: 16px;
  transform: translateY(120%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.product-card.show { transform: translateY(0); }
.product-card.hidden { display: none; }

.product-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}

.product-body {
  display: flex;
  gap: 14px;
  align-items: center;
}
.product-image {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  background: #f0f0f0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.product-info { flex: 1; min-width: 0; }
.product-info h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-price {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 6px;
}
.product-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.product-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0,0,0,0.06);
  color: var(--text-secondary);
}
.tag-green { background: #e8f5e9; color: #2e7d32; }

/* ── Chat Panel ─────────────────────────────────────────────────────── */
#chat-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 1px solid var(--glass-border);
  transition: max-height 0.35s ease, padding 0.35s ease;
  max-height: 50vh;
  display: flex;
  flex-direction: column;
}
#chat-panel.collapsed { max-height: 44px; overflow: hidden; }

.chat-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  flex-shrink: 0;
}
.chat-badge {
  background: #f44336;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.chat-badge.hidden { display: none; }

.chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 12px 12px;
}
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
}

.chat-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
}
.chat-bubble.me {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-bubble.them {
  align-self: flex-start;
  background: #f0f0f0;
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}
.chat-sender {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.7;
  display: block;
  margin-bottom: 2px;
}
.chat-text { margin: 0; word-break: break-word; }

.chat-system {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 4px 0;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-shrink: 0;
}
.chat-input-row input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fff;
  transition: var(--transition);
}
.chat-input-row input:focus { border-color: var(--secondary); }

.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}
.chat-send:hover { opacity: 0.85; }

/* ══════════════════════════════════════════════════════════════════════ */
/* ENDED SCREEN                                                         */
/* ══════════════════════════════════════════════════════════════════════ */
#ended-screen {
  align-items: center;
  justify-content: center;
  background: var(--surface);
}
.ended-container { text-align: center; padding: 32px; }
.ended-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #4caf50;
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}
.ended-container h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}
.ended-container p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}
.ended-btn {
  padding: 12px 32px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}
.ended-btn:hover { opacity: 0.9; }

/* ══════════════════════════════════════════════════════════════════════ */
/* UTILITIES                                                            */
/* ══════════════════════════════════════════════════════════════════════ */
.hidden { display: none !important; }

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

.shake {
  animation: shake 0.4s ease;
}

/* ── Animations ─────────────────────────────────────────────────────── */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.5; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ══════════════════════════════════════════════════════════════════════ */
/* RESPONSIVE                                                           */
/* ══════════════════════════════════════════════════════════════════════ */

/* Tablet */
@media (min-width: 600px) {
  #local-pip { width: 160px; height: 210px; }

  .product-card { margin: 16px; padding: 20px; }
  .product-image { width: 88px; height: 88px; }

  #chat-panel { max-height: 40vh; }
  .chat-bubble { max-width: 60%; }
}

/* Desktop */
@media (min-width: 1024px) {
  #call-screen { flex-direction: row; flex-wrap: wrap; }

  #call-header {
    width: 100%;
    padding: 10px 20px;
  }

  #video-area { flex: 1; height: calc(100% - 56px); }

  /* Side panel for chat on desktop */
  #chat-panel {
    position: static;
    width: 320px;
    max-height: none;
    height: calc(100% - 56px);
    border-top: none;
    border-left: 1px solid var(--glass-border);
    order: 2;
  }
  #chat-panel.collapsed { max-height: none; }
  .chat-toggle { display: none; }
  .chat-body { display: flex; padding-top: 12px; }

  #local-pip { width: 200px; height: 260px; bottom: 20px; right: 20px; }

  .product-card {
    left: auto;
    right: 340px;
    bottom: 16px;
    max-width: 400px;
  }
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-top)) {
  #call-header { padding-top: calc(8px + env(safe-area-inset-top)); }
  #chat-panel { padding-bottom: env(safe-area-inset-bottom); }
}

/* Scrollbar styling */
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 2px; }
