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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100vh;
  overflow: hidden;
}

.messenger-container {
  display: flex;
  height: 100vh;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: 320px;
  background: #f5f5f5;
  border-right: 1px solid #ddd;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px;
  background: #fff;
  border-bottom: 1px solid #ddd;
}

.sidebar-header h1 {
  font-size: 24px;
  margin-bottom: 8px;
}

.balance {
  font-size: 14px;
  color: #666;
  margin-bottom: 12px;
}

.new-message-btn {
  width: 100%;
  padding: 10px;
  background: #007aff;
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}

.new-message-btn:hover {
  background: #0051d5;
}

.conversations {
  flex: 1;
  overflow-y: auto;
}

.conversation {
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
  cursor: pointer;
  transition: background 0.2s;
}

.conversation:hover {
  background: #e8e8e8;
}

.conversation.active {
  background: #fff;
  border-left: 3px solid #007aff;
}

.conversation-phone {
  font-weight: 600;
  margin-bottom: 2px;
}

.conversation-number {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}

.conversation-meta {
  font-size: 12px;
  color: #888;
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.chat-header {
  padding: 20px;
  background: #f9f9f9;
  border-bottom: 1px solid #ddd;
}

.chat-title {
  font-size: 18px;
  font-weight: 600;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column-reverse;
}

.message {
  max-width: 60%;
  margin-bottom: 12px;
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
}

.message.outbound {
  align-self: flex-end;
  background: #007aff;
  color: white;
}

.message.inbound {
  align-self: flex-start;
  background: #e5e5ea;
  color: black;
}

.message-text {
  margin-bottom: 4px;
}

.message-meta {
  font-size: 11px;
  opacity: 0.7;
}

/* Compose Area */
.compose-area {
  display: flex;
  padding: 16px;
  border-top: 1px solid #ddd;
  gap: 12px;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 20px;
  font-size: 14px;
  outline: none;
}

#message-input:focus {
  border-color: #007aff;
}

#send-btn {
  padding: 12px 24px;
  background: #007aff;
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 600;
}

#send-btn:hover:not(:disabled) {
  background: #0051d5;
}

#send-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Empty State */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
  font-size: 16px;
}

/* CRM Sidebar */
.crm-sidebar {
  width: 300px;
  background: #f9f9f9;
  border-left: 1px solid #ddd;
  overflow-y: auto;
  padding: 20px;
}

.crm-panel h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.crm-field {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e0e0e0;
}

.crm-field label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}

.crm-field span {
  font-size: 14px;
  color: #333;
}

.crm-empty, .crm-error {
  text-align: center;
  color: #999;
  padding: 20px;
}

.crm-quote {
  background: #fff;
  padding: 12px;
  margin-bottom: 12px;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.crm-quote h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: #007aff;
}

/* New Message Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  padding: 24px;
  border-radius: 12px;
  width: 400px;
  max-width: 90%;
}

.modal-content h2 {
  margin: 0 0 20px 0;
  font-size: 20px;
}

.modal-content input,
.modal-content textarea {
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.modal-content textarea {
  min-height: 100px;
  resize: vertical;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.modal-actions .cancel-btn {
  background: #e0e0e0;
  color: #333;
}

.modal-actions .send-btn {
  background: #007aff;
  color: white;
}

.modal-actions .send-btn:hover {
  background: #0051d5;
}

/* CRM Toggle Button */
.crm-toggle-btn {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #007aff;
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 100;
}

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

/* Mobile Responsive */
@media (max-width: 768px) {
  .crm-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 85%;
    height: 100vh;
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.3s;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
  }

  .crm-sidebar.active {
    transform: translateX(0);
  }
}

@media (min-width: 769px) {
  .crm-toggle-btn {
    display: none !important;
  }
}

@media (max-width: 768px) {
  #message-input {
    font-size: 16px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transition: transform 0.3s ease-out;
  }
  
  .crm-sidebar {
    transition: transform 0.3s ease-out;
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 85%;
    height: 100vh;
    z-index: 150;
    transform: translateX(0);
  }
  
  .sidebar.hidden {
    transform: translateX(-100%);
  }
}

@media (max-width: 768px) {
  body {
    height: 100vh;
    height: 100dvh;
  }
  
  .messenger-container {
    height: 100vh;
    height: 100dvh;
  }
  
  .chat-area {
    height: 100vh;
    height: 100dvh;
  }
}

body.dark-mode {
  background: #000;
  color: #fff;
}

