:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #25d366;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --border: #e0e2e7;
    --text: #1a1d24;
    --muted: #5b6270;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.screen.login-box-parent { display: flex; }

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  text-align: center;
}

.login-box input {
  width: 100%;
  padding: 10px;
  margin: 12px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.login-box button, header button, section button {
  background: var(--accent);
  color: #06210f;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}

.error { color: #ff6b6b; min-height: 1.2em; font-size: 0.9em; }

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 1.1rem; margin: 0; flex: 1; }

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 24px 0;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  padding: 10px 16px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--text);
  border-bottom: 2px solid var(--accent);
}

.tab-panel { padding: 24px; max-width: 900px; margin: 0 auto; }

.row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.row input, .row select, textarea {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

textarea { min-height: 80px; width: 100%; font-family: inherit; }

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

.table th, .table td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }

.msg {
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 70%;
  font-size: 0.9rem;
}

.msg.in { background: var(--panel); border: 1px solid var(--border); align-self: flex-start; }
.msg.out { background: var(--accent); color: #06210f; align-self: flex-end; }
.msg .meta { font-size: 0.75rem; opacity: 0.7; margin-top: 4px; }

.split { display: flex; gap: 32px; }
.split > div { flex: 1; }

.simple-list { list-style: none; padding: 0; margin: 0; }
.simple-list li {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}
.simple-list li.selected { background: var(--panel); }

#qr-wrap { margin: 16px 0; }
#qr-img { max-width: 260px; border-radius: 8px; border: 1px solid var(--border); }
.hint { color: var(--muted); font-size: 0.9rem; }

.broadcast-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar > div {
  height: 100%;
  background: var(--accent);
}

/* ---- Inbox (chat list + thread) ---- */

.tab-panel.tab-inbox { max-width: none; padding: 0; height: calc(100vh - 105px); }

.inbox-layout {
  display: flex;
  height: 100%;
  border-top: 1px solid var(--border);
}

.chat-list-pane {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-list-header h2 { margin: 0; font-size: 1rem; }

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

.chat-list-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.chat-list-item:hover { background: var(--panel); }
.chat-list-item.selected { background: var(--panel); }

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--muted);
}

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

.chat-list-item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

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

.chat-list-item-time { font-size: 0.72rem; color: var(--muted); flex-shrink: 0; }

.chat-list-item-preview {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.unread-badge {
  background: var(--accent);
  color: #06210f;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 7px;
  flex-shrink: 0;
}

.chat-thread-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.thread-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.thread-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.thread-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

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

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--text);
}

.icon-btn:hover { background: var(--panel); }
.icon-btn.active { background: var(--accent); }

.thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thread-compose { padding: 12px 20px; margin: 0; border-top: 1px solid var(--border); }

.msg.deleted { opacity: 0.6; font-style: italic; }

.msg .quoted-ref {
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 0.8rem;
  opacity: 0.8;
  border-radius: 4px;
  background: rgba(0,0,0,0.08);
}

.msg .ack { margin-left: 6px; font-size: 0.8rem; }
.msg .ack.read { color: #34b7f1; }

.msg img.media, .msg video.media {
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
  display: block;
  margin-bottom: 4px;
}

.msg .media-file {
  display: block;
  margin-bottom: 4px;
}

.quoted-reply-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  font-size: 0.85rem;
}
