/* index-chat.css (chatbox, chatlist, chatroom, composer, message, avatar...) */

/* 聊天框 Chatbox */
.chatbox {
  position: fixed;
  bottom: 0;
  top: 10%;
  width: 580px;
  height: 535px;
  background: var(--card, #fff);
  border: 1px solid var(--divider, #ccc);
  box-shadow: var(--shadow, 0 0 10px rgba(0,0,0,.2));
  z-index: var(--z-chat, 1000);
  cursor: move;
  animation: fadeIn 0.3s ease-out;
  transform-origin: center;
  border-radius: var(--radius-lg, 16px);
}

@media (max-width: 600px) {
  .chatbox {
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 50dvh;
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }
}

/* 聊天列表 Chatlist */
.chatlist {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 380px;
  height: 480px;
  background: var(--card, #fff);
  border: 1px solid var(--divider, #ccc);
  box-shadow: var(--shadow, 0 0 10px rgba(0,0,0,.2));
  z-index: var(--z-chat, 1000);
  display: none;
  cursor: move;
  animation: fadeIn 0.3s ease-out;
  transform-origin: bottom right;
  border-radius: var(--radius-lg, 16px);
}

.close-button {
  float: right;
  cursor: pointer;
}

/* 可調高度外層包裹 */
.resizable-wrap {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: var(--current-height, var(--list-init, 480px));
  min-height: var(--list-min, 260px);
  max-height: var(--list-max, 80dvh);
  border-radius: var(--radius-lg, 16px);
  overflow: visible;
}

/* Resizable grip */
.grip {
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  user-select: none;
  background: transparent;
}
.grip .bar {
  width: clamp(36px, 14%, 120px);
  height: 4px;
  border-radius: 999px;
  background: var(--ring);
  position: relative;
  overflow: hidden;
}
.grip .fill {
  position: absolute;
  inset: 0;
  width: var(--progress, 50%);
  background: linear-gradient(90deg, var(--primary), color-mix(in oklab, var(--primary) 60%, var(--accent)));
}

/* 聊天面板 */
.panel {
  background: color-mix(in oklab, var(--card) 88%, transparent);
  border: 1px solid var(--divider);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: clip;
  backdrop-filter: blur(6px);
}
.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  border-bottom: 1px solid var(--divider);
  position: sticky;
  top: 0;
  background: linear-gradient(180deg,
    color-mix(in oklab, var(--card) 96%, transparent),
    color-mix(in oklab, var(--card) 92%, transparent)
  );
  z-index: var(--z-content, 2);
}

.title {
  font-weight: 700;
  font-size: 50px;
}

.search {
  position: relative;
  margin-left: auto;
  flex: 1 1 auto;
  max-width: 220px;
}
.search input {
  width: 100%;
  padding: 10px 36px 10px 36px;
  border-radius: 999px;
  background: color-mix(in oklab, var(--card) 70%, transparent);
  border: 1px solid var(--ring);
  outline: none;
  color: var(--text);
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.search input::placeholder {
  color: var(--muted);
}
.search input:focus {
  border-color: color-mix(in oklab, var(--primary) 60%, var(--ring));
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--primary) 18%, transparent);
  background: color-mix(in oklab, var(--card) 85%, transparent);
}
.search .icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  opacity: .7;
}

/* 聊天列表 Actions、下拉選單 */
.actions {
  position: relative;
}
.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: color-mix(in oklab, var(--card) 80%, transparent);
  border: 1px solid var(--ring);
  color: var(--text);
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .05s;
}
.btn-icon:hover {
  background: color-mix(in oklab, var(--card) 90%, transparent);
  border-color: color-mix(in oklab, var(--primary) 50%, var(--ring));
}
.dropdown2 {
  position: absolute;
  right: 0;
  top: 44px;
  min-width: 180px;
  background: color-mix(in oklab, var(--card) 95%, transparent);
  border: 1px solid var(--divider);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: none;
  z-index: var(--z-dropdown, 200);
}
.dropdown2.open {
  display: block;
}
.dropdown2 .item2 {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
}
.dropdown2 .item2:hover {
  background: color-mix(in oklab, var(--card) 90%, transparent);
}

