/* ==========================================================================
   Friend Chat — WhatsApp-inspired interface
   ========================================================================== */

:root {
  --accent: #00a884;
  --accent-strong: #008069;
  --accent-soft: #d9fdd3;
  --tick-blue: #53bdeb;

  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --panel-3: #f7f8fa;
  --border: #e9edef;
  --text: #111b21;
  --text-2: #667781;
  --text-3: #8696a0;

  --chat-bg: #efeae2;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --bubble-text: #111b21;
  --bubble-meta: #667781;
  --day-bg: #ffffff;

  --hover: #f5f6f6;
  --active: #f0f2f5;
  --danger: #ea0038;
  --danger-soft: #fdecef;

  --shadow-sm: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --shadow-md: 0 2px 12px rgba(11, 20, 26, 0.12);
  --shadow-lg: 0 20px 60px rgba(11, 20, 26, 0.22);

  --radius: 12px;
  --panel-width: clamp(320px, 32vw, 440px);

  --doodle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='none' stroke='%23111b21' stroke-opacity='0.035' stroke-width='1.4' stroke-linecap='round'%3E%3Ccircle cx='30' cy='30' r='9'/%3E%3Cpath d='M95 22c-6 0-10 4-10 9 0 6 5 9 10 9h11l-3-4c4-2 6-5 6-9 0-5-6-9-14-9z'/%3E%3Cpath d='M150 45l3-7 3 7 7 3-7 3-3 7-3-7-7-3z'/%3E%3Cpath d='M40 95c0-5 4-9 9-9s9 4 9 9-4 9-9 9v6'/%3E%3Cpath d='M120 120l7 7m0-7l-7 7'/%3E%3Cpath d='M20 150c8 0 14-6 14-14'/%3E%3Cpath d='M80 160h24M92 148v24'/%3E%3Cpath d='M160 140a10 10 0 1 0-20 0 10 10 0 0 0 20 0z'/%3E%3C/g%3E%3C/svg%3E");
}

[data-theme="dark"] {
  --accent: #00a884;
  --accent-strong: #00a884;
  --accent-soft: #005c4b;

  --panel: #111b21;
  --panel-2: #202c33;
  --panel-3: #182229;
  --border: #222d34;
  --text: #e9edef;
  --text-2: #8696a0;
  --text-3: #667781;

  --chat-bg: #0b141a;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --bubble-text: #e9edef;
  --bubble-meta: #a6becb;
  --day-bg: #182229;

  --hover: #202c33;
  --active: #2a3942;
  --danger: #f15c6d;
  --danger-soft: #3b1a22;

  --shadow-sm: 0 1px 0.5px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);

  --doodle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='none' stroke='%23e9edef' stroke-opacity='0.03' stroke-width='1.4' stroke-linecap='round'%3E%3Ccircle cx='30' cy='30' r='9'/%3E%3Cpath d='M95 22c-6 0-10 4-10 9 0 6 5 9 10 9h11l-3-4c4-2 6-5 6-9 0-5-6-9-14-9z'/%3E%3Cpath d='M150 45l3-7 3 7 7 3-7 3-3 7-3-7-7-3z'/%3E%3Cpath d='M40 95c0-5 4-9 9-9s9 4 9 9-4 9-9 9v6'/%3E%3Cpath d='M120 120l7 7m0-7l-7 7'/%3E%3Cpath d='M20 150c8 0 14-6 14-14'/%3E%3Cpath d='M80 160h24M92 148v24'/%3E%3Cpath d='M160 140a10 10 0 1 0-20 0 10 10 0 0 0 20 0z'/%3E%3C/g%3E%3C/svg%3E");
}

/* ------------------------------ base ----------------------------------- */

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: #d1d7db;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

