@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/inter-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/inter-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #0b0d11;
  --panel: #13161c;
  --panel-2: #191d25;
  --panel-3: #1f242e;
  --line: #242a34;
  --line-2: #2f3743;
  --text: #e8eaef;
  --dim: #949cab;
  --faint: #6b7383;
  --accent: #5b6bf5;
  --accent-2: #8b7cf6;
  --accent-soft: #5b6bf51f;
  --ok: #3fb96a;
  --warn: #e0a542;
  --err: #ec4b4e;
  --r: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* author display rules must not defeat the hidden attribute */
[hidden] { display: none !important; }
::selection { background: var(--accent); color: #fff; }

body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.6 Inter, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ============================================================== sidebar */

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 11px; align-items: center; padding: 0 6px 20px; }
.logo {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 4px 14px #5b6bf540;
}
.logo svg { width: 17px; height: 17px; stroke-width: 2; }
.brand-txt strong { display: block; font-size: 14.5px; font-weight: 600; letter-spacing: -.2px; }

.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--dim); }
.dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--faint);
  transition: .2s;
}
.conn.online .dot { background: var(--ok); box-shadow: 0 0 0 3px #3fb96a26; }
.conn.connecting .dot, .conn.resuming .dot { background: var(--warn); box-shadow: 0 0 0 3px #e0a54226; animation: pulse 1.2s infinite; }
.conn.bad-token .dot { background: var(--err); box-shadow: 0 0 0 3px #ec4b4e26; }
@keyframes pulse { 50% { opacity: .35; } }

nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
nav button {
  display: flex; align-items: center; gap: 10px;
  text-align: left; background: none; border: 0; color: var(--dim);
  padding: 8px 10px; border-radius: 9px; cursor: pointer;
  font: 500 13px/1 inherit; transition: .13s;
}
nav button svg { width: 16px; height: 16px; flex: 0 0 auto; opacity: .8; }
nav button span { flex: 1; }
nav button:hover { background: var(--panel-2); color: var(--text); }
nav button.active { background: var(--accent-soft); color: #b9c0ff; }
nav button.active svg { opacity: 1; }

.tick { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); opacity: 0; transition: .2s; }
.tick.on { opacity: 1; }

.badge {
  min-width: 19px; text-align: center; font-size: 10.5px; font-weight: 600;
  background: var(--panel-3); color: var(--dim);
  border-radius: 999px; padding: 2px 6px;
}
.badge:empty { display: none; }
.badge.alert { background: var(--err); color: #fff; }

.master {
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: var(--r); padding: 12px 13px; margin-top: 12px;
}
.master-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.master strong { display: block; font-size: 12.5px; font-weight: 600; }
.master small { color: var(--dim); font-size: 11px; }
.master-mode { margin-top: 9px; display: none; }
.master.on .master-mode { display: block; }
.mode-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: #b9c0ff;
}
.mode-chip.send { background: #3fb96a1f; color: #7fd79b; }

/* ================================================================= main */

main { flex: 1; padding: 34px 44px 90px; max-width: 1120px; }
.tab { display: none; }
.tab.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.page { margin-bottom: 24px; }
.page h1 { font-size: 24px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.4px; }
.page p { margin: 0; color: var(--dim); font-size: 13.5px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px;
  margin-bottom: 16px;
}
.card-head { margin-bottom: 16px; }
.card-head h2 { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 600; margin: 0 0 3px; }
.card-head p { margin: 0; color: var(--dim); font-size: 12.5px; max-width: 68ch; }
.ico { width: 15px; height: 15px; color: var(--accent-2); }

.muted { color: var(--dim); }
.small { font-size: 12px; }
.row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.toolbar { margin-bottom: 16px; }
.toolbar input[type=search] { max-width: 260px; }

.note {
  border: 1px solid #e0a54233; background: #e0a5420d;
  border-radius: var(--r); padding: 13px 16px; font-size: 12.5px; color: #d7bd8d;
}
.note b { color: var(--warn); }

/* stat cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px 18px;
}
.stat b { display: block; font-size: 26px; font-weight: 600; letter-spacing: -.8px; line-height: 1.2; }
.stat span { color: var(--dim); font-size: 11.5px; }

/* checklist */
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.checklist li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 9px; transition: .13s;
}
.checklist li:hover { background: var(--panel-2); }
.checklist .mark {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
  border: 1.5px solid var(--line-2); color: var(--faint);
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
}
.checklist .mark svg { width: 12px; height: 12px; stroke-width: 2.6; }
.checklist li.done .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.checklist .txt { flex: 1; font-size: 13px; }
.checklist .txt small { display: block; color: var(--dim); font-size: 11.5px; }
.checklist li.done .txt { color: var(--dim); }

/* ================================================================ forms */

.form { display: flex; flex-direction: column; gap: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px 20px; align-items: start; }
.grid .wide { grid-column: 1 / -1; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--dim); }
label .hint { font-size: 11.5px; font-weight: 400; color: var(--faint); line-height: 1.45; }
label .val { float: right; color: var(--text); font-variant-numeric: tabular-nums; }

input[type=text], input[type=password], input[type=number], input[type=search],
input[type=time], select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  color: var(--text);
  font: inherit;
  width: 100%;
  transition: .13s;
}
input::placeholder { color: var(--faint); }
textarea {
  resize: vertical; min-height: 88px; line-height: 1.6;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px;
}
input:hover, select:hover, textarea:hover { border-color: var(--line-2); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); background: var(--panel-3);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.code-input {
  font: 600 22px/1 ui-monospace, Consolas, monospace;
  letter-spacing: 10px; text-align: center; padding: 14px 12px;
}

input[type=range] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }

