/* ============================================
   ChatMail - Modern Chat UI for Outlook
   Discord/Signal/WhatsApp inspired design
   ============================================ */

:root {
  /* Dark theme (default - Discord inspired) */
  --bg-primary: #1e1f22;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #313338;
  --bg-chat: #313338;
  --bg-hover: #35373c;
  --bg-active: #404249;
  --bg-message-hover: rgba(255, 255, 255, 0.02);

  --text-primary: #f2f3f5;
  --text-secondary: #b5bac1;
  --text-muted: #6d6f78;
  --text-link: #00a8fc;

  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-light: rgba(88, 101, 242, 0.15);
  --green: #23a55a;
  --green-light: rgba(35, 165, 90, 0.15);
  --red: #da373c;
  --red-light: rgba(218, 55, 60, 0.15);
  --yellow: #f0b132;
  --orange: #e67e22;

  --border: #3f4147;
  --border-light: rgba(255, 255, 255, 0.06);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 50%;

  --sidebar-width: 300px;
  --header-height: 56px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Light theme */
[data-theme="light"] {
  --bg-primary: #f2f3f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f9fafb;
  --bg-chat: #ffffff;
  --bg-hover: #e9eaed;
  --bg-active: #dddee1;
  --bg-message-hover: rgba(0, 0, 0, 0.02);

  --text-primary: #1e1f22;
  --text-secondary: #4e5058;
  --text-muted: #80848e;
  --text-link: #006ce7;

  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-light: rgba(88, 101, 242, 0.1);
  --green: #23a55a;
  --green-light: rgba(35, 165, 90, 0.1);
  --red: #da373c;
  --red-light: rgba(218, 55, 60, 0.1);

  --border: #e0e1e5;
  --border-light: rgba(0, 0, 0, 0.06);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* ---- Theme Toggle Button ---- */
.theme-toggle-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.theme-toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
  border-color: var(--accent);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-active);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================
   Sidebar
   ============================================ */

/* ---- Server Bar (Discord-style) ---- */
.server-bar {
  width: 72px;
  min-width: 72px;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--border);
}

.server-icon {
  width: 48px;
  height: 48px;
  min-height: 48px;
  border: none;
  border-radius: 24px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  position: relative;
}

.server-icon:hover {
  border-radius: 16px;
  background: var(--accent);
  color: white;
}

.server-icon.active {
  border-radius: 16px;
  background: var(--accent);
  color: white;
}

.server-icon.active::before {
  content: '';
  position: absolute;
  left: -12px;
  width: 4px;
  height: 32px;
  background: var(--text-primary);
  border-radius: 0 4px 4px 0;
}

.server-icon:hover::before {
  content: '';
  position: absolute;
  left: -12px;
  width: 4px;
  height: 20px;
  background: var(--text-primary);
  border-radius: 0 4px 4px 0;
}

.server-icon-sm {
  width: 40px;
  height: 40px;
  min-height: 40px;
  border-radius: 20px;
  font-size: 14px;
}

.server-icon-sm:hover {
  border-radius: 12px;
}

.server-icon-sm.active {
  border-radius: 12px;
}

.server-icon-channel {
  font-size: 20px;
  font-weight: 700;
}

.server-separator {
  width: 32px;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  margin: 4px 0;
}

.server-channels {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.server-unread-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  background: var(--red);
  border: 3px solid var(--bg-primary);
  border-radius: var(--radius-full);
}

/* ---- List Panel ---- */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  position: relative;
  z-index: 10;
}

.sidebar-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.logo-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-actions {
  display: flex;
  gap: 4px;
}

/* ---- Search ---- */
.search-container {
  padding: 8px 12px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--bg-primary);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: background var(--transition-fast);
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-input:focus {
  background: var(--bg-tertiary);
  box-shadow: 0 0 0 2px var(--accent);
}

/* ---- Filter Tabs ---- */
.filter-tabs {
  display: flex;
  gap: 4px;
  padding: 4px 12px 8px;
}

