:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --chat-bg: #e5ddd5;
  --msg-out: #dcf8c6;
  --msg-in: #ffffff;
  --header: #075e54;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --chat-bg: #0b141a;
  --msg-out: #005c4b;
  --msg-in: #1f2c34;
  --header: #1f2c34;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Login Page */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
}

.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 40px 30px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-logo {
  text-align: center;
  margin-bottom: 30px;
}

.login-logo h1 {
  font-size: 28px;
  color: var(--primary);
  font-weight: 700;
}

.login-logo p {
  color: var(--text-muted);
  margin-top: 5px;
  font-size: 14px;
}

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

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

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border 0.2s;
}

.form-group input:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.otp-input {
  letter-spacing: 8px;
  font-size: 22px !important;
  text-align: center;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

.error-msg {
  background: #fef2f2;
  color: #dc2626;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 15px;
}

.success-msg {
  background: #ecfdf5;
  color: #059669;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 15px;
}

/* Chat Layout */
.app-container {
  display: flex;
  position: relative;
  height: 100vh;
  height: var(--app-h, 100dvh);
  max-width: 1400px;
  margin: 0 auto;
  background: var(--card);
  box-shadow: 0 0 40px rgba(0,0,0,0.1);
}

.sidebar {
  min-height: 0;
  width: 360px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--card);
}

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

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 600;
}

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

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: white;
  font-size: 16px;
  overflow: hidden;
  flex-shrink: 0;
}

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

.vbadge {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 4px;
  flex-shrink: 0;
}
.vbadge svg { width: 100%; height: 100%; display: block; }
.back-btn { display: none; }
.verify-btn.on { background: rgba(59,130,246,0.35); }

.verified-badge {
  color: #3b82f6;
  font-size: 14px;
  margin-left: 4px;
}

.chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

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

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

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

.chat-item-info p {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.unread-badge {
  background: var(--primary);
  color: white;
  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;
}

/* Chat Area */
.chat-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
}

.chat-header {
  flex-shrink: 0;
  background: var(--header);
  color: white;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.chat-header h3 {
  font-size: 16px;
  font-weight: 500;
}

.chat-header small {
  font-size: 12px;
  opacity: 0.8;
}

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

.icon-btn {
  background: transparent;
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.15);
}

.messages-container {
  flex: 1 1 0;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 8px;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.message.outgoing {
  align-self: flex-end;
  background: var(--msg-out);
  border-top-right-radius: 0;
}

.message.incoming {
  align-self: flex-start;
  background: var(--msg-in);
  border-top-left-radius: 0;
}

.message .time {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
}

.message.deleted {
  font-style: italic;
  color: var(--text-muted);
  font-size: 13px;
}

.message img.chat-image {
  max-width: 280px;
  border-radius: 8px;
  cursor: pointer;
}

.message .file-attach {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(0,0,0,0.05);
  border-radius: 6px;
}

.input-area {
  flex-shrink: 0;
  padding-bottom: calc(max(12px, env(safe-area-inset-bottom)) + 14px);
  background: var(--card);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border);
}

.input-area input[type="text"] {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: 24px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.input-area .icon-btn {
  color: var(--text-muted);
  width: 44px;
  height: 44px;
}

.input-area .send-btn {
  background: var(--primary);
  color: white;
}

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

.empty-chat svg {
  width: 80px;
  height: 80px;
  margin-bottom: 20px;
  opacity: 0.4;
}

/* Theme Toggle */
.theme-toggle {
  background: transparent;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: var(--card);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}

.modal h3 {
  margin-bottom: 20px;
  font-size: 18px;
}

/* Call UI */
.call-overlay {
  position: fixed;
  inset: 0;
  background: #0f172a;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
}

.call-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  margin-bottom: 20px;
}

.call-status {
  font-size: 16px;
  opacity: 0.8;
  margin-bottom: 40px;
}

.call-actions {
  display: flex;
  gap: 30px;
}

.call-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-btn.accept {
  background: #10b981;
  color: white;
}

.call-btn.reject, .call-btn.end {
  background: #ef4444;
  color: white;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: absolute;
    z-index: 10;
    height: 100%;
  }
  .sidebar.hidden-mobile {
    display: none;
  }
  .chat-area {
    width: 100%;
  }
  .back-btn { display: flex; }
  .message { max-width: 85%; }
  .chat-area.hidden-mobile {
    display: none;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