[data-theme="dark"] body { background: #0b141a; }

[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace; font-size: 11.5px; }
.muted { color: var(--text-2); }
.dot { color: var(--text-3); }
.spacer { flex: 1; }

.icon {
  width: 22px;
  height: 22px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button { font: inherit; color: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection { background: rgba(0, 168, 132, 0.25); }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(134, 150, 160, 0.45) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: rgba(134, 150, 160, 0.45); border-radius: 6px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------ shell ---------------------------------- */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  max-width: 1800px;
  margin: 0 auto;
  background: var(--panel);
  box-shadow: 0 8px 40px rgba(11, 20, 26, 0.18);
  overflow: hidden;
}

.panel {
  width: var(--panel-width);
  flex: 0 0 var(--panel-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  position: relative;
  z-index: 2;
}

/* --------------------------- chat list panel --------------------------- */

.panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  min-height: 60px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--avatar, #dfe5e7);
  color: var(--avatar-ink, #54656f);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  border: none;
  user-select: none;
  overflow: visible;
}

.avatar--me {
  width: 40px;
  height: 40px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.avatar--me:hover { border-color: var(--accent); }
.avatar--lg { width: 49px; height: 49px; font-size: 18px; }
.avatar--xl { width: 96px; height: 96px; font-size: 34px; }

.presence {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #8696a0;
  border: 2px solid var(--panel);
  transition: background 0.2s;
}
.presence.is-online { background: #25d366; }
.chat__peer .presence { border-color: var(--panel-2); }

.panel__brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.panel__brand strong { font-size: 16px; font-weight: 600; letter-spacing: 0.01em; }
.panel__brand span {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.panel__actions {
  margin-left: auto;
  display: flex;
  gap: 2px;
  color: var(--text-2);
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { background: var(--active); }

.panel__search {
  padding: 7px 12px 8px;
  background: var(--panel);
  flex: 0 0 auto;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 12px;
  background: var(--panel-2);
  border-radius: 8px;
  color: var(--text-2);
}
.search .icon { width: 18px; height: 18px; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
  color: var(--text);
}
.search input::placeholder { color: var(--text-2); }

.panel__list {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 8px;
  background: var(--panel);
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}
.chat-item:hover { background: var(--hover); }
.chat-item.is-active { background: var(--active); }
.chat-item.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  width: 3px;
  height: 46px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.chat-item { position: relative; }

.chat-item__main { flex: 1; min-width: 0; }
.chat-item__row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.chat-item__row--bottom { margin-top: 3px; align-items: center; }
.chat-item__name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item__time {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--text-2);
}
.chat-item.is-unread .chat-item__time { color: var(--accent); font-weight: 600; }
.chat-item__preview {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item__preview .icon { width: 16px; height: 16px; flex: 0 0 auto; }
.chat-item__preview .ticks { flex: 0 0 auto; }
.chat-item__preview .preview-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item.is-typing .chat-item__preview { color: var(--accent); font-style: italic; }

.badge {
  flex: 0 0 auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.panel__foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  font-size: 12px;
  color: var(--text-2);
}

.conn { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.conn__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f0a83a;
  flex: 0 0 auto;
  box-shadow: 0 0 0 3px rgba(240, 168, 58, 0.15);
}
.conn.is-online .conn__dot { background: #25d366; box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15); }
.conn.is-offline .conn__dot { background: #f15c6d; box-shadow: 0 0 0 3px rgba(241, 92, 109, 0.15); }

.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.link:hover { text-decoration: underline; }

.panel__empty {
  padding: 36px 24px;
  text-align: center;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.panel__empty .icon { width: 40px; height: 40px; opacity: 0.4; }
.panel__empty p { margin: 0; font-size: 14px; line-height: 1.5; }

.fab {
  display: none;
  position: fixed;
  right: 18px;
  bottom: calc(74px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  z-index: 24;
  place-items: center;
}
.fab .icon { width: 25px; height: 25px; }
.fab:active { transform: scale(0.95); }

/* --------------------------- welcome / chat ---------------------------- */

.chat {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--chat-bg);
  background-image: var(--doodle);
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  gap: 10px;
  border-bottom: 5px solid var(--accent);
  background: var(--panel-2);
  background-image: none;
}
.welcome__logo { margin-bottom: 8px; }
.logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 168, 132, 0.35);
}
.logo svg { width: 68%; height: 68%; display: block; }
.logo--xl { width: 110px; height: 110px; }

.welcome h1 {
  margin: 6px 0 0;
  font-size: clamp(24px, 2.4vw, 32px);
  font-weight: 300;
  letter-spacing: -0.01em;
  color: var(--text);
}
.welcome__text {
  margin: 2px 0 26px;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.6;
}
.welcome__hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
  font-size: 12.5px;
  border-top: 1px solid var(--border);
  padding-top: 22px;
  margin-bottom: 4px;
}
.welcome__hint .icon { width: 15px; height: 15px; }
.welcome__foot {
  position: absolute;
  bottom: 20px;
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
}

.chat__view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 60px;
  padding: 6px 12px 6px 14px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 12;
}

.chat__back { display: none; }

.chat__peer {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  padding: 4px 8px 4px 2px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  min-width: 0;
  flex: 1;
}
.chat__peer:hover { background: rgba(11, 20, 26, 0.05); }
[data-theme="dark"] .chat__peer:hover { background: rgba(255, 255, 255, 0.05); }

.chat__peerText {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.chat__peerText strong {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat__peerText small {
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat__peerText small.is-typing { color: var(--accent); }
.chat__peerText small.is-direct { color: var(--accent); }

.chat__tools { display: flex; gap: 2px; color: var(--text-2); }

.menu {
  position: absolute;
  top: 54px;
  right: 12px;
  min-width: 190px;
  padding: 6px 0;
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  overflow: hidden;
  animation: pop 0.12s ease-out;
}
.menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 20px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.menu button:hover { background: var(--hover); }
.menu button .icon { width: 18px; height: 18px; color: var(--text-2); }
.menu button.danger { color: var(--danger); }
.menu button.danger .icon { color: var(--danger); }

.chat__searchbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  z-index: 11;
}
.chat__searchbar .icon { width: 18px; height: 18px; flex: 0 0 auto; }
.chat__searchbar input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
  color: var(--text);
  min-width: 0;
}
.chat__searchcount { font-size: 12px; color: var(--text-2); white-space: nowrap; }

/* ------------------------------ messages -------------------------------- */

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px clamp(16px, 6%, 64px) 14px;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.messages.is-drag {
  outline: 2px dashed var(--accent);
  outline-offset: -10px;
  background-color: rgba(0, 168, 132, 0.07);
}

.day {
  align-self: center;
  margin: 14px 0 10px;
  padding: 5px 12px;
  border-radius: 7px;
  background: var(--day-bg);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 2;
}

.msg {
  display: flex;
  width: 100%;
  margin: 1px 0;
}
.msg--out { justify-content: flex-end; }
.msg--in { justify-content: flex-start; }

.bubble {
  position: relative;
  max-width: min(68ch, 78%);
  padding: 6px 9px 8px 9px;
  border-radius: 8px;
  background: var(--bubble-in);
  color: var(--bubble-text);
  box-shadow: var(--shadow-sm);
  font-size: 14.3px;
  line-height: 19px;
}
.bubble::after { content: ""; display: block; clear: both; }
.bubble::before {
  content: "";
  position: absolute;
  top: 0;
  width: 9px;
  height: 13px;
  background: var(--bubble-in);
}
.msg--in .bubble { border-top-left-radius: 0; }
.msg--in .bubble::before { left: -8px; clip-path: polygon(100% 0, 100% 100%, 0 0); }
.msg--out .bubble { background: var(--bubble-out); border-top-right-radius: 0; }
.msg--out .bubble::before { right: -8px; background: var(--bubble-out); clip-path: polygon(0 0, 100% 0, 0 100%); }

.msg.is-first-in-group .bubble { border-top-left-radius: 8px; }
.msg.is-first-in-group.msg--out .bubble { border-top-right-radius: 8px; }

.bubble__text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }

.bubble__meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 8px -2px -4px 10px;
  color: var(--bubble-meta);
  font-size: 11px;
  line-height: 15px;
  white-space: nowrap;
  user-select: none;
}

.ticks {
  width: 16px;
  height: 11px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--bubble-meta);
  vertical-align: -1px;
}
.ticks.is-read { color: var(--tick-blue); }
.ticks.is-pending { color: var(--bubble-meta); opacity: 0.75; }

.msg--out .bubble.is-pending { opacity: 0.9; }

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-2);
  padding: 40px 20px;
  max-width: 360px;
}
.chat-empty .logo { margin: 0 auto 16px; width: 64px; height: 64px; }
.chat-empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 6px; }
.chat-empty p { margin: 0; font-size: 13.5px; line-height: 1.6; }

/* file bubbles */
.bubble--file { min-width: 220px; }
.file { display: flex; align-items: center; gap: 11px; }
.file__icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(0, 168, 132, 0.12);
  color: var(--accent-strong);
  flex: 0 0 auto;
}
.file__icon .icon { width: 22px; height: 22px; }
.file__body { min-width: 0; flex: 1; }
.file__name {
  font-size: 13.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 210px;
}
.file__sub { font-size: 11.5px; color: var(--bubble-meta); margin-top: 2px; }
.file__download {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  border: 0;
}
.file__download:hover { background: rgba(0, 0, 0, 0.12); }
.file__download .icon { width: 18px; height: 18px; }

