:root {
  --bg: #efeae2;
  --panel: #f7f5ee;
  --header: #0f5f54;
  --ink: #17212b;
  --muted: #6b7785;
  --outgoing: #d9fdd3;
  --incoming: #ffffff;
  --accent: #128c7e;
  --line: #d8d4c9;
  --bubble-shadow: 0 2px 6px rgba(18, 39, 56, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Poppins, "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(18, 140, 126, 0.12), transparent 40%),
    radial-gradient(circle at bottom left, rgba(31, 97, 141, 0.1), transparent 36%),
    var(--bg);
  min-height: 100vh;
}

.app-shell {
  width: min(940px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 44px);
}

.hero p {
  margin-top: 8px;
  color: var(--muted);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 16px 0;
}

.action-card {
  border: none;
  border-radius: 16px;
  min-height: 78px;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
}

.action-card.create {
  background: linear-gradient(120deg, #128c7e, #1aa88f);
  color: #fff;
}

.action-card.join {
  background: linear-gradient(120deg, #1f618d, #328fca);
  color: #fff;
}

.panel {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.panel h2 {
  margin: 0 0 8px;
}

.panel p {
  margin: 0 0 10px;
  color: var(--muted);
}

input,
button {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  font: inherit;
}

input {
  background: #fff;
  width: 100%;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 10px;
}

button {
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}

button.ghost {
  background: #fff;
}

button.small {
  padding: 8px 12px;
}

.qr-box {
  min-height: 220px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 2px dashed var(--line);
  border-radius: 12px;
}

.reader {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 16px 16px 0 0;
  background: var(--header);
  color: #fff;
  padding: 14px;
}

.chat-header h2 {
  margin: 0;
  font-size: 19px;
}

.chat-header p {
  margin: 4px 0 0;
  font-size: 13px;
  opacity: 0.9;
}

.chat-messages {
  min-height: 55vh;
  max-height: 60vh;
  overflow-y: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-top: none;
  background:
    linear-gradient(rgba(239, 234, 226, 0.9), rgba(239, 234, 226, 0.9)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cpath fill='%23d9d4c9' fill-opacity='.35' d='M17 19h5v5h-5zm0 24h5v5h-5zm0 24h5v5h-5zm0 24h5v5h-5zM41 19h5v5h-5zm0 24h5v5h-5zm0 24h5v5h-5zm0 24h5v5h-5zM65 19h5v5h-5zm0 24h5v5h-5zm0 24h5v5h-5zm0 24h5v5h-5zM89 19h5v5h-5zm0 24h5v5h-5zm0 24h5v5h-5zm0 24h5v5h-5z'/%3E%3C/g%3E%3C/svg%3E");
}

.msg {
  max-width: min(78%, 420px);
  padding: 10px 12px;
  border-radius: 11px;
  margin-bottom: 10px;
  box-shadow: var(--bubble-shadow);
  overflow-wrap: anywhere;
}

.msg.in {
  background: var(--incoming);
  margin-right: auto;
  border-top-left-radius: 4px;
}

.msg.out {
  background: var(--outgoing);
  margin-left: auto;
  border-top-right-radius: 4px;
}

.msg.system {
  margin: 8px auto;
  text-align: center;
  background: #fff8cf;
  border: 1px solid #eee08a;
  border-radius: 999px;
  box-shadow: none;
  width: fit-content;
  font-size: 12px;
  color: #6f6323;
}

.msg-media-frame {
  width: min(280px, 100%);
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: #e0ddd3;
}

.msg-media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.msg-media-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: #59636f;
  font-size: 13px;
  background: #e4e1d6;
}

.msg a {
  color: #0e6b97;
  font-weight: 600;
  text-decoration: none;
}

.msg-text {
  white-space: pre-wrap;
}

.msg-text a {
  text-decoration: underline;
  word-break: break-word;
}

.msg-caption {
  margin-top: 6px;
  font-size: 12px;
}

.msg-transfer-status {
  margin-top: 4px;
  font-size: 12px;
  color: #5b6875;
}

.msg-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

.msg-mini-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid #a8cbbf;
  background: #f7fff8;
  color: #0d6a57;
  display: grid;
  place-items: center;
}

.msg-mini-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.msg-mini-btn svg {
  width: 15px;
  height: 15px;
  pointer-events: none;
}

.chat-composer {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 16px 16px;
  padding: 10px;
  background: #f3f0e7;
}

.hidden {
  display: none !important;
}

.media-viewer {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.94);
  z-index: 50;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 12px;
}

.viewer-content {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.viewer-content img,
.viewer-content video {
  max-width: 95vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 10px;
  background: #000;
}

.viewer-close,
.viewer-download {
  justify-self: end;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.viewer-download {
  justify-self: center;
}

.hold-menu {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.45);
  z-index: 60;
  display: grid;
  place-items: end center;
  padding: 14px;
}

.hold-card {
  width: min(360px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
  }

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

  .chat-messages {
    min-height: 62vh;
    max-height: 62vh;
  }

  .chat-composer {
    grid-template-columns: 1fr auto;
  }

  #attachBtn {
    grid-column: 1;
  }
}
