/* CSS Variables */
:root {
  --primary: #7c3aed;
  --primary-container: #8b5cf6;
  --on-primary: #ffffff;
  
  --surface: #f7f7f8;
  --on-surface: #1a1a1a;
  --on-surface-variant: #666666;
  
  --surface-container-lowest: #ffffff;
  --surface-container-low: #ffffff;
  --surface-container: #ffffff;
  --surface-container-high: #f1f1f1;
  --surface-container-highest: #eaeaec;
  
  --tertiary: #fbbf24;
  --tertiary-container: #fef3c7;
  
  --error: #ef4444;
  --on-error: #ffffff;
  
  --radius-card: 20px;
  --shadow-bento: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Helvetica Neue", Arial, sans-serif;
  background-color: var(--surface);
  color: var(--on-surface);
  line-height: 1.5;
  overflow: hidden;
}

/* App Container */
.app-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 24px;
}

/* TopNav */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 48px;
  flex-shrink: 0;
  padding: 0 8px;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 48px;
}

.logo {
  font-size: 20px;
  font-weight: 900;
  color: var(--on-surface);
  letter-spacing: -0.5px;
}

.nav-links {
  display: flex;
  gap: 32px;
}

.nav-links a {
  color: var(--on-surface-variant);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: color 0.2s;
}

.nav-links a:hover {
  color: var(--on-surface);
}

.nav-links a.active {
  color: var(--primary);
  font-weight: 700;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-icons {
  display: flex;
  gap: 16px;
}

.nav-icons button {
  background: none;
  border: none;
  color: var(--on-surface-variant);
  cursor: pointer;
  font-size: 16px;
  transition: color 0.2s;
}

.nav-icons button:hover {
  color: var(--on-surface);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  border: 1px solid var(--surface-container-highest);
  border-radius: 9999px;
  padding: 4px 12px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.user-profile img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.user-profile span {
  font-size: 12px;
  font-weight: 700;
}

.user-profile i {
  font-size: 10px;
  color: var(--on-surface-variant);
}

/* Main Content */
.main-content {
  flex: 1;
  display: grid;
  grid-template-columns: 2fr 3fr 5fr 2fr;
  gap: 24px;
  overflow: hidden;
}

/* Bento Card Style */
.bento-card {
  background: white;
  border: 1px solid var(--surface-container-highest);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-bento);
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.bento-label {
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #888;
  margin-bottom: 12px;
}

/* Sidebar */
.sidebar {
  background: white;
  border: 1px solid var(--surface-container-highest);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-bento);
  padding: 16px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-label {
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #888;
  margin-bottom: 12px;
}

.new-chat-btn {
  width: 100%;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  padding: 10px;
  border-radius: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.2);
  transition: transform 0.2s, box-shadow 0.2s;
  margin-bottom: 16px;
}

.new-chat-btn:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.3);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--on-surface-variant);
  font-size: 14px;
  transition: all 0.2s;
}

.nav-item:hover {
  color: var(--on-surface);
  background: var(--surface-container-high);
}

.nav-item.active {
  background: rgba(124, 58, 237, 0.1);
  color: var(--primary);
  font-weight: 600;
}

.nav-item i {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--surface-container-highest);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ChatList */
.chat-list {
  background: white;
  border: 1px solid var(--surface-container-highest);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-bento);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--surface-container-highest);
}

.chat-list-label {
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #888;
  margin-bottom: 12px;
}

.search-box {
  position: relative;
}

.search-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--on-surface-variant);
  opacity: 0.5;
  font-size: 14px;
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  background: var(--surface-container-high);
  border: none;
  border-radius: 12px;
  font-size: 14px;
  outline: none;
  transition: box-shadow 0.2s;
}

.search-box input:focus {
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

.search-box input::placeholder {
  color: var(--on-surface-variant);
  opacity: 0.4;
}

.chat-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-item {
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-item:hover {
  background: var(--surface-container-high);
}

.chat-item.active {
  background: var(--surface-container-high);
}

.chat-item-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  position: relative;
  flex-shrink: 0;
}

.chat-avatar img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
}

.unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  background: var(--error);
  color: var(--on-error);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  padding: 0 6px;
}

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

.chat-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}

.chat-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-name.active {
  font-weight: 700;
}

.chat-time {
  font-size: 10px;
  color: var(--on-surface-variant);
  white-space: nowrap;
}

.chat-message {
  font-size: 12px;
  color: var(--on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ChatWindow */
.chat-window {
  background: white;
  border: 1px solid var(--surface-container-highest);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-bento);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.chat-header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid rgba(234, 234, 236, 0.2);
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-title h2 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--on-surface);
}

.urgent-badge {
  padding: 2px 8px;
  background: rgba(251, 191, 36, 0.1);
  color: var(--tertiary);
  font-size: 10px;
  font-weight: 600;
  border-radius: 4px;
}

.chat-actions {
  display: flex;
  gap: 16px;
}

.chat-actions button {
  background: none;
  border: none;
  color: var(--on-surface-variant);
  cursor: pointer;
  font-size: 18px;
  transition: color 0.2s;
}

.chat-actions button:hover {
  color: var(--primary);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: rgba(247, 247, 248, 0.3);
}

