:root {
  --bg-main: #0a0d13;
  --bg-card: rgba(22, 28, 40, 0.75);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-header: rgba(14, 18, 27, 0.85);
  
  --color-primary: #00d26a;
  --color-primary-dark: #009e50;
  --color-primary-glow: rgba(0, 210, 106, 0.25);
  --color-accent: #00b4d8;
  
  --outgoing-bg: linear-gradient(135deg, #009e56 0%, #007a42 100%);
  --outgoing-glow: rgba(0, 158, 86, 0.2);
  
  --incoming-bg: rgba(26, 33, 48, 0.7);
  --incoming-border: rgba(255, 255, 255, 0.07);
  
  --text-primary: #f0f4f8;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

input, textarea {
  user-select: auto;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.4;
}

/* Screens */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% 0%, #151b27 0%, var(--bg-main) 70%);
}

.hidden {
  display: none !important;
}

/* Loading Screen */
.loading-screen {
  justify-content: center;
  align-items: center;
  z-index: 1000;
  background: var(--bg-main);
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.loading-logo {
  animation: pulseLogo 2s infinite ease-in-out;
}

@keyframes pulseLogo {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.08); opacity: 1; filter: drop-shadow(0 0 16px rgba(0, 210, 106, 0.5)); }
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* Auth Card & Profile Chooser */
.auth-screen {
  justify-content: center;
  align-items: center;
  padding: 20px;
  z-index: 500;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--bg-card-border);
  border-radius: 26px;
  padding: 30px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 35px rgba(0, 210, 106, 0.08);
}

.auth-icon {
  width: 68px;
  height: 68px;
  margin: 0 auto 16px;
  border-radius: 20px;
  background: rgba(0, 210, 106, 0.1);
  border: 1px solid rgba(0, 210, 106, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
}

.auth-card h2 {
  font-size: 23px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.auth-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 22px;
}

/* 1-Click Profile Cards */
.profile-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 18px;
  padding: 14px 16px;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.profile-card:hover, .profile-card:active {
  background: rgba(0, 210, 106, 0.08);
  border-color: rgba(0, 210, 106, 0.35);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.profile-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00d26a, #007a42);
  color: #05140b;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(0, 210, 106, 0.25);
}

.profile-avatar.partner-av {
  background: linear-gradient(135deg, #00b4d8, #0077b6);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(0, 180, 216, 0.25);
}

.profile-info {
  flex: 1;
}

.profile-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.profile-hint {
  font-size: 12px;
  color: var(--color-primary);
  font-weight: 500;
  margin-top: 2px;
}

.profile-arrow {
  color: var(--text-muted);
  transition: transform 0.2s;
}

.profile-card:hover .profile-arrow {
  transform: translateX(3px);
  color: var(--color-primary);
}

.manual-key-toggle {
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 4px;
  transition: color 0.2s;
  margin-top: 8px;
}

.manual-key-toggle:hover {
  color: var(--text-primary);
}

.manual-key-section {
  margin-top: 14px;
  animation: fadeIn 0.2s ease-out;
}

.auth-input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-input-wrapper input {
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--bg-card-border);
  border-radius: 14px;
  padding: 13px 16px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
}

.auth-input-wrapper input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 12px var(--color-primary-glow);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #05140b;
  font-weight: 700;
  font-size: 15px;
  border: none;
  border-radius: 14px;
  padding: 13px 20px;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.2s;
}

.btn-primary:active {
  transform: scale(0.98);
}

.auth-error {
  color: #ff5252;
  font-size: 13px;
  margin-top: 12px;
}

/* Chat Header */
.chat-header {
  position: relative;
  z-index: 10;
  height: calc(64px + var(--safe-top));
  padding-top: var(--safe-top);
  padding-left: 16px;
  padding-right: 16px;
  background: var(--bg-header);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--bg-card-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.avatar-wrapper {
  position: relative;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e293b, #334155);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 17px;
  color: #e2e8f0;
}

.status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #64748b;
  border: 2px solid var(--bg-main);
  transition: background-color 0.3s;
}

.status-dot.online {
  background: var(--color-primary);
  box-shadow: 0 0 8px var(--color-primary);
}