.filter-tab {
  flex: 1;
  padding: 6px 12px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.filter-tab.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ---- Section Headers ---- */
.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.dm-header {
  padding-top: 4px;
}

/* ---- Channels ---- */
.channels-section {
  padding: 0 8px;
}

.channels-section.hidden {
  display: none;
}

.channels-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-bottom: 60px;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.channel-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.channel-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
}

.channel-hash {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.channel-item.active .channel-hash {
  color: var(--accent);
}

.channel-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.channel-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 1px 6px;
  border-radius: 8px;
  flex-shrink: 0;
}

.channel-unread .channel-count {
  background: var(--accent);
  color: white;
}

/* ---- Channel Settings ---- */
.channel-setting-row {
  margin-bottom: 14px;
}

.channel-setting-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.emoji-picker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.emoji-option {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  color: var(--text-muted);
}

.emoji-option:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.emoji-option.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 1px var(--accent);
}

.color-picker-row {
  display: flex;
  gap: 6px;
}

.color-option {
  width: 28px;
  height: 28px;
  border: 2px solid transparent;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.color-option:hover {
  transform: scale(1.15);
}

.color-option.selected {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--text-muted);
}

.channel-members-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 150px;
  overflow-y: auto;
  margin-bottom: 8px;
}

.channel-member-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
}

.channel-member-item .member-email {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-member-item .member-badge {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 1px 6px;
  border-radius: 8px;
}

.channel-member-item .remove-member {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: var(--radius-full);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  opacity: 0;
  transition: all var(--transition-fast);
}

.channel-member-item:hover .remove-member {
  opacity: 1;
}

.channel-member-item .remove-member:hover {
  background: var(--red-light);
  color: var(--red);
}

.add-member-row {
  display: flex;
  gap: 6px;
}

.add-member-row input {
  flex: 1;
}

/* Channel icon in sidebar */
.channel-emoji {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* ---- Contacts List ---- */
.contacts-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 60px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.contact-item:hover {
  background: var(--bg-hover);
}

.contact-item.active {
  background: var(--bg-active);
}

.contact-item.unread .contact-name {
  font-weight: 600;
  color: var(--text-primary);
}

.contact-item.unread .contact-preview {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ---- Avatar ---- */
.avatar {
  position: relative;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  color: white;
  user-select: none;
  overflow: visible;
}

.avatar-sm {
  width: 34px;
  height: 34px;
  min-width: 34px;
  font-size: 12px;
}

.avatar-lg {
  width: 48px;
  height: 48px;
  min-width: 48px;
  font-size: 18px;
}

.avatar-group {
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
}

.avatar-text {
  position: relative;
  z-index: 1;
}

.avatar img {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  object-fit: cover;
}

.status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  border: 3px solid var(--bg-secondary);
  z-index: 2;
}

.status-dot.online {
  background: var(--green);
}

.status-dot.away {
  background: var(--yellow);
}

.status-dot.offline {
  background: var(--text-muted);
}

/* ---- Contact Info ---- */
.contact-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.contact-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.contact-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.contact-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.unread-badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

.flag-indicator {
  color: var(--yellow);
  flex-shrink: 0;
  display: flex;
}

/* ---- Sidebar Footer / User Profile ---- */
.sidebar-footer {
  position: fixed;
  bottom: 0;
  left: 72px;
  width: var(--sidebar-width);
  z-index: 100;
  padding: 0;
  border-top: none;
  background: #232428;
}

[data-theme="light"] .sidebar-footer {
  background: #ebedef;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  height: 52px;
}

.user-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-settings-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.user-settings-btn:hover {
  color: var(--text-primary);
}

.user-status {
  font-size: 11px;
  color: var(--green);
}

/* ---- Loading State ---- */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
  gap: 12px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Main Chat Area
   ============================================ */

#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* ---- Empty State ---- */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  margin-bottom: 16px;
  opacity: 0.4;
  color: var(--text-muted);
}

.empty-state h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  max-width: 300px;
}

.empty-state .hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---- Chat Header ---- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}

.chat-header.hidden {
  display: none;
}

.back-btn {
  display: none;
}

.chat-contact-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.chat-contact-details {
  min-width: 0;
}

