/* Baatchit — WhatsApp-style design. Light by default, dark follows the system. */
:root {
  color-scheme: light dark;
  /* ---- light theme (WhatsApp default look) ---- */
  --bg: #ffffff;
  --bg-2: #ffffff;
  --bg-3: #f0f2f5;
  --bg-4: #f5f6f6;
  --line: #e9edef;
  --text: #111b21;
  --text-dim: #667781;
  --accent: #00a884;
  --accent-bright: #25d366;
  --accent-dark: #017561;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --bubble-meta: rgba(17, 27, 33, .45);
  --chip: rgba(255, 255, 255, .92);
  --paper: #efeae2;
  --composer: #ffffff;
  --danger: #f15c6d;
  --warn: #f0b232;
  --shadow: 0 8px 28px rgba(11, 20, 26, .16);
  --radius: 12px;
  --radius-sm: 8px;
  --side-w: 30%;
  --wall: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260'%3E%3Cg fill='none' stroke='%23000000' stroke-opacity='.05' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 38h56a10 10 0 0 1 10 10v18a10 10 0 0 1-10 10H50l-14 12v-12H22a10 10 0 0 1-10-10V48a10 10 0 0 1 10-10Z'/%3E%3Cpath d='M150 58c-10-8-20-16-20-24a10 10 0 0 1 20-4 10 10 0 0 1 20 4c0 8-10 16-20 24Z'/%3E%3Ccircle cx='232' cy='52' r='14'/%3E%3Cpath d='M226 62a7 7 0 0 0 12 0M226 47v2M238 47v2'/%3E%3Cpath d='M56 128c0 14 10 24 24 24l6-10-10-8-6 4c-4-4-6-6-10-10l4-6-8-10c-6 4-10 10-10 16Z'/%3E%3Crect x='160' y='150' width='44' height='30' rx='7'/%3E%3Ccircle cx='182' cy='165' r='9'/%3E%3Cpath d='M170 150l4-6h20l4 6'/%3E%3Cpath d='M90 208v22M79 219h22'/%3E%3Ccircle cx='206' cy='226' r='5'/%3E%3Cpath d='M211 226v-20l10-4'/%3E%3C/g%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    /* ---- dark theme (WhatsApp dark) ---- */
    --bg: #0b141a;
    --bg-2: #111b21;
    --bg-3: #202c33;
    --bg-4: #2a3942;
    --line: #22343d;
    --text: #e9edef;
    --text-dim: #8696a0;
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --bubble-meta: rgba(233, 237, 239, .6);
    --chip: rgba(32, 44, 51, .85);
    --paper: #0b141a;
    --composer: #202c33;
    --shadow: 0 8px 28px rgba(0, 0, 0, .45);
    --wall: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.035' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 38h56a10 10 0 0 1 10 10v18a10 10 0 0 1-10 10H50l-14 12v-12H22a10 10 0 0 1-10-10V48a10 10 0 0 1 10-10Z'/%3E%3Cpath d='M150 58c-10-8-20-16-20-24a10 10 0 0 1 20-4 10 10 0 0 1 20 4c0 8-10 16-20 24Z'/%3E%3Ccircle cx='232' cy='52' r='14'/%3E%3Cpath d='M226 62a7 7 0 0 0 12 0M226 47v2M238 47v2'/%3E%3Cpath d='M56 128c0 14 10 24 24 24l6-10-10-8-6 4c-4-4-6-6-10-10l4-6-8-10c-6 4-10 10-10 16Z'/%3E%3Crect x='160' y='150' width='44' height='30' rx='7'/%3E%3Ccircle cx='182' cy='165' r='9'/%3E%3Cpath d='M170 150l4-6h20l4 6'/%3E%3Cpath d='M90 208v22M79 219h22'/%3E%3Ccircle cx='206' cy='226' r='5'/%3E%3Cpath d='M211 226v-20l10-4'/%3E%3C/g%3E%3C/svg%3E");
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--text-dim); }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.center { text-align: center; }

/* ------------------------------------------------------------- buttons */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 11px 20px;
  background: var(--bg-3);
  cursor: pointer;
  transition: filter .15s ease, transform .1s ease;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.round { min-width: 108px; }
