:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2529;
  --muted: #6b7c85;
  --line: #dde5e9;
  --accent: #2e7d4f;
  --accent-soft: #eaf5ee;
  --bad: #b71c1c;
  --bad-soft: #fdecea;
  --user: #f1f4f6;
  --shadow: 0 1px 3px rgba(20, 40, 50, .08);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "DejaVu Sans", Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}

body { display: flex; flex-direction: column; min-height: 100vh; }

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 10px; flex: 0 0 auto; }
.logo { font-weight: 700; color: var(--accent); letter-spacing: .3px; }
.sub { color: var(--muted); font-size: 12px; }
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: #e8eef1; color: #35525e; white-space: nowrap;
}
.badge.admin { background: var(--accent-soft); color: var(--accent); }

.controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.controls input[type="search"] { width: 220px; }
input, select, button {
  font: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: inherit;
}
input[type="date"] { padding: 4px 6px; }
button { cursor: pointer; }
button:hover { border-color: #b8c6cc; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.chk { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }

#banners { display: flex; flex-direction: column; gap: 6px; padding: 0 14px; }
#banners:empty { display: none; }
.banner {
  margin-top: 8px; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  background: #fff8e1; border: 1px solid #ffe0a3;
}
.banner.bad { background: var(--bad-soft); border-color: #f3c1bc; color: #8f1d16; }
.banner .actions { margin-top: 6px; display: flex; gap: 8px; }

.grid {
  display: grid;
  grid-template-columns: 280px 300px 1fr;
  gap: 0;
  flex: 1 1 auto;
  min-height: 0;
}
.grid.personal { grid-template-columns: 300px 1fr; }

.col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.col:last-child { border-right: 0; }
.col-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  font-weight: 600; font-size: 12.5px; color: #33505c; flex: 0 0 auto;
}
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.scroll { overflow-y: auto; flex: 1 1 auto; min-height: 0; }

/* сотрудники */
.user {
  padding: 9px 12px; border-bottom: 1px solid #eef2f4; cursor: pointer;
}
.user:hover { background: #f7fafb; }
.user.active { background: var(--accent-soft); border-left: 3px solid var(--accent); padding-left: 9px; }
.user .name { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.user .meta { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.user .link { font-size: 11.5px; margin-top: 3px; color: #35525e; }
.user .unlinked { color: var(--bad); }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 8px; background: #e8eef1; color: #35525e; }
.tag.manager { background: #fff3e0; color: #8a5a00; }

/* разговоры */
.session {
  padding: 9px 12px; border-bottom: 1px solid #eef2f4; cursor: pointer;
}
.session:hover { background: #f7fafb; }
.session.active { background: var(--accent-soft); border-left: 3px solid var(--accent); padding-left: 9px; }
.session .when { font-weight: 600; font-size: 13px; }
.session .meta { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.session .err { color: var(--bad); font-size: 11.5px; margin-top: 2px; }
.day-sep {
  padding: 7px 12px; font-size: 11px; font-weight: 700; color: var(--accent);
  background: #f3f8f5; border-bottom: 1px solid var(--line); letter-spacing: .3px;
}

/* переписка */
#chat { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); padding: 22px; text-align: center; }
.msg { max-width: 78%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.42; }
.msg.user { align-self: flex-start; background: var(--user); border: 1px solid #e3e9ec; border-bottom-left-radius: 3px; }
.msg.assistant { align-self: flex-end; background: var(--accent-soft); border: 1px solid #cfe6d8; border-bottom-right-radius: 3px; }
.msg.error { outline: 1.5px solid #e0a49e; background: #fff5f4; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg .voice { font-size: 12px; color: #546e7a; margin-top: 4px; padding-top: 4px; border-top: 1px dashed #cfd8dc; }
.msg .errline { color: var(--bad); font-size: 12px; margin-top: 4px; font-weight: 600; }

.chips { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  font-size: 11px; padding: 2px 8px; border-radius: 9px;
  background: #dfe9ec; color: #29434e; border: 0; cursor: pointer;
}
.chip:hover { background: #cfdde2; }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip .ms { opacity: .65; }
.files { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.file-link { font-size: 12px; color: var(--accent); text-decoration: none; }
.file-link:hover { text-decoration: underline; }

/* модальное окно */
.modal {
  position: fixed; inset: 0; background: rgba(18, 32, 38, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #fff; border-radius: 10px; width: min(900px, 96vw); max-height: 88vh;
  display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.modal-head button { border: 0; background: transparent; font-size: 16px; }
.modal-body { padding: 12px 14px; overflow: auto; }
.modal-body pre {
  white-space: pre-wrap; word-break: break-word; background: #f6f8f9;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 12px;
  max-height: 50vh; overflow: auto; margin: 6px 0 14px;
}
.modal-body h4 { margin: 12px 0 4px; font-size: 13px; }
.kv { display: grid; grid-template-columns: minmax(120px, 220px) 1fr; gap: 4px 12px; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 8px 0 4px; }
.stat { background: #f6f9fa; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat .v { font-size: 20px; font-weight: 700; color: var(--accent); }
.stat .l { font-size: 11.5px; color: var(--muted); }
.result-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.search-hit { padding: 8px 12px; border-bottom: 1px solid #eef2f4; cursor: pointer; }
.search-hit:hover { background: #f7fafb; }
.search-hit .snippet { font-size: 12px; color: #37474f; margin-top: 3px; }
mark { background: #fff59d; }

@media (max-width: 1100px) {
  .grid { grid-template-columns: 240px 260px 1fr; }
}
@media (max-width: 860px) {
  .grid, .grid.personal { grid-template-columns: 1fr; }
  .col { border-right: 0; border-bottom: 1px solid var(--line); max-height: 42vh; }
  .controls input[type="search"] { width: 150px; }
}

/* --- вход по email и паролю LibreChat (change larisa-employee-identity) --- */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 24, 38, 0.72);
  backdrop-filter: blur(2px);
}
.login-card {
  width: min(420px, calc(100vw - 32px));
  background: #fff;
  border-radius: 14px;
  padding: 22px 24px 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}
.login-card h2 { margin: 0 0 6px; font-size: 20px; }
.login-card label { display: block; margin: 12px 0 4px; font-size: 13px; color: #555; }
.login-card input {
  width: 100%;
  padding: 9px 11px;
  font-size: 14px;
  border: 1px solid #cfd6e4;
  border-radius: 8px;
  box-sizing: border-box;
}
.login-card .primary {
  margin-top: 16px;
  width: 100%;
  padding: 10px;
  font-size: 15px;
  border: 0;
  border-radius: 8px;
  background: #1f6feb;
  color: #fff;
  cursor: pointer;
}
.login-card .primary:hover { background: #1a5fd0; }
.login-error { min-height: 18px; margin-top: 10px; color: #b71c1c; font-size: 13px; }
.login-card .small { font-size: 12px; margin: 10px 0 0; }

/* --- метки каналов и карточка сотрудника --- */
.ch-tag {
  display: inline-block;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11px;
  background: #eef2f9;
  color: #39507a;
  border: 1px solid #dbe3f1;
}
.ch-tag.ch-telegram { background: #e8f4fd; color: #1b6fa8; border-color: #cbe6f9; }
.ch-tag.ch-librechat { background: #eef8ee; color: #226b2c; border-color: #d3ecd4; }
.ch-tag.ch-max { background: #f3eefc; color: #5b39a3; border-color: #e2d7f8; }

.channels { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.ch-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #f4f6fb;
  border: 1px solid #dfe5ef;
  color: #40506e;
}
.chip-x {
  border: 0;
  background: transparent;
  color: #b71c1c;
  cursor: pointer;
  font-size: 11px;
  padding: 0 1px;
}
.tag.on { background: #e6f6e9; color: #1f6b2a; border-color: #cbe9d1; }
.tag.off { background: #fdeaea; color: #a12323; border-color: #f6d3d3; }
.admin-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.role-select { font-size: 12px; padding: 2px 4px; border-radius: 6px; border: 1px solid #cfd6e4; }

/* атрибут hidden должен скрывать элемент, даже если у него задан display */
[hidden] { display: none !important; }
