:root {
  /* Galvamed brand palette (from logo) */
  --gv-navy: #1b2c5c;
  --gv-navy-2: #2f4a90;
  --gv-navy-light: #e6ecf6;
  --gv-blue: #288FC9;
  --gv-blue-hover: #1d6e9e;
  --gv-blue-light: #dde8f5;
  --gv-blue-soft: #eff5fb;
  --gv-red: #B8151B;
  --gv-red-hover: #8f0f14;
  --gv-red-light: #fbe9ea;
  --gv-silver: #b9bdc6;
  --gv-silver-light: #f0f2f5;
  --gv-bg: #eef1f6;
  --gv-card: #fff;
  --gv-text: #1c1c1f;
  --gv-text-soft: #54606e;
  --gv-text-mute: #8a96a4;
  --gv-border: #dde2ea;
  --gv-success: #1b8e3c;
  /* Bubble colors */
  --gv-bubble-mine: #dde8f5;
  --gv-bubble-mine-text: #1b2c5c;
  --gv-bubble-other: #ffffff;
  --gv-bubble-other-text: #1c1c1f;
  --gv-tick-sent: #8696a0;
  --gv-tick-read: #288FC9;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--gv-bg); color: var(--gv-text); overscroll-behavior: none; overflow: hidden; }
.hidden { display: none !important; }
.screen { height: 100vh; height: 100dvh; display: flex; }
button { cursor: pointer; }

/* AUTH */
#auth { align-items: center; justify-content: center; background: var(--gv-navy); padding: 16px; }
.card { background: #fff; padding: 32px; border-radius: 12px; width: 100%; max-width: 360px; box-shadow: 0 4px 24px rgba(0,0,0,.15); }
.auth-logo { display: block; margin: 0 auto 14px; width: 110px; height: 110px; filter: drop-shadow(0 6px 18px rgba(27, 44, 92, 0.25)); }
.card h1 { margin: 0 0 18px; color: #1b2c5c; text-align: center; font-size: 22px; font-weight: 700; }
.tabs { display: flex; margin-bottom: 16px; border-bottom: 1px solid #eee; }
.tab { flex: 1; padding: 10px; background: none; border: none; cursor: pointer; font-size: 14px; color: #777; border-bottom: 2px solid transparent; }
.tab.active { color: var(--gv-navy); border-bottom-color: var(--gv-navy); font-weight: 600; }
form { display: flex; flex-direction: column; gap: 10px; }
input { padding: 10px 12px; border: 1px solid #ddd; border-radius: 6px; font-size: 16px; font-family: inherit; }
button { padding: 10px; background: var(--gv-blue); color: #fff; border: none; border-radius: 6px; font-weight: 600; font-size: 14px; }
button:hover:not(:disabled) { filter: brightness(1.05); }
button:disabled { background: #ccc; cursor: not-allowed; }
.error { color: #d33; font-size: 13px; min-height: 18px; margin: 8px 0 0; }

/* Install PWA block on auth screen */
.install-block { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--gv-border); text-align: center; }
.btn-install { display: inline-flex; align-items: center; gap: 8px; padding: 11px 22px; background: linear-gradient(135deg, var(--gv-blue) 0%, var(--gv-blue-hover) 100%); color: #fff; border: none; border-radius: 24px; font-weight: 600; font-size: 14px; cursor: pointer; box-shadow: 0 4px 12px rgba(40, 143, 201, 0.4); transition: transform 0.15s, box-shadow 0.15s; }
.btn-install:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(40, 143, 201, 0.55); }
.install-hint { margin: 10px 0 0; font-size: 12px; color: var(--gv-text-soft); line-height: 1.5; }
.install-hint strong { color: var(--gv-navy); }

/* APP */
#app { background: var(--gv-card); overflow: hidden; }
#sidebar { width: 340px; border-right: 1px solid var(--gv-border); display: flex; flex-direction: column; background: var(--gv-silver-light); min-height: 0; }
#sidebar header { flex-shrink: 0; position: sticky; top: 0; z-index: 10; }
.side-tabs { flex-shrink: 0; position: sticky; top: 0; z-index: 9; }
.panel { flex: 1 1 0; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#sidebar header { padding: 12px 16px; background: linear-gradient(135deg, var(--gv-navy) 0%, var(--gv-navy-2) 100%); color: #fff; display: flex; align-items: center; justify-content: space-between; padding-top: calc(env(safe-area-inset-top) + 12px); }
.me strong { display: block; font-size: 15px; }
.me span { font-size: 12px; opacity: .7; }
.me-actions { display: flex; gap: 4px; }
.me-actions button { background: transparent; color: #fff; font-size: 18px; padding: 6px 10px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; line-height: 0; transition: background 0.15s; }
.me-actions button:hover { background: rgba(255,255,255,0.15); }
.me-actions button svg { display: block; }
.me-actions button.push-on { color: #ffd54f; }
.me-actions button.push-off { color: #fff; opacity: .65; }

/* tabs sidebar */
.side-tabs { display: flex; background: #fff; border-bottom: 1px solid var(--gv-border); }
.side-tab { flex: 1; background: none; color: var(--gv-text-soft); padding: 12px 4px; font-weight: 600; border-bottom: 2px solid transparent; border-radius: 0; font-size: 14px; white-space: nowrap; transition: color 0.15s, border-color 0.15s; }
.side-tab.active { color: var(--gv-navy); border-bottom-color: var(--gv-blue); background: #fff; }

/* (legacy declaration kept for compatibility — overridden by APP block above) */

/* contacts panel */
.search-box { padding: 10px; background: #fff; border-bottom: 1px solid var(--gv-border); }
.search-box input { width: 100%; }
#search-results { padding: 0; }
.section-title { padding: 12px 16px 6px; margin: 0; font-size: 11px; color: var(--gv-text-mute); text-transform: uppercase; letter-spacing: .8px; font-weight: 700; }
.add-contact { padding: 0 12px 16px; }
.add-contact form { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; }

/* lists */
#conv-list, #contact-list, #search-results.list { list-style: none; margin: 0; padding: 0; }
#search-results ul { list-style: none; margin: 0; padding: 0; }
.row { padding: 12px 16px; border-bottom: 1px solid #eee; cursor: pointer; display: flex; align-items: center; gap: 12px; background: #fff; }
.row:hover { background: #efefef; }
.row.active { background: var(--gv-blue-light); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--gv-blue); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 16px; flex-shrink: 0; text-transform: uppercase; }
.row-body { flex: 1; min-width: 0; }
.row .name { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.row .when { font-size: 11px; color: #777; font-weight: 400; flex-shrink: 0; }
.row .preview { font-size: 13px; color: #777; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 4px; align-items: center; }
.row .preview .ticks { display: inline-flex; align-items: center; color: #8696a0; flex-shrink: 0; }
.row .preview .ticks.read { color: #53bdeb; }
.row .preview .ticks svg { display: block; }
.row .unread-dot { width: 8px; height: 8px; background: var(--gv-blue); border-radius: 50%; margin-left: 8px; flex-shrink: 0; }
.row .sub { font-size: 12px; color: #999; }

/* chat */
#chat { flex: 1; display: flex; flex-direction: column; background: var(--gv-bg); min-width: 0; min-height: 0; height: 100%; }
#chat-header { padding: 10px 12px; padding-top: calc(env(safe-area-inset-top) + 10px); background: #fff; border-bottom: 1px solid var(--gv-border); display: flex; align-items: center; gap: 8px; min-height: 56px; box-shadow: 0 1px 4px rgba(27, 44, 92, 0.06); flex-shrink: 0; position: sticky; top: 0; z-index: 10; }
#chat-title { flex: 1; font-weight: 600; font-size: 15px; color: var(--gv-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.back-btn { display: none; background: transparent; color: var(--gv-navy); padding: 8px; min-width: 40px; min-height: 40px; border-radius: 50%; flex-shrink: 0; align-items: center; justify-content: center; border: none; cursor: pointer; transition: background 0.15s; }
.back-btn:hover, .back-btn:active { background: var(--gv-blue-soft); }
.back-btn svg { display: block; }
.ws { font-size: 14px; }
.ws-on { color: var(--gv-success); }
.ws-off { color: var(--gv-silver); }

#messages { list-style: none; margin: 0; padding: 16px; flex: 1 1 0; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 6px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#messages li { max-width: 75%; padding: 7px 11px 5px; border-radius: 10px; background: var(--gv-bubble-other); color: var(--gv-bubble-other-text); align-self: flex-start; box-shadow: 0 1px 2px rgba(27, 44, 92, 0.08); font-size: 14px; word-wrap: break-word; line-height: 1.4; }
#messages li.mine { align-self: flex-end; background: var(--gv-bubble-mine); color: var(--gv-bubble-mine-text); }
#messages li .meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 2px; font-size: 10.5px; color: var(--gv-text-mute); }
#messages li.mine .meta .ticks { display: inline-flex; align-items: center; color: var(--gv-tick-sent); line-height: 0; }
#messages li.mine .meta .ticks.read { color: var(--gv-tick-read); }
#messages li.mine .meta .ticks svg { display: block; }
#messages li .content { white-space: pre-wrap; }
.date-sep { align-self: center; background: rgba(255,255,255,.85); color: var(--gv-text-soft); font-size: 11px; padding: 4px 12px; border-radius: 12px; margin: 8px 0; font-weight: 500; box-shadow: 0 1px 2px rgba(27, 44, 92, 0.06); }

#form-message { display: flex; gap: 6px; padding: 8px; padding-bottom: calc(env(safe-area-inset-bottom) + 8px); background: #fff; border-top: 1px solid var(--gv-border); flex-direction: row; align-items: center; flex-shrink: 0; position: sticky; bottom: 0; z-index: 10; box-shadow: 0 -1px 4px rgba(27, 44, 92, 0.05); }
#msg-input { flex: 1; padding: 10px 14px; border-radius: 20px; border: 1px solid var(--gv-border); background: var(--gv-silver-light); transition: border-color 0.15s, background 0.15s; }
#msg-input:focus { outline: none; border-color: var(--gv-blue); background: #fff; }
.icon-btn { background: transparent; color: var(--gv-text-soft); padding: 8px; border-radius: 50%; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; min-width: 40px; min-height: 40px; transition: background 0.15s, color 0.15s; }
.icon-btn:hover { background: var(--gv-blue-soft); color: var(--gv-navy); }
#btn-send { background: var(--gv-blue); color: #fff; padding: 0; border-radius: 50%; width: 42px; height: 42px; min-width: 42px; display: inline-flex; align-items: center; justify-content: center; border: none; transition: background 0.15s; }
#btn-send:hover:not(:disabled) { background: var(--gv-blue-hover); }
#btn-send:disabled { background: var(--gv-silver); }
#btn-send svg { margin-left: 2px; }

/* media in messages */
#messages li .media { display: block; margin: -2px -4px 4px; }
#messages li .media img { max-width: 280px; max-height: 360px; border-radius: 6px; display: block; cursor: pointer; }
#messages li .file { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: rgba(0,0,0,.04); border-radius: 6px; margin-bottom: 4px; text-decoration: none; color: inherit; max-width: 280px; }
#messages li .file .fname { font-size: 13px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#messages li .file .fsize { font-size: 11px; color: #667781; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; }
.lightbox .close { position: absolute; top: 16px; right: 16px; color: #fff; background: rgba(0,0,0,.5); border-radius: 50%; width: 40px; height: 40px; font-size: 24px; cursor: pointer; border: none; }

/* verified / bot badges — Galvamed style */
.badge-icon { display: inline-flex; vertical-align: middle; margin-left: 3px; align-items: center; justify-content: center; width: 16px; height: 16px; }
.badge-icon svg { color: var(--gv-blue) !important; width: 14px !important; height: 14px !important; }
/* the bot icon (2nd badge) is silver */
.badge-icon + .badge-icon svg { color: var(--gv-silver) !important; }
/* banned tag */
.banned-tag { background: var(--gv-red); color: #fff; padding: 2px 8px; border-radius: 10px; font-size: 11px; margin-left: 6px; font-weight: 600; }

/* message links */
.msg-link { color: var(--gv-blue); text-decoration: underline; word-break: break-all; }
#messages li.mine .msg-link { color: var(--gv-blue-hover); }
#messages li .content strong { font-weight: 700; }

/* "see profile" hint icon next to chat title */
.see-profile { display: inline-block; margin-left: 6px; color: var(--gv-text-soft); font-size: 14px; opacity: .6; vertical-align: middle; }
#chat-title:hover .see-profile { opacity: 1; }

/* action buttons under a message (open link / copy code) */
.msg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg-action { display: inline-flex; align-items: center; gap: 4px; background: rgba(255,255,255,.85); border: 1px solid var(--gv-border); color: var(--gv-navy); padding: 5px 11px; border-radius: 14px; font-size: 12px; cursor: pointer; text-decoration: none; font-weight: 600; transition: background 0.15s, border-color 0.15s; }
#messages li.mine .msg-action { background: rgba(255,255,255,.9); }
.msg-action:hover { background: #fff; border-color: var(--gv-blue); }

/* bot conversation styling */
#app.is-bot-conv #form-message { flex-wrap: wrap; padding: 0; background: #fff8e1; }
#app.is-bot-conv #form-message::before {
  content: "🤖 Compte bot — vous ne pouvez pas répondre";
  display: block; width: 100%; text-align: center; padding: 14px; color: #6b5300; font-size: 13px; font-weight: 600;
}
#app.is-bot-conv #msg-input, #app.is-bot-conv #btn-send, #app.is-bot-conv #btn-emoji, #app.is-bot-conv #btn-attach, #app.is-bot-conv #btn-mic, #app.is-bot-conv #voice-recording { display: none !important; }
#app.is-bot-conv #messages li:not(.mine) { background: #fff8e1; border-left: 3px solid #ffc107; }

/* forwarded */
.forwarded { font-size: 11px; color: #888; font-style: italic; margin-bottom: 2px; }

/* starred mark */
.star-mark { margin-right: 4px; }

/* reactions */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.rxn { background: #fff; border: 1px solid var(--gv-border); border-radius: 12px; padding: 2px 8px; font-size: 12px; cursor: pointer; transition: all 0.15s; }
.rxn:hover { border-color: var(--gv-blue); }
.rxn.mine { background: var(--gv-blue-light); border-color: var(--gv-blue); font-weight: 600; color: var(--gv-navy); }

/* message context menu */
.msg-menu { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: #fff; border-radius: 10px; box-shadow: 0 4px 24px rgba(0,0,0,.25); z-index: 400; padding: 8px; max-width: 90%; width: 320px; }
.msg-menu-rxns { display: flex; gap: 4px; padding: 8px 4px; border-bottom: 1px solid #eee; flex-wrap: wrap; justify-content: center; }
.msg-menu-rxns button { background: transparent; border: none; font-size: 24px; padding: 4px 8px; cursor: pointer; border-radius: 50%; }
.msg-menu-rxns button:hover { background: #f0f0f0; }
.msg-menu > button:not(.rxn) { display: block; width: 100%; text-align: left; padding: 12px; background: transparent; color: #333; border: none; border-radius: 0; font-weight: 400; font-size: 14px; cursor: pointer; }
.msg-menu > button:hover { background: #f7f7f7; }

/* attach menu (WhatsApp-style popup above composer) */
.attach-menu { position: absolute; bottom: 72px; left: 12px; background: #fff; border-radius: 14px; box-shadow: 0 4px 20px rgba(0,0,0,.18); padding: 8px; z-index: 50; display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; min-width: 240px; }
.attach-menu button { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: transparent; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; color: #333; text-align: left; width: 100%; }
.attach-menu button:hover { background: #f0f0f0; }
.attach-menu .ico { font-size: 22px; width: 28px; text-align: center; }
#chat { position: relative; }
#app.is-bot-conv #btn-camera { display: none; }
#app.is-bot-conv #attach-menu { display: none !important; }

/* voice recording */
#voice-recording { display: flex; align-items: center; gap: 12px; padding: 12px 16px; padding-bottom: calc(env(safe-area-inset-bottom) + 12px); background: #fff; border-top: 1px solid #ddd; }
.vr-dot { width: 12px; height: 12px; border-radius: 50%; background: #ef4444; animation: vr-pulse 1s infinite; }
@keyframes vr-pulse { 0%, 100% { opacity: 1 } 50% { opacity: 0.3 } }
#vr-timer { font-family: monospace; font-size: 16px; color: var(--gv-navy); font-weight: 600; min-width: 50px; }
.vr-hint { flex: 1; color: #888; font-size: 13px; }
.vr-btn { padding: 8px 14px; border-radius: 16px; border: none; cursor: pointer; font-weight: 600; font-size: 13px; }
.vr-btn.cancel { background: #f0f0f0; color: #555; }
.vr-btn.send { background: var(--gv-blue); color: #fff; }

/* admin sub-tabs */
.admin-sub-tabs { display: flex; gap: 4px; padding: 8px 12px; background: #f7f7f7; border-bottom: 1px solid #eee; }
.adm-sub-tab { background: #fff; border: 1px solid #ddd; padding: 8px 14px; border-radius: 16px; cursor: pointer; font-size: 13px; color: #555; font-weight: 500; }
.adm-sub-tab.active { background: var(--gv-navy); border-color: var(--gv-navy); color: #fff; }
.sub-panel.hidden { display: none !important; }

/* emoji panel */
#emoji-panel { background: #fff; border-top: 1px solid #ddd; max-height: 240px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; padding: 8px; }
#emoji-panel button { background: transparent; border: none; font-size: 22px; padding: 6px; cursor: pointer; border-radius: 4px; }
#emoji-panel button:hover { background: #f0f0f0; }

/* starred indicator on a message */
#messages li.starred { box-shadow: 0 0 0 2px #ffc107, 0 1px 2px rgba(27, 44, 92, 0.08); }

/* pending (offline) message — bubble dimmed + clock icon */
#messages li.pending { opacity: 0.7; background: var(--gv-silver-light); color: var(--gv-text-soft); border: 1.5px dashed var(--gv-silver); }
#messages li.pending .meta .pending-tick { color: var(--gv-text-mute); }
#messages li.pending .meta .pending-tick svg { animation: pending-pulse 1.5s ease-in-out infinite; }
@keyframes pending-pulse { 0%, 100% { opacity: 0.6 } 50% { opacity: 1 } }

/* media grid (profile sheet) */
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.media-tile { aspect-ratio: 1 / 1; overflow: hidden; border-radius: 4px; cursor: pointer; background: #f0f0f0; }
.media-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* media grid (profile sheet) */
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.media-tile { aspect-ratio: 1 / 1; overflow: hidden; border-radius: 4px; cursor: pointer; background: #f0f0f0; }
.media-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* avatar with image */
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-lg { width: 96px; height: 96px; font-size: 32px; }

/* fab */
.fab { position: absolute; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%; background: var(--gv-blue); color: #fff; box-shadow: 0 4px 14px rgba(40, 143, 201, 0.45); border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 5; transition: background 0.15s, transform 0.15s; }
.fab:hover { background: var(--gv-blue-hover); transform: scale(1.05); }
.fab-assist { right: 88px; background: var(--gv-red, #B8151B); box-shadow: 0 4px 14px rgba(184, 21, 27, 0.45); width: 52px; height: 52px; bottom: 26px; }
.fab-assist:hover { background: #9d1116; }
#panel-convs { position: relative; }

/* Unread count badge in conv list */
.unread-badge { background: var(--gv-blue); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; margin-left: auto; flex-shrink: 0; }
.row.has-unread .name > span:first-child { font-weight: 700; }
.row.has-unread .when { color: var(--gv-blue); font-weight: 700; }
.row .preview .preview-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-flex; gap: 4px; align-items: center; }

/* "Messages non lus" divider in chat */
.unread-bar { display: flex; align-items: center; gap: 10px; margin: 14px 0; list-style: none; padding: 0; }
.unread-bar-line { flex: 1; height: 1px; background: var(--gv-blue); opacity: 0.4; }
.unread-bar-text { color: var(--gv-blue); font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 10px; background: rgba(40, 143, 201, 0.1); text-transform: uppercase; letter-spacing: 0.5px; }

/* sheet overlay */
.sheet-overlay { position: fixed; inset: 0; background: rgba(11, 20, 48, 0.55); z-index: 250; display: flex; align-items: stretch; justify-content: center; backdrop-filter: blur(2px); }
.sheet { background: var(--gv-card); width: 100%; max-width: 540px; height: 100%; overflow: hidden; display: flex; flex-direction: column; }
.sheet-header { padding: 14px 16px; padding-top: calc(env(safe-area-inset-top) + 14px); background: linear-gradient(135deg, var(--gv-navy) 0%, var(--gv-navy-2) 100%); color: #fff; display: flex; align-items: center; gap: 12px; }
.sheet-header h2 { margin: 0; font-size: 18px; font-weight: 600; }
.sheet-back { background: transparent; color: #fff; border: none; padding: 6px; min-width: 40px; min-height: 40px; cursor: pointer; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.sheet-back:hover, .sheet-back:active { background: rgba(255,255,255,0.15); }
.sheet-back svg { display: block; }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 0 32px; padding-bottom: calc(env(safe-area-inset-bottom) + 32px); }

/* version footer in settings */
.settings-version { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 20px 16px 28px; padding-bottom: calc(env(safe-area-inset-bottom) + 28px); color: #999; font-size: 12px; border-top: 1px solid #eee; margin-top: 12px; background: #fafafa; }
.settings-version img { opacity: 0.6; }

/* settings */
.settings-block { padding: 16px 20px; border-bottom: 1px solid var(--gv-border); }
.settings-block.center { text-align: center; padding-top: 24px; }
.settings-block h3 { margin: 12px 0 4px; color: var(--gv-text); }
.settings-block h4 { margin: 0 0 8px; font-size: 11px; color: var(--gv-navy); text-transform: uppercase; letter-spacing: .8px; font-weight: 700; }
.settings-block .readonly { padding: 10px 12px; background: var(--gv-silver-light); border-radius: 8px; font-size: 15px; color: var(--gv-text); }
.settings-block .hint { font-size: 12px; color: var(--gv-text-mute); margin: 6px 0 0; }
.settings-block .row-form { display: flex; gap: 8px; }
.settings-block .row-form input { flex: 1; }
.settings-block .row-form-stack { display: flex; flex-direction: column; gap: 8px; }
.avatar-edit { display: inline-flex; flex-direction: column; align-items: center; cursor: pointer; }
.avatar-edit-hint { margin-top: 8px; font-size: 12px; color: var(--gv-blue); font-weight: 600; }
.btn-primary { background: var(--gv-blue); color: #fff; padding: 12px 16px; border-radius: 8px; border: none; font-weight: 600; cursor: pointer; width: 100%; transition: background 0.15s; }
.btn-primary:hover { background: var(--gv-blue-hover); }
.btn-secondary { background: #fff; color: var(--gv-navy); padding: 10px 16px; border-radius: 8px; border: 1.5px solid var(--gv-navy); font-weight: 600; cursor: pointer; transition: all 0.15s; }
.btn-secondary:hover { background: var(--gv-navy); color: #fff; }
.btn-danger { background: var(--gv-red); color: #fff; padding: 12px 16px; border-radius: 8px; border: none; font-weight: 600; cursor: pointer; width: 100%; transition: background 0.15s; }
.btn-danger:hover { background: var(--gv-red-hover); }
.btn-mini { padding: 6px 12px; border-radius: 16px; background: var(--gv-blue); color: #fff; border: none; cursor: pointer; font-size: 14px; transition: background 0.15s; }
.btn-mini:hover { background: var(--gv-blue-hover); }
#qr-container { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: 8px; border: 1px solid var(--gv-border); }
.sub { font-size: 12px; color: var(--gv-text-mute); }

/* chips (group members) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { background: var(--gv-blue-light); color: var(--gv-navy); padding: 6px 10px; border-radius: 14px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.chip button { background: transparent; color: var(--gv-navy); border: none; font-size: 16px; cursor: pointer; padding: 0 2px; line-height: 1; }

/* admin */
.admin-tabs { display: flex; border-bottom: 1px solid var(--gv-border); padding: 0 8px; gap: 4px; background: var(--gv-silver-light); }
.admin-tab { background: none; padding: 12px 14px; border: none; cursor: pointer; color: var(--gv-text-soft); font-weight: 600; border-bottom: 2px solid transparent; border-radius: 0; transition: color 0.15s, border-color 0.15s; }
.admin-tab.active { color: var(--gv-navy); border-bottom-color: var(--gv-blue); background: #fff; }
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--gv-border); }
.stat { background: linear-gradient(135deg, var(--gv-blue-soft) 0%, #fff 100%); padding: 12px 10px; border-radius: 10px; text-align: center; border: 1px solid var(--gv-border); }
.stat strong { display: block; font-size: 22px; color: var(--gv-navy); font-weight: 700; }
.stat span { font-size: 11px; color: var(--gv-text-mute); }
#adm-user-search, #adm-search { width: 100%; margin: 12px 16px; width: calc(100% - 32px); }
.admin-list { padding: 0 8px; }
.admin-user, .admin-conv { display: flex; align-items: center; gap: 12px; padding: 12px; border-bottom: 1px solid #f0f0f0; }
.admin-user.user-banned { background: #fff0f0; }
.admin-user.user-banned .name { text-decoration: line-through; }
.banned-tag { background: #ef4444; color: #fff; padding: 2px 8px; border-radius: 10px; font-size: 11px; margin-left: 6px; }
.adm-u-name { cursor: pointer; }
.adm-u-name:hover { text-decoration: underline; }
.adm-ban-btn { font-size: 11px; padding: 4px 8px; cursor: pointer; border: none; border-radius: 4px; }
.adm-u-actions { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

/* admin conversation reader */
.admin-msg { background: #fff; padding: 8px 12px; border-radius: 8px; margin-bottom: 6px; box-shadow: 0 1px 2px rgba(27, 44, 92, 0.08); font-size: 14px; }
.admin-msg.system { background: var(--gv-blue-soft); text-align: center; font-style: italic; font-size: 12px; }
.adm-msg-head { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; font-size: 12px; color: var(--gv-text-mute); }
.adm-msg-head strong { color: var(--gv-navy); font-size: 13px; }
.adm-msg-body { color: var(--gv-text); line-height: 1.4; word-break: break-word; }
.adm-msg-body a { color: var(--gv-blue); }
.admin-conv:hover { background: var(--gv-blue-soft); }

/* system-wide notice (broadcast) */
.system-notice { position: fixed; top: env(safe-area-inset-top, 0); left: 50%; transform: translateX(-50%); background: var(--gv-navy); color: #fff; padding: 14px 40px 14px 18px; max-width: 480px; width: calc(100% - 32px); border-radius: 0 0 12px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.3); z-index: 500; font-size: 14px; }
.system-notice strong { display: block; margin-bottom: 4px; }
.system-notice .close { position: absolute; top: 6px; right: 8px; background: transparent; color: #fff; font-size: 22px; border: none; cursor: pointer; padding: 0 8px; }
.adm-u-body { flex: 1; min-width: 0; }
.adm-u-body .name { font-weight: 600; }
.adm-u-actions { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.adm-u-actions label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.admin-form { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.admin-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #555; }
.admin-form label.cb { flex-direction: row; align-items: center; gap: 6px; }
.input.full, input.full { width: 100%; }

/* call log */
.call-icon { display: inline-flex; align-items: center; flex-shrink: 0; }
.row.missed-incoming .name span:not(.when) { color: #ef4444; font-weight: 700; }
.row .name span.missed { color: #ef4444; }

/* CALL system message (in conversation) */
#messages li.system-msg { align-self: center; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.08); padding: 8px 12px; border-radius: 8px; max-width: 80%; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.call-event { display: flex; align-items: center; gap: 8px; }
.call-event-icons { display: inline-flex; align-items: center; gap: 2px; line-height: 0; }
.call-event-label { color: #333; }
.call-event.missed .call-event-label { color: #ef4444; font-weight: 600; }
.sys-time { font-size: 10px; color: #888; margin-left: auto; padding-left: 8px; }

/* group call (LiveKit) */
#gc-overlay { position: fixed; inset: 0; background: #111; z-index: 300; display: flex; flex-direction: column; color: #fff; }
#gc-header { padding: 14px 16px; padding-top: calc(env(safe-area-inset-top) + 14px); background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: space-between; }
#gc-header strong { font-size: 16px; }
#gc-header #gc-count { font-size: 12px; opacity: .8; }
#gc-grid { flex: 1; display: grid; gap: 4px; padding: 4px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-content: start; overflow-y: auto; }
.lk-tile { position: relative; aspect-ratio: 4/3; background: #222; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.lk-tile .tile-media { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.lk-tile .lk-vid { width: 100%; height: 100%; object-fit: cover; }
.lk-tile .lk-aud { display: none; }
.lk-tile .tile-info { position: absolute; bottom: 8px; left: 8px; right: 8px; display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.5); padding: 4px 8px; border-radius: 16px; font-size: 12px; }
.lk-tile .tile-info .avatar { width: 28px; height: 28px; font-size: 12px; background: var(--gv-navy); }
.lk-tile .tile-info span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#gc-controls { display: flex; gap: 16px; padding: 16px; padding-bottom: calc(env(safe-area-inset-bottom) + 16px); justify-content: center; background: rgba(0,0,0,.4); }
#gc-ring { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 16px; padding-top: calc(env(safe-area-inset-top) + 16px); background: var(--gv-navy); max-width: 480px; width: calc(100% - 32px); border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.4); }
#gc-ring .avatar { width: 48px; height: 48px; background: var(--gv-blue); }
#gc-ring .ring-body { flex: 1; display: flex; flex-direction: column; }

/* call ui */
.header-btn { background: transparent; color: #54656f; padding: 6px 8px; border-radius: 50%; min-width: 36px; min-height: 36px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.header-btn:hover { background: rgba(0,0,0,.05); }
#chat-header .header-btn svg { display: block; width: 20px; height: 20px; }

#call-overlay { position: fixed; inset: 0; background: #111; z-index: 300; display: flex; align-items: center; justify-content: center; color: #fff; }
#call-stage { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
#remote-video { width: 100%; height: 100%; object-fit: cover; background: #000; }
#local-video { position: absolute; top: 16px; right: 16px; width: 120px; height: 160px; border-radius: 8px; object-fit: cover; background: #333; border: 2px solid #fff; z-index: 2; }
#call-info { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; }
#call-info .avatar { width: 110px; height: 110px; font-size: 40px; margin: 0 auto 16px; background: var(--gv-navy); }
#call-info h2 { margin: 0 0 8px; font-size: 24px; font-weight: 500; }
#call-info p { margin: 0; font-size: 14px; opacity: .8; }
#call-stage video[srcObject]:not([srcObject=""]) ~ #call-info { display: none; }
/* Hide info once stream is active — simpler: hide when remote video has metadata */

#call-controls { position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); display: flex; gap: 20px; z-index: 3; }
.ctl { width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; display: inline-flex; align-items: center; justify-content: center; border: none; cursor: pointer; padding: 0; }
.ctl:hover { background: rgba(255,255,255,.25); }
.ctl.danger { background: #ef4444; }
.ctl.danger:hover { background: #dc2626; }
.ctl.accept { background: var(--gv-blue); }
.ctl.accept:hover { background: var(--gv-blue-hover); }

#ring-banner { display: flex; align-items: center; gap: 14px; padding: 16px; padding-top: calc(env(safe-area-inset-top) + 16px); background: var(--gv-navy); max-width: 480px; width: calc(100% - 32px); border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.4); }
#ring-banner .avatar { width: 48px; height: 48px; background: var(--gv-blue); }
.ring-body { flex: 1; display: flex; flex-direction: column; }
.ring-body strong { font-size: 16px; }
.ring-body span { font-size: 12px; opacity: .8; }
#ring-banner .ctl { width: 48px; height: 48px; }

/* Very narrow phones (≤ 380px) — hide camera button if too cramped */
@media (max-width: 380px) {
  #chat-title { font-size: 14px; }
  #chat-header .header-btn svg { width: 18px; height: 18px; }
  .header-btn { min-width: 32px; min-height: 32px; }
  .back-btn { min-width: 36px; min-height: 36px; padding: 6px; }
  .back-btn svg { width: 20px; height: 20px; }
  .icon-btn { min-width: 34px; min-height: 34px; padding: 4px; }
  .icon-btn svg { width: 20px; height: 20px; }
  /* drop emoji button on very narrow screens — keyboard has emojis */
  #btn-emoji { display: none; }
  .attach-menu { grid-template-columns: repeat(2, 1fr); }
  .attach-menu button { flex-direction: row; padding: 10px 8px; }
  #messages li { max-width: 86%; font-size: 14px; }
  .row { padding: 9px 10px; }
  .avatar { width: 40px; height: 40px; }
}

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--gv-navy); color: #fff; padding: 11px 20px; border-radius: 24px; font-size: 13px; z-index: 100; max-width: 90%; text-align: center; box-shadow: 0 6px 20px rgba(11, 20, 48, 0.35); font-weight: 500; }

/* mobile */
@media (max-width: 720px) {
  #sidebar { width: 100%; }
  #app.has-conv #sidebar { display: none; }
  #app:not(.has-conv) #chat { display: none; }
  .back-btn { display: block; }
  input { font-size: 16px; } /* prevents iOS auto-zoom */

  /* MESSAGES — better spacing + readability on phones */
  #messages { padding: 10px 8px; gap: 4px; }
  #messages li { font-size: 14.5px; padding: 7px 10px 5px; max-width: 82%; border-radius: 10px; }
  #messages li .meta { font-size: 10.5px; }
  #messages li .content { line-height: 1.4; }
  #messages li .media img { max-width: 240px; max-height: 300px; }
  #messages li .file { max-width: 240px; }
  .date-sep { font-size: 11px; padding: 3px 12px; margin: 6px 0; }

  /* COMPOSER — compact + always visible send/mic */
  #form-message { padding: 6px 6px; padding-bottom: calc(env(safe-area-inset-bottom) + 6px); gap: 2px; align-items: center; }
  .icon-btn { min-width: 38px; min-height: 38px; padding: 6px; }
  .icon-btn svg { width: 22px; height: 22px; }
  #btn-emoji { font-size: 22px; }
  #msg-input { padding: 9px 12px; font-size: 16px; min-width: 0; }
  #btn-send { width: 40px; height: 40px; min-width: 40px; }
  #btn-send svg { width: 20px; height: 20px; }

  /* attach menu : positioned to not cover composer */
  .attach-menu { left: 8px; right: 8px; bottom: 64px; grid-template-columns: repeat(4, 1fr); min-width: 0; }
  .attach-menu button { flex-direction: column; padding: 12px 6px; font-size: 11px; gap: 4px; }
  .attach-menu .ico { font-size: 24px; width: auto; }

  /* CONV LIST — denser */
  .row { padding: 10px 12px; gap: 10px; }
  .avatar { width: 44px; height: 44px; font-size: 15px; }
  .row .name { font-size: 14px; }
  .row .preview { font-size: 12.5px; }
  .row .when { font-size: 10.5px; }

  /* HEADER — already compact */
  .header-btn { padding: 4px 6px; min-width: 34px; min-height: 34px; }
  #chat-header .header-btn svg { width: 19px; height: 19px; }
  #chat-header { gap: 4px; padding: 8px 8px; padding-top: calc(env(safe-area-inset-top) + 8px); min-height: 52px; }
  #chat-title { font-size: 15px; font-weight: 600; }
  .back-btn { display: inline-flex; min-width: 40px; min-height: 40px; padding: 8px; margin-right: 2px; }
  .back-btn svg { width: 22px; height: 22px; }
  .ws { font-size: 12px; margin-right: 2px; }

  /* SIDEBAR */
  .side-tab { font-size: 13px; padding: 10px 2px; }
  #sidebar header { padding: 10px 14px; padding-top: calc(env(safe-area-inset-top) + 10px); }
  .me strong { font-size: 14px; }
  .me-actions button { padding: 4px 6px; }

  /* Group call tiles + system messages */
  #local-video { width: 90px; height: 120px; top: 12px; right: 12px; }
  #messages li.system-msg { font-size: 12px; padding: 6px 10px; max-width: 90%; }

  /* Voice recording bar */
  #voice-recording { padding: 10px 12px; padding-bottom: calc(env(safe-area-inset-bottom) + 10px); gap: 8px; }
  .vr-btn { padding: 7px 12px; font-size: 12px; }
  #vr-timer { font-size: 14px; min-width: 44px; }

  /* Sheets (settings/profile/admin) — go full-screen on phones */
  .sheet { max-width: 100%; border-radius: 0; }
  .sheet-header { padding: 12px 12px; padding-top: calc(env(safe-area-inset-top) + 12px); }
  .sheet-header h2 { font-size: 16px; }

  /* FAB position avoiding tab bar */
  .fab { right: 16px; bottom: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); }
}
