:root {
  --bg: #111111;
  --header-bg: #1a1a1a;
  --text-main: #f0f0f0;
  --text-muted: #9a9a9a;
  --self-bubble: #2d7f57;
  --other-bubble: #242424;
  --border: #2f2f2f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text-main);
}

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 540px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-title h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.chat-title p {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.clear-btn {
  border: 1px solid #414141;
  border-radius: 6px;
  padding: 6px 10px;
  background: #232323;
  color: #e0e0e0;
  font-size: 13px;
}

.call-btn {
  border: none;
  border-radius: 6px;
  padding: 7px 11px;
  background: #07c160;
  color: #fff;
  font-size: 13px;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  -webkit-overflow-scrolling: touch;
}

.message-row {
  display: flex;
  margin-bottom: 14px;
}

.message-row.self {
  justify-content: flex-end;
}

.message-row.other {
  justify-content: flex-start;
}

.message-wrap {
  max-width: 82%;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.message-row.self .message-meta {
  justify-content: flex-end;
}

.avatar-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bubble {
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-row.self .bubble {
  background: var(--self-bubble);
}

.message-row.other .bubble {
  background: var(--other-bubble);
}

.bubble.media-bubble {
  padding: 8px;
}

.bubble-media {
  display: block;
  width: 100%;
  max-width: 260px;
  border-radius: 8px;
  background: #000;
}

.media-fallback {
  color: #d6d6d6;
  text-decoration: underline;
}

.chat-input-area {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 10px calc(env(safe-area-inset-bottom, 0px) + 10px);
  border-top: 1px solid var(--border);
  background: var(--header-bg);
}

.media-picker {
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 8px 10px;
  background: #202020;
  color: #d8d8d8;
  font-size: 13px;
  cursor: pointer;
}

#mediaInput {
  display: none;
}

.chat-input-area input {
  flex: 1;
  min-width: 180px;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
  background: #202020;
  color: #efefef;
}

.chat-input-area input:focus {
  border-color: #07c160;
}

.chat-input-area button {
  border: none;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 15px;
  color: #fff;
  background: #07c160;
}

.chat-input-area button:active {
  transform: scale(0.98);
}

.placeholder {
  margin-top: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.hidden {
  display: none !important;
}

.modal-body {
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #1b1b1b;
  padding: 14px;
}

.modal-body h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.user-list {
  max-height: 280px;
  overflow: auto;
  margin-bottom: 12px;
}

.user-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #373737;
  background: #232323;
  color: #e9e9e9;
  border-radius: 8px;
  padding: 9px 10px;
  margin-bottom: 8px;
  text-align: left;
}

.user-item[disabled] {
  opacity: 0.45;
}

.secondary-btn {
  border: 1px solid #454545;
  border-radius: 6px;
  padding: 8px 12px;
  background: #232323;
  color: #e5e5e5;
}

.incoming-text {
  margin: 0 0 12px;
  color: #d7d7d7;
}

.incoming-actions {
  display: flex;
  gap: 10px;
}

.call-accept-btn,
.call-reject-btn {
  border: none;
  border-radius: 6px;
  padding: 9px 14px;
  color: #fff;
}

.call-accept-btn {
  background: #07c160;
}

.call-reject-btn {
  background: #fa5151;
}

.call-panel {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(540px, calc(100% - 16px));
  z-index: 15;
  border: 1px solid #333;
  border-radius: 12px;
  background: #141414;
  padding: 10px;
}

.call-panel-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  color: #ddd;
  font-size: 13px;
}

.video-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.video-grid video {
  width: 100%;
  height: 145px;
  border-radius: 8px;
  object-fit: cover;
  background: #000;
}

.hangup-btn {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 10px 0;
  background: #fa5151;
  color: #fff;
}
