:root {
  color-scheme: light dark;
  --bg: #f4f2ee; --panel: #ffffff; --panel2: #faf8f5; --line: #e3dfd7; --text: #1f1d1a; --muted: #6f6a61;
  --accent: #9a4a2b; --accent-soft: #f3e3da; --ok: #2f7d4f; --ok-soft: #dff1e6; --warn: #a66a00; --warn-soft: #fbeed2;
  --bad: #b3372f; --bad-soft: #f9dedb; --in: #ffffff; --out: #e6f0e2; --wa: #1fa855; --tg: #2a8fd6; --mx: #7a4be0; --mock: #8a8a8a;
  --radius: 10px; --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614; --panel: #201f1c; --panel2: #262421; --line: #36332e; --text: #ece8e1; --muted: #a09a8f;
    --accent: #e08a63; --accent-soft: #3a2a22; --ok: #6cc08d; --ok-soft: #1f3528; --warn: #e0b04a; --warn-soft: #3a3019;
    --bad: #ef7d74; --bad-soft: #40221f; --in: #2a2825; --out: #24382a;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.field > input, label.field > select { color: var(--text); font-size: 14px; }
label.check { display: flex; gap: 8px; align-items: center; }

/* каркас */
.shell { display: flex; height: 100vh; }
.nav { width: 190px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; flex-shrink: 0; }
.nav .brand { font-weight: 700; padding: 4px 10px 14px; line-height: 1.2; }
.nav .brand span { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text); cursor: pointer; }
.nav a:hover { background: var(--panel2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); }
.main { flex: 1; min-width: 0; overflow: auto; padding: 20px 24px; }
.main.flush { padding: 0; overflow: hidden; }
.badge { display: inline-block; border-radius: 20px; padding: 1px 8px; font-size: 11px; font-weight: 600; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.accent { background: var(--accent); color: #fff; border-color: transparent; }
.kind { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: 10px; font-weight: 700; align-items: center; justify-content: center; flex-shrink: 0; }
.kind.whatsapp { background: var(--wa); } .kind.telegram { background: var(--tg); } .kind.max { background: var(--mx); } .kind.mock { background: var(--mock); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat .num { font-size: 28px; font-weight: 700; }
.bar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel2); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel2); }
.tablewrap { overflow-x: auto; }
td.clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* чаты */
.chats { display: grid; grid-template-columns: 320px 1fr 300px; height: 100vh; }
.chatlist { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.chatlist .tools { padding: 10px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.chatlist .items { overflow: auto; flex: 1; }
.chatitem { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 10px; }
.chatitem:hover { background: var(--panel2); }
.chatitem.active { background: var(--accent-soft); }
.chatitem .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatitem .last { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatitem .meta { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread .head { padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; gap: 10px; align-items: center; }
.thread .msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 72%; padding: 7px 11px; border-radius: 12px; background: var(--in); border: 1px solid var(--line); align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg .t { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin-bottom: 4px; }
.day { align-self: center; font-size: 11px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 1px 10px; margin: 6px 0; }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 140px; }
.info { border-left: 1px solid var(--line); background: var(--panel); padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 16px; }
.empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); text-align: center; padding: 30px; }
.qr { background: #fff; padding: 8px; border-radius: 8px; width: 216px; height: 216px; display: block; margin: 10px 0; }
.code { font: 700 26px/1 ui-monospace, Menlo, monospace; letter-spacing: 3px; padding: 12px 0; }

.login { max-width: 340px; margin: 12vh auto; display: flex; flex-direction: column; gap: 12px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 50; max-width: 90vw; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.section { margin-bottom: 22px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
pre.mono { font: 12px/1.4 ui-monospace, Menlo, monospace; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

a.chatitem { text-decoration: none; color: inherit; }
.warn-text { color: var(--warn); }
.only-mobile, .nav a.only-mobile, .only-narrow, .info-toggle, .info-close { display: none; }
.row > .grow { min-width: 220px; } .row > .grow > input { width: 100%; }
.composer textarea { scrollbar-width: thin; }
.msg .react { display: flex; gap: 4px; margin: 4px 0 -14px; }
.msg .react span { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0 6px; font-size: 14px; line-height: 22px; }
.msg:has(.react) { margin-bottom: 10px; }
.attach { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel2); }
.attach img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.attach .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach .grow { min-width: 0; }
.thread { position: relative; }
.thread.drop::after { content: 'Отпустите файл, чтобы прикрепить'; position: absolute; inset: 8px; display: flex; align-items: center; justify-content: center; border: 2px dashed var(--accent); border-radius: 12px; background: color-mix(in srgb, var(--panel) 85%, transparent); color: var(--accent); font-weight: 600; pointer-events: none; z-index: 3; }
textarea:disabled, .btn:disabled { opacity: .5; }

@media (max-width: 1100px) {
  .chats { grid-template-columns: 280px 1fr; position: relative; }
  .info { display: none; position: absolute; right: 0; top: 0; bottom: 0; width: min(340px, 100%); z-index: 5; box-shadow: -8px 0 24px rgba(0,0,0,.25); }
  .chats.show-info .info { display: flex; }
  .info-toggle, .info-close { display: inline-block; }
  .info-close { align-self: flex-end; }
}
@media (max-width: 760px) {
  .shell { flex-direction: column; height: 100dvh; }
  .nav { width: auto; flex-direction: row; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); flex-shrink: 0; }
  .nav .brand, .nav .foot { display: none; }
  .nav a { white-space: nowrap; gap: 6px; }
  .only-mobile, .nav a.only-mobile { display: flex; }
  .row > .grow { min-width: 0; }
  .only-narrow { display: inline-block; }
  .main { padding: 14px; }
  .main.flush { min-height: 0; }
  .chats { grid-template-columns: 1fr; height: 100%; }
  .chats.open .chatlist { display: none; } .chats:not(.open) .thread { display: none; }
  .msg { max-width: 88%; }
}
