/* QIP 2005 / Windows XP look, adapted to phones.
   All colours live in variables so a theme switcher can override them later. */
:root {
  --font: Tahoma, Verdana, "DejaVu Sans", "Segoe UI", Geneva, Roboto, sans-serif;
  --fs: 14px;
  --fs-small: 12px;

  --desktop: #3a6ea5;
  --face: #ece9d8;            /* XP "3D face" */
  --face-light: #f7f6f0;
  --border-dark: #7f9db9;     /* XP edit border */
  --frame: #0831d9;
  --title-1: #0a4fd6;
  --title-2: #3d8af7;
  --title-3: #0846c6;
  --title-text: #ffffff;
  --list-bg: #ffffff;
  --group-text: #0c3b8c;
  --select-bg: #316ac5;
  --select-text: #ffffff;
  --text: #000000;
  --muted: #6b6b6b;
  --link: #0000ee;
  --nick-in: #0000c8;
  --nick-out: #c80000;
  --time: #808080;
  --balloon: #ffffe1;
  --btn-border: #003c74;
  --unread: #c80000;
  --ok: #2b8a1e;
  --bad: #c80000;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--desktop);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

a { color: var(--link); }

button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- Window frame ---------- */

.window {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--face);
  max-width: 720px;
  margin: 0 auto;
  border-left: 1px solid var(--frame);
  border-right: 1px solid var(--frame);
}
@supports (height: 100dvh) {
  .window { height: 100dvh; }
}

.titlebar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: calc(44px + var(--safe-top));
  padding: var(--safe-top) 6px 0 6px;
  background: linear-gradient(180deg, var(--title-2) 0%, var(--title-1) 12%, var(--title-1) 85%, var(--title-3) 100%);
  color: var(--title-text);
  font-weight: bold;
  text-shadow: 1px 1px 0 #00137a;
  user-select: none;
}
.titlebar .title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 15px;
}
.titlebar .title small { font-weight: normal; opacity: .85; font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; }
.titlebar .appicon { width: 22px; height: 22px; flex: none; }