.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex: 0 0 auto; }
.switch.big { width: 42px; height: 23px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #333b48; border-radius: 999px; cursor: pointer; transition: .18s; }
.switch span::before {
  content: ""; position: absolute; height: 14px; width: 14px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .18s;
}
.switch.big span::before { height: 17px; width: 17px; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch.big input:checked + span::before { transform: translateX(19px); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 11px 13px; transition: .13s;
}
.toggle-row:hover { border-color: var(--line-2); }
.toggle-row .t { font-size: 12.5px; font-weight: 500; color: var(--text); }
.toggle-row .hint { display: block; font-size: 11.5px; font-weight: 400; color: var(--dim); margin-top: 2px; }

button {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 8px 15px; border-radius: 9px; cursor: pointer;
  font: 500 13px/1.4 inherit; transition: .13s;
}
button:hover { border-color: var(--line-2); background: var(--panel-3); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #6b79ff; border-color: #6b79ff; }
button.ghost { background: none; }
button.ghost:hover { background: var(--panel-2); }
button.danger { background: none; border-color: #5d2b2d; color: #ff9294; }
button.danger:hover { background: #ec4b4e14; border-color: #7a383a; }
button.link { background: none; border: 0; color: #9aa4ff; padding: 8px 4px; }
button.link:hover { background: none; text-decoration: underline; }
button.sm { padding: 6px 11px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.help { margin-top: 14px; font-size: 12.5px; color: var(--dim); }
.help summary { cursor: pointer; color: #9aa4ff; width: fit-content; }
.help ol { padding-left: 20px; margin: 8px 0 0; }
kbd { background: var(--panel-3); border: 1px solid var(--line-2); border-radius: 5px; padding: 1px 5px; font-size: 11px; }
code { background: var(--panel-2); border-radius: 5px; padding: 1.5px 5px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; }

/* ============================================================== wizard */

.wsteps { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
.wstep { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 12.5px; font-weight: 500; }
.wstep i {
  width: 24px; height: 24px; border-radius: 50%; font-style: normal;
  border: 1.5px solid var(--line-2); display: grid; place-items: center;
  font-size: 11.5px; font-weight: 600; transition: .2s;
}
.wstep.active { color: var(--text); }
.wstep.active i { border-color: var(--accent); background: var(--accent); color: #fff; }
.wstep.done i { border-color: var(--ok); background: var(--ok); color: #fff; }
.wline { flex: 1; height: 1px; background: var(--line); max-width: 60px; }
.wbody { max-width: 420px; }

.done { text-align: center; padding: 12px 0 8px; }
.done-ico {
  width: 48px; height: 48px; border-radius: 50%; margin: 0 auto 14px;
  background: #3fb96a1f; color: var(--ok); display: grid; place-items: center;
}
.done-ico svg { width: 24px; height: 24px; stroke-width: 2.6; }
.done h2 { font-size: 16px; margin: 0 0 4px; }
.done p { margin: 0 0 18px; font-size: 13px; }

.account { display: flex; align-items: center; gap: 13px; margin-bottom: 18px; }
.account-txt { flex: 1; min-width: 0; }
.account-txt b { display: block; font-size: 14px; }
.account img, .avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 15px; font-weight: 600; color: #fff;
}
.state { font-size: 11.5px; padding: 4px 10px; border-radius: 999px; background: var(--panel-2); color: var(--dim); }
.state.online { background: #3fb96a1f; color: #7fd79b; }

/* ============================================================ contacts */

.split { display: grid; grid-template-columns: 292px 1fr; gap: 16px; align-items: start; }
.list {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  max-height: 72vh; overflow-y: auto; padding: 6px;
}
.list .item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; cursor: pointer; border-radius: 9px; transition: .12s;
}
.list .item:hover { background: var(--panel-2); }
.list .item.active { background: var(--accent-soft); }
.list .item img, .list .item .avatar { width: 32px; height: 32px; font-size: 12px; }
.list .item .txt { min-width: 0; flex: 1; }
.list .item b { display: block; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .item small { color: var(--dim); font-size: 11px; }
.pill {
  font-size: 9.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px;
  padding: 2px 7px; border-radius: 999px; background: var(--panel-3); color: var(--faint); flex: 0 0 auto;
}
.pill.on { background: #3fb96a1f; color: #7fd79b; }
.pill.off { background: #ec4b4e1f; color: #ff9294; }

.detail {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: 22px; min-height: 260px;
}
.detail h3 {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .7px;
  color: var(--faint); margin: 24px 0 10px;
}
.detail h3:first-of-type { margin-top: 18px; }

.profile-grid { display: grid; grid-template-columns: 140px 1fr; gap: 7px 16px; font-size: 12.5px; margin: 0; }
.profile-grid dt { color: var(--dim); }
.profile-grid dd { margin: 0; }

.chat {
  max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
}
.bubble {
  max-width: 76%; padding: 7px 12px; border-radius: 13px;
  background: var(--panel-2); font-size: 13px; white-space: pre-wrap; word-break: break-word;
}
.bubble.mine { align-self: flex-end; background: var(--accent); color: #fff; }

.empty { text-align: center; color: var(--dim); padding: 46px 20px; font-size: 13px; }
.empty svg { width: 30px; height: 30px; opacity: .3; margin-bottom: 10px; }

/* ============================================================== drafts */

.draft {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: 18px; margin-bottom: 12px;
}
.draft header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.draft header .avatar { width: 30px; height: 30px; font-size: 12px; }
.draft header b { font-size: 13px; }
.draft header time { color: var(--faint); font-size: 11px; margin-left: auto; }
.draft .incoming {
  background: var(--panel-2); border-left: 2px solid var(--line-2);
  padding: 9px 12px; border-radius: 0 9px 9px 0; font-size: 12.5px;
  color: var(--dim); margin-bottom: 11px; white-space: pre-wrap;
}
.draft textarea { min-height: 66px; font-family: inherit; font-size: 13.5px; }

/* ================================================================= log */

.log {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 8px; max-height: 72vh; overflow-y: auto;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px;
}
.log .line { display: flex; gap: 11px; padding: 3px 9px; border-radius: 6px; }
.log .line:hover { background: var(--panel-2); }
.log time { color: #545c6b; flex: 0 0 60px; }
.log .msg { white-space: pre-wrap; word-break: break-word; color: var(--dim); }
.log .l-ok .msg { color: #7fd79b; }
.log .l-warn .msg { color: #e6bb70; }
.log .l-error .msg { color: #ff9294; }
.log .l-ai .msg { color: #b9a8f8; }
.log .l-dm .msg { color: #7cc6ea; }

/* =============================================================== toast */

#toast {
  position: fixed; bottom: 24px; right: 24px; display: flex;
  flex-direction: column; gap: 8px; z-index: 50; pointer-events: none;
}
#toast div {
  background: var(--panel-2); border: 1px solid var(--line-2);
  border-left: 3px solid var(--accent);
  padding: 11px 17px; border-radius: 9px; font-size: 13px;
  box-shadow: 0 10px 30px #0009; animation: slide .22s ease;
}
#toast div.err { border-left-color: var(--err); }
#toast div.ok { border-left-color: var(--ok); }
@keyframes slide { from { opacity: 0; transform: translateX(18px); } }

/* ============================================================ responsive */

@media (max-width: 960px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  nav { flex-direction: row; flex-wrap: wrap; }
  nav button span { flex: none; }
  main { padding: 26px 20px 60px; }
  .split { grid-template-columns: 1fr; }
  .list { max-height: 320px; }
}

/* ============================================================ utilities */

.sprite { position: absolute; width: 0; height: 0; }
.mt0 { margin-top: 0; }
.mt8 { margin-top: 8px; }

/* ================================================================= auth */

body.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, #5b6bf514, transparent 70%),
    var(--bg);
}

.auth { width: 100%; max-width: 380px; }
.auth-brand { display: flex; align-items: center; gap: 11px; justify-content: center; margin-bottom: 22px; }
.auth-brand strong { font-size: 16px; font-weight: 600; letter-spacing: -.2px; }

.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px;
  box-shadow: 0 20px 50px #0006;
}
.auth-card .card-head { margin-bottom: 18px; }
.auth-card .form { gap: 15px; }
.auth-card button[type=submit] { margin-top: 2px; }

.auth-err {
  margin: 16px 0 0;
  border: 1px solid #ec4b4e40;
  background: #ec4b4e12;
  color: #ff9294;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 12.5px;
}

.auth-foot { text-align: center; color: var(--faint); font-size: 11.5px; margin-top: 18px; }

/* security tab */
.sec-list { display: flex; flex-direction: column; gap: 8px; }
.sec-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 11px 13px; font-size: 12.5px;
}
.sec-row .grow { flex: 1; min-width: 0; }
.sec-row b { font-weight: 500; }
.sec-row small { display: block; color: var(--dim); font-size: 11.5px; }
.sec-row code { font-size: 11px; }

.codes {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 14px;
  font-family: ui-monospace, Consolas, monospace; font-size: 13px; margin: 12px 0;
}

.totp-secret {
  font-family: ui-monospace, Consolas, monospace; font-size: 14px; letter-spacing: 1.5px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 14px; margin: 10px 0; word-break: break-all; user-select: all;
}

.panel-user {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; margin-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--dim);
}
.panel-user .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-user button { padding: 4px 6px; }
.panel-user svg { width: 14px; height: 14px; display: block; }

.adv-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border-top: 1px solid var(--line); margin-top: 10px; padding: 12px 10px 4px;
}
.adv-toggle strong { display: block; font-size: 12px; font-weight: 500; color: var(--dim); }
.adv-toggle small { font-size: 10.5px; color: var(--faint); }

.presets { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.state.bad { background: #ec4b4e1f; color: #ff9294; }
.conn.no-token .dot, .conn.rejected .dot { background: var(--warn); box-shadow: 0 0 0 3px #e0a54226; }

/* inline controls inside a row must not eat the label's space */
.sec-row select { width: auto; min-width: 150px; flex: 0 0 auto; }
.sec-row button { flex: 0 0 auto; white-space: nowrap; }
.sec-row .grow b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