.btn.accept { background: var(--accent); color: #fff; }
.btn.end { background: var(--danger); color: #fff; }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--bg-4); color: var(--text); }
.icon-btn.close { position: absolute; top: 10px; right: 10px; }

/* Green circular send button, WhatsApp-style. */
.icon-btn.send {
  background: var(--accent);
  color: #fff;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
.icon-btn.send:hover { background: var(--accent-dark); color: #fff; }

input, textarea, select {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--text-dim); }

/* ---------------------------------------------------------------- auth */
.auth-body { display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(420px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card.wide { width: min(620px, 100%); }
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-logo-img {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin: 0 auto 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.auth-brand h1 { margin: 0 0 6px; font-size: 22px; }
.auth-step .btn { width: 100%; margin-top: 16px; }
.phone-row { display: flex; align-items: center; gap: 8px; background: var(--bg-3); border-radius: var(--radius-sm); padding-left: 12px; }
.phone-row .cc { color: var(--text-dim); }
.phone-row input { background: transparent; }
#code { letter-spacing: .5em; text-align: center; font-size: 20px; }
.hint { font-size: 13px; color: var(--text-dim); margin: 12px 0 0; }
.auth-foot { font-size: 12px; text-align: center; margin-top: 20px; }

.alert { border-radius: var(--radius-sm); padding: 12px 14px; margin: 12px 0; }
.alert.bad { background: rgba(241, 92, 109, .12); border: 1px solid rgba(241, 92, 109, .4); }
.alert.ok { background: rgba(0, 168, 132, .12); border: 1px solid rgba(0, 168, 132, .4); }
.req ul { list-style: none; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.req li.ok { color: var(--accent); }
.req li.bad { color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.steps { padding-left: 18px; font-size: 14px; color: var(--text-dim); }
code { background: var(--bg-3); padding: 2px 6px; border-radius: 5px; font-size: 13px; }

/* --------------------------------------------------------------- shell */
.app-body { overflow: hidden; }
/* --app-height tracks the visual viewport so the composer stays above the
   keyboard, including inside the installed app. */
.shell { display: grid; grid-template-columns: minmax(300px, var(--side-w)) 1fr; height: var(--app-height, 100dvh); }

.sidebar { position: relative; display: flex; flex-direction: column; background: var(--bg-2); border-right: 1px solid var(--line); min-width: 0; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--bg-3); }
.side-title { font-weight: 700; flex: 1; }
.side-actions { display: flex; }
.side-search { padding: 8px 12px; }
.side-search input { background: var(--bg-3); border-radius: 999px; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-4) center/cover no-repeat;
  display: inline-grid; place-items: center;
  font-size: 15px; font-weight: 600; color: var(--text-dim);
  flex: 0 0 auto;
}
.avatar.xl { width: 96px; height: 96px; font-size: 32px; }
.avatar-btn { border: 0; background: none; padding: 0; cursor: pointer; }

.chat-list { flex: 1; overflow-y: auto; scrollbar-width: thin; }
.chat-row {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 10px;
  align-items: center; padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left;
}
.chat-row:hover { background: var(--bg-4); }
.chat-row[aria-current="true"] { background: var(--bg-4); }
.chat-row .row-main { min-width: 0; }
.chat-row .row-top { display: flex; justify-content: space-between; gap: 8px; }
.chat-row strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .preview { color: var(--text-dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row time { color: var(--text-dim); font-size: 12px; flex: 0 0 auto; }
.badge {
  background: var(--accent-bright); color: #fff; border-radius: 999px;
  min-width: 20px; padding: 1px 6px; font-size: 12px; font-weight: 700; text-align: center;
}
.pin { color: var(--text-dim); font-size: 12px; }
.empty { color: var(--text-dim); padding: 24px 16px; text-align: center; font-size: 14px; }
.conn-strip { background: var(--warn); color: #2a1d00; font-size: 13px; text-align: center; padding: 6px; }
.notice-bar { display: block; width: 100%; border: 0; cursor: pointer; background: var(--accent-bright); color: #fff; font-weight: 600; }
.notice-bar[hidden] { display: none !important; }

/* Floating new-chat button, WhatsApp-style. */
.fab {
  display: none;
  position: absolute;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 16px;
  background: var(--accent-bright);
  color: #fff;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .3);
  z-index: 40;
  transition: transform .12s ease;
}
.fab:active { transform: scale(.94); }

/* -------------------------------------------------------- conversation */
.conversation {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background-image: var(--wall);
  background-color: var(--paper);
  background-size: 360px auto;
}
.conversation.empty-state { display: grid; place-items: center; }
.welcome { text-align: center; max-width: 380px; padding: 0 20px; }
.welcome h2 { color: var(--text); }
.welcome p { color: var(--text-dim); }

.conv-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg-3); border-bottom: 1px solid var(--line); }
.conv-meta { flex: 1; min-width: 0; display: grid; }
.conv-meta strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta small { color: var(--text-dim); font-size: 12px; }
.conv-actions { display: flex; }
.only-mobile { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px 6vw 8px; display: flex; flex-direction: column; gap: 3px; }
.msg { max-width: min(78%, 560px); padding: 7px 10px 6px; border-radius: var(--radius); position: relative; word-wrap: break-word; }
.msg.in { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 2px; box-shadow: 0 1px 1px rgba(11, 20, 26, .08); }
.msg.out { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 2px; box-shadow: 0 1px 1px rgba(11, 20, 26, .08); }
/* WhatsApp bubble tails. */
.msg.in::before {
  content: ""; position: absolute; top: 0; left: -8px; width: 8px; height: 13px;
  background: var(--bubble-in); clip-path: polygon(0 0, 100% 0, 100% 100%);
}
.msg.out::after {
  content: ""; position: absolute; top: 0; right: -8px; width: 8px; height: 13px;
  background: var(--bubble-out); clip-path: polygon(0 0, 100% 0, 0 100%);
}
.msg.system { align-self: center; background: var(--chip); color: var(--text-dim); font-size: 12.5px; border-radius: 999px; padding: 4px 14px; box-shadow: 0 1px 1px rgba(11, 20, 26, .06); }
.msg .author { font-size: 12.5px; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; }
.msg .meta { display: flex; gap: 5px; align-items: center; justify-content: flex-end; font-size: 11px; color: var(--bubble-meta); margin-top: 2px; }
.msg .ticks.read { color: #53bdeb; }
.msg.deleted .text { font-style: italic; color: var(--text-dim); }
.msg img.media { max-width: 100%; border-radius: var(--radius-sm); display: block; cursor: zoom-in; }
.msg audio, .msg video { max-width: 100%; border-radius: var(--radius-sm); }
.msg .doc { display: flex; gap: 10px; align-items: center; background: rgba(0, 0, 0, .18); padding: 9px 11px; border-radius: var(--radius-sm); color: inherit; text-decoration: none; }
.msg .quote { border-left: 3px solid var(--accent); background: rgba(0, 0, 0, .2); padding: 4px 8px; border-radius: 5px; margin-bottom: 4px; font-size: 13px; }
.msg-actions { position: absolute; top: 2px; right: 4px; display: none; gap: 2px; }
.msg:hover .msg-actions { display: flex; }
.msg-actions button { border: 0; background: rgba(0, 0, 0, .35); color: #fff; border-radius: 5px; font-size: 11px; padding: 2px 6px; cursor: pointer; }
.day-sep { align-self: center; background: var(--chip); color: var(--text-dim); font-size: 12px; padding: 3px 12px; border-radius: 999px; margin: 10px 0 4px; box-shadow: 0 1px 1px rgba(11, 20, 26, .06); }

.typing-line { padding: 2px 6vw 6px; font-size: 13px; color: var(--accent); }

/* WhatsApp-style composer: pill input + green send circle over the wallpaper. */
.conv-foot { flex: 0 0 auto; background: transparent; padding-bottom: env(safe-area-inset-bottom); }
.composer { padding: 4px 10px 10px; background: transparent; }
.composer-row {
  display: flex; align-items: flex-end; gap: 4px;
  background: var(--composer);
  border-radius: 999px;
  padding: 4px 5px 4px 6px;
  box-shadow: 0 1px 3px rgba(11, 20, 26, .12);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; border-radius: 999px;
  background: transparent; border: 0; padding: 9px 8px;
}
.composer textarea:focus { border-color: transparent; }
.reply-strip { display: flex; justify-content: space-between; gap: 8px; background: var(--bg-3); border-left: 3px solid var(--accent); padding: 6px 10px; border-radius: 6px; margin-bottom: 8px; font-size: 13px; }
.reply-strip small { display: block; color: var(--accent); }
.upload-bar { margin-top: 8px; font-size: 13px; color: var(--text-dim); }
.recording { color: var(--danger) !important; }

/* ------------------------------------------------------------- dialogs */
.sheet {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  border-radius: 16px; padding: 24px; width: min(460px, 92vw); box-shadow: var(--shadow); position: relative;
}
.sheet::backdrop { background: rgba(0, 0, 0, .6); }
.sheet h2 { margin: 0 0 12px; font-size: 19px; }
.sheet h3 { margin: 18px 0 8px; font-size: 15px; }
.sheet hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.sheet .btn { width: 100%; margin-top: 14px; }
.people { display: grid; gap: 4px; max-height: 44vh; overflow-y: auto; margin-top: 10px; }
.person { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; padding: 8px; border-radius: 10px; cursor: pointer; background: none; border: 0; text-align: left; color: inherit; }
.person:hover { background: var(--bg-3); }
.person small { color: var(--text-dim); display: block; }
.person .pick { color: var(--accent); font-size: 13px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { background: var(--bg-4); border-radius: 999px; padding: 4px 10px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; background: none; color: var(--text-dim); cursor: pointer; }

/* ---------------------------------------------------------------- call */
/* The call screen stays dark in both themes, like WhatsApp. */
.call-overlay { position: fixed; inset: 0; overflow: hidden; background: #0b141a; z-index: 60; isolation: isolate; }
.call-backdrop { position: absolute; inset: -24px; z-index: -1; background: #111b21 center/cover no-repeat; filter: blur(24px) brightness(.34); transform: scale(1.12); }
.call-overlay::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(to bottom, rgba(6, 12, 15, .24), rgba(6, 12, 15, .45) 55%, rgba(6, 12, 15, .92)); }
.call-content { position: relative; z-index: 3; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: max(48px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom)); color: #e9edef; }
.call-person { display: grid; justify-items: center; gap: 9px; text-align: center; }
.call-avatar { width: clamp(132px, 30vw, 220px); height: clamp(132px, 30vw, 220px); font-size: clamp(42px, 9vw, 72px); box-shadow: 0 18px 55px rgba(0, 0, 0, .34); background-color: #2a3942; color: #8696a0; }
.call-person strong { font-size: clamp(25px, 5vw, 34px); font-weight: 600; }
.call-person #call-state { color: #e9edef; opacity: .8; }
.call-media { position: absolute; inset: 0; z-index: 1; background: #05090b; }
.call-overlay[data-media="audio"] .call-media, .call-overlay[data-incoming="true"] .call-media { display: none; }
.call-video.remote { width: 100%; height: 100%; object-fit: cover; background: #05090b; }
.call-preview { position: absolute; z-index: 4; top: max(18px, env(safe-area-inset-top)); right: 16px; width: clamp(105px, 25vw, 180px); aspect-ratio: 3 / 4; padding: 0; overflow: hidden; border: 2px solid rgba(255, 255, 255, .8); border-radius: 12px; background: #202c33; box-shadow: var(--shadow); cursor: pointer; }
.call-preview .local { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.call-media.swapped .remote { position: absolute; z-index: 4; top: max(18px, env(safe-area-inset-top)); right: 16px; width: clamp(105px, 25vw, 180px); height: auto; aspect-ratio: 3 / 4; object-fit: cover; border: 2px solid rgba(255, 255, 255, .8); border-radius: 12px; box-shadow: var(--shadow); }
.call-media.swapped .call-preview { inset: 0; width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; box-shadow: none; }
.call-overlay[data-media="video"][data-incoming="false"] .call-backdrop, .call-overlay[data-media="video"][data-incoming="false"] .call-avatar { display: none; }
.call-overlay[data-media="video"] .call-content { pointer-events: none; justify-content: space-between; background: linear-gradient(to bottom, rgba(0, 0, 0, .44), transparent 26%, transparent 58%, rgba(0, 0, 0, .72)); }
.call-overlay[data-media="video"] .call-person { align-self: flex-start; justify-items: start; }
.call-overlay[data-media="video"] .call-person strong { font-size: 21px; }
.call-overlay[data-media="video"] .call-buttons, .call-overlay[data-media="video"] .call-control { pointer-events: auto; }
.call-buttons { display: flex; gap: clamp(10px, 3vw, 22px); width: 100%; justify-content: center; align-items: flex-start; }
.call-control { width: 66px; padding: 0; border: 0; background: transparent; color: #e9edef; display: grid; justify-items: center; gap: 7px; cursor: pointer; }
.call-control-icon { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 50%; background: rgba(255, 255, 255, .16); backdrop-filter: blur(12px); transition: transform .15s ease, background .15s ease; }
.call-control:active .call-control-icon { transform: scale(.94); }
.call-control svg { width: 27px; height: 27px; }
.call-control-label { font-size: 12px; text-shadow: 0 1px 3px rgba(0, 0, 0, .7); }
.call-control.active .call-control-icon { background: #e9edef; color: #0b141a; }
.call-control.accept .call-control-icon { background: var(--accent); color: #fff; }
.call-control.end .call-control-icon { background: var(--danger); color: #fff; }
.call-overlay[data-incoming="true"] .call-buttons { justify-content: space-evenly; max-width: 360px; }

/* -------------------------------------------------------------- toasts */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 80; }
.toast { background: var(--bg-4); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); }
.toast.bad { background: rgba(241, 92, 109, .2); border-color: var(--danger); }

/* --------------------------------------------------------------- admin */
.admin-body { overflow-y: auto; }
.admin-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: var(--bg-3); }
.admin-head h1 { font-size: 18px; margin: 0; }
.admin-main { padding: 20px; display: grid; gap: 20px; max-width: 1200px; margin: 0 auto; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--text-dim); font-size: 13px; }
.panel { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-head input { max-width: 260px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
td .btn { padding: 6px 12px; font-size: 13px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; }
.settings-grid label { margin: 0; }
.settings-grid .check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.settings-grid .check input { width: auto; }
.tag { border-radius: 999px; padding: 2px 9px; font-size: 12px; background: var(--bg-4); }
.tag.banned { background: rgba(241, 92, 109, .25); color: var(--danger); }
.tag.online { background: rgba(0, 168, 132, .25); color: var(--accent-dark); }

/* --------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: flex; }
  .conversation { display: none; }
  .shell[data-view="chat"] .sidebar { display: none; }
  .shell[data-view="chat"] .conversation { display: flex; }
  .shell[data-view="chat"] .conversation.empty-state { display: grid; }
  .only-mobile { display: inline-grid; }
  .fab { display: grid; }
  .messages { padding: 12px 12px 6px; }
  .typing-line { padding: 2px 14px 6px; }
  .msg { max-width: 86%; }
  .call-overlay[data-media="video"] .call-buttons { gap: 5px; }
  .call-overlay[data-media="video"] .call-control { width: 57px; }
  .call-overlay[data-media="video"] .call-control-icon { width: 50px; height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}


/* Pull-to-refresh indicator */
#pull-hint {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translate(-50%, -120%);
  z-index: 60;
  padding: 6px 14px;
  border-radius: 0 0 12px 12px;
  background: var(--bg-3);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 6px 18px rgb(0 0 0 / 35%);
  transition: transform 220ms ease;
}
#pull-hint.on { transform: translate(-50%, 0); }

/* ------------------------------------------------- menu, sheets, contacts */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 70;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); min-width: 210px; padding: 6px; display: grid; gap: 2px;
  /* The header forces white text on its children — the popup must reset it
     or its items are white on a white panel. */
  color: var(--text) !important;
}
.menu button, .menu a {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  color: var(--text) !important; font: inherit; padding: 10px 12px; border-radius: 8px; cursor: pointer; text-decoration: none;
}
.menu button:hover, .menu a:hover { background: var(--bg-3); }
.menu .danger { color: var(--danger); }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 80; }
.sheet {
  position: fixed; z-index: 90; top: 50%; left: 50%; transform: translate(-50%, -50%);
  max-height: 88dvh; overflow-y: auto;
}
.sheet .close { position: sticky; top: 0; float: right; z-index: 2; background: var(--bg-2); }
.sheet label { display: block; margin-top: 12px; font-size: 13px; color: var(--text-dim); }
.photo-row { display: grid; grid-template-columns: 72px 1fr; gap: 14px; align-items: center; margin-bottom: 8px; }
.avatar.xl { width: 72px; height: 72px; font-size: 24px; }
.btn.slim { width: auto; margin: 4px 6px 0 0; padding: 7px 12px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.row-btns input { flex: 1 1 130px; }

/* ----------------------------------------- v6: steady layout and extras */

/* Three fixed rows: header, scrolling messages, composer pinned to the bottom. */
.msg-pane { flex: 1 1 auto; min-height: 0; position: relative; display: flex; }
.msg-pane .messages { flex: 1 1 auto; min-height: 0; }

.peer-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; border: 0; color: inherit; text-align: left; padding: 0; cursor: pointer; font: inherit; }
.peer-btn .conv-meta { display: grid; }

.jump-btn { position: absolute; right: 14px; bottom: 12px; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--bg-3); color: var(--text); font-size: 17px; cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); }

.select-bar { background: var(--bg-2); }

.msg.picked { outline: 2px solid var(--accent); }
.msg.flash { animation: flash 1.1s ease-out; }
@keyframes flash { from { background: rgba(0, 168, 132, .55); } }
.msg .fwd { font-size: 12px; color: var(--text-dim); font-style: italic; margin-bottom: 2px; }
.msg .quote { display: flex; gap: 8px; align-items: center; width: 100%; border: 0; border-left: 3px solid var(--accent); color: inherit; text-align: left; cursor: pointer; }
.msg .quote small { display: block; color: var(--accent); font-weight: 600; }
.msg .quote-thumb { width: 38px; height: 38px; object-fit: cover; border-radius: 4px; flex: 0 0 auto; }

.reactions { display: flex; gap: 4px; margin-top: 3px; }
.reaction { border: 0; background: rgba(0, 0, 0, .3); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: 12px; cursor: pointer; }
.reaction.mine { background: var(--accent); color: #fff; }

.react-row { display: flex; gap: 6px; justify-content: space-between; margin: 6px 0 14px; }
.react-pick { border: 0; background: var(--bg-3); border-radius: 50%; width: 42px; height: 42px; font-size: 21px; cursor: pointer; }
.msg-menu { display: grid; gap: 2px; }
.msg-menu button { text-align: left; background: none; border: 0; color: var(--text); font: inherit; padding: 12px 6px; border-radius: 8px; cursor: pointer; }
.msg-menu button:hover { background: var(--bg-3); }
.msg-menu button.danger { color: #f2777a; }

.person.on { background: var(--bg-3); }
.user-card { text-align: center; display: grid; gap: 6px; justify-items: center; }
.user-card h2 { margin: 6px 0 0; }

.msg .ticks { letter-spacing: -3px; margin-left: 4px; }

/* ===== v13: authentic WhatsApp look ===== */
:root { --wa-head: #008069; --wa-head-text: #ffffff; }
@media (prefers-color-scheme: dark) { :root { --wa-head: #1f2c34; --wa-head-text: #e9edef; } }
.side-head, .conv-head { background: var(--wa-head) !important; color: var(--wa-head-text) !important; min-height: 56px; }
.side-head .icon-btn, .conv-head .icon-btn, .conv-head .conv-meta strong, .conv-head .conv-meta small, .side-title { color: var(--wa-head-text) !important; }
.side-title { font-size: 1.25rem; letter-spacing: .2px; }
.conv-head .conv-meta small { opacity: .85; }
.side-search { background: var(--bg-2); }
.side-search input { background: var(--bg-3); border: 0; padding: 9px 16px; }
.chat-list > * { border-bottom: 1px solid var(--line); }
.composer-row { background: transparent !important; gap: 6px; padding: 6px 6px; align-items: flex-end; }
.composer-row textarea { background: var(--composer) !important; border-radius: 24px; padding: 11px 16px; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.composer-row .icon-btn:not(.send) { color: var(--muted, #667781); }
.icon-btn.send { width: 48px; height: 48px; flex: 0 0 48px; background: #00a884 !important; color: #fff !important; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.conv-foot { background: transparent; }
.fab { background: #00a884 !important; color: #fff !important; width: 56px; height: 56px; border-radius: 16px; box-shadow: 0 3px 8px rgba(0,0,0,.25); }
.msg { box-shadow: 0 1px .5px rgba(11,20,26,.13); border-radius: 8px; }

/* ---- swipe to reply, hold menus, media viewer (v14) ---- */

/* Long-press opens our own menus — never the browser copy/paste sheet. */
.msg, .chat-row { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* Slide the bubble right to reveal the reply cue. */
.msg.swiping, .msg.snap { transform: translateX(var(--swipe-x, 0px)); }
.msg.swiping { transition: none; }
.msg.snap { transition: transform .18s ease; }
.swipe-cue { position: absolute; top: 50%; transform: translateY(-50%); opacity: 0; transition: opacity .12s ease; color: var(--accent, #00a884); pointer-events: none; }
.msg.in .swipe-cue, .msg.out .swipe-cue { left: -34px; }

/* Full screen photo/video preview. */
.media-viewer { position: fixed; inset: 0; z-index: 90; background: rgba(11, 20, 26, .97); display: flex; flex-direction: column; }
.media-viewer[hidden] { display: none !important; }
.mv-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: #fff; background: rgba(11, 20, 26, .55); }
.mv-name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-bar .icon-btn { color: #fff; text-decoration: none; }
.mv-stage { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 8px; }
.mv-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.mv-stage video { max-width: 100%; max-height: 100%; width: auto; background: #000; }

/* ------------------------------------------------- voice recording bar */
.rec-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  margin: 6px 4px;
}
.rec-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--danger);
  animation: rec-pulse 1s ease-in-out infinite;
  flex: none;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.8); }
}
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--danger); flex: none; }
.rec-hint { flex: 1; color: var(--text-dim); font-size: 13px; }
.rec-bar .icon-btn.danger { color: var(--danger); }

/* ------------------------------------------------- profile screen */
#profile-screen {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: var(--bg);
  overflow-y: auto;
  display: block;
}
.profile-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--accent-dark);
  color: #fff;
}
.profile-head h2 { margin: 0; font-size: 17px; }
.profile-body {
  max-width: 520px;
  margin: 0 auto;
  padding: 18px 16px 40px;
  display: grid;
  gap: 14px;
  justify-items: center;
}
.profile-photo-btn { display: grid; justify-items: center; gap: 6px; background: none; border: 0; cursor: pointer; padding: 6px; }
.avatar.xxl { width: 132px; height: 132px; font-size: 44px; }
.profile-photo-hint { color: var(--accent); font-size: 13px; font-weight: 600; }
.profile-field { width: 100%; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.profile-field small { color: var(--accent); font-weight: 600; }
.profile-value { display: flex; align-items: center; gap: 8px; min-height: 30px; font-size: 16px; }
.profile-value span { flex: 1; overflow-wrap: anywhere; }
.profile-field input { width: 100%; border: 0; border-bottom: 2px solid var(--accent); background: transparent; padding: 4px 0; font-size: 16px; }

/* ------------------------------------------------- full-page contact info + settings banner */
.sheet.page-sheet {
  inset: 0; top: 0; left: 0; transform: none; width: 100%; max-width: none;
  max-height: none; height: 100dvh; border-radius: 0; padding: 0; z-index: 95;
  background: var(--bg);
}
.page-sheet .u-title { margin: 0; font-size: 22px; text-align: center; }
.page-sheet .u-phone { margin: 0; color: var(--text-dim); font-size: 15px; }
.u-actions { display: flex; gap: 10px; width: 100%; justify-content: center; }
.u-actions button, .u-list button {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--accent);
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 12px;
}
.u-actions button { flex: 1; max-width: 110px; padding: 10px 6px; display: grid; justify-items: center; gap: 4px; }
.u-actions button span { font-size: 20px; }
.u-list { width: 100%; display: grid; gap: 8px; }
.u-list button { text-align: left; padding: 14px 16px; color: inherit; }
.u-list .danger { color: var(--danger); }
.settings-me {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  padding: 8px 0 14px; margin-bottom: 8px; color: inherit; font: inherit; cursor: pointer;
}
.settings-me strong { display: block; font-size: 17px; }
.settings-me small { color: var(--text-dim); }
