/* Classic Yahoo! Messenger look: purple title bar, light-blue chrome,
   white chat pane with "name: message" lines. */
:root {
  --desk: #3a6ea5;
  --purple: #5c2d91;
  --purple-dark: #400090;
  --chrome-top: #f5f8fd;
  --chrome-bottom: #dbe5f3;
  --border: #7f9db9;
  --border-soft: #b9c9de;
  --text: #000000;
  --muted: #6d6d6d;
  --link: #1a3e8c;
  --select: #c7d7f0;
  --system: #7a7a7a;
  --font: Tahoma, Verdana, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden; /* only the message list scrolls */
  font: 13px var(--font);
  color: var(--text);
  background: var(--desk) linear-gradient(180deg, #4f86c6 0%, #2b5797 100%);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

input {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--border);
  background: #fff;
  outline: none;
}
input:focus { border-color: #3d6fd1; }

/* Raised XP-style buttons */
.ybtn {
  padding: 3px 10px;
  border: 1px solid #7a8fae;
  border-radius: 3px;
  background: linear-gradient(#ffffff, #e3eaf5);
  color: #000;
  white-space: nowrap;
}
.ybtn:hover { border-color: #e8a33a; background: linear-gradient(#fffdf5, #fde9c4); }
.ybtn:active { background: linear-gradient(#e3eaf5, #ffffff); }
.danger { color: #b00000; }

/* Window */
.window {
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px);
  margin: 16px auto;
  border: 1px solid var(--purple-dark);
  border-radius: 8px 8px 4px 4px;
  background: var(--chrome-bottom);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
  overflow: hidden;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 5px 8px;
  color: #fff;
  font-weight: bold;
  background: linear-gradient(#8a5cc7 0%, #6a35b0 45%, #4d1d96 55%, #5c2da3 100%);
}
.ylogo {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: #fff;
  color: var(--purple);
  font: italic 900 13px Georgia, serif;
}
.title-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.win-btns { display: flex; gap: 3px; }
.win-btns i {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 18px;
  border: 1px solid rgba(255, 255, 255, .6);
  border-radius: 3px;
  font-style: normal;
  font-size: 11px;
  background: rgba(255, 255, 255, .15);
}
.win-btns i:last-child { background: #d8553f; }

.menubar {
  display: flex;
  align-items: center;
  flex: none;
  gap: 2px;
  padding: 2px 4px;
  background: linear-gradient(var(--chrome-top), var(--chrome-bottom));
  border-bottom: 1px solid var(--border-soft);
}
.menubar button {
  padding: 2px 8px;
  border: 1px solid transparent;
  background: transparent;
}
.menubar button:hover { border-color: #94a8c8; background: #fff; }
.menu-spacer { flex: 1; }
.mobile-only { display: none; }

.admin-badge { display: none; }
body.admin .admin-badge {
  display: inline;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 3px;
  background: #c00;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
}

.frame {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 6px;
  padding: 6px;
}

/* Left panel: buddy-list style */
.sidebar {
  width: 220px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  overflow-y: auto;
  border: 1px solid var(--border);
  background: #fff;
}

.me {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border-soft);
  background: linear-gradient(#fbfcfe, #e9eff8);
}
.me-info { min-width: 0; }
.me-name { font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-label { font-size: 11px; color: #2a8a2a; }

/* Yellow smiley presence icon */
.ystatus {
  position: relative;
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #b78900;
  background: radial-gradient(circle at 35% 30%, #fff6a8, #ffd200 55%, #f0a800);
}
.ystatus::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 4px;
  height: 6px;
  border-bottom: 1.5px solid #6b4a00;
  border-radius: 0 0 50% 50%;
}

.group-title {
  padding: 2px 0;
  font-weight: bold;
  color: var(--link);
  border-bottom: 1px solid var(--border-soft);
}

.rooms { list-style: none; margin: 0; padding: 0; }
.rooms li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 12px;
  cursor: pointer;
}
.rooms li:hover { background: #eef3fb; }
.rooms li.active { background: var(--select); font-weight: bold; }
.room-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rooms .count { color: var(--muted); font-size: 11px; }

.new-room { display: flex; flex-direction: column; gap: 4px; }
.new-room-row { display: flex; gap: 4px; }
.check { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); cursor: pointer; }
.check input { width: auto; margin: 0; }
.hint { font-size: 11px; color: var(--muted); line-height: 1.5; }
code { background: #eef1f6; padding: 0 3px; border: 1px solid #d5dbe5; }

/* Chat area */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: 4px; }

.room-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  flex: none;
  padding: 4px 8px;
  border: 1px solid var(--border);
  background: linear-gradient(#fdfdfe, #e6edf7);
}
.room-banner b { color: var(--purple); }
.room-code { color: #b05a00; font-weight: bold; }
.banner-status { margin-left: auto; display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #aaa; }
.dot.on { background: #2db82d; }

.admin-bar { display: none; }
body.admin .admin-bar {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border: 1px solid #d9a441;
  background: #fff6dc;
  font-size: 12px;
}
.admin-label { font-weight: bold; color: #8a5a00; }
.admin-bar button[hidden] { display: none; }

.chat-body { flex: 1; display: flex; gap: 4px; min-height: 0; }

.messages {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: #fff;
  line-height: 1.45;
}

.line { padding: 1px 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.line .time { color: #9a9a9a; font-size: 11px; margin-right: 4px; }
.line .who { font-weight: bold; }
.line.system { color: var(--system); font-style: italic; }
.emo { font-style: normal; font-size: 1.15em; line-height: 1; }
.empty { color: var(--muted); font-style: italic; padding: 8px 0; }

.users {
  width: 170px;
  flex: none;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  background: #fff;
  overflow-y: auto;
}
.users-head {
  padding: 3px 6px;
  font-weight: bold;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(#fdfdfe, #e6edf7);
}
.users ul { list-style: none; margin: 0; padding: 2px 0; }
.users li { display: flex; align-items: center; gap: 6px; padding: 2px 6px; }
.users li:hover { background: #eef3fb; }
.users li .you { color: var(--muted); font-size: 11px; }

/* Formatting toolbar */
.fmt-bar {
  display: flex;
  align-items: center;
  flex: none;
  gap: 2px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-bottom: 0;
  background: linear-gradient(var(--chrome-top), var(--chrome-bottom));
}
.fmt {
  position: relative;
  min-width: 26px;
  height: 24px;
  padding: 0 5px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  font-family: "Times New Roman", serif;
  font-size: 15px;
}
.fmt:hover { border-color: #94a8c8; background: #fff; }
.fmt.on { border-color: #6c87b5; background: #c9d8f0; box-shadow: inset 1px 1px 2px rgba(0, 0, 0, .2); }
.sep { width: 1px; height: 18px; margin: 0 4px; background: var(--border-soft); }
.color-a { display: block; font-weight: bold; line-height: 16px; }
.color-bar { display: block; height: 4px; margin: 0 1px 1px; background: #000; }
#emoBtn { font-family: inherit; font-size: 16px; }

.pop-wrap { position: relative; }
.popup {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  z-index: 30;
  padding: 4px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, .3);
}
.popup.open { display: grid; }
.colors { grid-template-columns: repeat(8, 20px); gap: 3px; }
.colors button { width: 20px; height: 20px; padding: 0; border: 1px solid #888; }
.colors button.on { outline: 2px solid #000; outline-offset: 1px; }
.emoticons { grid-template-columns: repeat(8, 32px); gap: 2px; width: max-content; max-width: calc(100vw - 32px); }
.emoticons button {
  width: 32px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  font-size: 19px;
}
.emoticons button:hover { border-color: #94a8c8; background: #eef3fb; }

.composer {
  display: flex;
  flex: none;
  gap: 4px;
  margin-top: -4px;
  padding: 4px;
  border: 1px solid var(--border);
  background: #fff;
}
.composer input { border: 0; padding: 6px; }
.send { padding: 0 18px; font-weight: bold; }
.composer button[hidden] { display: none; }
.key { padding: 0 10px; }
/* Chat bị khoá: khách chỉ xem, ô chat và thanh định dạng mờ đi */
body.chat-closed .composer { background: #eef0f4; }
body.chat-closed .composer input { background: transparent; cursor: not-allowed; }
body.chat-closed .composer input,
body.chat-closed .send,
body.chat-closed .fmt-bar { opacity: .45; }
body.chat-closed .fmt-bar { pointer-events: none; }
body.chat-closed .send { cursor: not-allowed; }
body.chat-locked .new-room, body.chat-locked #renameBtn { opacity: .45; pointer-events: none; }

.statusbar {
  display: flex;
  justify-content: space-between;
  flex: none;
  padding: 2px 8px;
  font-size: 11px;
  color: #333;
  border-top: 1px solid var(--border-soft);
  background: linear-gradient(var(--chrome-top), var(--chrome-bottom));
}

/* Admin delete buttons on lines */
.del { display: none; }
body.admin .del {
  display: inline-block;
  margin-left: 6px;
  padding: 0 4px;
  border: 1px solid transparent;
  background: transparent;
  color: #b00;
  font: bold 11px var(--font);
  font-style: normal;
  opacity: .45;
}
body.admin .del:hover { opacity: 1; border-color: #d99; background: #fee; }

/* Dialogs & toast */
dialog {
  padding: 0;
  border: 1px solid var(--purple-dark);
  border-radius: 6px 6px 3px 3px;
  width: min(340px, calc(100vw - 32px));
  background: var(--chrome-bottom);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
}
dialog::backdrop { background: rgba(0, 0, 0, .25); }
.dlg-title {
  padding: 5px 8px;
  color: #fff;
  font-weight: bold;
  background: linear-gradient(#8a5cc7 0%, #6a35b0 45%, #4d1d96 55%, #5c2da3 100%);
}
.dlg-body { padding: 12px; }
dialog p { margin: 0 0 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; }
.error { color: #c00; font-size: 12px; min-height: 16px; margin-top: 4px; }
.big-code {
  padding: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--purple);
  font-size: 28px;
  font-weight: bold;
  text-align: center;
  letter-spacing: .1em;
  user-select: all;
}

/* Bots */
.line .who.bot::before { content: "🤖 "; }
.users li .bot-icon { width: 16px; text-align: center; font-size: 13px; line-height: 1; }
.typing { flex: none; min-height: 0; color: var(--muted); font-size: 11px; font-style: italic; padding: 0 4px; }
.typing:not(:empty) { padding: 2px 4px; }
dialog.wide { width: min(620px, calc(100vw - 16px)); max-height: calc(100vh - 16px); }
dialog.wide .dlg-body { max-height: calc(100vh - 60px); overflow-y: auto; }
.muted { color: var(--muted); font-weight: normal; font-size: 11px; }
.row { display: flex; gap: 6px; align-items: center; }
.bot-key { margin-bottom: 10px; }
.bot-key form { margin-bottom: 6px; }
.talk-box { border: 1px solid var(--border); background: #fff; padding: 6px 8px; margin-bottom: 10px; }
.talk-box summary { cursor: pointer; font-weight: bold; }
.talk-box p.muted { margin: 6px 0; font-size: 12px; }
.linkbtn { background: none; border: none; padding: 0; color: #00c; text-decoration: underline; cursor: pointer; font-size: 11px; font-weight: normal; }
.bot-key label, .bot-form label { display: block; font-weight: bold; margin-bottom: 8px; }
.bot-form label > input, .bot-form label > select, .bot-form textarea { display: block; margin-top: 3px; font-weight: normal; }
.bot-form [hidden] { display: none; }
.bot-form .check { font-weight: bold; display: flex; align-items: center; gap: 6px; }
.bot-form .check input, .bot-rooms input { width: auto; }
.bot-form .check.inline { margin: 0; font-weight: normal; }
.bot-form input[type=color] { width: 48px; height: 26px; padding: 1px; flex: none; }
.bot-form input[type=range] { padding: 0; }
textarea, select {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--border);
  background: #fff;
  font: inherit;
  color: inherit;
}
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.field-title { font-weight: bold; margin: 4px 0 4px; }
.bot-rooms { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.bot-rooms label { font-weight: normal; display: flex; gap: 4px; align-items: center; margin: 0; }
.bot-tabs { display: flex; gap: 4px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.bot-tabs button {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(#ffffff, #e3eaf5);
  margin-bottom: -1px;
}
.bot-tabs button.on { background: #fff; font-weight: bold; }
.bot-tabs { flex-wrap: wrap; }
.bot-tabs button.add { color: #060; }
.ybtn.danger { color: #b00; margin-right: auto; }
.dialog-actions [hidden] { display: none; }
.bot-status { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.bot-status .bad { color: #c00; }
.bot-test {
  min-height: 0;
  margin-top: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bot-test:not(:empty) { padding: 6px 8px; border: 1px solid var(--border); background: #fff; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  padding: 6px 12px;
  border: 1px solid #b8a04a;
  background: #ffffe1;
  color: #000;
  box-shadow: 2px 2px 6px rgba(0, 0, 0, .3);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }

.backdrop { display: none; }

/* Narrow screens: full-screen window, side panels become drawers */
@media (max-width: 860px) {
  .window { height: 100vh; height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .win-btns { display: none; }
  .mobile-only { display: inline-block; }
  .frame { padding: 4px; }
  .sidebar, .users {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 260px;
    max-width: 85vw;
    z-index: 20;
    transition: transform .2s;
  }
  .sidebar { left: 0; transform: translateX(-100%); }
  .users { right: 0; transform: translateX(100%); }
  .sidebar.open, .users.open { transform: none; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 10; }
  .emoticons { grid-template-columns: repeat(7, 32px); }
}
