/* Панель оператора: три колонки на десктопе, стопка на телефоне. */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e3e8ef;
  --text: #16202e;
  --muted: #6b7a90;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --danger: #d64545;
  --ok: #16a34a;
  --bubble-in: #f1f4f9;
  --bubble-out: #2563eb;
  --shadow: 0 1px 2px rgba(16, 32, 56, .06), 0 8px 24px rgba(16, 32, 56, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #161d26;
    --surface-2: #1b2430;
    --border: #26313f;
    --text: #e7edf5;
    --muted: #93a1b5;
    --accent: #4b83f0;
    --accent-soft: #1c2942;
    --bubble-in: #1f2937;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; }
.error { color: var(--danger); font-size: 13px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ вход */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-box {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-mark { font-size: 34px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box p { margin: -8px 0 8px; }
.login-box label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-box input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

/* --------------------------------------------------------------- каркас */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.conn {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  transition: background .2s;
}
.conn.live { background: var(--ok); }
.conn.dead { background: var(--danger); }
.search {
  width: min(320px, 40vw);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}
.layout { flex: 1; display: flex; min-height: 0; }
.pane { min-height: 0; }
.list-pane {
  width: 320px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.thread-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.card-pane {
  width: 300px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* --------------------------------------------------------- список диалогов */
.tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 7px 6px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
  font-size: 11px;
  line-height: 17px;
}
.pill.accent { background: var(--accent); color: #fff; }
.dialogs { overflow-y: auto; flex: 1; }
.dialog {
  display: flex;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.dialog:hover { background: var(--surface-2); }
.dialog.active { background: var(--accent-soft); }
.avatar {
  width: 38px; height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  font-weight: 650;
  text-transform: uppercase;
}
.dialog-main { min-width: 0; flex: 1; }
.dialog-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.dialog-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.dialog-preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dialog-tags { display: flex; gap: 6px; align-items: center; margin-top: 3px; }
.tag {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.tag.new { background: var(--accent); border-color: var(--accent); color: #fff; }
.tag.mine { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.tag.closed { opacity: .8; }
.unread {
  min-width: 20px; height: 20px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  display: grid; place-items: center;
  padding: 0 6px;
}

/* ------------------------------------------------------------------ тред */
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }
.empty-mark { font-size: 40px; text-align: center; }
.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.thread-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.t-name { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.ticket { color: var(--muted); font-weight: 500; font-size: 13px; }
.actions { display: flex; gap: 6px; flex-shrink: 0; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.msg { max-width: min(620px, 78%); display: flex; flex-direction: column; gap: 3px; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble {
  padding: 9px 12px;
  border-radius: 14px;
  background: var(--bubble-in);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.out .bubble { background: var(--bubble-out); color: #fff; }
.msg.out .bubble.failed { background: var(--danger); }
.meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; }
.msg.system {
  align-self: center;
  max-width: 80%;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.bubble img { max-width: 260px; border-radius: 10px; display: block; margin: 4px 0; }
.bubble a { color: inherit; }
.att-file {
  display: inline-flex; gap: 6px; align-items: center;
  padding: 6px 10px; margin: 3px 0;
  background: rgba(127, 127, 127, .12);
  border-radius: 8px;
  text-decoration: none;
}

/* -------------------------------------------------------------- композер */
.composer { border-top: 1px solid var(--border); background: var(--surface); padding: 10px 14px 12px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 180px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: flex; gap: 6px; align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 10px;
  font-size: 13px;
}
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); }

/* -------------------------------------------------------------- карточка */
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card-facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; font-size: 13px; }
.card-facts dt { color: var(--muted); }
.card-facts dd { margin: 0; overflow-wrap: anywhere; }
.card-label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.card-label textarea, .card-label select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  resize: vertical;
}

/* ---------------------------------------------------------------- кнопки */
button { cursor: pointer; }
.primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
}
.primary:disabled { opacity: .55; cursor: default; }
.ghost {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 13px;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.ghost.danger { color: var(--danger); }
.ghost.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.icon-btn {
  background: transparent;
  border: 0;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); }

/* --------------------------------------------------------------- модалка */
.modal {
  position: fixed; inset: 0;
  background: rgba(10, 16, 26, .45);
  display: grid; place-items: center;
  padding: 16px;
  z-index: 20;
}
.modal-box {
  width: min(620px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-body input, .modal-body textarea, .modal-body select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.code {
  font: 600 24px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 3px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.quick-item {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--surface-2);
}
.quick-item:hover { border-color: var(--accent); }
.quick-item b { display: block; font-size: 13px; }
.quick-item span { color: var(--muted); font-size: 13px; }

.only-mobile { display: none; }

@media (max-width: 900px) {
  .card-pane {
    position: fixed; inset: 0;
    z-index: 15;
    width: auto;
    display: none;
  }
  .card-pane.open { display: flex; }
  .only-mobile { display: inline-flex; }
  .only-desktop { display: none; }
  .search { width: 100%; order: 3; }
  .topbar { flex-wrap: wrap; }
  .list-pane { width: 100%; }
  .app.thread-open .list-pane { display: none; }
  .app:not(.thread-open) .thread-pane { display: none; }
  .msg { max-width: 88%; }
}
