/* MaliSMS in the look of the phone's own Messages app (loaded after style.css, so it wins).
   Inbox: big title that shrinks into a slim bar on scroll, round grey avatars, two-line previews, time on the right
   and a small blue unread count. Threads: grey bubbles on the left (senders), light-blue pills on the right (you),
   centred date lines, tappable links, and "Sender can't accept replies" for senders like M-PESA. */
:root, :root[data-theme="dark"] {
  --bg: #1b1b1f; --surface-1: #1b1b1f; --surface-2: #2b2b30; --surface-3: #303036;
  --border: #2f2f35; --border-subtle: #26262b; --text: #e6e1e6; --text-muted: #a9a4ab; --text-faint: #8a858c;
  --gm-blue: #a8c7fa; --gm-blue-text: #062e6f; --gm-recv: #2b2b30; --gm-badge: #a8c7fa; --gm-badge-text: #062e6f;
  --gm-avatar: #3a3a40; --gm-avatar-icon: #c4c0c6; --gm-link: #a8c7fa;
}
:root[data-theme="light"] {
  --bg: #ffffff; --surface-1: #ffffff; --surface-2: #f1f3f4; --surface-3: #e8eaed; --border: #e0e0e0; --border-subtle: #eeeeee;
  --text: #1f1f1f; --text-muted: #5f6368; --text-faint: #80868b;
  --gm-blue: #d3e3fd; --gm-blue-text: #041e49; --gm-recv: #f1f3f4; --gm-badge: #0b57d0; --gm-badge-text: #fff;
  --gm-avatar: #e3e3e3; --gm-avatar-icon: #747775; --gm-link: #0b57d0;
}
body { background: var(--bg); color: var(--text); font-family: "Google Sans", Roboto, "Inter", system-ui, sans-serif; }

/* ── Inbox ─────────────────────────────────────────────────────────────── */
.sidebar { background: var(--bg); border-right-color: var(--border-subtle); }
.sidebar__header { background: var(--bg); border-bottom: 0; }
.sidebar__logo svg, .sidebar__logo img { display: none; }
.sidebar__logo-text { font-size: 20px; font-weight: 400; color: var(--text); opacity: 0; transition: opacity .18s; }
.sidebar.gm-scrolled .sidebar__logo-text { opacity: 1; }
.gm-big-title { padding: 34px 20px 18px; text-align: center; font-size: 30px; font-weight: 400; color: var(--text); letter-spacing: -.01em;
  transition: opacity .18s, max-height .25s, padding .25s; max-height: 120px; overflow: hidden; }
.sidebar.gm-scrolled .gm-big-title { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; }
.search-box { background: var(--surface-2); border: 0; border-radius: 28px; }
.sidebar__label { display: none; }
.global-badge { background: var(--gm-badge); color: var(--gm-badge-text); }