.chat-contact-details h2 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-contact-email {
  font-size: 12px;
  color: var(--text-muted);
}

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

/* ---- Thread Filter Bar ---- */
.thread-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  animation: slideDown 0.15s ease;
}

.thread-filter-bar.hidden {
  display: none;
}

.thread-filter-label {
  color: var(--text-muted);
  white-space: nowrap;
}

.thread-filter-subject {
  flex: 1;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-filter-bar .btn-show-all {
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font);
  transition: all var(--transition-fast);
}

.thread-filter-bar .btn-show-all:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* ---- Message subject pills - clickable for thread filter ---- */
.message-subject {
  cursor: pointer;
}

.message-subject:hover {
  background: rgba(88, 101, 242, 0.25);
}

/* ---- Members Panel (right side) ---- */
.members-panel {
  width: 240px;
  min-width: 240px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.members-panel.hidden {
  display: none;
}

.members-panel-header {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  height: var(--header-height);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.members-panel-list {
  padding: 8px;
  flex: 1;
  overflow-y: auto;
}

.member-role-header {
  padding: 8px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
}

.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: default;
}

.member-row:hover {
  background: var(--bg-hover);
}

.member-row .member-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: white;
}

.member-row .member-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-row .member-name.member-you {
  color: var(--accent);
}

.member-row .member-status {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-row .member-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---- Messages Container ---- */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 0;
  min-height: 0;
}

.messages-container.hidden {
  display: none;
}

.messages-list {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 100%;
  padding: 0 16px;
}

/* ---- Messages ---- */
.message-group {
  display: flex;
  gap: 12px;
  padding: 4px 0;
  margin: 4px 0;
  border-radius: var(--radius-md);
}

.message-group:hover {
  background: var(--bg-message-hover);
}

.message-group .avatar {
  margin-top: 2px;
  flex-shrink: 0;
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.message-sender {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.message-sender.sent {
  color: var(--accent);
}

.message-timestamp {
  font-size: 11px;
  color: var(--text-muted);
}

.importance-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-full);
}

.message-subject {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
  padding: 2px 8px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  display: inline-block;
}

.message-body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message-body p {
  margin-bottom: 4px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.attachment-chip:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.attachment-icon {
  color: var(--text-muted);
}

/* ---- Date Separator ---- */
.date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}

.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.date-separator span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* ---- Typing Indicator ---- */
.typing-indicator {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-muted);
  display: none;
}

/* ============================================
   Composer
   ============================================ */

.composer {
  padding: 0 16px 16px;
  background: var(--bg-chat);
}

.composer.hidden {
  display: none;
}

/* ---- Reply Context Bar ---- */
.reply-context {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  animation: slideDown 0.15s ease;
}

.reply-context.hidden {
  display: none;
}

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

.reply-context-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
}

.reply-context-info span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Message Reply Button ---- */
.message-actions {
  display: none;
  gap: 2px;
  position: absolute;
  top: -8px;
  right: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  box-shadow: var(--shadow-sm);
  z-index: 5;
}

.message-group {
  position: relative;
}

.message-group:hover .message-actions {
  display: flex;
}

.message-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.message-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.message-action-btn.reply-btn:hover {
  color: var(--accent);
}

/* ---- New Thread Subject Input ---- */
.new-thread-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--green-light);
  border-left: 3px solid var(--green);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  animation: slideDown 0.15s ease;
}

.new-thread-bar.hidden {
  display: none;
}

.new-thread-bar input {
  flex: 1;
  padding: 4px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}

.new-thread-bar input:focus {
  border-color: var(--green);
}

.new-thread-bar input::placeholder {
  color: var(--text-muted);
}

.new-thread-label {
  font-size: 12px;
  color: var(--green);
  font-weight: 500;
  white-space: nowrap;
}

/* ---- Attachment Preview (Composer) ---- */
.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
}

.attachment-preview.hidden {
  display: none;
}

.attachment-staged {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 200px;
}

.attachment-staged .attachment-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.attachment-staged .attachment-size {
  color: var(--text-muted);
  font-size: 10px;
  white-space: nowrap;
}

