/* Переиспользуемые виджеты: карточки, кнопки, бейджи статусов, элементы
   списков, чат, трек-номер, инфо-блоки, кризисная помощь, таймлайн. */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px;
  box-shadow: var(--sh-sm);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 700;
}

.card h3 {
  margin: 20px 0 8px;
  font-size: 15.5px;
  font-weight: 700;
}

/* Кнопки. */
button.act,
button.ghost,
button.ok,
button.danger,
a.act,
a.ghost,
a.ok,
a.danger {
  min-height: 48px;
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  font: inherit;
  font-size: 15.5px;
  font-weight: 600;
  padding: 12px 20px;
  width: 100%;
  margin-top: 12px;
  transition: transform .16s ease, box-shadow .2s ease, background .2s ease,
    border-color .2s ease, color .2s ease, filter .2s ease;
}

/* Ссылки-кнопки для навигации между страницами. */
a.act,
a.ghost,
a.ok,
a.danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  text-decoration: none;
  width: auto;
}

button.act,
a.act {
  color: #fff;
  background: linear-gradient(135deg, var(--acc), var(--acc-2));
  box-shadow: var(--sh-acc);
}

button.act:hover,
a.act:hover {
  transform: translateY(-1.5px);
  filter: brightness(1.06);
}

button.act:active,
a.act:active {
  transform: translateY(0);
  filter: brightness(.97);
}

button.ghost,
a.ghost {
  background: #fff;
  color: var(--ink);
  border: 1.5px solid var(--line-2);
}

button.ghost:hover,
a.ghost:hover {
  border-color: var(--acc);
  color: var(--acc);
  background: var(--acc-soft);
}

button.ok,
a.ok {
  color: #fff;
  background: linear-gradient(135deg, var(--ok), var(--ok-2));
  box-shadow: 0 6px 18px rgba(30, 158, 106, .25);
}

button.ok:hover,
a.ok:hover {
  transform: translateY(-1.5px);
  filter: brightness(1.05);
}

button.danger,
a.danger {
  color: #fff;
  background: linear-gradient(135deg, var(--bad), var(--bad-2));
  box-shadow: 0 6px 18px rgba(229, 72, 77, .24);
}

button.danger:hover,
a.danger:hover {
  transform: translateY(-1.5px);
  filter: brightness(1.05);
}

button.small,
a.small {
  min-height: 38px;
  padding: 7px 14px;
  font-size: 14px;
  width: auto;
  margin-top: 0;
  border-radius: 10px;
}

