/* Per-tab live page chat — header top-right, dark/gold */

.page-chat {
  position: fixed;
  top: 2.55rem;
  right: 0.4rem;
  z-index: 10045;
  width: min(17.5rem, calc(100vw - 0.8rem));
  max-height: min(14.5rem, calc(100vh - 5rem));
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  background: rgba(10, 12, 16, 0.92);
  border: 1px solid rgba(201, 162, 39, 0.42);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  color: #e8d5a3;
  font-size: 0.72rem;
  line-height: 1.35;
  overflow: hidden;
}

.page-chat.is-collapsed {
  width: auto;
  max-height: none;
  min-width: 0;
}

.page-chat.is-collapsed .page-chat-body,
.page-chat.is-collapsed .page-chat-compose {
  display: none !important;
}

.page-chat-head {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.4rem;
  border-bottom: 1px solid rgba(201, 162, 39, 0.28);
  background: rgba(20, 18, 12, 0.55);
  flex: 0 0 auto;
  cursor: pointer;
  user-select: none;
}

.page-chat.is-collapsed .page-chat-head {
  border-bottom: none;
}

.page-chat-title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #f0d78a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-chat-room {
  color: rgba(232, 213, 163, 0.7);
  font-weight: 500;
  font-size: 0.65rem;
  margin-left: 0.2rem;
}

.page-chat-badge {
  flex: 0 0 auto;
  min-width: 1.1rem;
  padding: 0.05rem 0.28rem;
  border-radius: 999px;
  background: rgba(201, 162, 39, 0.22);
  border: 1px solid rgba(201, 162, 39, 0.4);
  color: #ffe9b0;
  font-size: 0.62rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.page-chat-badge:empty,
.page-chat-badge[data-count="0"] {
  display: none;
}

.page-chat-toggle {
  appearance: none;
  flex: 0 0 auto;
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 5px;
  border: 1px solid rgba(201, 162, 39, 0.4);
  background: rgba(30, 26, 16, 0.95);
  color: #e8d5a3;
  font: inherit;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.page-chat-toggle:hover {
  background: rgba(201, 162, 39, 0.28);
  color: #1a140c;
}

.page-chat-body {
  flex: 1 1 auto;
  min-height: 5.5rem;
  max-height: 8.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.35rem 0.4rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 162, 39, 0.45) transparent;
}

.page-chat-body::-webkit-scrollbar {
  width: 6px;
}
.page-chat-body::-webkit-scrollbar-thumb {
  background: rgba(201, 162, 39, 0.4);
  border-radius: 4px;
}

.page-chat-empty {
  margin: 0.55rem 0.15rem;
  color: rgba(200, 190, 160, 0.55);
  font-style: italic;
  text-align: center;
}

.page-chat-msg {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.1rem 0.35rem;
  margin: 0 0 0.4rem;
  padding: 0;
}

.page-chat-msg-meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
}

.page-chat-name {
  font-weight: 700;
  color: #f3dfa0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 9rem;
}

.page-chat-time {
  color: rgba(180, 170, 140, 0.55);
  font-size: 0.6rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.page-chat-text {
  grid-column: 1 / -1;
  color: #d8e0d4;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.page-chat-compose {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.3rem 0.4rem 0.4rem;
  border-top: 1px solid rgba(201, 162, 39, 0.22);
  background: rgba(8, 10, 12, 0.55);
}

.page-chat-name-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.page-chat-name-row label {
  flex: 0 0 auto;
  color: rgba(200, 185, 145, 0.7);
  font-size: 0.62rem;
}

.page-chat input[type="text"],
.page-chat input:not([type]) {
  appearance: none;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(120, 110, 80, 0.45);
  border-radius: 5px;
  background: rgba(18, 20, 24, 0.95);
  color: #e8e4d8;
  font: inherit;
  font-size: 0.7rem;
  padding: 0.28rem 0.4rem;
  outline: none;
}

.page-chat input:focus {
  border-color: rgba(201, 162, 39, 0.7);
  box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.25);
}

.page-chat-send-row {
  display: flex;
  gap: 0.3rem;
}

.page-chat-send-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.page-chat-send {
  appearance: none;
  flex: 0 0 auto;
  border: 1px solid rgba(201, 162, 39, 0.55);
  border-radius: 5px;
  background: rgba(50, 40, 18, 0.95);
  color: #ffe8b8;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.28rem 0.5rem;
  cursor: pointer;
  white-space: nowrap;
}

.page-chat-send:hover:not(:disabled) {
  background: rgba(201, 162, 39, 0.35);
  color: #1a140c;
}

.page-chat-send:disabled {
  opacity: 0.5;
  cursor: default;
}

.page-chat-status {
  min-height: 0.85rem;
  color: rgba(220, 160, 120, 0.9);
  font-size: 0.62rem;
}

.page-chat-status.is-ok {
  color: rgba(140, 200, 150, 0.85);
}

/* Narrow screens: collapse to a chat button by default styling */
@media (max-width: 720px) {
  .page-chat {
    top: auto;
    bottom: 3.4rem;
    right: 0.45rem;
    width: min(16.5rem, calc(100vw - 0.9rem));
    max-height: min(40vh, 16rem);
  }

  .page-chat.is-collapsed {
    bottom: 3.4rem;
  }

  .page-chat-body {
    max-height: 9rem;
  }
}

/* Keep clear of annotation pencil on the bottom-left; chat sits bottom-right on mobile */
body.ann-drawing .page-chat {
  opacity: 0.35;
  pointer-events: none;
}

/* Phones: page chat takes the top-right corner (where the sign-in card was),
   in the column beside Last generated so it never covers the still. It starts
   minimized; the whole head is a 32px tap target. */
@media (max-width: 540px) {
  .page-chat,
  .page-chat.is-collapsed {
    top: calc(max(0.4rem, env(safe-area-inset-top, 0px)) + 1.75rem);
    bottom: auto;
    right: max(0.45rem, env(safe-area-inset-right, 0px));
    z-index: 10049;
  }

  .page-chat {
    width: min(16.5rem, max(9rem, calc(100vw - 13.5rem)));
    max-height: min(60vh, 17rem);
  }

  .page-chat.is-collapsed {
    width: auto;
    max-width: max(9rem, calc(100vw - 13.5rem));
  }

  .page-chat-head {
    min-height: 2rem;
    padding: 0.15rem 0.2rem 0.15rem 0.5rem;
  }

  .page-chat-toggle {
    width: 2rem;
    height: 2rem;
    font-size: 0.9rem;
  }

  .page-chat-body {
    min-height: 3.5rem;
    max-height: 6.5rem;
  }

  .page-chat-send {
    min-height: 2rem;
  }

  .page-chat input[type="text"],
  .page-chat input:not([type]) {
    min-height: 2rem;
    font-size: 16px; /* no iOS zoom on focus */
  }
}
