:root {
  --bg-app: #0c1317;
  --bg-sidebar: #111b21;
  --bg-sidebar-header: #202c33;
  --bg-chat: #0b141a;
  --bg-chat-header: #202c33;
  --bg-input: #202c33;
  --bg-bubble-in: #202c33;
  --bg-bubble-out: #005c4b;
  --bg-search: #202c33;
  --bg-hover: #202c33;
  --bg-active: #2a3942;
  
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  --text-accent: #00a884;
  --accent-green: #00a884;
  --accent-green-hover: #02906f;
  --border-color: #222d34;
  --unread-badge: #00a884;
  --danger-color: #ea4335;
  --warning-color: #f59e0b;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.3);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

#app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
  background-color: var(--bg-sidebar);
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-thumb {
  background: rgba(134, 150, 160, 0.2);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(134, 150, 160, 0.4);
}

/* Sidebar */
.sidebar {
  width: 380px;
  min-width: 320px;
  max-width: 450px;
  height: 100%;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  height: 60px;
  background-color: var(--bg-sidebar-header);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #2a3942;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-info .user-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.user-info .conn-status {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--warning-color);
}
.status-dot.connected {
  background-color: var(--accent-green);
  box-shadow: 0 0 8px rgba(0, 168, 132, 0.6);
}

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

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 18px;
  transition: background-color 0.2s, color 0.2s;
}

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

/* Sidebar Search */
.sidebar-search-wrap {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-color);
}

.search-box {
  background-color: var(--bg-search);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  width: 100%;
}
.search-box input::placeholder {
  color: var(--text-secondary);
}

/* Chat List */
.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  transition: background-color 0.15s;
  position: relative;
}

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

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

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

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

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

.chat-time {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.chat-badge {
  background-color: var(--unread-badge);
  color: #111b21;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* Chat Main View */
.chat-main {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-chat);
  position: relative;
}

/* Empty State */
.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
  background-color: #111b21;
  border-bottom: 6px solid var(--accent-green);
}

.empty-logo {
  font-size: 64px;
  margin-bottom: 20px;
  color: var(--text-secondary);
}

.chat-empty-state h2 {
  font-size: 26px;
  font-weight: 300;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.chat-empty-state p {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 440px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.btn-primary {
  background-color: var(--accent-green);
  color: #111b21;
  border: none;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 20px;
  cursor: pointer;
  transition: background-color 0.2s;
}
.btn-primary:hover {
  background-color: var(--accent-green-hover);
}

/* Chat Active Header */
.chat-header {
  height: 60px;
  background-color: var(--bg-chat-header);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  z-index: 5;
}

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

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

.chat-header-text .subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Message Stream */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: var(--bg-chat);
  background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 20px 20px;
}

.date-divider {
  align-self: center;
  background-color: rgba(32, 44, 51, 0.9);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  margin: 10px 0;
  box-shadow: var(--shadow-sm);
}

.message-bubble {
  max-width: 65%;
  min-width: 80px;
  padding: 6px 10px 8px;
  border-radius: 8px;
  position: relative;
  font-size: 14.2px;
  line-height: 1.4;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  animation: fadeIn 0.15s ease-out;
}

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

.message-bubble.incoming {
  align-self: flex-start;
  background-color: var(--bg-bubble-in);
  color: var(--text-primary);
  border-top-left-radius: 0;
}

.message-bubble.outgoing {
  align-self: flex-end;
  background-color: var(--bg-bubble-out);
  color: var(--text-primary);
  border-top-right-radius: 0;
}

.bubble-text {
  white-space: pre-wrap;
  margin-bottom: 4px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 11px;
  color: rgba(233, 237, 239, 0.6);
  margin-top: 2px;
}

.bubble-status {
  font-size: 12px;
}

/* Media in bubble */
.bubble-media-img {
  max-width: 100%;
  max-height: 320px;
  border-radius: 6px;
  margin-bottom: 6px;
  display: block;
  cursor: pointer;
  background-color: #000;
}

.bubble-doc {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.2);
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 6px;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s;
}
.bubble-doc:hover {
  background: rgba(0, 0, 0, 0.35);
}

.doc-icon {
  font-size: 28px;
  color: var(--accent-green);
}

.doc-details {
  flex: 1;
  min-width: 0;
}

.doc-title {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Attachment Preview bar */
.attachment-preview-bar {
  background-color: var(--bg-sidebar-header);
  border-top: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--text-primary);
  overflow: hidden;
}

.preview-file-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.preview-file-size {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.btn-remove-attachment {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  border-radius: 50%;
}
.btn-remove-attachment:hover {
  color: var(--danger-color);
}

/* Chat Input Bar */
.chat-input-bar {
  min-height: 62px;
  background-color: var(--bg-input);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.chat-input-bar textarea {
  flex: 1;
  background-color: #2a3942;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14.5px;
  padding: 10px 14px;
  border-radius: 10px;
  resize: none;
  max-height: 120px;
  min-height: 42px;
  line-height: 1.4;
}

.chat-input-bar textarea::placeholder {
  color: var(--text-secondary);
}

.send-btn {
  background-color: var(--accent-green);
  color: #111b21;
  border: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  transition: background-color 0.2s, transform 0.1s;
}

.send-btn:hover {
  background-color: var(--accent-green-hover);
}
.send-btn:active {
  transform: scale(0.95);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-sidebar-header);
  border-radius: 16px;
  width: min(480px, 92vw);
  padding: 26px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  animation: modalPop 0.2s ease-out;
}

@keyframes modalPop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

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

.modal-header h3 {
  font-size: 18px;
  color: var(--text-primary);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input, .form-group textarea {
  width: 100%;
  background-color: #111b21;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  outline: none;
}
.form-group input:focus, .form-group textarea:focus {
  border-color: var(--accent-green);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.btn-secondary {
  background-color: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

/* QR Modal Specifics */
.qr-container {
  text-align: center;
  padding: 10px 0;
}
.qr-container img {
  width: 240px;
  height: 240px;
  background: white;
  padding: 12px;
  border-radius: 12px;
  margin: 14px auto;
  display: block;
}