.user-meta {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.status-subline {
  display: flex;
  align-items: center;
  min-height: 16px;
}

.user-status {
  font-size: 12px;
  color: var(--text-muted);
}

.user-status.online {
  color: var(--color-primary);
  font-weight: 500;
}

/* Typing Indicator */
.typing-indicator {
  font-size: 12px;
  color: var(--color-primary);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-dots {
  display: inline-flex;
  gap: 2px;
}

.typing-dots .dot {
  width: 3.5px;
  height: 3.5px;
  border-radius: 50%;
  background: var(--color-primary);
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dots .dot:nth-child(1) { animation-delay: 0s; }
.typing-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

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

/* Notification Bell Button */
.notify-btn {
  color: var(--text-muted);
  position: relative;
}

.notify-btn.active {
  color: var(--color-primary);
}

.notify-btn.pulse {
  animation: bellRing 3s infinite ease-in-out;
  color: #ffb703;
}

@keyframes bellRing {
  0%, 85%, 100% { transform: rotate(0deg); }
  88% { transform: rotate(14deg); }
  92% { transform: rotate(-14deg); }
  96% { transform: rotate(10deg); }
}

.security-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 210, 106, 0.08);
  border: 1px solid rgba(0, 210, 106, 0.2);
  padding: 4px 8px;
  border-radius: 20px;
}

.security-text {
  font-size: 11px;
  font-weight: 600;
  color: #00d26a;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  touch-action: manipulation;
}

.icon-btn:hover, .icon-btn:active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

/* Push Prompt Banner */
.push-banner {
  position: absolute;
  top: calc(70px + var(--safe-top));
  left: 16px;
  right: 16px;
  z-index: 40;
  background: #151e2e;
  border: 1px solid rgba(0, 210, 106, 0.25);
  border-radius: 16px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  animation: slideDown 0.3s ease-out;
}

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

.push-banner-content {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #e2e8f0;
}

.push-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-push-enable {
  background: var(--color-primary);
  border: none;
  color: #05140b;
  font-weight: 700;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.btn-push-dismiss {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

/* Context Menu */
.context-menu {
  position: absolute;
  top: calc(64px + var(--safe-top));
  right: 16px;
  z-index: 50;
  background: #182030;
  border: 1px solid var(--bg-card-border);
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.6);
  min-width: 200px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.menu-item:hover, .menu-item:active {
  background: rgba(255, 255, 255, 0.06);
}

.text-danger {
  color: #ff5252;
}

/* Messages Area */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.date-divider {
  text-align: center;
  margin: 10px 0;
}

.date-divider span {
  display: inline-block;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-row {
  display: flex;
  width: 100%;
  position: relative;
  transition: opacity 0.3s, transform 0.3s;
}

.msg-row.deleted {
  opacity: 0;
  transform: scale(0.9);
}

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

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

.msg-bubble-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 84%;
}

.msg-row.outgoing .msg-bubble-wrapper {
  flex-direction: row-reverse;
}

.msg-bubble {
  border-radius: 20px;
  padding: 10px 14px;
  position: relative;
  word-break: break-word;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  flex: 1;
}

.msg-row.outgoing .msg-bubble {
  background: var(--outgoing-bg);
  border-bottom-right-radius: 4px;
  color: #ffffff;
  box-shadow: 0 4px 14px var(--outgoing-glow);
}

.msg-row.incoming .msg-bubble {
  background: var(--incoming-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--incoming-border);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}

.msg-del-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
}

.msg-row:hover .msg-del-btn, .msg-row:focus-within .msg-del-btn {
  opacity: 0.7;
}

.msg-del-btn:hover {
  opacity: 1;
  color: #ff5252;
}

.msg-text {
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  user-select: text;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 10px;
  opacity: 0.75;
}

.msg-checks {
  display: inline-flex;
}

.msg-checks.read {
  color: #6ee7b7;
}

/* Audio Player Bubble */
.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 4px 0;
}

.audio-play-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.msg-row.incoming .audio-play-btn {
  background: var(--color-primary);
  color: #05140b;
}

.audio-waveform-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.waveform-canvas {
  width: 100%;
  height: 24px;
  cursor: pointer;
}

.audio-duration {
  font-size: 11px;
  opacity: 0.8;
}

/* Image Message */
.msg-image-wrapper {
  margin: -4px -8px 6px;
  border-radius: 14px;
  overflow: hidden;
  max-width: 260px;
  cursor: pointer;
}

.msg-image {
  width: 100%;
  height: auto;
  display: block;
}

/* Telegram-style Push-to-Talk Footer & Inline Record Bar */
.chat-footer {
  position: relative;
  z-index: 10;
  background: var(--bg-header);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--bg-card-border);
  padding: 8px 12px calc(8px + var(--safe-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.footer-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
}

/* Mic Voice Button with Telegram Push-to-Talk */
.voice-btn {
  background: rgba(0, 210, 106, 0.12);
  color: var(--color-primary);
  border: 1px solid rgba(0, 210, 106, 0.25);
  box-shadow: 0 0 12px rgba(0, 210, 106, 0.1);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  touch-action: none;
}

.voice-btn.recording {
  background: #ff4d4d !important;
  color: #ffffff !important;
  transform: scale(1.3);
  box-shadow: 0 0 25px rgba(255, 77, 77, 0.7);
  z-index: 25;
}

.send-btn {
  background: var(--color-primary);
  color: #05140b;
}

.input-wrapper {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  border-radius: 20px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
}

.input-wrapper textarea {
  width: 100%;
  max-height: 120px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  resize: none;
  line-height: 20px;
}

.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

/* Inline Telegram Recording Bar */
.inline-record-bar {
  flex: 1;
  height: 44px;
  background: rgba(255, 77, 77, 0.12);
  border: 1px solid rgba(255, 77, 77, 0.3);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  animation: fadeIn 0.2s ease-out;
  overflow: hidden;
}

.record-timer-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.record-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff4d4d;
  animation: pulseDot 1s infinite alternate;
}

@keyframes pulseDot {
  from { opacity: 0.3; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1.2); }
}

#inlineRecordTimer {
  font-weight: 700;
  color: #ff4d4d;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.slide-to-cancel {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: transform 0.1s linear, color 0.2s;
}

.slide-to-cancel.canceling {
  color: #ff4d4d;
  font-weight: 700;
}

/* Quick Tooltip Toast */
.quick-toast {
  position: absolute;
  bottom: calc(76px + var(--safe-bottom));
  right: 16px;
  background: #1c2436;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f0f4f8;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  z-index: 50;
  pointer-events: none;
  animation: fadeIn 0.2s ease-out;
}

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

/* Lightbox Modal */
.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox img {
  max-width: 100%;
  max-height: 90%;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

.lightbox-close {
  position: absolute;
  top: calc(20px + var(--safe-top));
  right: 20px;
  font-size: 36px;
  color: #fff;
  cursor: pointer;
  line-height: 1;
}
