:root {
  color-scheme: light;
  --primary: #07c160;
  --primary-dark: #06ad56;
  --bg: #ededed;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #8e8e93;
  --danger: #fa5151;
  --border: #e5e5e5;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --msg-bg: #ffffff;
  --msg-self-bg: #95ec69;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

#app {
  min-height: 100vh;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 8px;
  padding: 40px 30px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.admin-page {
  align-items: flex-start;
  padding-top: 20px;
}

.admin-card {
  width: min(1000px, 100%);
  background: var(--surface);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.admin-search-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.admin-search-row input {
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-size: 14px;
  width: 200px;
}

.admin-users {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #fafafa;
}

.admin-meta {
  flex: 1;
}

.admin-actions-inline {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 8px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.brand-logo {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  background: linear-gradient(135deg, #07c160, #06ad56);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 32px;
}

.brand h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  color: var(--muted);
  font-size: 14px;
}

.field input {
  padding: 12px 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-size: 16px;
  background: #fff;
  outline: none;
  transition: border-color 0.2s;
}

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

.primary-btn,
.ghost-btn,
.danger-btn {
  padding: 12px 24px;
  border-radius: 4px;
  border: none;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.primary-btn:hover,
.ghost-btn:hover,
.danger-btn:hover {
  opacity: 0.9;
}

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

.primary-btn:disabled {
  background: #b8e8c9;
  cursor: not-allowed;
}

.ghost-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  font-size: 14px;
}

.danger-btn {
  background: var(--danger);
  color: #fff;
  padding: 8px 16px;
  font-size: 14px;
}

.login-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
  background: var(--bg);
}

.side-nav {
  background: #f7f7f7;
  border-right: 1px solid var(--border);
  padding: 12px 0;
  display: none;
  flex-direction: column;
  gap: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text);
  transition: background 0.2s;
}

.nav-item:hover {
  background: #e9e9e9;
}

.nav-item.active {
  background: #e9e9e9;
  font-weight: 500;
}

.main-content {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

.top-bar {
  padding: 0 20px;
  height: 44px;
  background: #f7f7f7;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.top-bar strong {
  font-size: 17px;
  font-weight: 600;
}

.tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.bottom-nav {
  position: sticky;
  bottom: 0;
  display: flex;
  background: #f7f7f7;
  border-top: 1px solid var(--border);
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  z-index: 100;
}

.bottom-nav .nav-item {
  flex: 1;
  justify-content: center;
  padding: 8px 0;
  font-size: 10px;
  flex-direction: column;
  gap: 4px;
}

.bottom-nav .nav-item::before {
  content: "";
  width: 24px;
  height: 24px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.bottom-nav .nav-item[data-tab="messages"]::before {
  content: "💬";
  font-size: 20px;
}

.bottom-nav .nav-item[data-tab="contacts"]::before {
  content: "👥";
  font-size: 20px;
}

.bottom-nav .nav-item[data-tab="me"]::before {
  content: "👤";
  font-size: 20px;
}

.messages-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  flex: 1;
  min-height: 0;
  background: var(--bg);
}

.panel {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.thread-item:hover {
  background: #f5f5f5;
}

.thread-item.active {
  background: #e9e9e9;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 500;
  color: #fff;
  flex-shrink: 0;
  font-size: 18px;
}

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

.thread-meta h4 {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 500;
}

.thread-meta p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  display: grid;
  place-items: center;
  padding: 0 5px;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: #ededed;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 44px;
  background: #f7f7f7;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  min-height: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23c9c9c9' fill-opacity='0.1'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z'/%3E%3C/g%3E%3C/svg%3E");
}

.msg {
  max-width: 70%;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1.5;
  background: var(--msg-bg);
  position: relative;
  word-wrap: break-word;
  word-break: break-word;
}

.msg::before {
  content: "";
  position: absolute;
  top: 12px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

.msg:not(.self)::before {
  left: -8px;
  border-right: 8px solid var(--msg-bg);
}

.msg.self {
  align-self: flex-end;
  background: var(--msg-self-bg);
}

.msg.self::before {
  right: -8px;
  border-left: 8px solid var(--msg-self-bg);
}

.msg img {
  max-width: 200px;
  border-radius: 4px;
  display: block;
}

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

.chat-input {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 12px;
  background: #f7f7f7;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input textarea {
  resize: none;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex: 1;
  font-size: 16px;
  line-height: 1.4;
  max-height: 100px;
  outline: none;
  min-height: 36px;
}

.chat-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.emoji-panel {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px;
  background: #f7f7f7;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 150px;
  overflow-y: auto;
}

.emoji-item {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  background: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 24px;
}

.emoji-item:hover {
  background: #e5e5e5;
}

.emoji-item img {
  width: 28px;
  height: 28px;
}

.contacts-list {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex: 1;
}

.contact-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.contact-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.profile-card {
  background: var(--surface);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1;
  overflow-y: auto;
}

.profile-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  background: var(--primary);
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 500;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}

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

.profile-section {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px;
}

.profile-section-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.profile-btn-row {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.modal.active {
  display: flex;
}

.modal-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: min(300px, 90%);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .admin-card {
    padding: 16px;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-search-row input {
    width: 100%;
  }

  .side-nav {
    display: none;
  }

  .bottom-nav {
    display: flex;
  }

  .messages-layout {
    grid-template-columns: 1fr;
  }

  .desktop-only {
    display: none;
  }

  .mobile-only {
    display: block;
  }

  .login-card {
    padding: 30px 20px;
  }

  .brand-logo {
    width: 64px;
    height: 64px;
    font-size: 28px;
  }

  .msg {
    max-width: 80%;
  }

  .msg img {
    max-width: 180px;
  }
}

@media (min-width: 901px) {
  .side-nav {
    display: flex;
  }

  .bottom-nav {
    display: none;
  }

  .panel:first-child {
    border-right: 1px solid var(--border);
  }
}
