* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111;
  color: #eee;
}

.login-wrap,
.chat-wrap {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.login-wrap {
  min-height: 100svh;
  display: grid;
  place-items: center;
}

.card {
  width: 100%;
  background: #1b1b1b;
  border: 1px solid #333;
  border-radius: 18px;
  padding: 18px;
}

h1 {
  margin: 0;
  font-size: 28px;
}

.muted {
  color: #aaa;
  margin-top: 6px;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: #ccc;
}

input {
  width: 100%;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 12px;
  background: #111;
  color: #eee;
  font-size: 16px;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  background: #eee;
  color: #111;
  font-weight: 700;
  cursor: pointer;
}

button.secondary {
  background: #2a2a2a;
  color: #eee;
  border: 1px solid #444;
}

.error {
  color: #ff8a8a;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
}

/*** MESSAGES ***/
.messages {
  height: calc(100svh - 170px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 0 14px;
  scroll-behavior: smooth;
}

.empty {
  margin: auto;
  color: #888;
  text-align: center;
}

.date-separator {
  align-self: center;
  margin: 10px 0;
  padding: 5px 10px;
  border-radius: 999px;
  background: #222;
  color: #aaa;
  font-size: 12px;
}

.message {
  display: flex;
}

.message {
  touch-action: manipulation;
}

.quoted-reply {
  cursor: pointer;
}

.message-highlight .bubble {
  outline: 2px solid #aaa;
  outline-offset: 3px;
}

.message.mine {
  justify-content: flex-end;
}

.message.theirs {
  justify-content: flex-start;
}

.bubble {
  max-width: min(82%, 520px);
  border: 1px solid #333;
  border-radius: 18px;
  padding: 10px 12px;
  background: #1b1b1b;
}

.message.mine .bubble {
  background: #eaeaea;
  color: #111;
  border-color: #eaeaea;
}

.body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.35;
}

.meta {
  margin-top: 5px;
  font-size: 12px;
  opacity: 0.65;
}

.composer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding-top: 10px;
  background: #111;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.typing-indicator {
  min-height: 22px;
  padding: 0 4px 8px;
  color: #aaa;
  font-size: 14px;
  font-style: italic;
}

.reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #333;
  border-left: 4px solid #eee;
  background: #1b1b1b;
  border-radius: 14px;
  padding: 8px 10px;
  margin-bottom: 8px;
}

.reply-bar[hidden] {
  display: none !important;
}

.reply-bar > div {
  min-width: 0;
}

.reply-name {
  font-size: 13px;
  font-weight: 700;
  color: #eee;
}

.reply-text {
  margin-top: 2px;
  color: #aaa;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.reply-cancel {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 50%;
}

.quoted-reply {
  border-left: 3px solid currentColor;
  opacity: 0.72;
  padding-left: 8px;
  margin-bottom: 7px;
}

.quoted-name {
  font-size: 12px;
  font-weight: 700;
}

.quoted-text {
  font-size: 12px;
  overflow-wrap: anywhere;
}

.composer textarea {
  border: 1px solid #444;
  border-radius: 12px;
  padding: 12px;
  background: #111;
  color: #eee;
  font-size: 16px;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  overflow-y: auto;
  font: inherit;
  line-height: 1.35;
}

.message-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
}

.message-modal.is-open {
  pointer-events: auto;
}

.message-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.message-modal.is-open .message-modal-backdrop {
  opacity: 1;
}

.message-modal-content {
  position: absolute;
  right: 12px;
  bottom: 12px;

  width: min(180px, calc(50vw - 12px));

  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 22px;

  padding: 12px;

  display: flex;
  flex-direction: column;
  gap: 8px;

  z-index: 10000;

  transform: translateY(120%);
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

.message-modal.is-open .message-modal-content {
  transform: translateY(0);
}

.modal-btn {
  min-height: 36px;
  border-radius: 10px;
  font-size: 13px;
  padding: 8px 10px;
  letter-spacing: 1px;
}

.modal-btn-reply {
  background: #333333;
  color: #F5F5F5;
}

.modal-btn-cancel {
  background: #333333;
  color: #C0C0C0;
}

.modal-btn-edit {
  background: #333333;
  color: #F5F5F5;
}

.modal-btn-delete {
  background: #333333;
  color: #dc3545;
}

.deleted-message {
  color: #777;
  font-style: italic;
}

.message {
  touch-action: pan-y;
  will-change: transform;
}

.dashboard-conversation-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;

  text-align: left;

  background: #161616;
  border: 1px solid #2b2b2b;
  border-radius: 28px;

  padding: 20px 22px;
  color: #eee;
}