/* XP caption buttons */
.tbtn {
  flex: none;
  min-width: 36px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid #fff;
  border-radius: 4px;
  background: linear-gradient(180deg, #5f9cff 0%, #2765e6 50%, #1c55d6 100%);
  color: #fff;
  font-weight: bold;
  text-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
}
.tbtn:active { background: #1b47b8; }
.tbtn img { width: 18px; height: 18px; }

.menubar {
  flex: none;
  display: flex;
  border-bottom: 1px solid #aca899;
  background: var(--face);
}
.menubar button {
  flex: 1;
  padding: 10px 4px;
  border: 0;
  border-right: 1px solid #d4d0c8;
  background: none;
  cursor: pointer;
}
.menubar button.active {
  background: var(--face-light);
  font-weight: bold;
  box-shadow: inset 0 -3px 0 #f9b231;
}

/* ---------- Common controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 14px;
  border: 1px solid var(--btn-border);
  border-radius: 3px;
  background: linear-gradient(180deg, #ffffff 0%, #f3f2ec 60%, #d6d0c5 100%);
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { background: linear-gradient(180deg, #d6d0c5, #f3f2ec); }
.btn:disabled { color: #a0a0a0; border-color: #c9c7ba; cursor: default; }
.btn.primary { font-weight: bold; box-shadow: inset 0 0 0 1px #a6caf0; }
.btn.small { min-height: 28px; padding: 2px 8px; font-size: var(--fs-small); }
.btn img { width: 18px; height: 18px; }

.field { display: block; margin: 0 0 10px; }
.field > span { display: block; margin-bottom: 3px; }
.input, textarea.input, select.input {
  width: 100%;
  min-height: 34px;
  padding: 5px 6px;
  border: 1px solid var(--border-dark);
  background: #fff;
  border-radius: 0;
  font-size: 16px; /* prevents iOS zoom on focus */
}
textarea.input { resize: none; }

fieldset.group {
  margin: 10px;
  padding: 8px 10px 10px;
  border: 1px solid #d0d0bf;
  border-radius: 4px;
}
fieldset.group legend { color: #0046d5; padding: 0 4px; }

.muted { color: var(--muted); }
.error-text { color: var(--bad); margin: 6px 0; }
.hidden { display: none !important; }

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

.login {
  flex: 1;
  overflow: auto;
  padding: 18px 14px calc(18px + var(--safe-bottom));
}
.login .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 18px;
}
.login .logo img { width: 56px; height: 56px; }
.login .logo b { font-size: 22px; color: #0c3b8c; display: block; }
.login .tabs { display: flex; gap: 4px; margin-bottom: -1px; }
.login .tabs button {
  padding: 8px 14px;
  border: 1px solid #919b9c;
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(#fff, #ece9d8);
}
.login .tabs button.active { background: #fcfcfe; border-top: 2px solid #f9b231; font-weight: bold; }
.login .panel { border: 1px solid #919b9c; background: #fcfcfe; padding: 14px; }
.login .actions { display: flex; justify-content: flex-end; margin-top: 6px; }

/* ---------- Contact-list style room list ---------- */

.searchbar { flex: none; padding: 6px; border-bottom: 1px solid #d4d0c8; }

.clist {
  flex: 1;
  overflow-y: auto;
  background: var(--list-bg);
  border-top: 1px solid #aca899;
  -webkit-overflow-scrolling: touch;
}
.cgroup {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 8px;
  border: 0;
  border-bottom: 1px solid #eef0f6;
  background: linear-gradient(180deg, #f6f8fd, #e3e9f6);
  color: var(--group-text);
  font-weight: bold;
  text-align: left;
  cursor: pointer;
}
.cgroup .arrow { width: 12px; font-size: 10px; }
.citem {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  padding: 4px 10px 4px 22px;
  border: 0;
  border-bottom: 1px solid #f1f1f1;
  background: none;
  text-align: left;
  cursor: pointer;
}
.citem:active, .citem.selected { background: var(--select-bg); color: var(--select-text); }
.citem:active .muted { color: #dfe8ff; }
.citem .ico { width: 20px; height: 20px; flex: none; }
.citem .main { flex: 1; min-width: 0; }
.citem .name { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.citem .sub { display: block; font-size: var(--fs-small); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.citem.unread .name { font-weight: bold; color: var(--unread); }
.citem .count { font-size: var(--fs-small); flex: none; }
.citem .badge {
  flex: none;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 9px;
  background: var(--unread);
  color: #fff;
  font-size: var(--fs-small);
  font-weight: bold;
  text-align: center;
}
.blink { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

.empty { padding: 24px 16px; text-align: center; color: var(--muted); }

.statusbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px calc(6px + var(--safe-bottom));
  border-top: 1px solid #aca899;
  background: var(--face);
}
.statusbar .grow { flex: 1; min-width: 0; }
.statusbtn {
  flex: 1;
  min-width: 0;
  justify-content: flex-start;
  overflow: hidden;
}
.statusbtn span { overflow: hidden; text-overflow: ellipsis; }

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

.chatlog {
  flex: 1;
  overflow-y: auto;
  background: #fff;
  border-top: 1px solid #aca899;
  border-bottom: 1px solid #aca899;
  padding: 6px 8px 10px;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
}
.msg { margin: 0 0 8px; line-height: 1.35; }
.msg .head { display: flex; align-items: baseline; gap: 6px; }
.msg .nick {
  padding: 0;
  border: 0;
  background: none;
  font-weight: bold;
  color: var(--nick-in);
  cursor: pointer;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg.mine .nick { color: var(--nick-out); }
.msg .time { color: var(--time); font-size: var(--fs-small); }
.msg .body { white-space: pre-wrap; padding-left: 2px; }
.msg .body img.sm { width: 26px; height: 26px; vertical-align: -7px; }
/* GIFs from a QIP pack keep their native size */
.msg .body img.sm.px, .about img.sm.px { width: auto; height: auto; vertical-align: middle; }
.smilepanel img.px { width: auto; height: auto; max-width: 100%; }
.smilebtn img { object-fit: contain; }
.msg.pending { opacity: .55; }
.daysep {
  margin: 10px 0;
  text-align: center;
  color: var(--time);
  font-size: var(--fs-small);
}
.daysep span { background: #fff; padding: 0 8px; }
.daysep::before { content: ""; display: block; border-top: 1px dotted #b8b8b8; margin-bottom: -8px; }
.loadmore { text-align: center; padding: 6px; color: var(--muted); font-size: var(--fs-small); }

.newmsgs {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  padding: 6px 12px;
  border: 1px solid #000;
  border-radius: 12px;
  background: var(--balloon);
  box-shadow: 2px 2px 3px rgba(0,0,0,.3);
  cursor: pointer;
}
.logwrap { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px 6px calc(6px + var(--safe-bottom));
  background: var(--face);
}
.composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  line-height: 1.3;
}
.composer .btn { min-height: 40px; }
.smilebtn { width: 44px; padding: 0; }
.smilebtn img { width: 26px; height: 26px; }

.smilewrap { flex: none; border-top: 1px solid #aca899; background: #fff; }
.smiletabs { display: flex; background: var(--face); border-bottom: 1px solid #aca899; }
.smiletabs button {
  flex: 1;
  padding: 8px 2px;
  border: 0;
  border-right: 1px solid #d4d0c8;
  background: none;
  font-size: var(--fs-small);
  cursor: pointer;
}
.smiletabs button.active { background: #fff; font-weight: bold; box-shadow: inset 0 -3px 0 #f9b231; }
.smilepanel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  grid-auto-rows: 44px;
  align-content: start;
  gap: 2px;
  height: 30vh;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  background: #fff;
}
.smilepanel.emoji button { font-size: 26px; line-height: 1; padding: 0; }
.smilepanel button {
  height: 44px;
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
}
.smilepanel button:active { border-color: var(--select-bg); background: #c1d2ee; }
.smilepanel img { width: 30px; height: 30px; }

/* Presence drawer */
.drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 20; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(80vw, 300px);
  display: flex;
  flex-direction: column;
  background: var(--face);
  border-left: 2px solid var(--frame);
  z-index: 21;
  animation: slidein .15s ease-out;
}
@keyframes slidein { from { transform: translateX(100%); } }
.drawer .clist { flex: 1; }
.drawer-foot { flex: none; padding: 8px 8px calc(8px + var(--safe-bottom)); border-top: 1px solid #aca899; }
.drawer-foot .btn { width: 100%; }
.citem.offline .name { color: #808080 !important; }
.citem.offline .avatar { opacity: .5; }

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

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: rgba(0, 0, 0, .3);
}
.dialog {
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - 20px);
  display: flex;
  flex-direction: column;
  background: var(--face);
  border: 3px solid var(--frame);
  border-top: 0;
  border-radius: 8px 8px 0 0;
  box-shadow: 4px 4px 12px rgba(0,0,0,.4);
  overflow: hidden;
}
.dialog .titlebar { min-height: 36px; padding-top: 0; border-radius: 6px 6px 0 0; }
.dialog .titlebar .title { font-size: 14px; }
.dialog .tbtn.close {
  min-width: 30px;
  height: 26px;
  background: linear-gradient(180deg, #e8835f 0%, #d8482a 50%, #c53316 100%);
}
.dialog .content { flex: 1; overflow-y: auto; padding: 12px; }
.dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 12px 12px; }

/* Profile */
.profile-head { display: flex; gap: 12px; align-items: flex-start; }
.avatar {
  flex: none;
  width: 96px;
  height: 96px;
  object-fit: cover;
  border: 1px solid var(--border-dark);
  background: #fff;
}
.avatar.small { width: 32px; height: 32px; }
.profile-head .who { min-width: 0; flex: 1; }
.profile-head .nickline { display: flex; align-items: center; gap: 6px; font-weight: bold; font-size: 16px; overflow-wrap: anywhere; }
.profile-head .nickline img { width: 18px; height: 18px; flex: none; }
.rep {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.rep .score { font-size: 22px; font-weight: bold; min-width: 40px; }
.rep .score.pos { color: var(--ok); }
.rep .score.neg { color: var(--bad); }
.props { width: 100%; border-collapse: collapse; margin-top: 4px; }
.props td { padding: 4px 0; vertical-align: top; }
.props td:first-child { color: var(--muted); width: 38%; padding-right: 8px; }
.gifbar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0;
  -webkit-overflow-scrolling: touch;
}
.gifbar .gif { position: relative; flex: none; }
.gifbar img { height: 84px; max-width: 160px; object-fit: cover; border: 1px solid #aaa; display: block; background: #fff; }
.gifbar .del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 24px;
  height: 24px;
  border: 1px solid #fff;
  border-radius: 3px;
  background: #d8482a;
  color: #fff;
  font-weight: bold;
  padding: 0;
}
.about { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Replies, quotes, mentions */
.quote {
  margin: 2px 0 3px 2px;
  padding: 3px 8px;
  border-left: 3px solid #7f9db9;
  background: #f1f4fa;
  color: #444;
  font-size: var(--fs-small);
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.quote.static { cursor: default; white-space: normal; margin: 0 0 10px; font-size: var(--fs); }
.quote img.sm { width: 18px; height: 18px; vertical-align: -4px; }
.mention { color: #0046d5; font-weight: bold; cursor: pointer; }
.mention.me { background: #fff2a8; border-radius: 3px; padding: 0 2px; }
.msg.tome { background: #fffbd6; box-shadow: -8px 0 0 #fffbd6, 8px 0 0 #fffbd6; border-left: 3px solid #f9b231; padding-left: 4px; }
.msg.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 30% { background: #ffe58a; } 100% { background: transparent; } }
.msg { cursor: default; }
.replybar, .mentionbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--face-light);
  border-top: 1px solid #aca899;
}
.replybar .replyicon { color: #0046d5; font-weight: bold; }
.replybar .replytext { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: var(--fs-small); }
.replybar .replytext img.sm { width: 16px; height: 16px; vertical-align: -3px; }
.replyclose { flex: none; width: 32px; height: 32px; border: 1px solid #999; border-radius: 3px; background: #fff; }
.mentionbar { overflow-x: auto; }
.chip {
  flex: none;
  padding: 6px 10px;
  border: 1px solid #7f9db9;
  border-radius: 14px;
  background: #fff;
  color: var(--nick-in);
  font-weight: bold;
  white-space: nowrap;
}
.badge.at { background: #f9b231; color: #000; }
.menuicon { width: 22px; text-align: center; font-weight: bold; color: #0046d5; }
.titlebar .title small.typing { font-style: italic; opacity: 1; color: #ffe58a; }

/* X-status */
.xs { margin-left: 4px; font-size: 14px; line-height: 1; cursor: default; }
.xs.big { font-size: 20px; margin: 0 6px 0 0; }
.xline { display: flex; align-items: flex-start; margin-top: 4px; overflow-wrap: anywhere; }
.xdesc { display: block; color: #444; }
.xsgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; }
.xsbtn {
  height: 40px;
  border: 1px solid #c9c7ba;
  border-radius: 4px;
  background: #fff;
  font-size: 22px;
  padding: 0;
  cursor: pointer;
}
.xsbtn.none { font-size: 16px; color: #999; }
.xsbtn.current { border-color: #f9b231; box-shadow: 0 0 0 2px #f9b231; }

/* Nick colour picker */
.nickpreview { background: #fff; border: 1px solid var(--border-dark); padding: 6px 8px; margin-bottom: 8px; }
.nickpreview .time { color: var(--time); font-size: var(--fs-small); }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 6px; }
.swatch {
  position: relative;
  height: 36px;
  border: 1px solid #555;
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px #fff;
  cursor: pointer;
  padding: 0;
}
.swatch.current { outline: 2px solid #f9b231; outline-offset: 1px; }
.swatch-own {
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(#c00, #c80, #080, #088, #00c, #808, #c00);
  color: #fff;
  font-weight: bold;
  text-shadow: 0 0 2px #000;
}
.swatch-custom { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

.page { flex: 1; overflow-y: auto; padding-bottom: var(--safe-bottom); }

/* Status menu */
.menu { list-style: none; margin: 0; padding: 2px; background: #fff; border: 1px solid #aca899; }
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 4px 10px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.menu button:active, .menu button.current { background: var(--select-bg); color: #fff; }
.menu img { width: 18px; height: 18px; }

/* Balloon tooltip (toasts) */
.balloon {
  position: fixed;
  left: 50%;
  bottom: calc(76px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 24px);
  padding: 8px 12px 8px 10px;
  background: var(--balloon);
  border: 1px solid #000;
  border-radius: 6px;
  box-shadow: 2px 2px 4px rgba(0,0,0,.35);
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.balloon b { display: block; }

.conn-warn {
  flex: none;
  padding: 4px 8px;
  background: var(--balloon);
  border-bottom: 1px solid #c9b77a;
  font-size: var(--fs-small);
  text-align: center;
}

@media (min-width: 721px) {
  .window { top: 12px; bottom: 12px; border: 3px solid var(--frame); border-top: 0; border-radius: 8px 8px 0 0; box-shadow: 6px 6px 18px rgba(0,0,0,.4); height: auto; }
  .titlebar { border-radius: 6px 6px 0 0; }
}
