/* Modern Support Panel Theme - Clean, Responsive, Animated */

:root {
  --bg-grad-a: #f7f8fc;
  --bg-grad-b: #eef1ff;
  --primary: #6c63ff;
  --primary-2: #b3b0ff;
  --primary-dark: #5a52e5;
  --ink: #111827;
  --muted: #6b7280;
  --panel: #ffffff;
  --border: #e5e7eb;
  --glow: 0 10px 30px rgba(108,99,255,0.18);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(108,99,255,0.15);
  --shadow-lg: 0 8px 32px rgba(108,99,255,0.25);
}

/* Basic reset */
* { 
  box-sizing: border-box; 
  margin: 0;
  padding: 0;
}

html, body { 
  height: 100%; 
  overflow: hidden;
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, var(--bg-grad-a) 0%, var(--bg-grad-b) 100%);
  display: flex;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { 
  display: none !important; 
}

/* Layout */
.sidebar {
  width: 320px;
  min-width: 280px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 20px rgba(108,99,255,0.08);
  z-index: 5;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  height: 100vh;
  max-height: 100vh;
}

/* Glass header */
.glassHeader {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(108,99,255,0.12);
  box-shadow: var(--shadow-sm);
  border-radius: 16px;
}

.floatingHeader { 
  position: sticky; 
  top: 0; 
  z-index: 10; 
  margin: 12px;
  padding: 12px 20px;
}

/* Sidebar header */
.sidebarHeader {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(238,241,255,0.95) 100%);
}

.sidebarAvatar { 
  width: 44px; 
  height: 44px; 
  border-radius: 50%; 
  box-shadow: var(--shadow-sm);
  border: 2px solid rgba(108,99,255,0.2);
}

.sidebarTitle { 
  color: var(--primary); 
  font-weight: 700; 
  font-size: 22px;
  letter-spacing: -0.5px;
}

.addThreadBtn {
  margin-left: auto;
  width: 38px; 
  height: 38px;
  border-radius: 50%; 
  border: none; 
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font-size: 20px;
  font-weight: 300;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.addThreadBtn:hover { 
  transform: translateY(-2px) scale(1.05);
  box-shadow: var(--shadow-md);
}

.addThreadBtn:active {
  transform: translateY(0) scale(0.98);
}

.threadList { 
  padding: 8px; 
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(108,99,255,0.3) transparent;
}

.threadList::-webkit-scrollbar {
  width: 6px;
}

.threadList::-webkit-scrollbar-track {
  background: transparent;
}

.threadList::-webkit-scrollbar-thumb {
  background: rgba(108,99,255,0.3);
  border-radius: 3px;
}

.threadList::-webkit-scrollbar-thumb:hover {
  background: rgba(108,99,255,0.5);
}

.userItem {
  padding: 14px 12px;
  margin: 6px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
}

.userItem:hover {
  background: rgba(108,99,255,0.08);
  border-color: rgba(108,99,255,0.15);
  transform: translateX(4px);
}

.userPreview {
  flex: 1;
  min-width: 0;
}

.userPreview strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.userPreview div {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(239,68,68,0.3);
}

/* Top header */
header {
  display: flex; 
  align-items: center; 
  justify-content: space-between;
}

.adminInfo { 
  display: flex; 
  align-items: center; 
  gap: 12px; 
}

.adminAvatar { 
  width: 36px; 
  height: 36px; 
  border-radius: 50%; 
  box-shadow: var(--shadow-sm);
  border: 2px solid rgba(108,99,255,0.2);
}

.adminName { 
  color: var(--primary); 
  font-weight: 600; 
  font-size: 18px;
  letter-spacing: -0.3px;
}

.adminLabel { 
  color: var(--primary); 
  font-size: 14px;
  font-weight: 500;
}

/* Content area */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  height: calc(100vh - 100px);
}

