/* Signal Desktop Design Theme Stylesheet */
:root {
  /* Official Signal Color Palette */
  --signal-blue: #2c6bed;
  --signal-blue-hover: #1b52c5;
  --bg-sidebar: #202124;
  --bg-chat: #121212;
  --bg-bubble-received: #2d2e30;
  --bg-bubble-sent: var(--signal-blue);
  --border-color: #323336;
  --bg-input: #2d2e30;
  --text-primary: #f5f5f5;
  --text-secondary: #9e9e9e;
  --text-muted: #757575;
  --error-color: #f44336;
  --success-color: #4caf50;
  --font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

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

.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar Styling (Matches Signal Desktop Left Panel) */
.sidebar {
  width: 310px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title i {
  color: var(--signal-blue);
}

.status-badge {
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.offline {
  background-color: rgba(244, 67, 54, 0.15);
  color: var(--error-color);
}

.status-badge.online {
  background-color: rgba(76, 175, 80, 0.15);
  color: var(--success-color);
}

.status-badge.reconnecting {
  background-color: rgba(255, 171, 64, 0.15);
  color: #ffab40;
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.status-badge.offline .status-indicator {
  background-color: var(--error-color);
}

.status-badge.online .status-indicator {
  background-color: var(--success-color);
  animation: pulse 2s infinite;
}

.status-badge.reconnecting .status-indicator {
  background-color: #ffab40;
  animation: pulse 1s infinite;
}

.account-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.account-number {
  font-family: monospace;
  color: #fff;
  font-weight: 600;
}

/* Styled Button resembling Signal's clean flat buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 600;
  border-radius: 18px;
  cursor: pointer;
  transition: background-color 0.1s;
  border: none;
  font-size: 0.8rem;
  padding: 6px 14px;
}

.btn-primary {
  background-color: var(--signal-blue);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--signal-blue-hover);
}

/* Muted secondary button for Link Device — dimmer when already online */
.btn-link-device {
  background-color: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  font-size: 0.7rem;
  padding: 3px 9px;
  opacity: 0.7;
  transition:
    opacity 0.2s,
    border-color 0.2s;
}
.btn-link-device:hover {
  opacity: 1;
  border-color: var(--signal-blue);
  color: var(--text-primary);
}

.btn-sm {
  font-size: 0.75rem;
  padding: 5px 12px;
}

.btn-lg {
  font-size: 0.85rem;
  padding: 10px 18px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background-color: #3c3d40;
  color: var(--text-muted);
}

/* Unread indicator dot */
.unread-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--signal-blue);
  vertical-align: middle;
  margin-left: 4px;
  box-shadow: 0 0 4px var(--signal-blue);
}

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

/* Thread Search (Signal Desktop style) */
.search-wrapper {
  padding: 0 16px 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.search-input-container {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.search-input {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid transparent;
  color: var(--text-primary);
  padding: 7px 10px 7px 30px;
  font-size: 0.82rem;
  border-radius: 14px;
  outline: none;
  transition: border-color 0.1s;
}

.search-input:focus {
  border-color: var(--signal-blue);
}

/* Threads List (Matches Signal Desktop perfectly) */
.thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
}

.thread-empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
  font-size: 0.82rem;
}

.thread-item {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background-color 0.1s;
  border-left: 3px solid transparent;
}

.thread-item:hover {
  background-color: rgba(255, 255, 255, 0.04);
}

.thread-item.active {
  background-color: rgba(44, 107, 237, 0.12);
  border-left-color: var(--signal-blue);
}

.thread-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
}

.thread-avatar.direct {
  background-color: #515c6a;
}

.thread-avatar.group {
  background-color: #2c6bed;
}

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

.thread-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.thread-meta {
  font-size: 0.74rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Right Chat Pane (Signal Desktop style) */
.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-chat);
}

.chat-header {
  height: 56px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background-color: var(--bg-sidebar);
}

.chat-header-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: #fff;
}

.chat-header-subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* Message History Area */
.message-history {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: 12px;
  text-align: center;
  max-width: 400px;
  margin: 0 auto;
}

.message-empty-state i {
  font-size: 2.5rem;
  color: var(--border-color);
}

.message-empty-state p {
  font-size: 0.88rem;
  line-height: 1.5;
}

.message-row {
  display: flex;
  margin-bottom: 2px;
}

