/* -------------------------------------------------------------------------- */
/* Chat (chat.mcking.site)                                                    */
/*                                                                            */
/* Loads projects.css first for tokens, topbar, buttons and dialogs; this      */
/* file only adds the chat layout so the page matches the rest of the site.    */
/* -------------------------------------------------------------------------- */

/* Custom display rules must not override the hidden attribute. */
[hidden] {
  display: none !important;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.chat-main {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  padding: clamp(24px, 4vw, 44px) 0 56px;
}

/* Login ------------------------------------------------------------------- */

.chat-login {
  display: grid;
  flex: 1 1 auto;
  place-items: center;
}

.chat-login-form {
  display: flex;
  width: min(320px, 100%);
  flex-direction: column;
  gap: 14px;
}

.chat-login-form h1 {
  margin: 0;
  font-size: clamp(40px, 7vw, 64px);
  font-weight: 400;
  letter-spacing: -0.06em;
  line-height: 0.95;
}

.chat-login-copy {
  margin: -4px 0 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.chat-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.chat-field > span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
}

.chat-field input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font-size: 12px;
}

.chat-field input:focus {
  border-color: var(--line-strong);
}

.chat-login-submit {
  height: 40px;
  margin-top: 2px;
}

.chat-status {
  min-height: 14px;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.45;
}

.chat-status.is-error {
  color: var(--danger);
}

/* Chat card ---------------------------------------------------------------- */

.chat-card {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  height: min(680px, calc(100vh - 200px));
  grid-template-columns: 250px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
}

/* Sidebar ----------------------------------------------------------------- */

.chat-sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 2px;
  padding: 16px 14px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}

.chat-me {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.chat-avatar {
  display: grid;
  width: 30px;
  height: 30px;
  flex: none;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-size: 12px;
  text-transform: uppercase;
}

.chat-me-info {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.chat-me-info strong {
  overflow: hidden;
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-me-info span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
}

.chat-sidebar-title {
  margin: 16px 0 6px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
}

.chat-sidebar-title:first-of-type {
  margin-top: 12px;
}

.chat-conversations,
.chat-contacts {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-conversation,
.chat-contact {
  position: relative;
  display: flex;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  text-align: left;
  transition: background-color 140ms ease;
}

.chat-conversation:hover,
.chat-contact:hover,
.chat-conversation.is-active,
.chat-contact.is-active {
  background: var(--hover);
}

.chat-conversation {
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
}

.chat-conversation-top {
  display: flex;
  gap: 8px;
  align-items: baseline;
  justify-content: space-between;
}

.chat-conversation strong {
  overflow: hidden;
  font-size: 11px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-time {
  flex: none;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8px;
}

.chat-preview {
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-unread {
  position: absolute;
  top: 7px;
  right: 8px;
  display: grid;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  place-items: center;
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 8px;
}

.chat-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--line-strong);
  opacity: 0.5;
}

.chat-dot.is-online {
  background: #4ade80;
  opacity: 1;
}

.chat-contact-name {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.chat-contact-name strong {
  overflow: hidden;
  font-size: 11px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-contact-name small {
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-muted {
  margin: 4px 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
}

/* Room -------------------------------------------------------------------- */

.chat-room {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.chat-empty {
  display: grid;
  flex: 1;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

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

.chat-thread-head {
  display: flex;
  flex: none;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.chat-thread-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.chat-thread-status {
  margin: 3px 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
}

.chat-messages {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  gap: 6px;
  padding: 16px 20px;
  overflow-y: auto;
}

.chat-day {
  align-self: center;
  margin: 10px 0 4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.06em;
}

.chat-bubble-row {
  display: flex;
  max-width: 100%;
  gap: 8px;
  align-items: flex-end;
  justify-content: flex-start;
}

.chat-bubble-row.is-mine {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: min(72%, 520px);
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px 10px 10px 3px;
  font-size: 12px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.chat-bubble-row.is-mine .chat-bubble {
  border-color: var(--line-strong);
  background: var(--bg);
  border-radius: 10px 10px 3px 10px;
}

.chat-bubble-time {
  flex: none;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8px;
}

.chat-composer {
  display: flex;
  flex: none;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 20px 14px;
  border-top: 1px solid var(--line);
}

.chat-composer textarea {
  flex: 1;
  min-height: 42px;
  max-height: 150px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}

.chat-composer textarea:focus {
  border-color: var(--line-strong);
}

.chat-composer .project-button {
  height: 42px;
  padding: 0 18px;
}

/* Dialogs ----------------------------------------------------------------- */

.chat-dialog--wide {
  width: min(600px, calc(100vw - 32px));
}

.chat-admin {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  max-height: 84vh;
  overflow-y: auto;
}

.chat-admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-admin-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.04em;
}

.chat-admin-create {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 8px;
  align-items: end;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.chat-admin-list {
  display: flex;
  max-height: 42vh;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.chat-admin-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
}

.chat-admin-info {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.chat-admin-info strong {
  font-size: 12px;
  font-weight: 500;
}

.chat-admin-info span {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
}

.chat-admin-actions {
  display: flex;
  flex: none;
  gap: 6px;
}

.chat-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--fg);
  color: var(--bg);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.chat-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 820px) {
  .chat-card {
    height: auto;
    min-height: 70vh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .chat-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-admin-create {
    grid-template-columns: minmax(0, 1fr);
  }

  .chat-bubble {
    max-width: 84%;
  }
}