.file__progress {
  height: 4px;
  margin-top: 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.09);
  overflow: hidden;
}
[data-theme="dark"] .file__progress { background: rgba(255, 255, 255, 0.14); }
.file__progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.2s linear;
}
.file__status { font-size: 11px; color: var(--bubble-meta); margin-top: 5px; }

.file__media {
  display: block;
  width: 100%;
  max-width: 320px;
  max-height: 320px;
  object-fit: cover;
  border-radius: 6px;
  margin-top: 4px;
  background: rgba(0, 0, 0, 0.05);
}

/* jump-to-bottom */
.jump {
  position: absolute;
  right: 22px;
  bottom: 84px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: var(--panel);
  color: var(--text-2);
  box-shadow: var(--shadow-md);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 8;
}
.jump .icon { width: 20px; height: 20px; }
.jump span:not(:empty) {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

/* ------------------------------ composer -------------------------------- */

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel-2);
  position: relative;
  z-index: 10;
}

.composer__attach { color: var(--text-2); }

.composer__box {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 4px 5px;
  background: var(--panel);
  border-radius: 9px;
  box-shadow: var(--shadow-sm);
}
.composer__box .icon-btn { width: 36px; height: 36px; }
.composer__box .icon-btn .icon { width: 21px; height: 21px; }

