:root {
  --bg: #0b0f14; --surface: #131a22; --surface2: #1a232d; --line: #222d39;
  --text: #e8eef5; --muted: #8a99aa; --accent: #5b8def; --accent-ink: #fff;
  --ok: #3fbf8f; --danger: #e5584f; --bubble-in: #1a232d; --bubble-out: #2a5bd7;
  --sab: env(safe-area-inset-bottom, 0px); --sat: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { overflow: hidden; -webkit-user-select: none; user-select: none; }
#app { height: var(--tg-viewport-stable-height, 100dvh); display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: var(--text); -webkit-user-select: text; user-select: text; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

/* écrans centrés */
.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px 24px calc(24px + var(--sab)); text-align: center; overflow-y: auto; }
.center h2 { margin: 0; font-size: 22px; }
.center p { margin: 0; max-width: 340px; }
.logo { font-size: 54px; filter: drop-shadow(0 6px 18px rgba(91,141,239,.35)); }
.lock { gap: 6px; }

/* clavier aléatoire */
.padwrap { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.padwrap h2 { margin: 0; font-size: 20px; }
.hint { min-height: 20px; margin: 0; color: var(--muted); font-size: 14px; }
.dots { display: flex; gap: 10px; margin: 8px 0 18px; min-height: 14px; flex-wrap: wrap; justify-content: center; }
.dots i { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--muted); transition: background .1s, border-color .1s; }
.dots i.on { background: var(--text); border-color: var(--text); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; }
.key { aspect-ratio: 1.25; border-radius: 18px; background: var(--surface2); font-size: 28px; font-weight: 500; touch-action: manipulation; transition: transform .06s; }
.key:active { transform: scale(.94); }
.key.aux { background: transparent; font-size: 15px; color: var(--muted); }
.padwrap.busy { opacity: .6; pointer-events: none; }