.conv-item { gap: 14px; padding: 12px 18px; border-radius: 0; background: none; animation: none; }
.conv-item:hover, .conv-item.active { background: color-mix(in srgb, var(--text) 6%, transparent); }
.conv-item .avatar { width: 46px; height: 46px; flex: 0 0 46px; font-size: 0; background: var(--gm-avatar) !important; color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23c4c0c6'%3E%3Ccircle cx='12' cy='8.5' r='4'/%3E%3Cpath d='M4 20c.8-4 4.2-6 8-6s7.2 2 8 6z'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important; background-position: center 60% !important; background-size: 62% !important; }
.conv-item--new .avatar { background-image: none !important; font-size: 22px; color: var(--gm-badge-text); background: var(--gm-badge) !important; }
.conv-item .online-dot { display: none; }
.conv-item__name { font-size: 16px; font-weight: 400; color: var(--text-muted); }
.conv-item__time { font-size: 12px; color: var(--text-faint); font-style: normal; }
.conv-item__preview { font-size: 14px; line-height: 1.35; color: var(--text-faint); white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.conv-item.has-unread .conv-item__name, .conv-item.has-unread .conv-item__preview { color: var(--text); font-weight: 500; }
.conv-item.has-unread .conv-item__time { color: var(--text); }
.conv-item__bottom { align-items: flex-start; gap: 10px; }
.unread-badge { min-width: 20px; height: 18px; padding: 0 6px; border-radius: 9px; background: var(--gm-badge); color: var(--gm-badge-text); font-size: 11px; font-weight: 500; line-height: 18px; }
.conv-item__bottom svg { display: none; } /* the old lock icon on notification senders */

/* floating "start chat" button, bottom right */
.gm-fab { position: fixed; right: 18px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 40; width: 56px; height: 56px; border: 0; border-radius: 18px;
  display: grid; place-items: center; background: var(--gm-badge); color: var(--gm-badge-text); box-shadow: 0 3px 10px rgb(0 0 0 / 35%); cursor: pointer; }
.gm-fab svg { width: 24px; height: 24px; }
.app.chat-open .gm-fab, .app:has(.chat-view:not(.hidden)) .gm-fab { display: none; }
@media (min-width: 701px) { .gm-fab { right: auto; left: calc(var(--sidebar-w) - 76px); } }

/* ── Thread ────────────────────────────────────────────────────────────── */
.chat-panel, .chat-view { background: var(--bg); }
.chat-header { background: var(--bg); border-bottom: 0; box-shadow: none; }
.chat-header__avatar .avatar, .chat-header__avatar > * { background: var(--gm-avatar) !important; color: var(--gm-avatar-icon) !important; }
.chat-header__name { font-size: 18px; font-weight: 400; }
.chat-header__sub { display: none; }
.chat-view.gm-no-reply .chat-header__actions [title="Call"] { display: none; } /* senders like M-PESA: no call button */
.messages-area { background: var(--bg); padding: 10px 14px 16px; }
.date-separator { justify-content: center; margin: 18px 0 10px; }
.date-separator__line { display: none; }
.date-separator__label { background: none; border: 0; padding: 0; font-size: 12px; color: var(--text-faint); }
.gm-texting { margin: 0 0 10px; text-align: center; font-size: 12px; color: var(--text-faint); }
.msg-avatar { display: none; }
.msg-row { margin-top: 3px; }
.msg-row--theirs .msg-bubble { max-width: 82%; padding: 11px 14px; border-radius: 20px; background: var(--gm-recv); color: var(--text); font-size: 15px; line-height: 1.45; box-shadow: none; }
.msg-row--mine .msg-bubble { padding: 9px 16px; border-radius: 22px; background: var(--gm-blue); color: var(--gm-blue-text); font-size: 15px; line-height: 1.4; box-shadow: none; }
.msg-bubble a { color: inherit; text-decoration: underline; word-break: break-all; }
.msg-row--theirs .msg-bubble a { color: var(--gm-link); }
.msg-meta { font-size: 11px; color: var(--text-faint); }
.msg-row:not(:last-child) .msg-meta { display: none; } /* only the newest message shows its time, like the phone */

/* the bottom bar */
.no-reply-notice { justify-content: center; gap: 4px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); border: 0; background: var(--bg); color: var(--text-muted); font-size: 13px; }
.no-reply-notice svg { display: none; }
.no-reply-notice a { color: var(--gm-link); }
.reply-bar { background: var(--bg); border: 0; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
.reply-bar__inner { background: var(--surface-2); border: 0; border-radius: 28px; }
.reply-bar__send { background: var(--gm-badge); color: var(--gm-badge-text); border-radius: 50%; }

/* the start-up screen: plain, no glow */
.loader { background: var(--bg); }
.loader__tagline, .loader__bar-wrap { display: none; }

/* ── Matched to the phone's Messages app (colours measured from its screen, dark mode) ── */
:root, :root[data-theme="dark"] { --gm-top: #2a2a2d; --gm-sheet: #1d1d20; --gm-name: #e4e4e7; --gm-preview: #c4c4c7; --gm-time: #a9a9ac;
  --gm-badge: #94b8ff; --gm-badge-text: #0a1c44; --gm-avatar: #303030; --gm-fab: #244ea3; --gm-fab-icon: #d6e3ff; --bg: #1d1d20; }
:root[data-theme="light"] { --gm-top: #f3f6fc; --gm-sheet: #ffffff; --gm-name: #1f1f1f; --gm-preview: #444746; --gm-time: #5f6368;
  --gm-fab: #0b57d0; --gm-fab-icon: #ffffff; }
.sidebar, .sidebar__header, .sidebar__search { background: var(--gm-top); }
.gm-big-title { background: var(--gm-top); padding: 46px 20px 26px; font-size: 32px; }
.sidebar__search { padding-bottom: 12px; }
.search-box { background: color-mix(in srgb, var(--gm-name) 9%, var(--gm-top)); }
.conv-list { background: var(--gm-sheet); border-radius: 26px 26px 0 0; padding-top: 6px; }
.conv-item__name, .conv-item.has-unread .conv-item__name { color: var(--gm-name); font-weight: 500; font-size: 16px; }
.conv-item__preview { color: var(--gm-preview); font-weight: 400; }
.conv-item.has-unread .conv-item__preview { color: var(--gm-name); font-weight: 500; }
.conv-item__time { color: var(--gm-time); font-size: 12px; font-weight: 400; }
.conv-item.has-unread .conv-item__time { color: var(--gm-name); font-weight: 500; }
.unread-badge, .global-badge { background: var(--gm-badge) !important; color: var(--gm-badge-text) !important; box-shadow: none !important; border: 0 !important; outline: 0; font-weight: 600; }
.conv-item .avatar { background-color: var(--gm-avatar) !important; }
.gm-fab { width: 58px; height: 58px; border-radius: 50%; background: var(--gm-fab); color: var(--gm-fab-icon); box-shadow: 0 2px 8px rgb(0 0 0 / 40%); }
.chat-header, .chat-view, .messages-area, .no-reply-notice, .reply-bar { background: var(--gm-sheet); }

/* Thread header: the same round grey person avatar as the inbox (no letters) */
.chat-header__avatar .avatar { font-size: 0 !important; color: transparent !important; width: 40px; height: 40px;
  background: var(--gm-avatar) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23c4c0c6'%3E%3Ccircle cx='12' cy='8.5' r='4'/%3E%3Cpath d='M4 20c.8-4 4.2-6 8-6s7.2 2 8 6z'/%3E%3C/svg%3E") center 60% / 62% no-repeat !important; }

/* Link preview card under the wallet's newest link (its app logo, then name and website), with the round share button */
.gm-link-row { align-items: center; gap: 10px; margin-top: 4px; }
.gm-link-card { display: grid; width: min(260px, 70vw); overflow: hidden; border-radius: 18px; background: var(--gm-recv); color: var(--text); text-decoration: none; }
.gm-link-card__img { display: grid; place-items: center; aspect-ratio: 1 / 1; background: #fff; }
.gm-link-card__img img { width: 100%; height: 100%; object-fit: cover; }
.gm-link-card__cap { display: grid; gap: 2px; padding: 10px 14px 12px; }
.gm-link-card__cap b { font-weight: 500; font-size: 14px; }
.gm-link-card__cap small { color: var(--text-faint); font-size: 12px; }
.gm-link-share { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid color-mix(in srgb, var(--text) 35%, transparent); border-radius: 50%; color: var(--text); }

/* "Sender can't accept replies. Contact them directly. Learn more" */
.no-reply-notice { font-size: 13.5px; color: var(--gm-preview, var(--text-muted)); padding-top: 16px; }
.gm-learn { color: var(--gm-badge); text-decoration: underline; text-underline-offset: 2px; cursor: default; }

/* exact match to the phone's M-PESA thread */
:root, :root[data-theme="dark"] { --gm-thread: #131317; }
:root[data-theme="light"] { --gm-thread: #ffffff; }
.chat-view, .messages-area, .chat-header, .no-reply-notice, .reply-bar { background: var(--gm-thread); }
.msg-row--theirs .msg-bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.gm-link-card { width: min(285px, 72vw); border-radius: 22px; }
.gm-link-card__cap { background: #002610; color: #e8f0ea; padding: 14px 16px 12px; }
.gm-link-card__cap small { color: #9fb3a5; }
.gm-link-card__cap b { font-size: 15px; }
.chat-header__actions [title="Call"] + .gm-more, .gm-more { display: inline-grid; }
.gm-more svg { width: 22px; height: 22px; }
.chat-view { position: relative; }
.gm-to-bottom { position: absolute; left: 50%; bottom: 84px; z-index: 20; transform: translateX(-50%); display: grid; place-items: center; width: 44px; height: 44px;
  border: 0; border-radius: 50%; background: #3a3a3f; color: #e4e4e7; box-shadow: 0 2px 8px rgb(0 0 0 / 45%); cursor: pointer; }
.gm-to-bottom[hidden] { display: none; }
:root[data-theme="light"] .gm-to-bottom { background: #e3e3e3; color: #1f1f1f; }
.gm-link-share { border: 1.5px solid #c4c4c7; width: 38px; height: 38px; color: #e4e4e7; }
.gm-u { text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }

/* a message with a link and its preview card read as one piece (no gap, the bubble's bottom corners square) */
.msg-row.gm-has-card .msg-bubble { width: min(285px, 72vw); max-width: none; border-bottom-left-radius: 0; border-bottom-right-radius: 0; padding-bottom: 12px; }
.msg-row.gm-has-card .msg-meta { display: none; }
.gm-link-row { margin-top: 0 !important; }
.gm-link-card { border-top-left-radius: 0; border-top-right-radius: 0; }
/* the ⋮ menu stays at the top right on phones too */
.chat-header__actions { display: flex !important; margin-left: auto; }
.chat-header__actions .icon-btn:not(.gm-more):not([title="Call"]) { display: none; }
.gm-link-share { border: 1.5px solid #8e8e93; color: #d0d0d4; background: transparent; width: 40px; height: 40px; }
/* the picture keeps its own rounded corners over the bubble, like the phone (no white box around it) */
.gm-link-card { background: var(--gm-recv); }
.gm-link-card__img { background: transparent; aspect-ratio: auto; }
.gm-link-card__img img { display: block; width: 100%; height: auto; object-fit: contain; }
/* the preview picture: rounded like an app icon, the bubble behind its top corners and white behind its bottom, as on the phone */
.gm-link-card__img { background: linear-gradient(to bottom, transparent 50%, #fff 50%); }
.gm-link-card__img img { border-radius: 26px; box-shadow: 0 2px 3px rgb(0 0 0 / 18%); }

/* ── Exact M-PESA thread look (measured from the phone, dark mode) ── */
:root, :root[data-theme="dark"] { --gm-recv: #1f1f23; --gm-head: #1f1f23; --gm-thread: #131317; }
:root[data-theme="light"] { --gm-head: #f3f6fc; }
.chat-header { background: var(--gm-head) !important; }
.chat-view { background: var(--gm-head) !important; }
.messages-area { background: var(--gm-thread) !important; border-radius: 28px 28px 0 0; }
/* the text bubble flows straight into its picture: no gap, square top corners on the picture, the app icon's rounded bottom on white */
.msg-row.gm-has-card { margin-bottom: 0 !important; padding-bottom: 0 !important; }
.msg-row.gm-has-card > div, .msg-row.gm-has-card .msg-bubble { margin-bottom: 0 !important; }
.gm-link-row { margin-top: -3px !important; padding-top: 0 !important; }
.gm-link-card__img { background: #fff !important; }
.gm-link-card__img img { border-radius: 0 0 30px 30px; box-shadow: 0 3px 3px -1px rgb(0 0 0 / 30%); }
/* "Sender can't accept replies…": a rounded sheet at the bottom, text on the left, like the phone */
.no-reply-notice { display: block; margin: 0; padding: 22px 26px calc(22px + env(safe-area-inset-bottom)); border-radius: 30px 30px 0 0;
  background: var(--gm-head) !important; color: #e3e3e7; font-size: 15.5px; line-height: 1.5; text-align: left; }
:root[data-theme="light"] .no-reply-notice { color: #1f1f1f; }
.gm-learn { color: #a8c7fa; }
