/* SGENYX Secure Messenger DEMO.
   Palette and type follow the SGENYX Factory standard (standalone.css, factory-v0.7.5): one serious blue,
   a brand bar that is dark in both appearances with the on-dark wordmark, product name and version under it.
   Square corners everywhere (operator rule). */
:root {
  color-scheme: light;
  --bg: #f3f5f8; --surface: #ffffff; --surface-alt: #f6f8fb; --surface-sunken: #edf1f5;
  --text: #1b2430; --text-soft: #465568; --muted: #708096; --faint: #94a0b2;
  --border: #dde3ea; --border-strong: #c7d0db;
  --primary: #2474c6; --primary-hover: #1d62aa; --primary-soft: #eaf3fc; --primary-line: #bad6f1; --on-primary: #ffffff;
  --danger: #b42318; --danger-soft: #fdeceb; --success: #0a6c46; --warn: #96601a; --warn-soft: #fbf1e2; --warn-line: #e8cfa6;
  --nav-bg: #1d2733; --nav-bg-alt: #263444; --nav-text: #b5c0ce; --nav-text-strong: #ffffff; --nav-border: #2b3746;
  --out: #eaf3fc; --out-line: #bad6f1;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f151d; --surface: #19212c; --surface-alt: #202a37; --surface-sunken: #141b24;
    --text: #eef2f7; --text-soft: #c1cad6; --muted: #96a4b6; --faint: #748297;
    --border: #2b3746; --border-strong: #425064;
    --primary: #4f9bf5; --primary-hover: #6fb0ff; --primary-soft: #152438; --primary-line: #2b4a72; --on-primary: #08121f;
    --danger: #ff8b80; --danger-soft: #2c1613; --success: #5cc994; --warn: #e5ab5b; --warn-soft: #2a2013; --warn-line: #5c4522;
    --nav-bg: #111821; --nav-bg-alt: #1b2633; --nav-text: #98a4b4; --nav-border: #24303e;
    --out: #152438; --out-line: #2b4a72;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f151d; --surface: #19212c; --surface-alt: #202a37; --surface-sunken: #141b24;
  --text: #eef2f7; --text-soft: #c1cad6; --muted: #96a4b6; --faint: #748297;
  --border: #2b3746; --border-strong: #425064;
  --primary: #4f9bf5; --primary-hover: #6fb0ff; --primary-soft: #152438; --primary-line: #2b4a72; --on-primary: #08121f;
  --danger: #ff8b80; --danger-soft: #2c1613; --success: #5cc994; --warn: #e5ab5b; --warn-soft: #2a2013; --warn-line: #5c4522;
  --nav-bg: #111821; --nav-bg-alt: #1b2633; --nav-text: #98a4b4; --nav-border: #24303e;
  --out: #152438; --out-line: #2b4a72;
}

