:root {
  --bg: #f3efe6;
  --ink: #1d1a16;
  --muted: #6d645a;
  --line: #e2d9cc;
  --card: #fffdf9;
  --accent: #0d6b52;
  --accent-ink: #f4fff9;
  --danger: #8d2f2f;
  --shadow: 0 16px 40px rgba(60, 42, 20, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 15px/1.45 "Segoe UI", "Helvetica Neue", sans-serif;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 22px 28px 8px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; font-weight: 620; }
h1 { font-size: 28px; letter-spacing: -0.03em; }
h2 { font-size: 15px; }

.top-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.provider {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.provider select { width: auto; }

.total { margin: 0; color: var(--muted); }

.tg-manual-warn {
  margin: 0;
  padding: 10px 28px;
  background: var(--danger);
  color: #fffdf9;
  font-weight: 650;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.tabs button {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 7px 14px;
  white-space: nowrap;
}

.tabs button.active {
  background: var(--card);
  color: var(--accent);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  padding: 12px 20px 28px;
  align-items: start;
}

.layout > * { min-width: 0; }

.filters, .table-wrap, dialog form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.filters {
  max-height: calc(100vh - 180px);
  max-height: calc(100dvh - 180px);
  overflow: auto;
  padding: 8px 16px 16px;
  position: sticky;
  top: 12px;
}

.group-filters {
  margin-bottom: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 4px 16px 8px;
}

.group-filters summary {
  cursor: pointer;
  font-weight: 620;
  padding: 10px 0;
}

.group-filters .filters {
  position: static;
  max-height: 52vh;
  margin: 0 0 8px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.filters section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.filters label, .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  position: relative;
}

input, select, textarea, button {
  font: inherit;
  color: var(--ink);
}

textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  border: 1px solid #d9d0c3;
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
}

.ai-box button { width: 100%; margin-top: 10px; }
#ai-status { margin: 8px 0 0; min-height: 1.2em; }

input, select {
  width: 100%;
  border: 1px solid #d9d0c3;
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
}

input:focus, select:focus {
  outline: 2px solid rgba(13, 107, 82, 0.25);
  border-color: var(--accent);
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checks {
  max-height: 180px;
  overflow: auto;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  background: #fff;
}

.checks.short { max-height: 140px; }

.checks label {
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 4px 2px;
  color: var(--ink);
  font-size: 13px;
}

.checks input { width: auto; margin-top: 2px; }

.toggle {
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
}

.toggle input { width: auto; margin-top: 1px; }

button.help {
  position: absolute;
  top: 0;
  right: 0;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid #cfc6b8;
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  line-height: 14px;
  font-weight: 650;
  cursor: help;
}

.filters label:has(> .help) { padding-right: 22px; }

.filters .toggle button.help {
  position: static;
  flex: none;
  margin: 1px 0 0 4px;
  vertical-align: -2px;
}

.help-tip {
  position: fixed;
  z-index: 40;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #2a2622;
  color: #fffdf9;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  pointer-events: none;
}

html.hints-editing button.help {
  cursor: pointer;
  border-color: var(--accent);
  color: var(--accent);
}

button.edit-hints[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.help-editor {
  position: fixed;
  z-index: 50;
  width: min(320px, calc(100vw - 16px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf9;
  box-shadow: var(--shadow);
}

.help-editor p { margin: 0 0 6px; }
.help-editor textarea { width: 100%; min-height: 88px; resize: vertical; }
.help-editor .row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.help-editor .row button { padding: 7px 10px; }
.help-editor .status { margin-top: 6px; }

.hint { color: var(--muted); font-size: 13px; line-height: 1.45; }
.filters .hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.suggest-wrap { position: relative; }

.suggest {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: calc(100% - 2px);
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow: auto;
}

.suggest button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 7px;
  padding: 7px 8px;
}

.suggest button:hover { background: #f3f7f4; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: 8px;
  padding: 12px 0 4px;
  background: linear-gradient(to top, var(--card) 72%, transparent);
}

button {
  border: 0;
  border-radius: 9px;
  padding: 9px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

button:disabled { opacity: 0.45; cursor: default; }

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid #d9d0c3;
}

button.danger, button.tiny {
  background: transparent;
  color: var(--danger);
  border: 1px solid #e4c8c8;
}

button.tiny { padding: 4px 8px; }

.selection-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.selection-bar select,
.selection-bar input {
  width: 240px;
}

.selection-bar label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.group-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.action-cluster {
  min-width: 0;
  padding: 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.action-cluster > p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.cluster-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.cluster-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.cluster-row input,
.cluster-row select {
  width: 200px;
  max-width: 100%;
}

#group-create button { width: 100%; margin-top: 10px; }
#group-create-status, #detail-group-status { margin: 8px 0 0; min-height: 1.2em; }

.group-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: calc(100vh - 380px);
  overflow: auto;
}

.group-list button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
}

.group-list button:hover,
.group-list button.active { background: #f3f7f4; }

.group-list button.active { border-color: var(--line); }

.group-list .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-list .count {
  flex-shrink: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#group-list > li > button {
  cursor: grab;
}

#group-list > li.dragging > button {
  cursor: grabbing;
  opacity: 0.55;
}

.check-col { width: 42px; }
.check-col input { width: auto; }

.detail-legal,
.detail-lpr,
.detail-director-extra {
  margin: 0 0 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.legal-fields {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 0.7fr) auto;
  gap: 8px 12px;
  align-items: end;
}

.legal-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  cursor: copy;
}

.legal-fields button { margin-bottom: 1px; }

.legal-scope {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  cursor: default;
}

.legal-scope select { width: auto; }

#group-legal-inn-scope { width: 280px; }

#legal-status { margin: 8px 0 0; min-height: 1.2em; font-size: 12px; }

.detail-director-extra h3 {
  margin: 14px 0 6px;
  font-size: 14px;
}

.egrul-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin-bottom: 8px;
}
.egrul-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.egrul-fields input { width: 100%; }

.detail-director-extra .hint { margin: 0 0 8px; }

.detail-director-extra .lpr-fields input {
  width: 100%;
}

#director-extra-status { margin: 8px 0 0; min-height: 1.2em; font-size: 12px; }

.detail-lpr h2 { margin-bottom: 8px; }

.lpr-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 12px;
}

.lpr-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

#group-legal-progress,
#group-lpr-progress { margin: 8px 0 0; }

.lpr-fields textarea {
  min-height: 64px;
  resize: vertical;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.crm-query {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.crm-query textarea { min-height: 52px; }

.lpr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.lpr-actions p { margin: 0; }

.lpr-status { font-size: 12px; align-self: center; }

#lpr-telegram-status { margin: 8px 0 0; min-height: 1.2em; font-size: 12px; }

.tg-log {
  margin: 6px 0 0;
  padding: 8px 12px 8px 28px;
  max-height: 168px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.lpr-tg-list { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }

.lpr-tg-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px 12px;
}

.lpr-tg-card.is-main { border-color: var(--accent); }

.lpr-tg-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.lpr-tg-head h3 { margin: 0; font-size: 15px; }

.lpr-tg-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  max-width: 70%;
}

.lpr-tg-head .mark {
  flex-shrink: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.lpr-tg-head button { flex-shrink: 0; }

.lpr-tg-card dl { grid-template-columns: 110px minmax(0, 1fr); }

.lpr-tg-card .tg-photos {
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  margin-top: 8px;
}

#detail-title,
#detail-body dd { cursor: copy; }

#detail-body dd.muted { cursor: default; }

#detail-title.copied,
#detail-body dd.copied {
  background: #e7f6ec;
  border-radius: 4px;
}

#detail-title.copied::after,
#detail-body dd.copied::after {
  content: "Скопировано";
  margin-left: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

tr.lpr-row { cursor: default; }
tr.lpr-row:hover { background: transparent; }
tr.lpr-row td { padding-top: 0; }

.detail-creatives,
.detail-groups {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.creative-card,
.applied-creative {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.creative-card h3,
.applied-creative h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.applied-creative p { margin: 0 0 8px; }

.creative-card textarea,
.ai-prompt textarea,
.applied-creative .creative-message {
  white-space: pre-wrap;
  tab-size: 8;
}

.creative-card label,
.applied-creative label,
#creative-editor > label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.ai-prompt { margin-top: 10px; }

.ai-prompt-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.ai-prompts > .ghost { margin-top: 8px; }

.applied-creative a {
  display: inline-block;
  margin: 0 16px 8px 0;
}

.position-editor { margin: 4px 0 8px; }
.position-editor > p { margin: 0 0 6px; }
.position-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.position-list {
  max-height: 280px;
  overflow: auto;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.position-list label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  padding: 6px 8px;
  color: inherit;
  font-size: 14px;
}
.position-list label + label { border-top: 1px solid var(--line); }
.position-list .query { flex: 1; }
.position-list .pos {
  min-width: 3em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.applied-creative img {
  display: block;
  width: 100%;
  height: auto;
  margin-bottom: 8px;
  border-radius: 8px;
}

.applied-creative .shot-caption {
  margin: 8px 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.applied-creative img.report-shot {
  width: auto;
  max-width: 100%;
  background: #dbe5ea;
}

.detail-creatives h2,
.detail-groups h2 { margin-bottom: 8px; }

.membership {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.membership li {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f3f7f4;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 3px 3px 10px;
  font-size: 13px;
}

.membership button {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 2px 8px;
  line-height: 1.2;
}

.membership button:hover { color: var(--danger); }

.inline-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inline-add select { width: min(320px, 100%); }
#detail-creative-pick { width: min(160px, 100%); }

#group-title { overflow-wrap: anywhere; }

.results-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.results-bar p { margin: 0; }

.pager { display: flex; align-items: center; gap: 8px; }
.pager button { background: var(--card); color: var(--ink); border: 1px solid #d9d0c3; }
.page-size {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.pager select { width: auto; padding: 6px 8px; }

.table-wrap { overflow: auto; max-height: calc(100vh - 150px); }

table { width: 100%; border-collapse: collapse; min-width: 980px; }

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #faf7f2;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

tbody tr { cursor: pointer; }
tbody tr:hover { background: #f6fbf8; }

td { font-size: 14px; }
td button.linkish {
  background: none;
  color: inherit;
  border: 0;
  padding: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
td button.linkish:hover { color: var(--accent); }

.branch-count {
  margin-left: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.chain-mark,
.sent-mark,
.reply-mark {
  margin-left: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.muted { color: var(--muted); }
.status { color: var(--danger); }

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop { background: rgba(29, 26, 22, 0.35); }

dialog form { padding: 18px 20px 22px; max-height: calc(100vh - 48px); overflow: auto; }

dialog header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 12px;
}

dl { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 8px 12px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
dd a { color: var(--accent); }

.tg-board {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.tg-board section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.tg-accounts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tg-accounts-head h2 { margin: 0; }

.tg-role-title {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.tg-role-empty { margin: 0 0 4px; }

.tg-accounts-head button { width: auto; padding: 6px 12px; }

.tg-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tg-check {
  flex-shrink: 0;
  width: 22px;
  text-align: center;
  font-weight: 700;
}

.tg-check.ok { color: var(--accent); }

.tg-check.bad { color: var(--danger); }

.tg-row > button:first-child { flex: 1; min-width: 0; }

.tg-account-label {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.tg-account-label .session-file {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tg-row .tiny { width: auto; padding: 6px 10px; }

.tg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

#tg-settings button,
#tg-create button,
#tg-profile button,
#tg-photo-add button { width: 100%; margin-top: 10px; }

.tg-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.tg-photo {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.tg-photo img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #efe8dc;
}

.tg-photo .mark {
  display: block;
  padding: 8px 10px 0;
  color: var(--muted);
  font-size: 13px;
}

.tg-photo .tg-actions { margin: 8px; }

.tg-photo .tg-actions button,
.tg-photo .tg-actions label { width: 100%; }

.tg-photo input[type="file"] { display: none; }

#view-telegram input[type="file"] { padding: 6px; }

@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .filters { position: static; max-height: none; }
  .table-wrap { max-height: none; }
  .selection-bar select,
  .selection-bar input,
  .inline-add select,
  .cluster-row input,
  .cluster-row select { width: 100%; }
  .group-actions { grid-template-columns: 1fr; }
  .lpr-fields,
  .legal-fields { grid-template-columns: 1fr; }
  .tg-board { grid-template-columns: 1fr; }
}

.msg-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  height: calc(100vh - 118px);
  padding: 12px 20px 20px;
}

.msg-threads,
.msg-chat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.msg-threads header,
.msg-chat header,
.msg-form {
  padding: 14px 16px;
}

.msg-chat header {
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#msg-org {
  flex: 0 0 auto;
  white-space: nowrap;
}
.msg-form { border-top: 1px solid var(--line); }
.msg-threads header h2,
.msg-chat header h2 { margin: 0; }
.msg-threads header p,
.msg-chat header p,
#msg-status { margin: 6px 0 0; }

.msg-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

#msg-threads {
  max-height: none;
  margin: 0;
  padding: 8px;
}

.msg-thread-label {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.msg-preview,
.msg-check {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-check { font-size: 11px; }

.msg-unread {
  flex-shrink: 0;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 12px;
}

#msg-threads-empty { margin: 0 16px 16px; }

.msg-line {
  display: flex;
  margin: 8px 12px;
}

.msg-line.out { justify-content: flex-end; }

.msg-bubble {
  max-width: min(520px, 86%);
  padding: 8px 10px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-line.out .msg-bubble {
  background: #e7f4ee;
  border-color: #cfe4da;
}

.msg-line.error .msg-bubble { border-color: #e4c8c8; }

.msg-line.unread .msg-bubble { box-shadow: inset 3px 0 0 #d7a21e; }

.msg-line.out.unread .msg-bubble { box-shadow: inset -3px 0 0 #d7a21e; }

.msg-meta.is-read { color: #2f7d57; }

.msg-meta.is-unread { color: #9a6b12; }

.msg-bubble p { margin: 0; }

.msg-bubble img,
.msg-bubble video {
  display: block;
  max-width: 240px;
  border-radius: 8px;
  margin-bottom: 6px;
}

.msg-bubble a { color: var(--accent); }

.msg-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.msg-form textarea { min-height: 64px; }

.msg-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.msg-tools .file-btn {
  display: inline-flex;
  align-items: center;
  border: 1px solid #d9d0c3;
  border-radius: 9px;
  padding: 9px 14px;
  cursor: pointer;
  background: transparent;
}

.msg-tools input[type="file"] { display: none; }
.msg-tools #msg-send { margin-left: auto; }
#msg-attach { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 980px) {
  .msg-layout { grid-template-columns: 1fr; height: auto; }
  .msg-threads, .msg-chat { min-height: 420px; }
}

html.is-demo [data-demo-hide] { display: none !important; }
[data-demo-only] { display: none !important; }
html.is-demo [data-demo-only] { display: block !important; }

#demo-director { margin: 0 0 16px; }
.demo-director-bar {
  position: relative;
  height: 8px;
  margin: 10px 0;
  overflow: hidden;
  border-radius: 99px;
  background: var(--line);
}
.demo-director-bar::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 35%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: demo-director-slide 1.1s ease-in-out infinite;
}
@keyframes demo-director-slide {
  from { transform: translateX(-120%); }
  to { transform: translateX(340%); }
}
#demo-director-result { display: grid; gap: 6px; margin-top: 8px; }
#demo-director-result p { margin: 0; }
.demo-tg-card {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.demo-tg-title { margin: 14px 0 0; font-size: 15px; }
.demo-tg-card h3 { margin: 0 0 8px; font-size: 15px; }
.demo-tg-card dl {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 4px 10px;
  margin: 0;
}
.demo-tg-card dt { color: var(--muted); }
.demo-tg-card dd { margin: 0; white-space: pre-wrap; }
.demo-limit { width: 72px; margin-left: 6px; }

.limit-notice {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 40;
  width: min(360px, calc(100% - 32px));
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.limit-notice p { margin: 0; }
.limit-notice a { color: var(--accent); }
.limit-notice button { justify-self: end; }

.demo-gate,
.panel-gate { display: none; }

html.is-demo-locked .demo-gate,
html.is-panel-locked .panel-gate {
  display: grid;
  place-items: center;
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
}

.demo-gate section,
.panel-gate section {
  width: min(420px, calc(100% - 32px));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.demo-gate h2,
.panel-gate h2 { margin: 8px 0 14px; }
.demo-gate label,
.panel-gate label { display: grid; gap: 6px; }
.demo-gate input,
.panel-gate input { width: 100%; }
.demo-gate button,
.panel-gate button { margin-top: 12px; }

.demo-key {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}
