/* ==========================================================================
   RESET & SYSTEM DEFINITIONS
   ========================================================================== */
:root {
  --bg-main: #0a0e17;
  --bg-card: #151c2c;
  --bg-card-glass: rgba(21, 28, 44, 0.65);
  --border-light: rgba(255, 255, 255, 0.08);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dark: #1f2937;
  
  --primary: #06c755; /* LINE Green */
  --primary-hover: #05b04b;
  --primary-glow: rgba(6, 199, 85, 0.25);
  
  --error: #ef4444;
  --chat-bg-customer: #222e43;
  --chat-bg-agent: #06c755;
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font-family: 'Outfit', 'Helvetica Neue', Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

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

/* ==========================================================================
   1. LOGIN SCREEN STYLING
   ========================================================================== */
#login-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle at center, #1b263b 0%, #0a0e17 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  transition: opacity 0.5s ease;
}

.login-card {
  background: var(--bg-card-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.logo-icon {
  font-size: 48px;
  margin-bottom: 16px;
  display: inline-block;
  animation: bounce 2s infinite;
}

.login-header h2 {
  font-size: 26px;
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.login-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 30px;
}

.input-group input {
  width: 100%;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 16px;
  outline: none;
  text-align: center;
  transition: var(--transition-smooth);
}

.input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: rgba(255, 255, 255, 0.08);
}

#btn-login {
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-family);
  transition: var(--transition-smooth);
}

#btn-login:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px var(--primary-glow);
}

#btn-login:active {
  transform: translateY(0);
}

.error-msg {
  color: var(--error);
  font-size: 13px;
  margin-top: 15px;
  height: 20px;
}

/* ==========================================================================
   2. MAIN APP LAYOUT
   ========================================================================== */
#app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  background: var(--bg-main);
  overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
  width: 340px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.pulse-icon {
  width: 10px;
  height: 10px;
  background: var(--primary);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 0 var(--primary-glow);
  animation: pulse 1.5s infinite;
}

.sidebar-title h3 {
  font-size: 20px;
  font-weight: 600;
}

.search-bar input {
  width: 100%;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  color: var(--text-main);
  font-family: var(--font-family);
  outline: none;
  font-size: 14px;
  transition: var(--transition-smooth);
}

.search-bar input:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.08);
}

/* --- CHAT LIST --- */
.chat-list {
  flex-grow: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: var(--transition-smooth);
}

.chat-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.chat-item.active {
  background: rgba(255, 255, 255, 0.06);
  border-left-color: var(--primary);
}

.chat-item.unread {
  background: rgba(6, 199, 85, 0.03);
}

.chat-item.unread .chat-item-name {
  font-weight: 700;
  color: #ffffff;
}

.chat-item.unread .chat-item-msg {
  font-weight: 500;
  color: #ffffff;
}

.unread-dot {
  width: 8px;
  height: 8px;
  background-color: var(--primary);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 8px var(--primary);
  animation: pulse 1.5s infinite;
}

.avatar-container {
  position: relative;
}

.avatar-img {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  background: #374151;
}

.chat-item-details {
  flex-grow: 1;
  min-width: 0; /* Important for ellipsis */
}

