:root {
  --bg: #0b0d12; --panel: #12151d; --panel2: #171b25; --line: #232838;
  --ink: #e9ecf5; --muted: #8b93a7; --me: #3b5bdb; --you: #232838;
  --accent: #6d8bff; --danger: #ff6b6b; --ok: #45d17a;
  --safe-t: env(safe-area-inset-top); --safe-b: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); overflow: hidden;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---- voile anti-capture ---- */
#veil {
  position: fixed; inset: 0; z-index: 1000; background: var(--bg);
  display: none; align-items: center; justify-content: center;
  color: var(--muted); letter-spacing: .3em; text-transform: uppercase; font-size: 14px;
}
#veil.on { display: flex; }

/* ---- filigrane ---- */
#wm {
  position: fixed; inset: 0; z-index: 50; pointer-events: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="150"><text x="8" y="80" transform="rotate(-22 100 75)" fill="%23ffffff" fill-opacity="0.045" font-family="sans-serif" font-size="26">Moi</text></svg>');
}

/* ---- écrans ---- */
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.on { display: flex; }
.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.pad { padding: calc(24px + var(--safe-t)) 24px calc(24px + var(--safe-b)); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 4px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.spin { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.field {
  width: 100%; max-width: 460px; background: var(--panel2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 16px;
  user-select: text; -webkit-user-select: text; -webkit-touch-callout: default;
}
.btn { width: 100%; max-width: 460px; border: 0; border-radius: 12px; padding: 13px 16px; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--me); color: #fff; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.small { width: auto; padding: 7px 11px; font-size: 13px; border-radius: 10px; }

/* ---- barres ---- */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.bar .title { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#peer-status { font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 4px; }
#peer-status.on { color: var(--ok); }
.icon { background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; min-width: 40px; height: 40px; font-size: 18px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon.send { background: var(--me); color: #fff; border: 0; }

/* ---- onglets ---- */
.tab { display: none; flex: 1; min-height: 0; overflow-y: auto; }
.tab.on { display: block; }
#tabbar { display: flex; border-top: 1px solid var(--line); background: var(--panel); padding-bottom: var(--safe-b); }
#tabbar button { flex: 1; background: none; border: 0; color: var(--muted); padding: 12px 4px; font-size: 14px; font-weight: 600; cursor: pointer; position: relative; }
#tabbar button.on { color: var(--ink); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.badge:empty { display: none; }

/* ---- listes ---- */
.list { display: flex; flex-direction: column; }
.section-title { padding: 16px 16px 6px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.row-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0;
  color: var(--ink); text-align: left; width: 100%;
}
.row-item.tap { cursor: pointer; }
.row-item.stack { flex-direction: column; align-items: stretch; }
.row-item.stack .actions { justify-content: flex-start; }
.row-item.tap:active { background: var(--panel2); }
.who-line { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.uname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex: none; }
.meta-right { display: flex; align-items: center; gap: 6px; flex: none; }
.empty { padding: 12px 16px; }
.searchbar { padding: 12px 16px 0; }
.searchbar .field { max-width: none; }

/* ---- moi ---- */
.cards { display: flex; flex-direction: column; gap: 14px; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.card .field, .card .btn { max-width: none; }
.big-name { font-size: 20px; font-weight: 700; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 8px; }
.switch-row input { width: 22px; height: 22px; }
.lbl { font-size: 13px; color: var(--muted); margin-top: 6px; }
.state { background: var(--panel2); border-radius: 12px; padding: 10px 12px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.btn-row { display: flex; gap: 8px; }
.cards > .btn { max-width: none; }

/* ---- fil ---- */
#log { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; }
.row.me { justify-content: flex-end; }
.row.you { justify-content: flex-start; }
.bubble { max-width: 78%; background: var(--you); border-radius: 16px; padding: 8px 11px; }
.row.me .bubble { background: var(--me); }
.who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.row.me .who { color: #cdd7ff; }
.txt { white-space: pre-wrap; word-break: break-word; user-select: text; -webkit-user-select: text; }
.meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; align-items: center; }
.row.me .meta { color: #cdd7ff; justify-content: flex-end; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; font-size: 11px; cursor: pointer; padding: 0; }
.media img, .media video { max-width: 100%; border-radius: 10px; display: block; }
.chip { display: inline-block; background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 14px; cursor: pointer; text-decoration: none; }

/* ---- composer ---- */
#composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + var(--safe-b)); background: var(--panel); border-top: 1px solid var(--line); }
#text { flex: 1; resize: none; max-height: 140px; background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: 18px; padding: 10px 14px; font: inherit; user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }

/* ---- menu ---- */
#menu { position: fixed; inset: 0; z-index: 800; background: rgba(0,0,0,.5); display: none; align-items: flex-end; }
#menu.on { display: flex; }
.sheet { width: 100%; background: var(--panel); border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; }
.sheet .btn { max-width: none; }
.sheet-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet select { background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; }

/* ---- toast ---- */
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); z-index: 1100; background: #000; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90%; text-align: center; }
#toast.show { opacity: .95; }
#toast.bad { background: #7a1f1f; }
