:root {
  --primary: #c75d4d;
  --primary-hover: #b34a3a;
  --primary-light: #fef4f1;
  --accent-sage: #52796f;
  --accent-amber: #d97706;
  --bg-app: #f8f6f2;
  --bg-surface: #ffffff;
  --border-subtle: #eae5dc;
  --border-focus: #c75d4d;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --danger: #ef4444;
  --success: #10b981;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 6px rgba(40, 30, 20, 0.04);
  --shadow-md: 0 8px 24px rgba(40, 30, 20, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Apple SD Gothic Neo", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* App Header */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  flex-shrink: 0;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), #e07a5f);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 1.1rem;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.3px;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
}

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

.lang-select {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  font-size: 0.85rem;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-light);
  border: 1px solid rgba(199, 93, 77, 0.2);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
}

/* Main Layout */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Sidebar Navigation */
.app-sidebar {
  width: 220px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 4px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary);
  color: #ffffff;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.nav-spacer {
  flex: 1;
}

/* Main Content Area */
.main-content {
  flex: 1;
  overflow-y: auto;
  position: relative;
  background: var(--bg-app);
}

.view-page {
  display: none;
  height: 100%;
  padding: 24px;
  overflow-y: auto;
}

.view-page.active {
  display: block;
}

/* Auth View */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 20px;
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  padding: 32px;
}

.auth-card h2 {
  font-size: 1.4rem;
  color: var(--primary);
  margin-bottom: 8px;
}

.auth-card p.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

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

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

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  background: #faf9f6;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-control:focus {
  border-color: var(--border-focus);
  background: #ffffff;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
  margin-top: 8px;
}

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

.auth-toggle {
  text-align: center;
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-toggle a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

/* Home View */
.welcome-hero {
  background: linear-gradient(135deg, #ffffff 0%, var(--primary-light) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.welcome-hero h1 {
  font-size: 1.6rem;
  color: var(--primary);
  margin-bottom: 8px;
}

.id-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  padding: 4px 12px;
  border-radius: 14px;
  font-family: monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 8px;
}

.quick-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.quick-tile {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.quick-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--primary);
}

.quick-tile h3 {
  font-size: 1.05rem;
  color: var(--text-main);
  margin-bottom: 6px;
}

.quick-tile p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Chats View (Split Pane) */
.chats-layout {
  display: flex;
  height: calc(100vh - 110px);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.conversations-sidebar {
  width: 320px;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  background: #fdfcfb;
}

.conv-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 700;
  font-size: 1.1rem;
}

.conv-list {
  flex: 1;
  overflow-y: auto;
}

.conv-item {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid #f1ece4;
  transition: background 0.15s ease;
}

.conv-item:hover {
  background: var(--primary-light);
}

.conv-item.active {
  background: #fbf0ec;
  border-left: 4px solid var(--primary);
}

.avatar-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #e2d9cd;
  color: var(--text-main);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

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

.conv-info-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.conv-name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 0.72rem;
  color: var(--text-light);
}

.conv-last-msg {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}

/* Chat Main Pane */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #faf8f5;
}

.chat-header {
  padding: 14px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.message-row {
  display: flex;
  flex-direction: column;
  max-width: 70%;
}

.message-row.outgoing {
  align-self: flex-end;
  align-items: flex-end;
}

.message-row.incoming {
  align-self: flex-start;
  align-items: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.92rem;
  position: relative;
  word-break: break-word;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.message-row.outgoing .message-bubble {
  background: var(--primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.message-row.incoming .message-bubble {
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
}

.message-meta {
  font-size: 0.68rem;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-light);
}

.message-meta .status-badge {
  font-weight: 600;
}

.message-actions {
  display: inline-flex;
  gap: 6px;
  margin-left: 8px;
}

.btn-action-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.72rem;
  cursor: pointer;
  text-decoration: underline;
}

.message-row.recalled-msg .message-bubble {
  background: #f1ece5;
  color: var(--text-light);
  font-style: italic;
  border: 1px dashed var(--border-subtle);
}

/* Chat Input Bar */
.chat-input-bar {
  padding: 14px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 10px;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border-subtle);
  border-radius: 24px;
  outline: none;
  font-size: 0.92rem;
}

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

.btn-send {
  padding: 0 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 24px;
  font-weight: 600;
  cursor: pointer;
}

/* Directory / People View */
.people-container {
  max-width: 800px;
  margin: 0 auto;
}

.search-box {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.member-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.member-card h4 {
  font-size: 1rem;
  margin-top: 10px;
}

.member-card .uid {
  font-size: 0.78rem;
  font-family: monospace;
  color: var(--text-light);
  margin-bottom: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  box-shadow: var(--shadow-md);
  display: none;
  z-index: 1000;
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--success);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .app-sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60px;
    flex-direction: row;
    padding: 0;
    border-top: 1px solid var(--border-subtle);
    border-right: none;
    z-index: 200;
    background: var(--bg-surface);
  }
  
  .nav-item {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    font-size: 0.65rem;
    padding: 6px 0;
    border-radius: 0;
    margin: 0;
    text-align: center;
  }
  
  .nav-item svg {
    width: 18px;
    height: 18px;
  }
  
  .view-page {
    padding: 14px;
    padding-bottom: 74px;
  }
  
  .chats-layout {
    flex-direction: column;
    height: calc(100vh - 140px);
  }
  
  .conversations-sidebar {
    width: 100%;
    height: 100%;
  }
  
  .chat-window {
    display: none;
    width: 100%;
    height: 100%;
  }
  
  .chat-window.mobile-active {
    display: flex;
  }
  
  .conversations-sidebar.mobile-hidden {
    display: none;
  }
}