/* Empty/No selection */
.noSelection { 
  padding: 60px 32px; 
  text-align: center; 
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.noSelectionIcon { 
  font-size: 64px; 
  margin-bottom: 16px;
  filter: drop-shadow(0 4px 12px rgba(108,99,255,0.2));
}

.noSelectionText { 
  font-size: 18px;
  font-weight: 500;
  color: var(--muted);
}

/* Chat area */
.chatArea { 
  display: flex; 
  flex-direction: column; 
  min-height: 0; 
  height: calc(100vh - 120px);
  max-height: calc(100vh - 120px);
  margin: 12px;
  margin-top: 0;
  overflow: hidden;
  position: relative;
  flex: 1;
}

.chatHeader {
  display: flex; 
  align-items: center; 
  gap: 12px; 
  justify-content: space-between;
  padding: 14px 18px; 
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  flex-shrink: 0;
}

.threadUser { 
  display: flex; 
  align-items: center; 
  gap: 10px; 
  color: var(--primary); 
  font-size: 17px;
  font-weight: 600;
}

.threadUserIcon { 
  font-size: 24px; 
}

.threadMeta { 
  font-size: 12px; 
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.typingIndicator { 
  color: var(--primary); 
  font-weight: 600; 
}

.lastSeen { 
  color: var(--muted);
  font-size: 11px;
}

/* Messages - WhatsApp style scrolling */
.messages {
  flex: 1 1 auto;
  overflow-y: auto; 
  overflow-x: hidden;
  padding: 20px 16px; 
  padding-bottom: 24px;
  display: flex; 
  flex-direction: column; 
  gap: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.4) 0%, rgba(238,241,255,0.3) 100%);
  border-radius: 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(108,99,255,0.3) transparent;
  min-height: 0;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(108,99,255,0.3);
  border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
  background: rgba(108,99,255,0.5);
}

.msg { 
  display: flex; 
  flex-direction: column; 
  max-width: min(75%, 580px);
  animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg.user { 
  align-self: flex-start; 
}

.msg.admin { 
  align-self: flex-end; 
}

.bubble {
  background: #fff; 
  border: 1px solid var(--border);
  padding: 14px 16px; 
  border-radius: 20px 20px 8px 20px;
  box-shadow: var(--shadow-sm);
  font-size: 15px; 
  line-height: 1.5;
  word-wrap: break-word;
}

.msg.user .bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; 
  border-color: transparent; 
  border-radius: 20px 20px 20px 8px;
  box-shadow: var(--shadow-md);
}

.msg.admin .bubble {
  background: #fff;
  border-radius: 20px 20px 8px 20px;
}

.msgText { 
  white-space: pre-wrap; 
  word-break: break-word;
}

.msgLink { 
  color: inherit; 
  text-decoration: underline;
  opacity: 0.9;
}

.msg.user .msgLink { 
  color: rgba(255,255,255,0.95);
}

.msgMeta { 
  margin-top: 6px; 
  font-size: 11px; 
  color: #667085;
  opacity: 0.7;
}

.msg.user .msgMeta { 
  color: rgba(255,255,255,0.8);
  align-self: flex-start;
}

.msg.admin .msgMeta {
  align-self: flex-end;
}

/* Footer composer */
.floatingFooter {
  flex-shrink: 0;
  display: flex; 
  align-items: flex-end; 
  gap: 10px; 
  padding: 14px 16px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  margin-top: 12px;
}

.emojiBtn, .floatingSendBtn {
  width: 44px; 
  height: 44px; 
  border-radius: 50%; 
  border: none; 
  cursor: pointer;
  display: flex; 
  align-items: center; 
  justify-content: center;
  background: #fff; 
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.emojiBtn { 
  font-size: 22px;
}

.emojiBtn:hover { 
  background: var(--primary); 
  color: #fff; 
  transform: translateY(-2px) scale(1.05);
  box-shadow: var(--shadow-md);
}

.floatingSendBtn {
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); 
  color: #fff;
  font-size: 20px;
  font-weight: 300;
}

.floatingSendBtn:hover { 
  transform: translateY(-2px) scale(1.08);
  box-shadow: var(--shadow-md);
}

.floatingSendBtn:active {
  transform: translateY(0) scale(0.95);
}