body.dark-mode .sidebar {
  background: #1c1c1e;
  border-right-color: #38383a;
}

body.dark-mode .sidebar-header {
  background: #2c2c2e;
  border-bottom-color: #38383a;
}

body.dark-mode .conversation {
  border-bottom-color: #38383a;
}

body.dark-mode .conversation:hover {
  background: #2c2c2e;
}

body.dark-mode .conversation.active {
  background: #1c1c1e;
}

body.dark-mode .chat-area {
  background: #000;
}

body.dark-mode .chat-header {
  background: #1c1c1e;
  border-bottom-color: #38383a;
}

body.dark-mode .messages {
  background: #000;
}

body.dark-mode .message.inbound {
  background: #3a3a3c;
  color: #fff;
}

body.dark-mode .compose-area {
  border-top-color: #38383a;
}

body.dark-mode #message-input {
  background: #1c1c1e;
  border-color: #38383a;
  color: #fff;
}

body.dark-mode .crm-sidebar {
  background: #1c1c1e;
  border-left-color: #38383a;
  color: #fff;
}

body.dark-mode .crm-field {
  border-bottom-color: #38383a;
}

body.dark-mode .crm-field label {
  color: #8e8e93;
}

body.dark-mode .crm-field span {
  color: #fff;
}

body.dark-mode .crm-quote {
  background: #2c2c2e;
  border-color: #38383a;
}

body.dark-mode .crm-empty,
body.dark-mode .crm-error {
  color: #8e8e93;
}

body.dark-mode .modal-content {
  background: #2c2c2e;
  color: #fff;
}

body.dark-mode .modal-content input,
body.dark-mode .modal-content textarea {
  background: #1c1c1e;
  border-color: #38383a;
  color: #fff;
}

.theme-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  transition: background 0.2s;
}

.theme-toggle:hover {
  background: rgba(0, 0, 0, 0.05);
}

body.dark-mode .theme-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

.theme-toggle svg {
  position: absolute;
  transition: all 0.3s ease;
}

.theme-toggle .sun-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.theme-toggle .moon-icon {
  opacity: 0;
  transform: rotate(90deg) scale(0);
}

body.dark-mode .theme-toggle .sun-icon {
  opacity: 0;
  transform: rotate(-90deg) scale(0);
}

body.dark-mode .theme-toggle .moon-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.empty-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

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

body.dark-mode .empty-logo img {
  filter: invert(1);
}

.date-separator {
  text-align: center;
  margin: 20px 0 12px 0;
  font-size: 12px;
  color: #8e8e93;
  font-weight: 500;
}

body.dark-mode .date-separator {
  color: #8e8e93;
}

@keyframes glow-red {
  0%, 100% {
    box-shadow: 0 0 5px rgba(255, 59, 48, 0.3), 0 0 10px rgba(255, 59, 48, 0.2);
  }
  50% {
    box-shadow: 0 0 10px rgba(255, 59, 48, 0.5), 0 0 20px rgba(255, 59, 48, 0.3);
  }
}

@keyframes glow-yellow {
  0%, 100% {
    box-shadow: 0 0 5px rgba(255, 204, 0, 0.3), 0 0 10px rgba(255, 204, 0, 0.2);
  }
  50% {
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.5), 0 0 20px rgba(255, 204, 0, 0.3);
  }
}

.conversation.event-this-week {
  animation: glow-red 2s ease-in-out infinite;
  border-left: 3px solid #ff3b30;
}

.conversation.event-next-week {
  animation: glow-yellow 2s ease-in-out infinite;
  border-left: 3px solid #ffcc00;
}

.crm-action-btn {
  width: 100%;
  padding: 12px;
  margin: 16px 0;
  background: #007aff;
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}

.crm-action-btn:hover {
  background: #0051d5;
}

body.dark-mode .crm-action-btn {
  background: #0a84ff;
}

body.dark-mode .crm-action-btn:hover {
  background: #007aff;
}

.crm-action-btn-small {
  padding: 8px 12px;
  margin: 4px 4px 4px 0;
  background: #007aff;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  font-size: 13px;
}

.crm-action-btn-small:hover {
  background: #0051d5;
}

body.dark-mode .crm-action-btn-small {
  background: #0a84ff;
}

body.dark-mode .crm-action-btn-small:hover {
  background: #007aff;
}

.unread-badge {
  display: inline-block;
  background: #007aff;
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 8px;
  min-width: 18px;
  text-align: center;
}

body.dark-mode .unread-badge {
  background: #0a84ff;
}