#msgInput {
  flex: 1;
  min-width: 0;
  max-height: 130px;
  padding: 8px 2px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 20px;
}
#msgInput::placeholder { color: var(--text-2); }

.send {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.send .icon { width: 23px; height: 23px; margin-left: 2px; }
.send:hover { background: var(--accent-strong); }
.send:active { transform: scale(0.94); }
.send:disabled {
  background: var(--panel-3);
  color: var(--text-3);
  cursor: default;
  box-shadow: none;
}

/* ------------------------------- login ---------------------------------- */

.login {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(1000px 600px at 20% 10%, rgba(0, 168, 132, 0.18), transparent 60%),
    linear-gradient(135deg, #0b141a 0%, #111b21 45%, #0b141a 100%);
  overflow-y: auto;
}

.login__card {
  display: grid;
  grid-template-columns: 1.02fr 0.98fr;
  width: 100%;
  max-width: 900px;
  background: var(--panel);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
  animation: rise 0.35s ease-out;
}

.login__art {
  position: relative;
  overflow: hidden;
  padding: 48px 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  color: #fff;
  background: linear-gradient(150deg, #00a884 0%, #008069 55%, #006e5b 100%);
}
.login__art::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--doodle);
  opacity: 0.22;
  pointer-events: none;
}
.login__art > * { position: relative; z-index: 1; }
.login__art .logo {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: none;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.login__art h2 {
  font-size: 26px;
  line-height: 1.25;
  font-weight: 600;
  margin: 6px 0 0;
}
.login__art p { margin: 0; font-size: 14px; line-height: 1.6; opacity: 0.9; }

.login__points {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login__points li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.45;
  opacity: 0.95;
}
.login__points .icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin-top: 1px;
  color: #fff;
}

.login__form {
  padding: 52px 46px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login__form h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.login__sub { margin: 8px 0 28px; color: var(--text-2); font-size: 14px; line-height: 1.5; }
.login__meta { min-height: 18px; margin: 12px 0 0; font-size: 12.5px; color: var(--danger); }
.login__foot {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
}

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field span { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.field input {
  height: 46px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  outline: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.12); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s, opacity 0.15s;
  white-space: nowrap;
}
.btn .icon { width: 17px; height: 17px; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn--ghost { background: var(--panel-2); color: var(--text); }
.btn--ghost:hover:not(:disabled) { background: var(--hover); }
.btn--danger { background: var(--danger-soft); color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn--block { width: 100%; }
#loginForm .btn { height: 48px; font-size: 15px; margin-top: 4px; }

/* ------------------------------- modal ---------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(11, 20, 26, 0.55);
  backdrop-filter: blur(2px);
  animation: fade 0.15s ease-out;
}
.modal__card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 22px 24px 20px;
  animation: rise 0.2s ease-out;
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
}
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal__head h2 { margin: 0; font-size: 19px; font-weight: 600; }
.modal__card > p.muted { margin: 0 0 16px; font-size: 13.5px; line-height: 1.55; }
.modal__hint {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 12px;
}
.modal__hint .icon { width: 14px; height: 14px; flex: 0 0 auto; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal__actions .btn { min-width: 96px; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}
.tab {
  flex: 1;
  height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab.is-active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }

.tabpane .btn--block { margin-top: 14px; }

.codebox { text-align: center; }
.codebox__code {
  margin: 8px 0 4px;
  padding: 16px 8px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 10px;
  text-indent: 10px;
  font-variant-numeric: tabular-nums;
}
.codebox__timer { margin: 4px 0 12px; font-size: 12.5px; color: var(--text-2); }
.codebox__actions { display: flex; gap: 8px; justify-content: center; }
.codebox__actions .btn { height: 38px; font-size: 13px; }

.code-input {
  width: 100%;
  height: 58px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  text-align: center;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 12px;
  text-indent: 12px;
  font-variant-numeric: tabular-nums;
  outline: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.code-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.12); }
.code-input::placeholder { color: var(--text-3); font-weight: 400; }

/* ------------------------------ drawers --------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 240;
  background: rgba(11, 20, 26, 0.45);
  backdrop-filter: blur(1px);
  animation: fade 0.15s ease-out;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(390px, 100vw);
  z-index: 250;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.25);
  transform: translateX(102%);
  transition: transform 0.22s cubic-bezier(0.32, 0.72, 0.28, 1);
  visibility: hidden;
}
.drawer.is-open { transform: translateX(0); visibility: visible; }

.drawer__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 14px 22px;
  background: var(--panel-2);
  min-height: 64px;
}
.drawer__head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.drawer__body { padding: 24px 20px 28px; overflow-y: auto; flex: 1; }

.profile { text-align: center; margin-bottom: 26px; }
.profile .avatar { margin: 0 auto 12px; }
.profile h3 { margin: 0 0 4px; font-size: 19px; font-weight: 500; }
.profile p { margin: 0; }

.card {
  background: var(--panel-2);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h4 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}
.kv { margin: 0 0 12px; display: flex; flex-direction: column; gap: 9px; }
.kv > div { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.kv dt { margin: 0; font-size: 12.5px; color: var(--text-2); flex: 0 0 auto; }
.kv dd { margin: 0; font-size: 12.5px; text-align: right; overflow-wrap: anywhere; }
.card .btn { height: 38px; font-size: 13px; }
.hint { margin: 10px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--text-3); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 11px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}
.row:last-child { border-bottom: 0; }
.row > span:last-child { color: var(--text-2); font-size: 12.5px; }
.row:hover > span:last-child { color: var(--accent); }

.drawer__body > .btn--danger { margin-top: 4px; }

/* contact drawer card */
.contact-hero { text-align: center; margin-bottom: 22px; }
.contact-hero .avatar { margin: 0 auto 12px; }
.contact-hero h3 { margin: 0 0 4px; font-size: 20px; font-weight: 500; }
.contact-hero p { margin: 0; font-size: 13px; color: var(--text-2); }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 11.5px;
  color: var(--text-2);
}
.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8696a0;
}
.status-pill.is-online::before { background: #25d366; }

.addr-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0, 168, 132, 0.12);
  color: var(--accent-strong);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
[data-theme="dark"] .addr-badge { color: #7ce6c8; }

.contact-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.contact-actions .btn { width: 100%; height: 40px; font-size: 13.5px; justify-content: flex-start; padding-left: 14px; }
.contact-actions .btn--danger { justify-content: flex-start; }

/* ------------------------------- toasts --------------------------------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  padding: 10px 18px;
  border-radius: 8px;
  background: #323739;
  color: #fff;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s ease-out;
  max-width: 100%;
  text-align: center;
}
.toast.is-error { background: #b3261e; }
.toast.is-success { background: #0f6f5c; }
.toast.is-out { animation: toast-out 0.2s ease-in forwards; }

/* ------------------------------- emoji ---------------------------------- */

.emoji-pop {
  position: fixed;
  z-index: 350;
  width: min(320px, calc(100vw - 24px));
  max-height: 260px;
  overflow-y: auto;
  padding: 10px;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  animation: pop 0.12s ease-out;
}
.emoji {
  border: 0;
  background: transparent;
  border-radius: 7px;
  font-size: 21px;
  line-height: 1;
  padding: 6px 0;
  cursor: pointer;
}
.emoji:hover { background: var(--hover); }

/* ----------------------------- animations ------------------------------- */

@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.99); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------ responsive ------------------------------ */

@media (max-width: 860px) {
  body { background: var(--panel); }

  .app { max-width: none; box-shadow: none; }

  .panel__head,
  .chat__head {
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  #msgInput,
  .field input,
  .code-input {
    font-size: 16px; /* avoid automatic zoom on iOS */
  }

  .panel {
    width: 100%;
    flex: 1 1 100%;
    border-right: 0;
  }

  .chat {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: none;
  }
  .app.chat-open .chat { display: flex; }
  .app.chat-open .panel { display: none; }

  .chat__back { display: inline-flex; }

  .welcome { border-bottom-width: 4px; }
  .welcome__foot { position: static; margin-top: 24px; }

  .messages { padding: 12px 14px 10px; }
  .bubble { max-width: 84%; font-size: 14px; }

  .composer { padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 4px; }
  .send { width: 44px; height: 44px; }
  .composer__box .icon-btn { width: 34px; height: 34px; }

  .jump { right: 14px; bottom: 74px; }
  .toasts { bottom: 80px; }
  .fab { display: grid; }

  .login { padding: 0; align-items: stretch; }
  .login__card {
    grid-template-columns: 1fr;
    max-width: none;
    border-radius: 0;
    min-height: 100dvh;
  }
  .login__art { padding: 30px 26px 26px; gap: 8px; }
  .login__art h2 { font-size: 21px; }
  .login__art p { font-size: 13px; }
  .login__points { display: none; }
  .login__art .logo { width: 64px; height: 64px; margin-bottom: 2px; }
  .login__form { padding: 30px 24px 40px; }

  .modal { padding: 12px; align-items: end; }
  .modal__card { max-width: none; border-radius: 16px 16px 12px 12px; }
}

@media (max-width: 380px) {
  .panel__brand span { max-width: 90px; }
  .panel__head { padding: 8px 10px; }
  .chat-item { padding: 9px 12px; }
  .codebox__code { font-size: 28px; letter-spacing: 7px; text-indent: 7px; }
}

@media (min-width: 861px) and (max-width: 1100px) {
  :root { --panel-width: 340px; }
  .messages { padding-left: 5%; padding-right: 5%; }
}