.btnrow {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btnrow > button,
.btnrow > a {
  flex: 1;
  min-width: 150px;
}

/* Бейджи статусов: мягкие пастели + точка-индикатор. */
.badge {
  position: relative;
  display: inline-block;
  padding: 3.5px 11px 3.5px 22px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  background: #eef2f7;
  color: #3f4c63;
  vertical-align: middle;
  white-space: nowrap;
}

.badge::before {
  content: "";
  position: absolute;
  left: 9.5px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .85;
}

.badge.new { background: #e3f2fd; color: #1565c0; }
.badge.assigned { background: #ede9fe; color: #6d3fb4; }
.badge.in_progress { background: #fef4d6; color: #9a6b0a; }
.badge.needs_clarification { background: #ffedd5; color: #b45309; }
.badge.answer_ready { background: #dcfce7; color: #15803d; }
.badge.completed { background: #d7f5e7; color: #0f7a55; }
.badge.closed_no_response,
.badge.rejected { background: #fdecec; color: #b34444; }
.badge.returned { background: #fce7f3; color: #ad3a6c; }
.badge.urgent { background: #fdecec; color: #c53a3a; }
.badge.crisis { background: linear-gradient(135deg, #e5484d, #f0777c); color: #fff; }
.badge.transfer { background: #fef3c7; color: #a16207; }
.badge.overdue { background: linear-gradient(135deg, #e5484d, #f0777c); color: #fff; }
.badge.normal { background: #eef2f7; color: #5b6b82; }
.badge.low { background: #f1f4f8; color: #93a1b5; }

.badge.crisis::before,
.badge.overdue::before {
  background: #fff;
}

.overdue-counter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #fdecec;
  color: #c53a3a;
  border-radius: 999px;
  padding: 2.5px 11px;
  font-size: 12.5px;
  font-weight: 700;
}

.overdue-counter::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Элемент списка обращений. */
.item {
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
  margin: 9px 0;
  background: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 7px;
  box-shadow: var(--sh-sm);
  transition: transform .18s ease, box-shadow .2s ease, border-color .2s ease;
}

.item:hover {
  border-color: var(--acc);
  box-shadow: var(--sh-md);
  transform: translateY(-2px);
}

.item:active {
  transform: translateY(0);
}

.item.urgent {
  border-color: rgba(229, 72, 77, .4);
  background: #fffafa;
}

.item.urgent:hover {
  border-color: var(--bad);
}

.item .l1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item .cat {
  font-weight: 700;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.item .l2 {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 13px;
  color: var(--mut);
}

.presence {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--acc-soft);
  color: var(--acc);
  border-radius: 999px;
  padding: 4px 13px;
  font-size: 12.5px;
  font-weight: 700;
  margin: 4px 0;
}

.presence::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.kv {
  font-size: 14.5px;
  margin: 5px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.kv b {
  color: var(--mut);
  font-weight: 600;
  flex-shrink: 0;
  overflow-wrap: anywhere;
}

.kv span {
  flex: 1;
  min-width: 120px;
  overflow-wrap: anywhere;
}

/* Чат. */
.msgs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 46vh;
  overflow-y: auto;
  padding: 6px 4px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  border: 1px solid rgba(228, 233, 241, .8);
  background: #f1f4f8;
  font-size: 15px;
  overflow-wrap: anywhere;
  box-shadow: var(--sh-sm);
}

.msg.mine {
  align-self: flex-end;
  background: var(--acc-soft);
}

.msg .a {
  font-size: 12px;
  color: var(--mut);
  margin-bottom: 3px;
}

.track {
  font-size: clamp(19px, 5.5vw, 25px);
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--acc);
  padding: 16px 10px;
  background: linear-gradient(135deg, var(--acc-soft), rgba(255, 255, 255, .65));
  border: 1.5px solid var(--line);
  border-radius: 14px;
  text-align: center;
  user-select: all;
  overflow-wrap: anywhere;
}

.note {
  font-size: 13.5px;
  color: var(--mut);
  margin: 8px 0;
  overflow-wrap: anywhere;
}

.ok-box {
  background: #f0fbf5;
  border: 1px solid #bfe9d2;
  color: #177a4c;
  padding: 12px 14px;
  border-radius: 12px;
  margin: 10px 0;
  font-size: 14.5px;
}

.err-box {
  background: #fdf3f3;
  border: 1px solid #f5caca;
  color: #a33c3c;
  padding: 12px 14px;
  border-radius: 12px;
  margin: 10px 0;
  font-size: 14.5px;
  overflow-wrap: anywhere;
}

/* В публичном профиле подсказки формы — тёплый нейтральный тон
   вместо тревожного красного. */
.applicant-mode .err-box {
  background: #fdf8ec;
  border-color: #f3e0a6;
  color: #8a6a1c;
}

.applicant-mode .badge.rejected,
.applicant-mode .badge.closed_no_response {
  background: #eef1f5;
  color: #5d6b80;
}

.crisis-call {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fff;
  border: 1.5px solid #f3c9c9;
  border-radius: 14px;
  padding: 13px 14px;
  margin-top: 10px;
  box-shadow: var(--sh-sm);
}

.crisis-call .crisis-txt {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.crisis-call .crisis-t {
  font-size: 14.5px;
  font-weight: 700;
  color: #8f2a2a;
  overflow-wrap: anywhere;
}

.crisis-call .crisis-d {
  font-size: 12.5px;
  color: var(--mut);
  overflow-wrap: anywhere;
}

.crisis-call a.crisis-tel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--bad), var(--bad-2));
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: .02em;
  text-decoration: none;
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 48px;
  user-select: text;
  overflow-wrap: anywhere;
  box-shadow: 0 6px 18px rgba(229, 72, 77, .3);
}

.crisis-call a.crisis-tel:active {
  filter: brightness(.95);
}

@media (min-width: 640px) {
  .crisis-call {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .crisis-call .crisis-txt {
    flex: 1;
  }

  .crisis-call a.crisis-tel {
    flex: none;
    margin-left: 12px;
  }
}

.timeline {
  list-style: none;
  padding: 0 0 0 4px;
  margin: 0;
  font-size: 14px;
}

.timeline li {
  padding: 7px 0 7px 20px;
  border-left: 2px solid var(--line-2);
  position: relative;
  margin-left: 6px;
  overflow-wrap: anywhere;
}

.timeline li::before {
  content: "";
  position: absolute;
  left: -7.5px;
  top: 12px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--acc), var(--acc-2));
  box-shadow: 0 0 0 4px var(--acc-soft);
}

.chatwrap {
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  background: #f8fafc;
}

pre.raw {
  background: #f8fafc;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 8px 0;
}

.savedlist a {
  color: var(--acc);
  font-weight: 700;
  text-decoration: none;
  font-size: 15px;
}

.savedlist a:hover {
  text-decoration: underline;
}

/* События аудита рендерятся простыми div — длинные логины/причины
   не должны раздвигать карточку. */
#dEvents > div {
  overflow-wrap: anywhere;
}

.divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 22px 0 0;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px 12px;
  flex-wrap: wrap;
  margin: 16px 0 8px;
}

/* Заголовок карточки — без отступа сверху, чтобы кнопки рядом стояли ровно. */
.card > .panel-head:first-child {
  margin-top: 0;
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  flex: 1;
  min-width: 160px;
}

.panel-head > button,
.panel-head > .btnrow,
.panel-head > .note {
  flex: none;
}

/* Единая строка фильтров: подпись над полем, все поля одной высоты —
   кнопки и выпадающие списки всегда стоят по одной линии. */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 12px;
  margin: 10px 0 6px;
}

.filters .f {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.filters .f > label {
  margin: 0 0 5px;
  font-size: 12px;
}

.filters select,
.filters input {
  width: auto;
  min-height: 46px;
  padding: 9px 12px;
  /* 16px — iOS Safari не автозумит страницу при фокусе (зум включается
     на полях с меньшим кеглем и не всегда возвращается). */
  font-size: 16px;
}

.filters select { min-width: 150px; }
.filters input[type=date] { min-width: 138px; }

/* Слитная группа кнопок-периодов (7 / 30 дней / всё время). */
.seg {
  display: inline-flex;
  border: 1.5px solid var(--line-2);
  border-radius: var(--radius-s);
  overflow: hidden;
  background: #fff;
}

.seg button {
  width: auto;
  min-height: 46px;
  margin: 0;
  padding: 8px 14px;
  border: 0;
  border-right: 1.5px solid var(--line-2);
  border-radius: 0;
  background: transparent;
  color: var(--mut);
  font-size: 14px;
}

.seg button:last-child { border-right: 0; }

.seg button:hover {
  color: var(--acc);
  background: var(--acc-soft);
}

.seg button.on {
  color: var(--acc);
  background: var(--acc-soft);
}

.act-line {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.act-line .grow {
  flex: 1;
  min-width: 0;
}

.act-line label {
  margin-top: 0;
}

.act-line > button {
  margin-top: 0;
  width: 100%;
}

.actions-panel {
  border: 1.5px solid var(--line);
  background: linear-gradient(180deg, var(--acc-soft), rgba(255, 255, 255, 0) 96px), #fbfcfe;
  border-radius: 14px;
  padding: 4px 14px 14px;
  margin-top: 16px;
}

.actions-panel h3:first-child {
  margin-top: 12px;
}

.danger-zone {
  border: 1.5px dashed #f0b9b9;
  background: #fffafa;
  border-radius: 14px;
  padding: 10px 14px 14px;
  margin-top: 14px;
}

.danger-zone label {
  margin-bottom: 0;
}

.danger-zone .act-line {
  margin: 0;
}

.danger-zone > button {
  width: 100%;
  margin-top: 0;
}

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

.det-head > button {
  flex: none;
  margin-top: 0;
}

.det-head h2 {
  margin: 0;
  flex: 1;
  min-width: 180px;
  overflow-wrap: anywhere;
}

.chat-send {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 10px;
}

.chat-send textarea {
  flex: 1;
  min-height: 58px;
  width: auto;
}

.chat-send button {
  width: auto;
  margin-top: 0;
  flex: none;
  min-width: 120px;
}

.form-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.act-hint {
  background: linear-gradient(135deg, var(--acc-soft), rgba(255, 255, 255, .55));
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 13px;
  font-size: 14px;
  margin: 10px 0;
  overflow-wrap: anywhere;
}

.plainlist {
  margin: 8px 0 12px;
  padding-left: 20px;
}

.plainlist li {
  margin: 6px 0;
}

.muted-h {
  color: var(--mut);
  font-weight: 600;
}

#avFile {
  width: auto;
  padding: 9px;
  background: #fff;
}

/* Служебные плашки входа. */
.login-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  margin: 0 auto 6px;
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--acc), var(--acc-2));
  box-shadow: var(--sh-acc);
}

.login-head {
  text-align: center;
  margin-bottom: 4px;
}

.login-head h2 {
  justify-content: center;
}

.login-sub {
  color: var(--mut);
  font-size: 14.5px;
  margin: 2px 0 6px;
}

.demo-chip {
  display: inline-block;
  margin: 3px 4px 3px 0;
  padding: 4px 11px;
  border-radius: 999px;
  background: #f1f4f9;
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--mut);
}

@media (min-width: 640px) {
  .act-line {
    flex-direction: row;
    align-items: flex-end;
  }

  .act-line > button {
    flex: none;
    min-width: 160px;
    width: auto;
  }

  .chat-send button {
    min-width: 130px;
  }
}

/* === Дашборд администратора: KPI-плитки, графики, полосы нагрузки. === */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 14px 0 6px;
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: linear-gradient(180deg, var(--acc-soft), rgba(255, 255, 255, .7)), #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.kpi .kpi-v {
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
}

.kpi .kpi-l {
  font-size: 13px;
  color: var(--mut);
  font-weight: 600;
}

.kpi .kpi-h {
  font-size: 12.5px;
  color: var(--mut);
}

.kpi.ok .kpi-v { color: var(--ok); }
.kpi.bad .kpi-v { color: var(--bad); }
.kpi.warn .kpi-v { color: #d97706; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 12px;
  margin: 10px 0 16px;
}

.chart-box {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 12px 14px 8px;
  min-width: 0;
}

.chart-box.wide { grid-column: 1 / -1; }

.chart-box h3 { margin: 2px 0 8px; }

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-svg .ax {
  font-size: 10px;
  fill: var(--mut);
}

.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--mut);
  font-weight: 600;
  margin-bottom: 4px;
}

.chart-legend i,
.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: baseline;
}

.donut-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.donut {
  width: 130px;
  height: 130px;
  flex: none;
  transform: rotate(0deg);
}

.donut-c {
  font-size: 8px;
  font-weight: 800;
  fill: var(--ink);
}

.donut-t {
  font-size: 3.6px;
  fill: var(--mut);
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
  flex: 1;
}

.legend .lg-row {
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend .lg-row b { margin-left: auto; }

.legend .lg-row em {
  font-style: normal;
  color: var(--mut);
  font-size: 12px;
  min-width: 34px;
  text-align: right;
}

.hbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 7px 0;
  font-size: 13.5px;
}

.hbar .hbar-l {
  width: 42%;
  min-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.hbar .hbar-track {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
}

.hbar .hbar-track i {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.hbar b { min-width: 30px; text-align: right; }

.wload {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 6px 0;
  background: #fff;
}

.wload.hot {
  border-color: #f0b9b9;
  background: #fffafa;
}

.wload .wload-l {
  font-weight: 700;
  min-width: 200px;
}

.wload .wload-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 160px;
}

.loadbar {
  position: relative;
  display: inline-block;
  width: 110px;
  height: 10px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
  vertical-align: middle;
}

.loadbar i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: var(--ok);
}

.loadbar.warn i { background: #e8a13c; }
.loadbar.bad i { background: var(--bad); }

.loadbar-n {
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 560px) {
  .wload .wload-l { min-width: 100%; }
  .legend { min-width: 130px; }
  /* Сегмент периодов на узких экранах впритык — ужимаем отступы, */
  .seg button { padding-left: 10px; padding-right: 10px; }
}