.dashboard-conversation-item > div:first-child {
  flex: 1;
  min-width: 0;
}

.dashboard-conversation-item strong {
  display: block;
  font-size: 20px;
  margin-bottom: 8px;
}

.dashboard-conversation-item span {
  display: block;
  color: #9a9a9a;
  font-size: 12px;
}

.conversation-side {
  flex: 0 0 120px;
  display: grid;
  grid-template-rows: auto auto;
  justify-items: end;
  align-self: stretch;
}

.conversation-side-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.conversation-side time {
  color: #777;
  font-size: 12px;
  white-space: nowrap;
}

.conversation-menu-btn {
  align-self: end;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #999;
  font-size: 24px;
  line-height: 1;
}

/*.conversation-side {
  display: grid;
  justify-items: end;
  gap: 6px;
  flex: 0 0 auto;
}*/


/* .conversation-menu-btn {
  width: 34px;
  height: 34px;
  padding: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  border: none;
  border-radius: 50%;

  background: transparent;
  color: #999;

  font-size: 22px;
  line-height: 1;

  cursor: pointer;
} */

.conversation-menu-btn:active {
  background: #2a2a2a;
}

.dashboard-conversation-item time {
  color: #777;
  font-size: 12px;
  white-space: nowrap;
}

.dashboard-create {
  background: #1b1b1b;
  border: 1px solid #333;
  border-radius: 18px;
  padding: 14px;
}

/* === FIX: message action sheet === */

.message-modal-content.actions {
  right: 12px;
  bottom: 12px;
  width: min(260px, calc(100vw - 24px));
}

#messageActionsView,
#conversationActionsView {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#messageActionsView[hidden],
#messageEditView[hidden],
#messageDeleteView[hidden] {
  display: none !important;
}

.message-modal-content.editor {
  left: 12px;
  right: 12px;
  bottom: 12px;
  width: auto;
}

/* === FIX: conversations/dashboard spacing === */

.conversation-list {
  display: grid;
  gap: 10px;
}

.new-conversation-btn {
  width: 100%;
  margin-bottom: 12px;
}

.conversation-input {
  position: static !important;
  width: 100%;
  display: block;
  margin-bottom: 10px;

  border: 1px solid #444;
  border-radius: 12px;
  padding: 12px;

  background: #111;
  color: #eee;
  font-size: 16px;
}

/* === Future-proof old conversation modal if still present anywhere === */

.conversation-modal {
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
}

.conversation-modal.is-open {
  pointer-events: auto;
}

.conversation-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.35s ease;
}

.conversation-modal.is-open .conversation-modal-backdrop {
  opacity: 1;
}

.conversation-modal-content {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;

  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 22px;
  padding: 12px;

  transform: translateY(-120%);
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.conversation-modal.is-open .conversation-modal-content {
  transform: translateY(0);
}

.conversation-title-btn {
  padding: 0;
  border: 0;
  background: transparent;
  color: #eee;
  font: inherit;
  font-size: 28px;
  font-weight: 800;
  text-align: left;
}
/* === FINAL LAYOUT FIXES === */

html,
body {
  height: 100%;
}

body {
  overflow: hidden;
}

.login-wrap,
.chat-wrap {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 18px;
}

/* Chat page: no vertical page wiggle, only messages scroll */
.chat-wrap {
  height: 100svh;
  max-height: 100svh;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  height: auto !important;
  min-height: 0;
  overflow-y: auto;
}

/* Header title should not look like a white button */
.conversation-title-btn {
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  color: #eee !important;
  font-size: 28px;
  font-weight: 800;
  text-align: left;
}

/* Message action sheet */
.message-modal-content {
  transform: translateY(calc(100% + 80px));
}

.message-modal-content.actions {
  left: auto;
  right: 12px;
  bottom: 20px;
  width: min(440px, calc(100vw - 24px));
}

.message-modal-content.editor {
  left: 12px;
  right: 12px;
  bottom: 20px;
  width: auto;
}

#messageActionsView,
#conversationActionsView {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#messageActionsView[hidden],
#messageEditView[hidden],
#messageDeleteView[hidden] {
  display: none !important;
}