.message-row.sent {
  justify-content: flex-end;
}

.message-row.received {
  justify-content: flex-start;
}

.message-wrapper {
  max-width: 65%;
  display: flex;
  flex-direction: column;
}

.message-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-bottom: 2px;
  padding: 0 4px;
}

.message-row.sent .message-meta {
  text-align: right;
}

/* Message Bubble with elegant Signal-like style */
.message-bubble {
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 0.86rem;
  line-height: 1.45;
  word-break: break-word;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-row.sent .message-bubble {
  background-color: var(--bg-bubble-sent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-row.received .message-bubble {
  background-color: var(--bg-bubble-received);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

/* Inline Attachment Display (Images / Videos) */
.attachment-item {
  margin-bottom: 8px;
}
.attachment-item:last-child {
  margin-bottom: 0;
}
.message-media {
  max-width: 280px;
  max-height: 200px;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Composer / Input Area sits elegantly at the bottom */
.composer {
  padding: 16px 24px;
  background-color: var(--bg-chat);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Clipboard Pasted Media Preview Bar sits just above input */
.media-preview-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 4px;
}

.preview-thumbnail-wrapper {
  position: relative;
  width: 50px;
  height: 50px;
}

.preview-thumbnail {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border-color);
}

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

.preview-filename {
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-size {
  font-size: 0.68rem;
  color: var(--text-secondary);
}

.btn-remove-preview {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  font-size: 0.9rem;
  transition: color 0.1s;
}

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

.composer-form {
  display: flex;
  align-items: center;
  background-color: var(--bg-input);
  border-radius: 18px;
  padding: 2px 14px 2px 6px;
  gap: 8px;
}

/* Hidden File Input to facilitate clicking icon to upload */
.file-upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  font-size: 1.1rem;
  transition: color 0.1s;
}

.file-upload-label:hover {
  color: #fff;
}

.composer-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 10px 8px;
  font-size: 0.85rem;
  outline: none;
}

.composer-input::placeholder {
  color: var(--text-muted);
}

.btn-composer-send {
  background: none;
  border: none;
  color: var(--signal-blue);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: transform 0.1s;
}

.btn-composer-send:hover:not(:disabled) {
  transform: scale(1.1);
  color: #fff;
}

.btn-composer-send:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Modal styling */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background-color: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  max-width: 440px;
  width: 100%;
  padding: 24px;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.25rem;
}

.modal-close:hover {
  color: #fff;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-title i {
  color: var(--signal-blue);
}

.modal-instructions {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-instructions ol {
  padding-left: 20px;
}

.modal-instructions li {
  margin-bottom: 4px;
}

.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background-color: var(--bg-chat);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  min-height: 250px;
  margin-bottom: 16px;
}

.qr-placeholder {
  color: var(--text-muted);
  text-align: center;
}

.qr-placeholder i {
  font-size: 3rem;
  margin-bottom: 8px;
  color: var(--border-color);
}

.qr-loading {
  text-align: center;
  color: var(--signal-blue);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.qr-loading i {
  font-size: 2rem;
}

.qr-image {
  width: 192px;
  height: 192px;
  background-color: #fff;
  padding: 8px;
  border-radius: 6px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.qr-fallback {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: monospace;
  text-align: center;
  word-break: break-all;
  padding: 0 16px;
}

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

.modal-actions .btn {
  flex: 1;
}

.link-status {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 8px;
}

.link-status.info {
  color: #fbbf24;
}

.link-status.error {
  color: var(--error-color);
}

.link-status.success {
  color: var(--success-color);
}

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

.animate-spin {
  animation: spin 1s linear infinite;
}

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

.hidden {
  display: none !important;
}

/* Scroll anchor sentinel — sits at end of message list, used by scrollIntoView */
.scroll-sentinel {
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Local SVG Icon utility classes */
.icon {
  width: 1.1em;
  height: 1.1em;
  display: inline-block;
  vertical-align: -0.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-lg {
  width: 2.5rem;
  height: 2.5rem;
}

/* Autolinked URLs styling */
.message-link {
  color: #64b5f6;
  text-decoration: underline;
  word-break: break-all;
}

.message-link:hover {
  color: #90caf9;
}

/* Emoji Reactions styling */
.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 0.15rem 0.5rem;
  font-size: 0.8rem;
  cursor: default;
  user-select: none;
}

.reaction-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
