/* Корпоративная палитра: графит, тёплый серый, бордо. Без синего и фиолетового. */
:root {
  --graphite: #23262a;
  --graphite-2: #2e3236;
  --graphite-3: #3a3f44;
  --side-text: #d9d8d3;
  --side-muted: #8f9193;
  --bg: #f4f3f0;
  --panel: #ffffff;
  --line: #dedcd6;
  --line-2: #ebe9e4;
  --text: #1e2124;
  --muted: #6b6e72;
  --accent: #7b2333;
  --accent-hover: #641b29;
  --accent-soft: #f3e7e9;
  --ok: #3d5a3f;
  --danger: #8a2a1f;
  --radius: 6px;
  --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- Кнопки и поля ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius);
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
a.btn { display: inline-block; color: var(--text); text-decoration: none; }
.btn:hover { background: #f7f6f3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.link-btn { background: none; border: 0; padding: 0; cursor: pointer; color: inherit; text-align: left; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; background: #fff; outline: none;
}
.input:focus { border-color: var(--graphite-3); box-shadow: 0 0 0 3px rgba(35, 38, 42, .08); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.error-text { color: var(--danger); min-height: 1.4em; font-size: 13px; }

/* ---------- Вход ---------- */
.login-page { display: flex; align-items: center; justify-content: center; background: var(--graphite); }
.login-card {
  width: 360px; background: var(--panel); border-radius: 8px; padding: 32px 30px 26px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.login-card .brand-mark { margin-bottom: 18px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.login-card .btn { width: 100%; padding: 10px; }
.login-foot { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }

.brand-mark { width: 30px; height: 30px; border-radius: 5px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; inset: 8px; border: 2px solid #fff; border-radius: 2px; }

/* ---------- Мессенджер ---------- */
.layout { display: flex; height: 100vh; }
.sidebar { width: 290px; flex: none; background: var(--graphite); color: var(--side-text); display: flex; flex-direction: column; }
.brand { display: flex; gap: 12px; align-items: center; padding: 18px 18px 16px; border-bottom: 1px solid var(--graphite-2); }
.brand-name { font-weight: 600; color: #fff; }
.brand-sub { font-size: 12px; color: var(--side-muted); }
.me { display: flex; gap: 10px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--graphite-2); }
.me .muted { color: var(--side-muted); font-size: 12px; }
.side-scroll { flex: 1; overflow-y: auto; padding: 8px 0; }
.side-section { margin-bottom: 10px; }
.side-title {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 18px 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--side-muted);
}
.icon-btn {
  width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--graphite-3);
  background: none; color: var(--side-text); cursor: pointer; line-height: 1; font-size: 15px;
}
.icon-btn:hover { background: var(--graphite-2); }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-item { display: flex; align-items: center; gap: 10px; padding: 7px 18px; cursor: pointer; border-left: 3px solid transparent; }
.conv-item:hover { background: var(--graphite-2); }
.conv-item.active { background: var(--graphite-2); border-left-color: var(--accent); color: #fff; }
.conv-item .hash { width: 26px; text-align: center; color: var(--side-muted); font-weight: 600; }
.conv-item .conv-main { flex: 1; min-width: 0; }
.conv-item .conv-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-sub { font-size: 12px; color: var(--side-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item.unread .conv-name { color: #fff; font-weight: 600; }
.badge { background: var(--accent); color: #fff; font-size: 11px; border-radius: 9px; padding: 1px 7px; min-width: 20px; text-align: center; }
.side-empty { padding: 4px 18px; font-size: 12px; color: var(--side-muted); }
.side-footer { border-top: 1px solid var(--graphite-2); padding: 12px 18px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.side-footer a { color: var(--side-text); text-decoration: none; }
.side-footer a:hover, .side-footer .link-btn:hover { color: #fff; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff; background: var(--graphite-3);
}
.avatar.small { width: 26px; height: 26px; font-size: 11px; }
.avatar.t1 { background: #5b4a3a; } .avatar.t2 { background: #4a5548; } .avatar.t3 { background: #6a2f39; } .avatar.t4 { background: #4d5157; }

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.chat > section { display: flex; flex-direction: column; height: 100%; }
.empty { margin: auto; color: var(--muted); }
.chat-head { padding: 16px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head h1 { font-size: 17px; }
.chat-head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.user-pick label { display: flex; gap: 10px; align-items: center; flex: 1; cursor: pointer; }
.user-pick input[type=checkbox] { margin: 0; accent-color: var(--accent); }
.pick-top { display: grid; gap: 8px; }
.pick-count { font-size: 12px; color: var(--muted); margin-top: 6px; }
.chat-head .muted { font-size: 13px; }
.messages { flex: 1; overflow-y: auto; padding: 12px 24px 18px; background: var(--panel); }
.load-more { display: block; margin: 4px auto 12px; }
.day-sep { display: flex; align-items: center; gap: 12px; margin: 18px 0 8px; color: var(--muted); font-size: 12px; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; border-top: 1px solid var(--line-2); }
.msg { display: flex; gap: 12px; padding: 6px 0 2px; }
.msg.cont { padding-top: 0; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg-body { flex: 1; min-width: 0; }
.msg-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.msg-head .name { font-weight: 600; }
.msg-head .pos, .msg-head .time { font-size: 12px; color: var(--muted); }
.role-tag { font-size: 11px; color: var(--accent); border: 1px solid #e2c9ce; background: var(--accent-soft); border-radius: 3px; padding: 0 5px; }
.msg-text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.composer { display: flex; gap: 10px; padding: 14px 24px 18px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 180px; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 12px; outline: none; background: #fff;
}
.composer textarea:focus { border-color: var(--graphite-3); }
.readonly-note { padding: 14px 24px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; background: #faf9f7; }

/* ---------- Вложения и голосовые ---------- */
.btn.icon { padding: 0; width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); flex: none; }
.btn.icon:hover { color: var(--text); }
.record-bar { display: flex; align-items: center; gap: 12px; padding: 14px 24px 18px; border-top: 1px solid var(--line); }
.record-bar .spacer { flex: 1; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: recpulse 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 42px; }
@keyframes recpulse { 50% { opacity: .25; } }
.uploads:empty { display: none; }
.uploads { border-top: 1px solid var(--line); padding: 8px 24px 0; }
.upload-row { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 8px; }
.upload-row .name { flex: 0 1 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row .bar { flex: 1; height: 6px; background: var(--line-2); border-radius: 3px; overflow: hidden; }
.upload-row .bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-row .pct { width: 40px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.att { margin-top: 4px; }
.att-image img { display: block; max-width: 340px; max-height: 300px; border-radius: 6px; border: 1px solid var(--line-2); cursor: zoom-in; background: #f7f6f3; }
.att-card { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; max-width: 460px; background: #fbfaf8; }
.att-ext { width: 40px; height: 40px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; text-transform: uppercase; }
.att-info { flex: 1; min-width: 0; }
.att-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.att-meta { font-size: 12px; color: var(--muted); }
.att-actions { display: flex; gap: 6px; flex: none; }
.att-media audio { display: block; width: 360px; max-width: 100%; margin-top: 6px; }
.att-media video { display: block; max-width: 480px; max-height: 320px; border-radius: 6px; margin-top: 6px; background: #000; }
.att-voice { display: flex; align-items: center; gap: 10px; }
.att-voice audio { width: 300px; max-width: 100%; height: 40px; }
.att-voice .att-meta { white-space: nowrap; }
.att-small { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 4px; }
.img-full { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; }
.modal.wide { width: 900px; }
.drop-hint { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(123, 35, 51, .08); border: 2px dashed var(--accent); color: var(--accent); font-weight: 600; z-index: 5; pointer-events: none; }
.chat > section.dragging .drop-hint { display: flex; }
.chat > section { position: relative; }

/* ---------- Просмотрщик документов ---------- */
.viewer { position: fixed; inset: 0; z-index: 48; background: #3a3d41; display: flex; flex-direction: column; }
.viewer-head { display: flex; align-items: center; gap: 10px; padding: 10px 18px; background: var(--graphite); color: #fff; }
.viewer-head .v-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-head .v-pages { color: var(--side-muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.viewer-head .btn { background: var(--graphite-2); border-color: var(--graphite-3); color: #fff; }
.viewer-head .btn:hover { background: var(--graphite-3); }
.viewer-body { flex: 1; overflow: auto; padding: 20px; }
.viewer-page { display: block; margin: 0 auto 16px; background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.35); width: 900px; max-width: 100%; min-height: 200px; }
.viewer-msg { color: #e6e5e1; text-align: center; margin-top: 18vh; font-size: 15px; }
.viewer-msg .btn { margin-top: 14px; }
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.2); border-top-color: #fff; border-radius: 50%; margin: 0 auto 14px; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert-badge { display: inline-block; background: var(--danger); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 7px; margin-left: 6px; }

/* ---------- Модальные окна ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 22, 24, .5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: var(--panel); border-radius: 8px; width: 420px; max-width: calc(100vw - 32px); max-height: 85vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal h2 { font-size: 16px; padding: 18px 20px 0; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.user-pick { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow-y: auto; border: 1px solid var(--line-2); border-radius: var(--radius); }
.user-pick li { display: flex; gap: 10px; align-items: center; padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.user-pick li:last-child { border-bottom: 0; }
.user-pick li:hover { background: #f7f6f3; }
.secret-box { background: #f7f6f3; border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px 12px; font-family: Consolas, monospace; user-select: text !important; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--graphite); color: #fff; padding: 10px 16px; border-radius: var(--radius); z-index: 60; font-size: 13px; }
.toast.error { background: var(--danger); }

/* ---------- Админка ---------- */
.admin-page { background: var(--bg); }
.topbar { background: var(--graphite); color: #fff; display: flex; align-items: center; gap: 14px; padding: 12px 24px; }
.topbar .brand-name { flex: 1; }
.topbar a { color: var(--side-text); text-decoration: none; font-size: 13px; }
.topbar a:hover { color: #fff; }
.tabs { display: flex; gap: 2px; padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab { padding: 12px 16px; border: 0; background: none; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.admin-main { padding: 20px 24px; max-width: 1440px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 18px; overflow-x: auto; }
.card h2 { font-size: 15px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin-bottom: 0; }
.card-head select { max-width: 260px; }
.dept-tag { display: inline-block; font-size: 12px; background: #eeece7; color: #4a4d51; border-radius: 3px; padding: 1px 7px; white-space: nowrap; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-row label.field { flex: 1; min-width: 150px; margin-bottom: 0; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.grid tr.dim td { color: var(--muted); }
table.grid td.actions { text-align: right; min-width: 250px; }
table.grid td.actions .btn { margin: 0 0 4px 4px; }
.status { font-size: 12px; padding: 1px 7px; border-radius: 3px; }
.status.ok { background: #e7ede6; color: var(--ok); }
.status.off { background: #f3e5e2; color: var(--danger); }
.filters { display: flex; gap: 10px; margin-bottom: 12px; }
.filters select { max-width: 260px; }
.decode-result { margin-top: 14px; }
.check-row { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.check-row input { accent-color: var(--accent); }
hr.sep { border: 0; border-top: 1px solid var(--line-2); margin: 18px 0; }

/* ---------- Антислив ---------- */
.app-page, .admin-page { -webkit-user-select: none; user-select: none; }
input, textarea, .allow-copy { -webkit-user-select: text; user-select: text; }
#wm-layer {
  position: fixed; inset: 0; pointer-events: none; z-index: 55;
  background-repeat: repeat;
}
#shield {
  position: fixed; inset: 0; z-index: 45; display: none; align-items: center; justify-content: center;
  background: rgba(35, 38, 42, .35); color: #fff; font-size: 15px; text-align: center;
}
body.shielded #root { filter: blur(16px); }
body.shielded #shield { display: flex; }
@media print {
  body * { display: none !important; }
  body::after { content: "Печать материалов запрещена"; display: block; padding: 40px; font-size: 20px; }
}
@media (max-width: 760px) {
  .sidebar { width: 230px; }
  .messages, .composer, .chat-head { padding-left: 14px; padding-right: 14px; }
}