* { box-sizing: border-box; border-radius: 0 !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); display: flex; flex-direction: column;
  font: 14px/1.45 var(--font);
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface); border: 1px solid var(--border-strong); padding: 6px 12px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text);
}
button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
button.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-primary); }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { background: var(--surface); border: 1px solid var(--border-strong); padding: 7px 10px; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
code { font: 12px/1.2 var(--font-mono); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.pad { padding: 0 14px; }
.error { color: var(--danger); margin: 0; }

/* Brand bar: dark in both appearances, on-dark wordmark, product name and version under it (Factory ADR-0033/0040). */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px;
  background: var(--nav-bg); color: var(--nav-text); border-bottom: 1px solid var(--nav-border); flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; align-items: flex-start; row-gap: 4px; }
.brand-logo { display: block; height: 20px; width: auto; }
.brand-product { display: flex; gap: 8px; align-items: baseline; line-height: 1.15; }
.brand-product__name { font-size: 12.5px; font-weight: 600; color: rgba(255, 255, 255, .92); letter-spacing: .01em; }
.brand-product__version { font-size: 11px; color: rgba(255, 255, 255, .55); font-variant-numeric: tabular-nums; }
.tools { display: flex; align-items: center; gap: 10px; }
.tools a { color: var(--nav-text); text-decoration: none; font-size: 13px; }
.tools a:hover { color: var(--nav-text-strong); }
.tools button { background: transparent; border-color: var(--nav-border); color: var(--nav-text); padding: 4px 10px; }
.tools button:hover { background: var(--nav-bg-alt); color: var(--nav-text-strong); border-color: var(--nav-border); }
.lang { display: inline-flex; }
.lang button + button { border-left: 0; }
.tools .lang button.active, .lang button.active { background: var(--nav-bg-alt); color: var(--nav-text-strong); font-weight: 600; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.conn .dot { width: 8px; height: 8px; background: #d9534f; display: inline-block; }
.conn.on .dot { background: #3fb67a; }

main { flex: 1; min-height: 0; display: flex; }

.register { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
.card { background: var(--surface); border: 1px solid var(--border); padding: 26px; width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; }
.card h1 { margin: 0; font-size: 18px; font-weight: 650; }
.card p { margin: 0; }
.card label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 12px; color: var(--text-soft); }

.app { flex: 1; display: grid; grid-template-columns: 300px 1fr; min-height: 0; }
.side { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.me { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.me-name { font-weight: 650; font-size: 15px; }
.side-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 16px 6px; }
.contacts { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.contacts li button {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text);
  padding: 10px 16px; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 14px;
}
.contacts li button:hover { background: var(--surface-alt); color: var(--text); }
.contacts li button.active { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.contacts .c-name { font-weight: 600; }
.contacts .c-last { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contacts .c-unread { background: var(--primary); color: var(--on-primary); font-size: 11px; font-weight: 700; padding: 1px 7px; align-self: center; }
.contacts .c-flag { font-size: 11px; font-weight: 600; color: var(--success); align-self: center; }
.contacts .c-flag.warn { color: var(--warn); }
.side-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.side-foot button { flex: 1; }

.chat { display: flex; min-height: 0; min-width: 0; }
.chat-empty { margin: auto; padding: 24px; text-align: center; }
.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 16px; min-height: 50px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chat-title { flex: 1; min-width: 120px; }
.chat-name { font-weight: 650; font-size: 15px; }
.back { display: none; }
.ttl { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.ttl select { padding: 4px 6px; font-size: 13px; }
.verified-yes { color: var(--success); }
.verified-no { color: var(--muted); }

.banner { padding: 10px 16px; border-bottom: 1px solid var(--warn-line); font-size: 13px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }

.messages { list-style: none; margin: 0; padding: 16px; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(72%, 560px); padding: 8px 11px; border: 1px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.in { align-self: flex-start; background: var(--surface); }
.msg.out { align-self: flex-end; background: var(--out); border-color: var(--out-line); }
.msg .meta { display: flex; gap: 8px; justify-content: flex-end; font-size: 11px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.msg .st.read { color: var(--primary); font-weight: 700; }
.msg .st.failed { color: var(--danger); cursor: pointer; }
.msg .timer { color: var(--warn); }
.sys { align-self: center; font-size: 12px; color: var(--muted); padding: 2px 8px; }

.composer { display: flex; gap: 8px; padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; max-height: 140px; }

dialog { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 22px; max-width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 16, 24, .55); }
dialog h2 { margin: 0 0 8px; font-size: 16px; font-weight: 650; }
.digits { font: 600 19px/1.6 var(--font-mono); letter-spacing: .06em; background: var(--surface-sunken); border: 1px solid var(--border); padding: 12px 16px; margin: 12px 0; text-align: center; white-space: pre-wrap; }
.row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
.about { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }

@media (max-width: 760px) {
  .top { padding: 8px 12px; }
  .app { grid-template-columns: 1fr; }
  .app .chat { display: none; }
  body.in-chat .app .side { display: none; }
  body.in-chat .app .chat { display: flex; }
  .back { display: inline-block; }
  .msg { max-width: 86%; }
  .tools a, .conn #connText { display: none; }
}
