@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0b141a;
  --bg-secondary: #111b21;
  --bg-tertiary: #1f2c34;
  --bg-chat: #0b141a;
  --bg-hover: #202c33;
  --bg-active: #2a3942;
  --bg-bubble-sent: #005c4b;
  --bg-bubble-recv: #202c33;
  --bg-input: #2a3942;
  --bg-glass: rgba(17, 27, 33, 0.85);
  --border-color: #2a3942;
  --border-light: #313d45;
  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  --text-link: #53bdeb;
  --accent: #00a884;
  --accent-hover: #06cf9c;
  --accent-dim: rgba(0, 168, 132, 0.15);
  --danger: #ea4335;
  --warning: #f59e0b;
  --online: #00a884;
  --offline: #667781;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

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

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== LOGIN PAGE ===== */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0b141a 0%, #111b21 50%, #1a2e38 100%);
  position: relative;
  overflow: hidden;
}

.login-wrapper::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 40%, rgba(0,168,132,0.08) 0%, transparent 50%),
              radial-gradient(circle at 70% 60%, rgba(0,168,132,0.05) 0%, transparent 50%);
  animation: bgPulse 15s ease-in-out infinite;
}

@keyframes bgPulse {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-2%, -2%) scale(1.05); }
}

.login-card {
  position: relative;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: cardIn 0.6s ease-out;
}

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

.login-logo {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  font-size: 32px;
  box-shadow: 0 4px 20px rgba(0,168,132,0.3);
}

.login-title {
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

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

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

.form-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font);
  transition: border-color var(--transition);
  outline: none;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.login-error {
  background: rgba(234,67,53,0.1);
  border: 1px solid rgba(234,67,53,0.3);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.login-error.show { display: block; animation: shake 0.4s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ===== APP LAYOUT ===== */
.app-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-primary);
}

.top-header {
  display: flex;
  align-items: center;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  min-height: 56px;
  padding: 0;
}

.brand {
  padding: 0 16px;
  min-width: 200px;
  display: flex;
  align-items: center;
}

.brand h2 {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.brand h2 span { color: var(--accent); }

.header-actions {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  margin-left: auto;
  align-items: center;
}

.app-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 380px;
  min-width: 380px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: width var(--transition);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--transition);
}

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

/* Device Tabs — Pill Style */
.device-tabs {
  display: flex;
  padding: 0 16px;
  gap: 8px;
  background: transparent;
  border-bottom: none;
  overflow-x: auto;
  flex-shrink: 0;
  flex: 1;
  align-items: center;
}

.device-tab {
  position: relative;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 240px;
}

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

.device-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 12px var(--accent-dim);
}

.device-tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-tab-badge {
  background: #ffffff;
  color: #0b141a;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.device-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(234, 67, 53, 0.4);
}

.device-status-dot.online { background: var(--online); box-shadow: 0 0 6px rgba(0,168,132,0.5); }

/* Search */
.search-box {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper .search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 9px 12px 9px 38px;
  background: var(--bg-input);
  border: none;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
}

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

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

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid rgba(42,57,66,0.3);
}

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

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
  overflow: hidden;
}

.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }

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

.chat-name-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

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

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

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

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

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

.chat-group-icon { color: var(--text-muted); margin-right: 4px; }

/* ===== MAIN CHAT AREA ===== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  position: relative;
}

.chat-area-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
}

.chat-area-empty .empty-icon { font-size: 72px; opacity: 0.3; }
.chat-area-empty h3 { font-size: 20px; font-weight: 400; color: var(--text-secondary); }
.chat-area-empty p { font-size: 14px; max-width: 400px; text-align: center; }

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

.chat-header-info { flex: 1; }
.chat-header-name { font-size: 16px; font-weight: 500; }

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

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

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message-date-divider {
  text-align: center;
  margin: 16px 0;
}

.message-date-divider span {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  font-weight: 500;
}

.message-bubble {
  max-width: 65%;
  padding: 6px 8px 4px;
  border-radius: 8px;
  position: relative;
  word-wrap: break-word;
  animation: msgIn 0.2s ease;
}

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

.message-bubble.sent {
  align-self: flex-end;
  background: var(--bg-bubble-sent);
  border-top-right-radius: 0;
}

.message-bubble.received {
  align-self: flex-start;
  background: var(--bg-bubble-recv);
  border-top-left-radius: 0;
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-hover);
  margin-bottom: 2px;
}

.message-text {
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.message-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.message-time {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
}

.message-status { font-size: 14px; color: rgba(255,255,255,0.5); }
.message-status.read { color: var(--text-link); }

/* Media messages */
.message-image {
  max-width: 330px;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 4px;
  cursor: pointer;
}

.message-image img {
  width: 100%;
  display: block;
  transition: transform 0.2s;
}

.message-image:hover img { transform: scale(1.02); }

.message-document {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.15);
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 4px;
  min-width: 240px;
}

.message-document .doc-icon { font-size: 28px; flex-shrink: 0; }

.message-document .doc-info {
  flex: 1;
  min-width: 0;
}

.message-document .doc-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.message-audio {
  min-width: 280px;
  padding: 8px;
  background: rgba(0,0,0,0.15);
  border-radius: 6px;
  margin-bottom: 4px;
}

.message-audio audio { width: 100%; height: 36px; }

.message-location {
  padding: 8px;
  background: rgba(0,0,0,0.15);
  border-radius: 6px;
  margin-bottom: 4px;
  min-width: 200px;
}

.message-contact {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(0,0,0,0.15);
  border-radius: 6px;
  margin-bottom: 4px;
}

.message-sticker { max-width: 180px; margin-bottom: 4px; }
.message-sticker img { width: 100%; }

.message-reply-quote {
  background: rgba(0,0,0,0.2);
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== MESSAGE INPUT ===== */
.message-input-area {
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
}

.attach-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

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

.message-input-wrapper {
  flex: 1;
  position: relative;
}

.message-input {
  display: block;
  width: 100%;
  height: 42px;
  padding: 11px 16px;
  background: var(--bg-input);
  border: none;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  resize: none;
  min-height: 42px;
  max-height: 150px;
  line-height: 1.4;
}

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

.send-btn {
  width: 42px;
  height: 42px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ===== ATTACHMENT MENU ===== */
.attach-menu {
  position: absolute;
  bottom: 70px;
  left: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  min-width: 200px;
  animation: menuIn 0.2s ease;
}

.attach-menu.show { display: flex; }

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

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  border-radius: var(--radius);
  transition: background var(--transition);
}

.attach-menu-item:hover { background: var(--bg-hover); }
.attach-menu-item .menu-icon { font-size: 20px; width: 28px; text-align: center; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.show { display: flex; }

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

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 24px;
  width: 90%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-header h3 { font-size: 18px; font-weight: 600; }

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-hover);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover { background: var(--bg-active); color: var(--text-primary); }

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

.file-preview {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius);
  margin-top: 8px;
  object-fit: contain;
}

/* ===== LOADING ===== */
.loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11,20,26,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 280px;
}

.toast.success { border-left: 3px solid var(--accent); }
.toast.error { border-left: 3px solid var(--danger); }

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

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: 100%; }
  .chat-area { display: none; }
  .chat-area.active { display: flex; position: absolute; inset: 0; z-index: 10; }
  .messages-container { padding: 12px 16px; }
  .message-bubble { max-width: 85%; }
}