/* 列表區域 */
.list-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.list {
  flex: 1 1 auto;
  overflow: auto;
  overscroll-behavior: contain;
}
.section-label {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: .12em;
  padding: 10px 16px 6px;
}
.item-row {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  align-items: center;
  cursor: pointer;
  transition: background .15s;
  border-left: 3px solid transparent;
}
.item-row:hover {
  background: color-mix(in oklab, var(--card) 85%, transparent);
}
.item-row.active {
  background: color-mix(in oklab, var(--primary) 12%, transparent);
  border-left-color: var(--primary);
}

/* 聊天頭像 Avatar */
.avatar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
}
.avatar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 120% at 0% 100%, rgba(255,255,255,.18), transparent 60%);
  mix-blend-mode: soft-light;
}
.avatar[data-color="1"] { background: linear-gradient(135deg, #6d8cff, #5ec5ff); }
.avatar[data-color="2"] { background: linear-gradient(135deg, #7fdbca, #57c6e1); }
.avatar[data-color="3"] { background: linear-gradient(135deg, #ff9a8b, #ff6a88); }
.avatar[data-color="4"] { background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.avatar[data-color="5"] { background: linear-gradient(135deg, #fca5a5, #ef4444); }
.avatar[data-color="6"] { background: linear-gradient(135deg, #22c55e, #16a34a); }

.presence { 
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--card);
  background: var(--muted);
}
.presence.online { background: var(--success); }
.presence.idle { background: #f59e0b; }
.presence.busy { background: var(--danger); }

/* 聊天訊息列 */
.meta {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
}
.name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.preview {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badges {
  display: flex;
  gap: 8px;
}
.unread {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  line-height: 1;
  box-shadow: 0 6px 14px color-mix(in oklab, var(--primary) 35%, transparent);
}

/* 聊天室 Chatroom (訊息區) */
.chatroom {
  display: none;
  flex-direction: column;
  height: 700px;
}
.chatroom.show {
  display: flex;
  animation: slideIn .28s ease-out;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chatroom .panel-header {
  gap: 10px;
}
.chatroom .peer {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.chatroom .peer .name {
  font-weight: 700;
  font-size: 16px;
}
.chatroom .peer .sub {
  font-size: 12px;
  color: var(--muted);
}

.messages {
  flex: 1 1 auto;
  overflow: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: color-mix(in oklab, var(--card) 92%, transparent);
}

.msg {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: end;
  max-width: 80%;
}
.msg.me {
  margin-left: auto;
  grid-template-columns: 1fr auto;
}
.msg .bubble {
  background: color-mix(in oklab, var(--card) 85%, transparent);
  border: 1px solid var(--divider);
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--text);
  box-shadow: var(--shadow);
}
.msg .bubble .content {
  white-space: pre-wrap;
  word-break: break-word;
}
.msg .info {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.msg.me .bubble {
  background: color-mix(in oklab, var(--primary) 18%, var(--card));
  border-color: color-mix(in oklab, var(--primary) 35%, var(--divider));
}
.msg.me .info {
  justify-content: flex-end;
}
.msg .head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.msg .uname {
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
}

/* 輸入區 Composer */
.composer {
  border-top: 1px solid var(--divider);
  padding: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  background: linear-gradient(180deg, color-mix(in oklab, var(--card) 96%, transparent), color-mix(in oklab, var(--card) 92%, transparent));
}
.input {
  flex: 1;
  position:relative;
}
.input textarea {
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in oklab, var(--card) 80%, transparent);
  border: 1px solid var(--ring);
  outline: none;
  color: var(--text);
}
.btn2 {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--ring);
  background: color-mix(in oklab, var(--card) 85%, transparent);
  color: var(--text);
  cursor: pointer;
}
.btn.primary {
  background: var(--primary);
  border-color: color-mix(in oklab, var(--primary) 60%, var(--ring));
  color: #fff;
}

/* 已讀訊息小圖標區 */
.read-receipt {
  display: inline-flex;
  gap: 2px;
  align-items: center;
  color: color-mix(in oklab, var(--primary) 70%, #9aa3b2);
}
.read-receipt .tick {
  width: 14px;
  height: 14px;
}

/* 右側空狀態 placeholder */
.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 480px;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  border: 1px solid var(--divider);
  border-radius: var(--radius-lg);
  background: color-mix(in oklab, var(--card) 92%, transparent);
  box-shadow: var(--shadow);
}

/* 結尾響應式 */
@media (max-width: 1000px) {
  .chatroom {
    height: 70dvh;
  }
}

/* 動畫效果 */
@keyframes fadeIn {
  from { opacity: 0; transform: scale(.95); }
  to { opacity: 1; transform: scale(1); }
}