.floatingFileLabel { 
  cursor: pointer; 
  width: 44px; 
  height: 44px; 
  border-radius: 50%;
  border: 1px solid var(--border); 
  display: inline-flex; 
  align-items: center; 
  justify-content: center;
  background: #fff; 
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.floatingFileLabel:hover {
  background: rgba(108,99,255,0.1);
  border-color: var(--primary);
  transform: translateY(-2px);
}

.floatingFileLabel input[type="file"] { 
  display: none; 
}

.attachIcon { 
  font-size: 20px; 
  color: var(--primary); 
}

.floatingInput {
  flex: 1; 
  min-height: 44px; 
  max-height: 120px; 
  resize: none;
  border: 1.5px solid var(--border); 
  border-radius: 24px; 
  padding: 12px 16px; 
  outline: none;
  background: rgba(247,248,252,0.8); 
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  transition: all 0.2s ease;
}

.floatingInput:focus { 
  box-shadow: 0 0 0 3px rgba(108,99,255,0.15); 
  border-color: var(--primary);
  background: #fff;
}

.imagePreviewContainer { 
  display: flex; 
  align-items: center; 
  gap: 8px; 
  border: 1px solid var(--border); 
  padding: 6px; 
  border-radius: 12px; 
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.imagePreview { 
  height: 50px; 
  max-width: 120px; 
  object-fit: cover; 
  border-radius: 8px; 
}

.floatingSmallBtn { 
  background: rgba(108,99,255,0.1); 
  border: none; 
  border-radius: 50%; 
  padding: 6px; 
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  transition: all 0.2s ease;
}

.floatingSmallBtn:hover { 
  background: var(--primary); 
  color: #fff;
  transform: scale(1.1);
}

/* Image bubble */
.imageWrap { 
  position: relative; 
  overflow: hidden; 
  border-radius: 14px; 
  margin-top: 8px; 
  border: 1px solid var(--border); 
  background: #f7f9fc; 
  max-width: min(80vw, 450px);
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.msg.user .imageWrap {
  border-color: rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.1);
}

img.chatImage { 
  display: block; 
  width: 100%; 
  height: auto; 
  max-height: 60vh; 
  min-height: 100px;
  object-fit: contain; 
  border-radius: 14px; 
  cursor: zoom-in;
  transition: opacity 0.3s ease, transform 0.2s ease;
  opacity: 0;
  background: transparent;
}

img.chatImage.loaded {
  opacity: 1;
}

.imageWrap.loaded img.chatImage {
  opacity: 1;
}

img.chatImage:hover {
  transform: scale(1.01);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.imageSkeleton {
  min-height: 200px;
  width: 100%;
  background: linear-gradient(90deg, #eef3fb 0%, #f7f9fd 50%, #eef3fb 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  border-radius: 14px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.imageWrap.loaded .imageSkeleton { 
  display: none !important; 
}

.imageWrap.loaded {
  min-height: auto;
}

.imageWrap.error .imageSkeleton { 
  display: flex !important; 
  align-items: center; 
  justify-content: center; 
  color: #ef4444; 
  font-size: 13px;
  background: linear-gradient(90deg, #fee2e2 0%, #fecaca 50%, #fee2e2 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  z-index: 2;
}

.imageWrap.error img.chatImage {
  display: none !important;
}

/* Image viewer overlay */
.imageViewerOverlay { 
  position: fixed; 
  inset: 0; 
  background: rgba(8,15,26,0.92); 
  display: none; 
  align-items: center; 
  justify-content: center; 
  z-index: 9998; 
  opacity: 0; 
  transition: opacity 0.2s ease;
  backdrop-filter: blur(8px);
}

.imageViewerOverlay.open { 
  opacity: 1; 
}

.imageViewerOverlay:not(.hidden) { 
  display: flex; 
}

.imageViewerContent { 
  position: relative; 
  max-width: 94vw; 
  max-height: 94vh;
  animation: zoomIn 0.3s ease;
}

@keyframes zoomIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.imageViewerImg { 
  max-width: 94vw; 
  max-height: 94vh; 
  border-radius: 12px; 
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  transition: opacity 0.3s ease;
  opacity: 0;
}

.imageViewerImg.loaded {
  opacity: 1;
}

.imageViewerClose { 
  position: absolute; 
  top: -16px; 
  right: -16px; 
  width: 40px; 
  height: 40px; 
  border-radius: 50%; 
  border: none; 
  background: #fff; 
  color: #111827; 
  box-shadow: 0 4px 12px rgba(0,0,0,0.3); 
  cursor: pointer;
  font-size: 24px;
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.imageViewerClose:hover {
  transform: scale(1.1) rotate(90deg);
  background: #ef4444;
  color: #fff;
}

.imageViewerDownload { 
  position: absolute; 
  bottom: -44px; 
  right: 0; 
  color: #fff; 
  text-decoration: underline;
  font-size: 14px;
  transition: opacity 0.2s ease;
}

.imageViewerDownload:hover {
  opacity: 0.8;
}

/* Login overlay */
.overlay { 
  position: fixed; 
  inset: 0; 
  background: rgba(0,0,0,0.6); 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  z-index: 9999;
  backdrop-filter: blur(8px);
}

.loginBox.glassHeader { 
  min-width: 360px; 
  max-width: 90vw;
  padding: 36px 32px 28px 32px; 
  text-align: center;
  animation: slideUp 0.4s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.loginBox img {
  margin-bottom: 16px;
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(108,99,255,0.3);
  border: 3px solid rgba(108,99,255,0.2);
}

.loginTitle { 
  color: var(--primary); 
  font-weight: 700; 
  margin: 0 0 20px;
  font-size: 24px;
  letter-spacing: -0.5px;
}

.loginInput { 
  width: 100%; 
  padding: 14px 16px; 
  border: 2px solid var(--border); 
  border-radius: 12px; 
  outline: none;
  font-size: 15px;
  font-family: inherit;
  transition: all 0.2s ease;
  background: rgba(255,255,255,0.9);
}

.loginInput:focus { 
  box-shadow: 0 0 0 4px rgba(108,99,255,0.15); 
  border-color: var(--primary);
  background: #fff;
}

.loginInput:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#panelPasswordBtn {
  width: 100%;
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

#panelPasswordBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.help { 
  margin-top: 16px; 
  font-size: 12px; 
  color: var(--muted);
  line-height: 1.5;
}

/* Animations */
.animatedSidebar { 
  animation: slideInLeft 0.6s cubic-bezier(0.68,-0.55,0.27,1.55); 
}

.animatedMain { 
  animation: fadeIn 0.6s ease; 
}

.animatedHeader { 
  animation: fadeDown 0.5s ease; 
}

.animatedMessages { 
  animation: fadeIn 0.8s ease; 
}

.animatedFooter { 
  animation: fadeUp 0.5s ease; 
}

.animatedChatArea { 
  animation: fadeIn 0.8s ease; 
}

.animatedFade { 
  animation: fadeIn 1s ease; 
}

@keyframes slideInLeft { 
  from { 
    transform: translateX(-30px); 
    opacity: 0; 
  } 
  to { 
    transform: translateX(0); 
    opacity: 1; 
  } 
}

@keyframes fadeIn { 
  from { 
    opacity: 0; 
  } 
  to { 
    opacity: 1; 
  } 
}

@keyframes fadeDown { 
  from { 
    transform: translateY(-15px); 
    opacity: 0; 
  } 
  to { 
    transform: translateY(0); 
    opacity: 1; 
  } 
}

@keyframes fadeUp { 
  from { 
    transform: translateY(15px); 
    opacity: 0; 
  } 
  to { 
    transform: translateY(0); 
    opacity: 1; 
  } 
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
  20%, 40%, 60%, 80% { transform: translateX(8px); }
}

/* Responsive */
@media (max-width: 960px) {
  .sidebar { 
    width: 280px; 
    min-width: 260px; 
  }
  
  .msg {
    max-width: min(80%, 500px);
  }
}

@media (max-width: 720px) {
  body { 
    flex-direction: column; 
  }
  
  .sidebar { 
    width: 100%; 
    min-width: 0; 
    border-right: none; 
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }
  
  .main { 
    width: 100%; 
    min-height: 60vh;
  }
  
  .floatingHeader {
    margin: 8px;
    padding: 10px 16px;
  }
  
  .chatArea {
    margin: 8px;
  }
  
  .floatingFooter {
    padding: 12px;
  }
  
  .msg {
    max-width: 85%;
  }
  
  .loginBox.glassHeader {
    min-width: 90vw;
    padding: 28px 24px;
  }
}

/* Loading state */
#threadsList:empty::before {
  content: "Loading threads...";
  display: block;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* Smooth transitions */
* {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