#messageEditView,
#messageDeleteView {
  width: 100%;
}

.modal-edit-textarea {
  width: 100%;
  min-height: 130px;
  max-height: 260px;
  resize: none;
  display: block;
  background: #111;
  color: #eee;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  font: inherit;
  line-height: 1.4;
}

/* Dashboard must scroll normally */
body:has(.dashboard-create),
body:has(.dashboard-conversation-item) {
  overflow-y: auto;
}

body:has(.dashboard-create) .chat-wrap,
body:has(.dashboard-conversation-item) .chat-wrap {
  height: auto;
  max-height: none;
  min-height: 100svh;
  display: block;
}

/* Dashboard create form should not stick */
.dashboard-create {
  position: static;
  margin-top: 12px;
}

.conversation-input {
  position: static !important;
  display: block;
  width: 100%;
  margin-bottom: 10px;
}

.create-conversation-modal {
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
}

.create-conversation-modal.is-open {
  pointer-events: auto;
}

.create-conversation-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.35s ease;
}

.create-conversation-modal.is-open .create-conversation-backdrop {
  opacity: 1;
}

.create-conversation-content {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;

  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 22px;
  padding: 14px;

  transform: translateY(-120%);
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.create-conversation-modal.is-open .create-conversation-content {
  transform: translateY(0);
}

.dashboard-wrap {
  height: auto;
  max-height: none;
  min-height: 100svh;
  display: block;
}

.create-conversation-content .conversation-input {
  position: static !important;
  display: block;
  width: 100%;
  margin-bottom: 10px;
}

/* === FINAL MODAL LAYOUT === */

/* Conversations: create modal slides from bottom */
.create-conversation-content {
  top: auto;
  bottom: 20px;
  transform: translateY(calc(100% + 80px));
}

.create-conversation-modal.is-open .create-conversation-content {
  transform: translateY(0);
}

.conversation-modal-title,
.modal-delete-text {
  margin-bottom: 12px;
}

/* Shared modal action rows */
.modal-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.modal-edit-actions .modal-btn {
  flex: 0 0 auto;
  min-width: 110px;
}

/* Chat action sheet: one column */
.message-modal-content.actions {
  right: 12px;
  bottom: 20px;
  width: min(260px, calc(100vw - 24px));
}

#messageActionsView,
#conversationActionsView {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

/* Delete view: normal text spacing */
.modal-delete-text {
  text-align: left;
  padding: 4px 2px 0;
  font-size: 16px;
  color: #eee;
}

/* Edit modal textarea clean full width */
.modal-edit-textarea {
  width: 100%;
  min-height: 130px;
  max-height: 260px;
  resize: none;
  display: block;
  background: #111;
  color: #eee;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  line-height: 1.4;
}

/* Inputs inside create modal */
.create-conversation-content .conversation-input {
  margin-bottom: 10px;
}

.new-conversation-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;

  width: 58px;
  height: 58px;
  border-radius: 50%;

  padding: 0;
  font-size: 32px;
  line-height: 1;
}

.dashboard-wrap {
  padding-bottom: 96px;
}

.chat-topbar {
  justify-content: flex-start;
}

.back-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 34px;
  line-height: 1;
  background: #111111;
  color: #eee;
}

.chat-title-block {
  min-width: 0;
}

.chat-title {
  font-size: 22px;
  font-weight: 800;
}

.chat-subtitle {
  color: #aaa;
  font-size: 14px;
  margin-top: 2px;
}

#conversationActionsView,
#conversationRenameView,
#conversationAddMemberView,
#conversationLeaveView {
  width: 100%;
}

#conversationActionsView[hidden],
#conversationRenameView[hidden],
#conversationAddMemberView[hidden],
#conversationLeaveView[hidden] {
  display: none !important;
}

.unread-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;

  display: inline-grid;
  place-items: center;

  border-radius: 999px;
  background: #eee;
  color: #111;

  font-size: 12px;
  font-weight: 800;
}

* {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

