:root {
  --brand: #455e7c;
  --accent: #04b6cd;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #111418;
  --muted: #6b7280;
  --line: #e3e5ea;
  --bubble-in: #e9ebef;
  --good: #1f9d55;
  --warn-bg: #fff4e5;
  --warn: #b45309;
  --bad-bg: #fde8e8;
  --bad: #c81e1e;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #1a1f26;
    --text: #eef1f5;
    --muted: #9aa3ae;
    --line: #2a313a;
    --bubble-in: #262c35;
    --warn-bg: #3a2a12;
    --warn: #f6ad55;
    --bad-bg: #3b1616;
    --bad: #f98080;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
#app { height: 100dvh; display: flex; flex-direction: column; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input[type="text"], input[type="password"], textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  outline: none;
  font-size: 16px; /* prevents iOS zoom on focus */
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 4px 0; }
.error { color: var(--bad); font-size: 14px; margin: 4px; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; word-break: break-word; }

.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.small { width: 18px; height: 18px; }
.icon.tiny { width: 13px; height: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 8px; color: var(--accent); }
.danger-text { color: var(--bad); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  display: grid; place-items: center; background: transparent; color: var(--brand);
}
@media (prefers-color-scheme: dark) { .icon-btn { color: var(--accent); } }
.icon-btn:active { background: var(--line); }
.icon-btn-spacer { width: 40px; }

/* ---------- layout ---------- */
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-bottom: env(safe-area-inset-bottom); }
.screen.center { justify-content: center; padding: 24px max(20px, env(safe-area-inset-left)); max-width: 440px; width: 100%; margin: 0 auto; gap: 24px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.content { padding: 8px 16px 24px; overflow-y: auto; max-width: 640px; width: 100%; margin: 0 auto; }

.brand { text-align: center; }
.brand-logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: 0 6px 20px rgb(0 0 0 / .15); }
.brand h1 { margin: 14px 0 6px; font-size: 30px; }
.brand p { margin: 0 auto; max-width: 34ch; }
.lock-badge { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center; background: var(--brand); color: #fff; }
.lock-badge .icon { width: 32px; height: 32px; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
.bar-title { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.bar-title strong { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--bad); }
.badge.online .dot { background: var(--good); }
.badge.connecting .dot { background: var(--warn); }

.banner {
  display: flex; align-items: flex-start; gap: 10px; text-align: left; width: 100%;
  padding: 10px 14px; border: 0; font-size: 14px;
}
.banner.warn { background: var(--warn-bg); color: var(--text); }
.banner.warn .icon { color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--text); }
.banner.bad .icon { color: var(--bad); }

/* ---------- contacts ---------- */
.list { list-style: none; margin: 8px 12px; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border: 0; background: none; text-align: left; }
.row:active { background: var(--line); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: flex; align-items: center; gap: 5px; font-weight: 600; }
.row-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.unread { min-width: 20px; padding: 1px 7px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 700; background: hsl(var(--hue) 45% 52%);
}
.trust { display: inline-flex; }
.trust.good { color: var(--good); }
.trust.bad { color: var(--bad); }
.empty { text-align: center; padding: 60px 24px; }
.empty h2 { margin: 0 0 6px; font-size: 20px; }

/* ---------- chat ---------- */
.chat { height: 100dvh; }
.messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 8px 13px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
.msg.out .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 6px; }
.msg.in .bubble { background: var(--bubble-in); border-bottom-left-radius: 6px; }
.msg-meta { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); margin: 2px 6px 0; }
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea { resize: none; max-height: 140px; border-radius: 20px; padding: 9px 14px; line-height: 1.35; }
.send-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none; display: grid; place-items: center; background: var(--brand); color: #fff; }
.send-btn:disabled { background: var(--line); color: var(--muted); }

/* ---------- cards / settings ---------- */
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 20px 6px 6px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; margin-top: 10px; }
.card.bad { background: var(--bad-bg); }
.card.bad p { margin-top: 0; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; }
.kv.column { flex-direction: column; align-items: flex-start; }
.code-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 8px; text-align: center; font: 600 18px ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .02em; user-select: text; -webkit-user-select: text; }
.switch-row { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
input[type="checkbox"][role="switch"] {
  appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; margin: 0;
  background: var(--line); position: relative; transition: background .2s; cursor: pointer;
}
input[type="checkbox"][role="switch"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .2s;
}
input[type="checkbox"][role="switch"]:checked { background: var(--good); }
input[type="checkbox"][role="switch"]:checked::after { transform: translateX(20px); }
input[type="checkbox"][role="switch"]:disabled { opacity: .5; }

/* ---------- modal & privacy cover ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .4); display: grid; place-items: center; padding: 20px; z-index: 10; }
.modal-card { background: var(--surface); border-radius: 18px; padding: 20px; width: min(100%, 380px); display: flex; flex-direction: column; gap: 10px; }
.modal-card form { display: flex; flex-direction: column; gap: 10px; }
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card p { margin: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

#cover { display: none; position: fixed; inset: 0; z-index: 20; background: var(--brand); place-items: center; }
#cover img { width: 96px; height: 96px; border-radius: 22px; }
body.covered #cover { display: grid; }

/* ---------- attachments, receipts, codes ---------- */
.composer { align-items: flex-end; gap: 4px; }
.composer-btn { width: 36px; height: 40px; flex: none; }
.composer textarea { flex: 1; min-width: 0; }
.tick { display: inline-flex; }
.tick.read { color: var(--accent); }
.icon.tiny.wide { width: 17px; }
.bubble.has-media { padding: 4px; background: transparent !important; }
.msg.out .bubble.has-media > span, .msg.in .bubble.has-media > span { display: block; padding: 6px 9px 4px; }
.media { border-radius: 14px; overflow: hidden; background: var(--bubble-in); }
.media-img { display: block; max-width: min(260px, 70vw); max-height: 340px; width: auto; height: auto; object-fit: cover; cursor: zoom-in; }
.media-video { display: block; max-width: min(280px, 72vw); max-height: 360px; background: #000; }
.media.audio { background: none; }
.media-audio { display: block; width: min(260px, 70vw); }
.media-missing { padding: 12px 14px; font-size: 14px; color: var(--muted); }
.upload-progress { font-size: 12px; color: var(--muted); margin: 2px 6px 0; }
.big-code { display: block; text-align: center; font-size: 19px; font-weight: 700; letter-spacing: .06em; padding: 14px 8px; border-radius: 12px; background: var(--bg); user-select: all; -webkit-user-select: all; }
.code-input { font-family: ui-monospace, "SF Mono", Menlo, monospace; text-transform: uppercase; letter-spacing: .05em; }
.center-text { align-items: center; }
.banner.rounded { border-radius: 12px; }
.rec { display: flex; align-items: center; gap: 10px; font-size: 17px; justify-content: center; padding: 10px 0; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bad); animation: blink 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; }
@keyframes blink { 50% { opacity: .25; } }
.modal-card.viewer { background: transparent; padding: 0; width: auto; max-width: 100%; }
.viewer-img { max-width: 100vw; max-height: 82dvh; border-radius: 8px; cursor: zoom-out; }
.viewer-actions { display: flex; justify-content: center; gap: 10px; margin-top: 10px; }
.media-save { display: inline-flex; align-items: center; gap: 3px; padding: 2px 4px; font-size: 12px; }
input[type="email"] { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 16px; outline: none; }