.attachment-staged .remove-attachment {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  transition: all var(--transition-fast);
}

.attachment-staged .remove-attachment:hover {
  background: var(--red-light);
  color: var(--red);
}

/* ---- Clickable Attachments on Messages ---- */
.attachment-chip {
  cursor: pointer;
}

.attachment-chip.loading {
  opacity: 0.6;
  pointer-events: none;
}

.composer-toolbar {
  display: flex;
  gap: 4px;
  padding: 4px 0 8px;
}

.composer-input-area {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 4px;
  border: 1px solid var(--border);
  transition: border-color var(--transition-fast);
}

.composer-input-area:focus-within {
  border-color: var(--accent);
}

.message-input {
  flex: 1;
  min-height: 36px;
  max-height: 120px;
  overflow-y: auto;
  padding: 7px 8px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-primary);
  line-height: 1.5;
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.send-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.composer-input-area .icon-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

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

/* ============================================
   Buttons
   ============================================ */

.icon-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn {
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: none;
  color: var(--text-secondary);
}

.btn-secondary:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ============================================
   Modal (Compose)
   ============================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 90%;
  max-width: 560px;
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 80vh;
  animation: slideUp 0.25s ease;
}

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

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 16px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.compose-field {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition-fast);
}

.compose-field:focus {
  border-color: var(--accent);
}

.compose-field::placeholder {
  color: var(--text-muted);
}

.compose-body {
  flex: 1;
  min-height: 150px;
  padding: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.5;
  outline: none;
  overflow-y: auto;
}

.compose-body:focus {
  border-color: var(--accent);
}

.compose-body:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* ============================================
   Responsive / Mobile
   ============================================ */

/* ============================================
   Mobile Layout (Discord-style)
   Server bar hidden, sidebar slides over chat
   ============================================ */

@media (max-width: 768px) {
  /* Hide server bar on mobile — use swipe/back to navigate */
  .server-bar {
    display: none;
  }

  /* Sidebar takes full width, overlays chat */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85vw;
    max-width: 320px;
    min-width: unset;
    z-index: 200;
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }

  #sidebar.sidebar-hidden {
    transform: translateX(-100%);
    box-shadow: none;
  }

  /* Fixed footer follows sidebar width on mobile */
  .sidebar-footer {
    left: 0;
    width: 85vw;
    max-width: 320px;
  }

  .sidebar-hidden .sidebar-footer {
    transform: translateX(-100%);
  }

  /* Members panel hidden on mobile by default */
  .members-panel {
    display: none !important;
  }

  /* Show back button in chat header */
  .back-btn {
    display: flex !important;
  }

  /* Chat header adjustments */
  .chat-header {
    padding: 8px 12px;
  }

  .chat-contact-details h2 {
    font-size: 14px;
  }

  /* Composer adjustments */
  .composer {
    padding: 0 8px 8px;
  }

  /* Full-width chat area */
  #chat-area {
    width: 100vw;
  }

  /* Search container */
  .search-container {
    padding: 8px;
  }

  /* Modal adjustments */
  .modal {
    width: 95%;
    max-width: none;
    margin: 16px;
  }
}

/* Small phones */
@media (max-width: 400px) {
  #sidebar {
    width: 100vw;
    max-width: none;
  }

  .sidebar-footer {
    width: 100vw;
    max-width: none;
  }
}

/* ============================================
   Animations & Micro-interactions
   ============================================ */

.contact-item {
  animation: none;
}

.first-load .contact-item {
  animation: listItemIn 0.3s ease backwards;
}

@keyframes listItemIn {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.message-group {
  animation: none;
}

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

/* ---- No conversations state ---- */
.no-conversations {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  gap: 8px;
}

.no-conversations p {
  font-size: 13px;
}

/* ---- Thread subject pill ---- */
.thread-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
  cursor: pointer;
}

.thread-pill:hover {
  background: rgba(88, 101, 242, 0.25);
}

/* ---- New messages divider ---- */
.new-messages-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  color: var(--red);
}

.new-messages-divider::before,
.new-messages-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--red);
  opacity: 0.4;
}

.new-messages-divider span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