.time-divider {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.time-divider span {
  font-size: 11px;
  color: var(--on-surface-variant);
  opacity: 0.6;
  background: rgba(255, 255, 255, 0.5);
  padding: 4px 12px;
  border-radius: 9999px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 80%;
  margin-bottom: 24px;
}

.message.me {
  flex-direction: row-reverse;
  margin-left: auto;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message.me .message-content {
  align-items: flex-end;
}

.message-sender {
  font-size: 12px;
  color: var(--on-surface-variant);
  font-weight: 500;
  margin: 0 4px;
}

.message-bubble {
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.6;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message:not(.me) .message-bubble {
  background: var(--surface-container-high);
  color: var(--on-surface);
  border-bottom-left-radius: 2px;
}

.message.me .message-bubble {
  background: var(--primary);
  color: var(--on-primary);
  border-bottom-right-radius: 2px;
}

.message-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--on-surface-variant);
}

.message-status i {
  color: var(--primary);
  font-size: 12px;
}

/* Referral Popup */
.referral-popup {
  position: absolute;
  bottom: 120px;
  right: 24px;
  width: 320px;
  background: white;
  border: 2px solid var(--primary);
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
  padding: 20px;
  z-index: 50;
  animation: popupIn 0.3s ease;
}

@keyframes popupIn {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.popup-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.popup-title span {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}

.pending-count {
  padding: 2px 8px;
  background: rgba(124, 58, 237, 0.1);
  color: var(--primary);
  font-size: 10px;
  border-radius: 9999px;
  font-weight: 700;
}

.popup-user {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.user-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--error);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
}

.user-info p {
  font-weight: 700;
  color: var(--on-surface);
  margin-bottom: 4px;
}

.intent-badge {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  font-size: 10px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.popup-suggestion {
  margin-bottom: 16px;
}

.suggestion-label {
  font-size: 11px;
  color: var(--on-surface-variant);
  font-weight: 500;
  margin-bottom: 4px;
}

.suggestion-dept {
  font-size: 14px;
  font-weight: 700;
  color: var(--on-surface);
}

.popup-actions {
  display: flex;
  gap: 8px;
}

.popup-actions button {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: none;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s;
}

.btn-confirm {
  background: var(--primary);
  color: var(--on-primary);
}

.btn-confirm:hover {
  background: rgba(124, 58, 237, 0.9);
}

.btn-ignore {
  background: var(--surface-container-high);
  color: var(--on-surface);
}

.btn-ignore:hover {
  background: var(--surface-container-highest);
}

/* Chat Input Area */
.chat-input-area {
  padding: 16px;
  border-top: 1px solid rgba(234, 234, 236, 0.2);
  background: white;
}

.input-toolbar {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  padding: 0 8px;
}

.input-toolbar button {
  background: none;
  border: none;
  color: var(--on-surface-variant);
  cursor: pointer;
  font-size: 16px;
  transition: color 0.2s;
}

.input-toolbar button:hover {
  color: var(--primary);
}

.input-wrapper {
  position: relative;
  padding: 0 8px;
}

.input-wrapper textarea {
  width: 100%;
  background: var(--surface-container-low);
  border: none;
  border-radius: 12px;
  padding: 12px;
  padding-bottom: 48px;
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  transition: box-shadow 0.2s;
}

.input-wrapper textarea:focus {
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

.input-wrapper textarea::placeholder {
  color: var(--on-surface-variant);
  opacity: 0.5;
}

.input-actions {
  position: absolute;
  bottom: 12px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.account-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-selector span {
  font-size: 11px;
  color: var(--on-surface-variant);
}

.selector {
  display: flex;
  align-items: center;
  gap: 4px;
  background: white;
  border: 1px solid rgba(234, 234, 236, 0.3);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

.selector i {
  font-size: 10px;
}

.send-btn {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.2);
  transition: transform 0.2s, box-shadow 0.2s;
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

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

/* RightPanel */
.right-panel {
  background: white;
  border: 1px solid var(--surface-container-highest);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-bento);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100%;
  overflow-y: auto;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-label {
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #888;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.view-all {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.view-all:hover {
  text-decoration: underline;
}

.group-info {
  background: var(--surface-container-high);
  padding: 20px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-label {
  font-size: 11px;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.info-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--on-surface);
}

.members-list {
  background: var(--surface-container-high);
  border-radius: 16px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.member-item:hover {
  background: white;
}

.member-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
}

.member-info {
  min-width: 0;
}

.member-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-role {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-top: 2px;
}

.member-role.admin {
  background: rgba(124, 58, 237, 0.1);
  color: var(--primary);
}

.member-role.external {
  color: var(--on-surface-variant);
}

.invite-section {
  display: flex;
  justify-content: center;
  padding-top: 12px;
  border-top: 1px solid var(--surface-container-highest);
}

.invite-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 9999px;
  transition: background 0.2s;
}

.invite-btn:hover {
  background: rgba(124, 58, 237, 0.05);
}

.invite-btn i {
  font-size: 16px;
}

/* Scrollbar Hide */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}

.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Responsive */
@media (max-width: 1400px) {
  .main-content {
    grid-template-columns: 2fr 3fr 4fr 2fr;
  }
}

@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 2fr 3fr 5fr;
  }
  .right-panel {
    display: none;
  }
}

@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr 2fr;
  }
  .sidebar {
    display: none;
  }
}
