* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-theme-bg-color, #17212b);
  color: var(--tg-theme-text-color, #ffffff);
}

.hidden { display: none !important; }

.screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.center-card {
  margin: auto;
  width: min(420px, 90vw);
  text-align: center;
  padding: 24px;
}

.center-card h1 { font-size: 22px; margin-bottom: 8px; }

.muted {
  color: var(--tg-theme-hint-color, #708499);
  font-size: 14px;
  margin: 8px 0 16px;
}

input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 10px;
  border: 1px solid var(--tg-theme-hint-color, #708499);
  background: var(--tg-theme-secondary-bg-color, #232e3c);
  color: var(--tg-theme-text-color, #ffffff);
  font-size: 16px;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--tg-theme-button-color, #5288c1);
  color: var(--tg-theme-button-text-color, #ffffff);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:active { opacity: 0.8; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(127, 127, 127, 0.2);
  flex-shrink: 0;
}

.topbar h1 { font-size: 18px; margin: 0; flex: 1; }

.new-dialog-form {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(127, 127, 127, 0.2);
}
.new-dialog-form input { margin-bottom: 0; flex: 1; }
.new-dialog-form .btn-primary { width: auto; white-space: nowrap; }

.icon-btn {
  background: none;
  border: none;
  color: var(--tg-theme-link-color, #6ab3f3);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.dialogs-list, .messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.dialog-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(127, 127, 127, 0.08);
}

.dialog-row:active { background: rgba(127, 127, 127, 0.1); }

.dialog-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--tg-theme-secondary-bg-color, #232e3c);
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
}

.dialog-info { flex: 1; min-width: 0; }
.dialog-title { font-weight: 600; font-size: 15px; }
.dialog-title.muted-icon::before { content: "🔕 "; }

.unread-badge {
  background: var(--tg-theme-button-color, #5288c1);
  color: var(--tg-theme-button-text-color, #fff);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
}

.messages-list { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }

.msg-row {
  max-width: 80%;
  align-self: flex-start;
  background: var(--tg-theme-secondary-bg-color, #232e3c);
  border-radius: 12px;
  padding: 8px 12px;
}

.msg-sender { font-size: 13px; font-weight: 600; color: var(--tg-theme-link-color, #6ab3f3); margin-bottom: 2px; }
.msg-sender-clickable { cursor: pointer; text-decoration: underline; }
.msg-text { font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.msg-attachment img, .msg-attachment video { max-width: 100%; border-radius: 8px; margin-top: 6px; }
.msg-poll { border-left: 3px solid var(--tg-theme-button-color, #5288c1); padding-left: 8px; margin-top: 4px; }

.msg-file {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(127, 127, 127, 0.12);
  text-decoration: none;
  color: inherit;
}
.msg-file-icon { font-size: 22px; }
.msg-file-name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file-action { font-size: 12px; color: var(--tg-theme-link-color, #6ab3f3); font-weight: 600; }

.msg-row { position: relative; }
.reaction-picker {
  position: absolute;
  top: -38px;
  left: 0;
  display: flex;
  gap: 4px;
  background: var(--tg-theme-secondary-bg-color, #232e3c);
  border-radius: 20px;
  padding: 6px 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 10;
}
.reaction-option { font-size: 20px; cursor: pointer; padding: 0 2px; }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(127, 127, 127, 0.2);
  flex-shrink: 0;
}

.composer input { margin-bottom: 0; flex: 1; }
