/* ═══════════════════════════════════════════════════════════════
   Anchor HQ — Chat Section (The Tavern)
   Stardew Valley NPC-dialogue theme with wood-panel sidebar,
   speech bubbles, parchment input, and pixel quill send button.
   ═══════════════════════════════════════════════════════════════ */

/* ── Layout shell ─────────────────────────────────────────────── */
.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  height: calc(100vh - 140px);
  min-height: 400px;
  border: 3px solid var(--wood, #6b4423);
  border-radius: var(--radius, 6px);
  overflow: hidden;
  box-shadow:
    3px 3px 0 var(--wood-dark, #3a2415),
    inset 0 0 0 1px rgba(218, 165, 32, 0.08);
  image-rendering: pixelated;
}

/* ══════════════════════════════════════════════════════════════
   SIDEBAR — Conversations Journal
   ══════════════════════════════════════════════════════════════ */
.chat-list {
  background:
    linear-gradient(
      180deg,
      var(--panel, #2a1f14) 0%,
      var(--panel-soft, #352a1e) 100%
    );
  border-right: 3px solid var(--wood, #6b4423);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Worn leather spine texture on the right edge */
.chat-list::after {
  content: '';
  position: absolute;
  top: 0;
  right: -3px;
  width: 3px;
  height: 100%;
  background:
    repeating-linear-gradient(
      to bottom,
      var(--wood, #6b4423) 0px,
      var(--wood, #6b4423) 10px,
      var(--wood-dark, #3a2415) 10px,
      var(--wood-dark, #3a2415) 12px
    );
  z-index: 1;
}

/* ── Sidebar header ───────────────────────────────────────────── */
.chat-list-header {
  padding: 14px 16px;
  border-bottom: 2px solid var(--wood, #6b4423);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background:
    linear-gradient(
      180deg,
      rgba(107, 68, 35, 0.15) 0%,
      transparent 100%
    );
}

.chat-list-header h3 {
  font-family: var(--font-pixel, 'Press Start 2P', monospace);
  font-size: .55rem;
  font-weight: 700;
  color: var(--gold, #daa520);
  letter-spacing: .03em;
  text-transform: uppercase;
}

/* ── New chat button ──────────────────────────────────────────── */
.new-chat-btn {
  padding: 5px 12px;
  border-radius: 2px;
  border: 2px solid var(--wood, #6b4423);
  background:
    linear-gradient(
      135deg,
      var(--gold-soft, rgba(218, 165, 32, 0.2)),
      rgba(218, 165, 32, 0.08)
    );
  color: var(--gold-bright, #f0c040);
  font-family: var(--font-pixel, 'Press Start 2P', monospace);
  font-size: .48rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 180ms ease;
  text-transform: uppercase;
  box-shadow: 1px 1px 0 var(--wood-dark, #3a2415);
}

.new-chat-btn:hover {
  background: var(--gold, #daa520);
  color: var(--wood-dark, #3a2415);
  box-shadow:
    0 0 8px rgba(218, 165, 32, 0.2),
    1px 1px 0 var(--wood-dark, #3a2415);
}

.new-chat-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* ── Thread list (scrollable journal pages) ───────────────────── */
.chat-list-items {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--wood, #6b4423) transparent;
}

.chat-list-items::-webkit-scrollbar {
  width: 6px;
}

.chat-list-items::-webkit-scrollbar-track {
  background: transparent;
}

.chat-list-items::-webkit-scrollbar-thumb {
  background: var(--wood, #6b4423);
  border-radius: 0;
}

/* ── Individual thread — pixel bookmark style ─────────────────── */
.chat-thread {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all 150ms ease;
  position: relative;
}

/* Left bookmark stripe */
.chat-thread::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: transparent;
  transition: background 150ms ease;
}

.chat-thread:hover {
  background: rgba(218, 165, 32, 0.05);
}

.chat-thread:hover::before {
  background: rgba(218, 165, 32, 0.3);
}

/* Active thread — golden bookmark */
.chat-thread.active {
  background: var(--gold-soft, rgba(218, 165, 32, 0.15));
  border-left: none;
}

.chat-thread.active::before {
  width: 4px;
  background: var(--gold, #daa520);
  box-shadow: 0 0 6px rgba(218, 165, 32, 0.25);
}

/* Pixel notch on active thread bookmark */
.chat-thread.active::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 5px solid var(--gold, #daa520);
}

.chat-thread-title {
  font-size: .82rem;
  font-weight: 700;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.chat-thread-preview {
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
}

.chat-thread-time {
  font-size: .62rem;
  color: var(--muted);
  margin-top: 3px;
  opacity: .7;
}

/* Unread dot — pixel gem */
.chat-unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 0;
  background: var(--gold, #daa520);
  flex-shrink: 0;
  box-shadow: 0 0 4px rgba(218, 165, 32, 0.5);
  animation: unread-pulse 2s ease-in-out infinite;
}

@keyframes unread-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

/* ══════════════════════════════════════════════════════════════
   MAIN PANEL — Chat Messages
   ══════════════════════════════════════════════════════════════ */
.chat-messages {
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(
      180deg,
      var(--bg, #1e1610) 0%,
      rgba(30, 22, 16, 0.98) 100%
    );
}

/* ── Chat header — tavern signboard ───────────────────────────── */
.chat-messages-header {
  padding: 14px 20px;
  border-bottom: 3px solid var(--wood, #6b4423);
  flex-shrink: 0;
  background:
    linear-gradient(
      180deg,
      var(--panel, #2a1f14) 0%,
      var(--panel-soft, #352a1e) 100%
    );
  position: relative;
}

/* Decorative wood grain stripes */
.chat-messages-header::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 0;
  right: 0;
  height: 3px;
  background:
    repeating-linear-gradient(
      to right,
      var(--wood, #6b4423) 0px,
      var(--wood, #6b4423) 8px,
      var(--wood-dark, #3a2415) 8px,
      var(--wood-dark, #3a2415) 10px
    );
}

.chat-messages-header h3 {
  font-family: var(--font-pixel, 'Press Start 2P', monospace);
  font-size: .58rem;
  font-weight: 700;
  color: var(--gold, #daa520);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Messages body ────────────────────────────────────────────── */
.chat-messages-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--wood, #6b4423) transparent;
}

.chat-messages-body::-webkit-scrollbar {
  width: 6px;
}

.chat-messages-body::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages-body::-webkit-scrollbar-thumb {
  background: var(--wood, #6b4423);
  border-radius: 0;
}

/* ── Base message bubble ──────────────────────────────────────── */
.chat-msg {
  max-width: 75%;
  padding: 10px 14px;
  font-size: .82rem;
  line-height: 1.55;
  white-space: pre-wrap;
  position: relative;
  transition: all 150ms ease;
}

/* ── Anchor messages — NPC speech bubble ──────────────────────── */
.chat-msg.anchor {
  align-self: flex-start;
  background:
    linear-gradient(
      145deg,
      var(--panel, #2a1f14),
      var(--panel-soft, #352a1e)
    );
  color: var(--text);
  border: 2px solid var(--wood, #6b4423);
  border-radius: 2px 8px 8px 2px;
  box-shadow:
    2px 2px 0 var(--wood-dark, #3a2415),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  margin-left: 10px;
}

/* NPC speech bubble tail (left side pixel arrow) */
.chat-msg.anchor::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 10px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 8px solid var(--wood, #6b4423);
}

.chat-msg.anchor::after {
  content: '';
  position: absolute;
  left: -5px;
  top: 11px;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-right: 6px solid var(--panel, #2a1f14);
}

/* ── Yas messages — dialogue choice style ─────────────────────── */
.chat-msg.yas {
  align-self: flex-end;
  background:
    linear-gradient(
      145deg,
      var(--gold, #daa520),
      var(--gold-bright, #f0c040)
    );
  color: var(--wood-dark, #3a2415);
  border: 2px solid var(--gold-bright, #f0c040);
  border-radius: 8px 2px 2px 8px;
  box-shadow:
    -2px 2px 0 var(--wood-dark, #3a2415),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  margin-right: 10px;
  font-weight: 500;
}

/* Dialogue choice arrow (right side) */
.chat-msg.yas::before {
  content: '';
  position: absolute;
  right: -8px;
  top: 10px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 8px solid var(--gold-bright, #f0c040);
}

.chat-msg.yas::after {
  content: '';
  position: absolute;
  right: -5px;
  top: 11px;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid var(--gold-bright, #f0c040);
}

/* ── Message timestamps ───────────────────────────────────────── */
.chat-msg-time {
  font-size: .6rem;
  color: var(--muted);
  margin-top: 4px;
  font-family: var(--font-body, 'Inter', sans-serif);
  opacity: .7;
}

.chat-msg.yas .chat-msg-time {
  text-align: right;
  color: rgba(58, 37, 21, 0.5);
}

/* ══════════════════════════════════════════════════════════════
   INPUT AREA — Parchment writing desk
   ══════════════════════════════════════════════════════════════ */
.chat-input-area {
  padding: 12px 16px;
  border-top: 3px solid var(--wood, #6b4423);
  background:
    linear-gradient(
      0deg,
      var(--panel, #2a1f14),
      var(--panel-soft, #352a1e)
    );
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  position: relative;
}

/* Top wood grain border */
.chat-input-area::before {
  content: '';
  position: absolute;
  top: -3px;
  left: 0;
  right: 0;
  height: 3px;
  background:
    repeating-linear-gradient(
      to right,
      var(--wood, #6b4423) 0px,
      var(--wood, #6b4423) 8px,
      var(--wood-dark, #3a2415) 8px,
      var(--wood-dark, #3a2415) 10px
    );
}

/* ── Text input — parchment scroll ────────────────────────────── */
.chat-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 2px;
  border: 2px solid var(--border);
  background:
    linear-gradient(
      180deg,
      var(--panel-soft, #352a1e),
      rgba(53, 42, 30, 0.8)
    );
  color: var(--text);
  font-size: .82rem;
  font-family: var(--font-body, 'Inter', sans-serif);
  outline: none;
  resize: none;
  max-height: 100px;
  transition: border-color 200ms ease, box-shadow 200ms ease;
  line-height: 1.5;
}

.chat-input:focus {
  border-color: var(--gold, #daa520);
  box-shadow:
    0 0 8px rgba(218, 165, 32, 0.12),
    inset 0 0 12px rgba(218, 165, 32, 0.03);
}

.chat-input::placeholder {
  color: var(--muted);
  font-style: italic;
  font-size: .76rem;
}

/* ── Send button — pixel quill ────────────────────────────────── */
.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 2px;
  background:
    linear-gradient(
      145deg,
      var(--gold, #daa520),
      var(--gold-bright, #f0c040)
    );
  border: 2px solid var(--wood, #6b4423);
  color: var(--wood-dark, #3a2415);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 180ms ease;
  flex-shrink: 0;
  align-self: flex-end;
  box-shadow:
    2px 2px 0 var(--wood-dark, #3a2415),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  position: relative;
}

.chat-send-btn:hover {
  filter: brightness(1.12);
  box-shadow:
    0 0 10px rgba(218, 165, 32, 0.25),
    2px 2px 0 var(--wood-dark, #3a2415),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.chat-send-btn:active {
  transform: translateY(1px);
  box-shadow:
    1px 1px 0 var(--wood-dark, #3a2415),
    inset 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* ── Empty state ──────────────────────────────────────────────── */
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: .82rem;
  font-style: italic;
  gap: 8px;
}

.chat-empty::before {
  content: '~';
  font-family: var(--font-pixel, 'Press Start 2P', monospace);
  font-size: 1.2rem;
  color: var(--wood, #6b4423);
  opacity: .4;
}

/* ══════════════════════════════════════════════════════════════
   TYPING INDICATOR — .chat-typing
   Three bouncing pixel dots for "Anchor is writing..."
   ══════════════════════════════════════════════════════════════ */
.chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background:
    linear-gradient(
      145deg,
      var(--panel, #2a1f14),
      var(--panel-soft, #352a1e)
    );
  border: 2px solid var(--wood, #6b4423);
  border-radius: 2px 8px 8px 2px;
  margin-left: 10px;
  box-shadow: 2px 2px 0 var(--wood-dark, #3a2415);
}

/* NPC tail on typing bubble */
.chat-typing::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 10px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 8px solid var(--wood, #6b4423);
}

.chat-typing span {
  display: block;
  width: 6px;
  height: 6px;
  background: var(--gold, #daa520);
  border-radius: 0;
  animation: typing-bounce 1.2s ease-in-out infinite;
  image-rendering: pixelated;
}

.chat-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: .4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
    background: var(--gold-bright, #f0c040);
    box-shadow: 0 0 4px rgba(218, 165, 32, 0.4);
  }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .chat-layout {
    grid-template-columns: 220px 1fr;
  }

  .chat-list-header h3 {
    font-size: 0.48rem;
  }

  .new-chat-btn {
    font-size: 0.42rem;
    padding: 4px 8px;
  }

  .chat-thread-title {
    font-size: 0.78rem;
  }

  .chat-messages-body {
    padding: 14px 16px;
  }
}


/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile: stack on narrow viewports
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .chat-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: calc(100vh - 100px);
  }

  .chat-list {
    border-right: none;
    border-bottom: 3px solid var(--wood, #6b4423);
    max-height: 160px;
  }

  .chat-list::after {
    display: none;
  }

  /* Compact sidebar header */
  .chat-list-header {
    padding: 10px 12px;
  }

  .chat-list-header h3 {
    font-size: 0.48rem;
  }

  .new-chat-btn {
    padding: 6px 10px;
    font-size: 0.42rem;
    min-height: 36px;
  }

  /* Compact thread items */
  .chat-thread {
    padding: 8px 12px;
  }

  .chat-thread-title {
    font-size: 0.78rem;
    gap: 4px;
  }

  .chat-thread-preview {
    font-size: 0.68rem;
  }

  /* Messages area */
  .chat-msg {
    max-width: 88%;
    padding: 8px 12px;
    font-size: 0.78rem;
  }

  .chat-messages-header {
    padding: 10px 14px;
  }

  .chat-messages-header h3 {
    font-size: 0.5rem;
  }

  .chat-messages-body {
    padding: 12px 14px;
    gap: 8px;
  }

  /* Input area: proper mobile sizing */
  .chat-input-area {
    padding: 10px 12px;
    gap: 6px;
  }

  .chat-input {
    padding: 10px 12px;
    font-size: 0.78rem;
    min-height: 44px;
  }

  .chat-input::placeholder {
    font-size: 0.72rem;
  }

  .chat-send-btn {
    width: 44px;
    height: 44px;
  }

  /* Message bubbles: reduce margin on arrows */
  .chat-msg.anchor {
    margin-left: 6px;
  }

  .chat-msg.yas {
    margin-right: 6px;
  }

  .chat-msg-time {
    font-size: 0.55rem;
  }

  /* Typing indicator */
  .chat-typing {
    margin-left: 6px;
    padding: 8px 12px;
  }
}