.chat-item-row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.chat-item-name {
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.chat-item-row2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chat-item-msg {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-grow: 1;
}

.badge-channel {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  white-space: nowrap;
}

/* Differentiating channels with unique badge backgrounds (Consistent color per channel) */
.badge-channel.ch-color-0 { background-color: rgba(6, 199, 85, 0.15); color: #06c755; border: 1px solid rgba(6, 199, 85, 0.3); }
.badge-channel.ch-color-1 { background-color: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.3); }
.badge-channel.ch-color-2 { background-color: rgba(236, 72, 153, 0.15); color: #f472b6; border: 1px solid rgba(236, 72, 153, 0.3); }
.badge-channel.ch-color-3 { background-color: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-channel.ch-color-4 { background-color: rgba(139, 92, 246, 0.15); color: #a78bfa; border: 1px solid rgba(139, 92, 246, 0.3); }
.badge-channel.ch-color-5 { background-color: rgba(20, 184, 166, 0.15); color: #2dd4bf; border: 1px solid rgba(20, 184, 166, 0.3); }
.badge-channel.ch-color-6 { background-color: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-channel.ch-color-7 { background-color: rgba(244, 63, 94, 0.15); color: #fb7185; border: 1px solid rgba(244, 63, 94, 0.3); }
.badge-channel.ch-color-8 { background-color: rgba(168, 85, 247, 0.15); color: #c084fc; border: 1px solid rgba(168, 85, 247, 0.3); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.user-status {
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  display: inline-block;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-family);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-text:hover {
  color: var(--error);
}

/* Loading Spinner */
.loading-spinner {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 30px 10px;
}

/* ==========================================================================
   3. CHAT PANEL STYLING
   ========================================================================== */
.chat-window {
  flex-grow: 1;
  background: #111827;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* --- EMPTY STATE --- */
.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  text-align: center;
  padding: 40px;
}

.empty-icon {
  font-size: 64px;
  color: rgba(255, 255, 255, 0.05);
  margin-bottom: 20px;
}

.empty-state h4 {
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 6px;
}

.empty-state p {
  color: var(--text-muted);
  font-size: 14px;
}

/* --- ACTIVE STATE --- */
.active-state {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  padding: 18px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.customer-info-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar-large {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  background: #374151;
}

.customer-info-header h4 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

/* --- MESSAGES HISTORY --- */
.chat-history {
  flex-grow: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: radial-gradient(circle at bottom right, rgba(17, 24, 39, 0.8) 0%, #0d121f 100%);
}

.msg-wrapper {
  display: flex;
  width: 100%;
}

.msg-wrapper.received {
  justify-content: flex-start;
}

.msg-wrapper.sent {
  justify-content: flex-end;
}

.msg-bubble {
  max-width: 60%;
  padding: 12px 18px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  position: relative;
}

.msg-wrapper.received .msg-bubble {
  background: var(--chat-bg-customer);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
}

.msg-wrapper.sent .msg-bubble {
  background: var(--chat-bg-agent);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
  display: block;
}

.msg-wrapper.sent .msg-meta {
  text-align: right;
  color: rgba(255, 255, 255, 0.7);
}

/* Image message style */
.msg-image {
  max-width: 260px;
  max-height: 350px;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
  display: block;
  margin-top: 4px;
}

.msg-image:hover {
  opacity: 0.9;
}

/* --- INPUT AREA --- */
.chat-input-area {
  padding: 20px 24px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 14px;
  align-items: center;
}

.chat-input-area input {
  flex-grow: 1;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 15px;
  outline: none;
  transition: var(--transition-smooth);
}

.chat-input-area input:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.08);
}

#btn-send {
  background: var(--primary);
  color: white;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition-smooth);
}

#btn-send:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
  box-shadow: 0 4px 12px var(--primary-glow);
}

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

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(6, 199, 85, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(6, 199, 85, 0); }
  100% { box-shadow: 0 0 0 0 rgba(6, 199, 85, 0); }
}

/* ==========================================================================
   DASHBOARD STYLING
   ========================================================================== */
.btn-dashboard {
  background: rgba(6, 199, 85, 0.15);
  color: var(--primary);
  border: 1px solid rgba(6, 199, 85, 0.3);
  padding: 6px 12px;
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-dashboard:hover {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 10px var(--primary-glow);
}

.dashboard-panel {
  padding: 30px;
  height: 100%;
  overflow-y: auto;
  background: radial-gradient(circle at top left, #111827 0%, #0d121f 100%);
  display: flex;
  flex-direction: column;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 20px;
  margin-bottom: 30px;
}

.dashboard-title-wrapper h2 {
  font-size: 24px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 4px;
}

.dashboard-title-wrapper p {
  font-size: 14px;
  color: var(--text-muted);
}

.btn-close {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-close:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  border-color: rgba(239, 68, 68, 0.2);
}

.dashboard-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 24px;
  padding: 16px 20px;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-light);
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.select-filter {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 8px;
  font-family: var(--font-family);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.select-filter:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.08);
}

.dashboard-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  transition: var(--transition-smooth);
}

.stat-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.stat-card.unread {
  border-color: rgba(245, 158, 11, 0.3);
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.03);
}

.stat-card.unread:hover {
  border-color: rgba(245, 158, 11, 0.6);
  box-shadow: 0 10px 20px rgba(245, 158, 11, 0.1);
}

.stat-card.read {
  border-color: rgba(6, 199, 85, 0.3);
  box-shadow: 0 0 15px rgba(6, 199, 85, 0.03);
}

.stat-card.read:hover {
  border-color: var(--primary);
  box-shadow: 0 10px 20px rgba(6, 199, 85, 0.1);
}

.stat-icon {
  font-size: 36px;
  background: rgba(255, 255, 255, 0.03);
  padding: 12px;
  border-radius: 12px;
  display: block;
}

.stat-card h3 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-card p {
  font-size: 32px;
  font-weight: 700;
  color: #ffffff;
}

.dashboard-table-container {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 30px;
}

.dashboard-table-container h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #ffffff;
}

.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.dashboard-table th {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 16px;
}

.dashboard-table td {
  font-size: 15px;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-light);
  padding: 16px;
}

.dashboard-table tr:last-child td {
  border-bottom: none;
}

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

.btn-line-manager {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  text-decoration: none;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition-smooth);
}

.btn-line-manager:hover {
  background: rgba(6, 199, 85, 0.15);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 4px 12px var(--primary-glow);
}