/* boutons */
.btn { padding: 12px 20px; border-radius: 12px; font-weight: 600; background: var(--surface2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: var(--surface2); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; } .row > * { flex: 1; }
.seg { display: flex; gap: 8px; }
.seg button { width: 46px; height: 46px; border-radius: 12px; background: var(--surface2); font-weight: 600; }
.seg button.on { background: var(--accent); }
.warnbox { text-align: left; background: #2a2218; border: 1px solid #5a4620; color: #f0d9a8; border-radius: 12px; padding: 12px 14px; font-size: 14px; max-width: 340px; }
.warnbox ul { margin: 6px 0 0; padding-left: 18px; } .warnbox li { margin: 3px 0; }

/* vues */
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.bar { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--sat) * 0) 12px 10px; background: var(--surface); border-bottom: 1px solid var(--line); min-height: 56px; }
.bar h1 { margin: 0 0 0 4px; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.bar b { display: block; line-height: 1.15; } .bar .sub { font-size: 12px; color: var(--muted); }
.ibtn { width: 40px; height: 40px; border-radius: 50%; font-size: 20px; display: grid; place-items: center; flex: none; }
.ibtn:active { background: var(--surface2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); } .dot.ok { background: var(--ok); } .dot.off { background: var(--danger); }
.avatar { border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; flex: none; }

.list { flex: 1; overflow-y: auto; }
.row-item { display: flex; gap: 12px; align-items: center; width: 100%; padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); }
.row-item:active { background: var(--surface); }
.line { display: flex; align-items: center; gap: 8px; }
.line b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time { font-size: 12px; color: var(--muted); }
.prev { flex: 1; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: #fff; min-width: 20px; height: 20px; border-radius: 10px; font-size: 12px; font-weight: 600; display: grid; place-items: center; padding: 0 6px; }
.tag { background: var(--surface2); color: var(--muted); border-radius: 6px; font-size: 11px; padding: 1px 6px; }
.empty { text-align: center; padding: 70px 30px; color: var(--text); } .empty .big { font-size: 46px; margin-bottom: 10px; }

/* conversation */
.banner-wrap:empty { display: none; }
.banner { background: var(--surface2); padding: 12px 14px; border-bottom: 1px solid var(--line); } .banner p { margin: 0 0 10px; font-size: 14px; }
.banner.warn { background: #2e1c1b; }
.msgs { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; -webkit-user-select: text; user-select: text; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; text-transform: capitalize; }
.b { max-width: 82%; padding: 8px 12px 5px; border-radius: 16px; word-break: break-word; }
.b.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 5px; }
.b.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 5px; }
.b.sys { align-self: center; background: transparent; color: var(--muted); font-size: 14px; padding: 4px 10px; }
.txt { white-space: pre-wrap; }
.meta { font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.link { color: #ffd479; text-decoration: underline; font-size: 11px; }
.media img, .media video { display: block; max-width: min(260px, 100%); max-height: 320px; border-radius: 10px; }
.media.audio audio { width: 220px; max-width: 100%; height: 40px; }
.ph { padding: 24px 40px; color: var(--muted); }
.file { color: inherit; text-decoration: none; display: block; padding: 4px 0; } .file small { opacity: .7; }
.composer { display: flex; align-items: flex-end; gap: 4px; padding: 8px 8px calc(8px + var(--sab)); background: var(--surface); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; background: var(--surface2); border: 0; border-radius: 20px; padding: 10px 14px; outline: none; max-height: 140px; line-height: 1.3; }
.ibtn.send { background: var(--accent); color: #fff; font-size: 17px; }
.recording { align-items: center; gap: 10px; }
.recdot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* feuilles et dialogues */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; z-index: 50; }
.sheet { width: 100%; max-height: 88dvh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 18px calc(18px + var(--sab)); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 14px; }
.sheet h3 { margin: 0 0 8px; } .sheet p { margin: 0 0 12px; }
.confirm .row { margin-top: 14px; }
.menu { display: flex; flex-direction: column; } .menu button { text-align: left; padding: 15px 4px; border-bottom: 1px solid var(--line); font-size: 17px; } .menu button:last-child { border: 0; }
.pinsheet { display: flex; flex-direction: column; align-items: center; gap: 8px; padding-bottom: 8px; }
.addsheet { display: flex; flex-direction: column; gap: 12px; } .addsheet h3, .addsheet p { margin: 0; }
.or { text-align: center; color: var(--muted); font-size: 13px; }
.searchrow { display: flex; gap: 8px; } .searchrow input { flex: 1; background: var(--surface2); border: 0; border-radius: 12px; padding: 12px 14px; outline: none; }
.linkbox { background: var(--surface2); border-radius: 12px; padding: 12px; font-size: 13px; word-break: break-all; margin-bottom: 10px; -webkit-user-select: text; user-select: text; }
.addout:empty { display: none; }
.profile { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 0; }
.infosheet { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.safety { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font: 600 17px ui-monospace, Menlo, monospace; background: var(--surface2); border-radius: 12px; padding: 14px; margin: 6px 0 12px; -webkit-user-select: text; user-select: text; }

/* réglages */
.settings { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border-radius: 14px; overflow: hidden; }
.me { display: flex; gap: 12px; align-items: center; padding: 14px; } .me small { display: block; color: var(--muted); }
.setting { display: flex; align-items: center; gap: 12px; padding: 14px; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.card > :last-child { border-bottom: 0; }
.setting small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; font-weight: 400; }
.setting select { background: var(--surface2); border: 0; border-radius: 8px; padding: 6px 8px; }
.danger-zone b { color: #ff7b72; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 14px; background: var(--surface2); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + i { background: var(--ok); } .switch input:checked + i::after { transform: translateX(18px); }
.foot { color: var(--muted); font-size: 12.5px; text-align: center; margin: 4px 8px 16px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--sab)); transform: translateX(-50%); background: #2a3644; color: var(--text); padding: 10px 16px; border-radius: 12px; z-index: 99; max-width: 88%; font-size: 14px; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.viewer { position: fixed; inset: 0; background: #000; z-index: 80; display: grid; place-items: center; } .viewer img { max-width: 100%; max-height: 100%; } .viewer .x { position: absolute; top: 14px; right: 14px; color: #fff; background: rgba(255,255,255,.15); }

/* appel */
.call { position: fixed; inset: 0; z-index: 90; background: radial-gradient(circle at 50% 30%, #1d2b3d, #0b0f14); display: flex; flex-direction: column; align-items: center; }
.call .remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; background: #000; }
.call.video .remote { display: block; }
.call .local { position: absolute; top: 14px; right: 14px; width: 96px; height: 130px; object-fit: cover; border-radius: 12px; background: #000; display: none; z-index: 2; transform: scaleX(-1); }
.call.video .local { display: block; }
.cinfo { position: relative; z-index: 1; margin-top: 16vh; display: flex; flex-direction: column; align-items: center; gap: 6px; text-shadow: 0 1px 8px rgba(0,0,0,.6); }
.cinfo h2 { margin: 8px 0 0; } .ctime { font-size: 17px; } .cinfo small { color: var(--muted); }
.cbtns { position: absolute; z-index: 3; bottom: calc(40px + var(--sab)); display: flex; gap: 22px; }
.cbtn { width: 64px; height: 64px; border-radius: 50%; font-size: 26px; background: rgba(255,255,255,.18); backdrop-filter: blur(8px); display: grid; place-items: center; }
.cbtn.red { background: var(--danger); } .cbtn.green { background: var(--ok); } .cbtn.on { background: #fff; color: #000; }
