/* Palette and controls follow the reference client (internal/api/web). */
:root {
  --bg: #f4f5f7; --panel: #fff; --line: #e3e5e8; --text: #1d2129; --muted: #737a86;
  --accent: #2f6fde; --accent-soft: #e8effc; --ok: #2ea44f; --warn: #c0392b; --amber: #b7791f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b; --panel: #1d2026; --line: #2b2f37; --text: #e6e8eb; --muted: #8b929c;
    --accent: #5b8ff0; --accent-soft: #23304a; --ok: #3fb950; --warn: #e5736a; --amber: #d29922;
  }
}
* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
body { margin: 0; font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 16px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--accent); }

input, select, textarea {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
input[type=checkbox] { padding: 0; }
button { padding: 6px 12px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; font: inherit; white-space: nowrap; }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--warn); border: 1px solid var(--line); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); }

header { display: flex; gap: 12px; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
header .who { margin-left: auto; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.layout { display: grid; grid-template-columns: 180px 1fr; min-height: calc(100vh - 49px); }
nav { background: var(--panel); border-right: 1px solid var(--line); padding: 8px 0; }
nav button { display: block; width: 100%; text-align: left; background: none; color: var(--text); border-radius: 0; padding: 9px 16px; }
nav button:hover { background: var(--bg); }
nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { padding: 16px 20px; min-width: 0; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr:last-child td { border-bottom: 0; }
tr.selectable { cursor: pointer; }
tr.selectable:hover td { background: var(--bg); }
tr.selected td { background: var(--accent-soft); }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 4px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }

.state { display: inline-flex; align-items: center; gap: 6px; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.state.online::before { background: var(--ok); }
.state.connecting::before, .state.offline::before, .state.login::before, .state.new::before { background: var(--amber); }
.state.proxy_down::before, .state.logged_out::before, .state.blocked::before { background: var(--warn); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-size: 12px; margin: 1px 2px 1px 0; }
.tag.deny { background: transparent; color: var(--warn); border: 1px solid var(--warn); }

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.form .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form .row > input, .form .row > select { flex: 1; min-width: 0; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px 12px; }
.checks label { display: flex; gap: 6px; align-items: center; color: var(--text); font-size: 13px; }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); padding: 18px 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog .buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.qr { display: flex; justify-content: center; padding: 8px; background: #fff; border-radius: 8px; }
.qr svg { width: 220px; height: 220px; }
.secret { padding: 8px; border: 1px dashed var(--line); border-radius: 6px; word-break: break-all; user-select: all; }

/* Chats: dialog list on the left, conversation on the right. Bubbles and
   the --out color follow the reference client. */
:root { --out: #dcf3d6; }
@media (prefers-color-scheme: dark) { :root { --out: #2c4a2f; } }
.messenger {
  display: grid; grid-template-columns: 320px minmax(0, 1fr); height: calc(100vh - 49px - 32px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.dialogs { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.dialogs-head { display: grid; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.dialogs-head .row { display: flex; gap: 8px; align-items: center; }
.dialogs-head select { flex: 1; min-width: 0; }
.dialogs-list { flex: 1; overflow-y: auto; }
.dialog { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.dialog:hover { background: var(--bg); }
.dialog.active { background: var(--accent-soft); }
.dialog .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog .time { color: var(--muted); font-size: 12px; }
.dialog .last { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { justify-self: end; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; text-align: center; }
.badge.muted { background: var(--muted); }

.conversation { display: flex; min-width: 0; min-height: 0; }
.conversation-in { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.conversation-head { display: flex; gap: 10px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); min-height: 50px; }
.conversation-head .title { font-weight: 600; }
.conversation-head .back { display: none; }
.conversation-head .seen { color: var(--muted); font-size: 12px; }
.conversation-head .seen.online { color: var(--accent); }
.online-dot { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 50%; background: var(--ok); vertical-align: middle; }
.empty.pick { flex: 1; align-self: center; }
.messages { flex: 1; overflow-y: auto; padding: 10px 16px; display: flex; flex-direction: column; gap: 4px; background: var(--bg); }
.messages .more { align-self: center; font-size: 12px; }
.msg-row { display: flex; flex-direction: column; align-items: flex-start; }
.msg-row.out { align-items: flex-end; }
.msg-row.service { align-items: center; }
.day { align-self: center; margin: 8px 0 4px; }
.day span, .service-text { padding: 2px 10px; border-radius: 10px; background: var(--panel); color: var(--muted); font-size: 12px; }
.msg { max-width: min(560px, 75%); padding: 6px 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.msg-row.out .msg { background: var(--out); border-color: transparent; }
.msg .sender { color: var(--accent); font-size: 12px; font-weight: 600; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .meta { color: var(--muted); font-size: 11px; text-align: right; }
.msg .pic { display: block; max-width: 100%; width: 280px; min-height: 60px; margin: 2px 0 4px; border-radius: 6px; background: var(--line); cursor: zoom-in; object-fit: cover; }
.msg .pic.broken { min-height: 0; height: 0; }
.msg .file { display: block; margin: 2px 0 4px; background: var(--accent-soft); color: var(--accent); white-space: normal; text-align: left; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; field-sizing: content; min-height: 34px; max-height: 160px; }

dialog.viewer { width: auto; max-width: calc(100vw - 32px); }
dialog.viewer img, dialog.viewer video { display: block; max-width: 100%; max-height: calc(100vh - 140px); margin: 0 auto; border-radius: 6px; }

.signin { max-width: 380px; margin: 12vh auto; }
.toast { position: fixed; right: 16px; bottom: 16px; max-width: 420px; padding: 10px 14px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0, 0, 0, .15); }
.toast.error { border-color: var(--warn); color: var(--warn); }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  nav { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 0; }
  nav button { width: auto; }
  .split { grid-template-columns: 1fr; }
  main.flush { padding: 0; }
  .messenger { grid-template-columns: 1fr; height: calc(100vh - 49px - 41px); border: 0; border-radius: 0; }
  .messenger.open .dialogs, .messenger:not(.open) .conversation { display: none; }
  .conversation-head .back { display: inline-block; }
}
