/*
 * The same look the phones wear, in a browser.
 *
 * The colours are the client's own keys, taken from TgPalette.swift so that
 * somebody who uses the app on a phone and the web side by side sees one
 * product rather than two. Light and dark follow the system; there is no
 * switch, because the one in the operating system is the switch.
 */

:root {
  --bg: #ffffff;
  --gray: #f0f0f0;
  --panel: #ffffff;
  --ink: #000000;
  --ink-dim: #808080;
  --ink-faint: #a8a8a8;
  --accent: #3390ec;
  --accent-ink: #ffffff;
  --divider: #e6e6e6;
  --bubble-in: #ffffff;
  --bubble-out: #eeffde;
  --bubble-out-ink: #000000;
  --wallpaper: #dbddbb;
  --danger: #e53935;
  --row-hover: #f4f4f5;
  --shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17212b;
    --gray: #0e1621;
    --panel: #17212b;
    --ink: #ffffff;
    --ink-dim: #8b9398;
    --ink-faint: #6d7883;
    --accent: #5eb5f7;
    --accent-ink: #ffffff;
    --divider: #101921;
    --bubble-in: #182533;
    --bubble-out: #2b5278;
    --bubble-out-ink: #ffffff;
    --wallpaper: #151e27;
    --danger: #ec6657;
    --row-hover: #202b36;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--gray);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ─────────────────────────────── вход ─────────────────────────────── */

.signin {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.signin form {
  width: min(380px, 100%);
  background: var(--panel);
  border-radius: 14px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.signin h1 { margin: 0 0 4px; font-size: 24px; }
.signin .sub { margin: 0 0 22px; color: var(--ink-dim); font-size: 14px; }

.field {
  width: 100%;
  padding: 13px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: var(--bg);
  outline: none;
}
.field:focus { border-color: var(--accent); }

.primary {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.primary:disabled { opacity: .55; cursor: default; }

.error { color: var(--danger); font-size: 14px; margin: 10px 0 0; }
.hint { color: var(--ink-dim); font-size: 13px; margin: 16px 0 0; }

/* ──────────────────────────── основной вид ─────────────────────────── */

.app { display: flex; height: 100%; }

.list {
  width: 380px;
  min-width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
}

.bar {
  height: 56px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--divider);
  flex: 0 0 auto;
}
.bar .title { font-weight: 600; font-size: 17px; flex: 1; }
.bar .state { font-size: 12px; color: var(--ink-dim); }

.icon-btn {
  border: 0;
  background: transparent;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--ink-dim);
}
.icon-btn:hover { background: var(--row-hover); color: var(--ink); }

.search { padding: 8px 12px; border-bottom: 1px solid var(--divider); }
.search input { margin: 0; }

.rows { overflow-y: auto; flex: 1; }

.row {
  display: flex;
  gap: 11px;
  padding: 9px 12px;
  cursor: pointer;
  align-items: center;
}
.row:hover { background: var(--row-hover); }
.row.active { background: var(--accent); }
.row.active .name, .row.active .last, .row.active .time { color: var(--accent-ink); }

.avatar {
  width: 48px; height: 48px;
  flex: 0 0 48px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 17px;
  user-select: none;
}

.row .text { min-width: 0; flex: 1; }
.row .head { display: flex; align-items: baseline; gap: 8px; }
.row .name { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 12px; color: var(--ink-faint); }
.row .last {
  color: var(--ink-dim); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff; font-size: 12px; font-weight: 600;
  display: grid; place-items: center;
}
.row.active .badge { background: #fff; color: var(--accent); }

/* ──────────────────────────── переписка ───────────────────────────── */

.thread { flex: 1; display: flex; flex-direction: column; background: var(--wallpaper); }

.thread .bar { background: var(--panel); }

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.day {
  align-self: center;
  margin: 10px 0;
  padding: 3px 10px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .25);
  color: #fff;
  font-size: 13px;
}

.bubble {
  max-width: min(520px, 76%);
  padding: 6px 10px 7px;
  border-radius: 14px;
  background: var(--bubble-in);
  box-shadow: var(--shadow);
  align-self: flex-start;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.mine { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-ink); }
.bubble .meta { font-size: 11px; color: var(--ink-faint); float: right; margin: 6px 0 0 8px; }
.bubble.system {
  align-self: center; background: rgba(0, 0, 0, .25); color: #fff;
  box-shadow: none; font-size: 13px; padding: 4px 10px;
}

.composer {
  flex: 0 0 auto;
  padding: 10px 14px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 11px 14px;
  border-radius: 18px;
  border: 0;
  background: var(--panel);
  box-shadow: var(--shadow);
  outline: none;
}
.send {
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.send:disabled { opacity: .5; cursor: default; }

.empty {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--ink-dim);
  padding: 24px;
}
.empty h2 { margin: 0 0 6px; font-size: 17px; color: var(--ink); }
.empty p { margin: 0; font-size: 14px; max-width: 320px; }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
  font-size: 13px;
}
.notice button { border: 0; background: transparent; color: inherit; }

.banner {
  padding: 10px 14px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: 13px;
}

@media (max-width: 760px) {
  .list { width: 100%; }
  .app.has-open .list { display: none; }
  .app:not(.has-open) .thread { display: none; }
}
