:root {
  --bg:        #f2f4f6;
  --surface:   #ffffff;
  --sunk:      #e9edf0;
  --ink:       #161c21;
  --ink-soft:  #4d5a66;
  --muted:     #79868f;
  --rule:      #d9e0e5;
  --accent:    #1f6feb;
  --accent-ink:#ffffff;

  --s-new:     #c2410c;
  --s-new-bg:  #ffedd5;
  --s-work:    #1d4ed8;
  --s-work-bg: #dbeafe;
  --s-assign:  #6d28d9;
  --s-assign-bg:#ede9fe;
  --s-done:    #15803d;
  --s-done-bg: #dcfce7;
  --s-cancel:  #64748b;
  --s-cancel-bg:#e2e8f0;

  --danger:    #b91c1c;
  --radius:    8px;
  --shadow:    0 1px 2px rgba(22,28,33,.06), 0 6px 20px -14px rgba(22,28,33,.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Шапка ---------- */

.topbar {
  background: #16212b;
  color: #e8edf1;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.topbar-in {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  color: #fff;
  margin-right: 14px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a {
  color: #b7c4cf;
  padding: 8px 12px;
  border-radius: 6px;
  white-space: nowrap;
}
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav a.on { background: rgba(255,255,255,.14); color: #fff; }
.topbar .spacer { flex: 1; }
.whoami { color: #94a6b3; font-size: 13.5px; white-space: nowrap; }
.btn-exit {
  background: none;
  border: 1px solid rgba(255,255,255,.22);
  color: #b7c4cf;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
}
.btn-exit:hover { background: rgba(255,255,255,.1); color: #fff; }

/* ---------- Каркас ---------- */

.wrap { max-width: 1280px; margin: 0 auto; padding: 22px 18px 60px; }
.page-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
h1 { font-size: 23px; margin: 0; font-weight: 650; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 650; }

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px; }
.card + .card { margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Плитки ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; margin-bottom: 18px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.tile b { display: block; font-size: 27px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 13px; }
.tile.new    { border-left-color: var(--s-new); }
.tile.work   { border-left-color: var(--s-work); }
.tile.assign { border-left-color: var(--s-assign); }
.tile.today  { border-left-color: var(--accent); }
.tile.ok     { border-left-color: var(--s-done); }
.tile.warn   { border-left-color: var(--s-cancel); }
/* Плитка-ссылка: цифра, по которой можно провалиться в отобранный список. */
a.tile { color: inherit; text-decoration: none; transition: border-color .12s, box-shadow .12s; }
a.tile:hover { box-shadow: 0 4px 14px -8px rgba(22,28,33,.5); }
a.tile:hover span { color: var(--ink-soft); }
a.bar { color: inherit; text-decoration: none; }
a.bar:hover .fill { filter: brightness(.9); }
a.bar:hover span:first-child { color: var(--ink); }

/* ---------- Таблицы ---------- */

.tablewrap { overflow-x: auto; }
/* Вторая строка в ячейке: длительность, статус заявки, направление. */
td .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: top; }
th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  font-weight: 600;
  background: var(--sunk);
  white-space: nowrap;
}
tbody tr:hover { background: #f7f9fa; }
tbody tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-night td:first-child { box-shadow: inset 3px 0 0 #7c3aed; }

/* ---------- Ярлыки ---------- */

.chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.chip.new       { background: var(--s-new-bg);    color: var(--s-new); }
.chip.in_work   { background: var(--s-work-bg);   color: var(--s-work); }
.chip.assigned  { background: var(--s-assign-bg); color: var(--s-assign); }
.chip.done      { background: var(--s-done-bg);   color: var(--s-done); }
.chip.cancelled { background: var(--s-cancel-bg); color: var(--s-cancel); }
.chip.src       { background: var(--sunk); color: var(--ink-soft); font-weight: 500; }
.chip.night     { background: #ede9fe; color: #6d28d9; }

/* ---------- Формы ---------- */

label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; font-weight: 500; }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=date],
input[type=search], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
textarea { min-height: 84px; resize: vertical; }
.field { margin-bottom: 14px; }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

.btn {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover { background: var(--sunk); filter: none; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 6px 11px; font-size: 13.5px; }
.btn.wide { width: 100%; text-align: center; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 14px;
}
.filters .field { margin: 0; min-width: 150px; }
.filters .grow { flex: 1; min-width: 220px; }

/* Предупреждение о дубле: оператор заводит заявку руками на человека,
   по которому заявку уже завёл его же звонок. */
.dup-warn { border-left: 3px solid var(--s-work); }
.phone-hint {
  margin-top: 6px;
  font-size: 13px;
  color: var(--s-work);
  background: var(--s-work-bg);
  border-radius: var(--radius);
  padding: 7px 10px;
}
.phone-hint a { font-weight: 600; }

/* ---------- Сообщения ---------- */

.flash {
  padding: 11px 15px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  border: 1px solid;
  font-size: 14px;
}
.flash.ok  { background: var(--s-done-bg); border-color: #86efac; color: #14532d; }
.flash.err { background: #fee2e2; border-color: #fca5a5; color: #7f1d1d; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- Карточка заявки ---------- */

.deflist { display: grid; grid-template-columns: 130px 1fr; gap: 9px 14px; font-size: 14px; }
.deflist dt { color: var(--muted); }
.deflist dd { margin: 0; }
.deflist a { word-break: break-word; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  padding: 10px 0 10px 16px;
  border-left: 2px solid var(--rule);
  position: relative;
  font-size: 14px;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -5px; top: 15px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--rule);
}
.timeline li.t-status::before { background: var(--s-work); }
.timeline li.t-assign::before { background: var(--s-assign); }
.timeline li.t-price::before  { background: var(--s-done); }
.timeline .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs img {
  width: 96px; height: 96px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--rule);
}

/* ---------- Вход ---------- */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #16212b;
}
.login-box { width: 100%; max-width: 360px; background: #fff; border-radius: 10px; padding: 28px; }
.login-box h1 { font-size: 19px; margin-bottom: 4px; }
.login-box p.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }

/* ---------- Мастер: мобильный вид ---------- */

.jobs { display: flex; flex-direction: column; gap: 12px; }
.job {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--s-assign);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.job.in_work { border-left-color: var(--s-work); }
.job.done    { border-left-color: var(--s-done); }
.job .who { font-weight: 650; font-size: 16px; }
.job .line { color: var(--ink-soft); font-size: 14px; }
.job .tel { font-size: 17px; font-weight: 600; }
.job .foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 4px; }

.sum-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.sum-strip div {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.sum-strip b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; }
.sum-strip span { font-size: 12px; color: var(--muted); }

.bar { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.bar .track { flex: 1; height: 8px; background: var(--sunk); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); }

@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  /* Колонка с кнопками встаёт первой: на телефоне иначе её не найти. */
  .grid2 > .actions-first { order: -1; }
}
@media (max-width: 640px) {
  .wrap { padding: 16px 12px 50px; }
  .fields2 { grid-template-columns: 1fr; }
  .deflist { grid-template-columns: 110px 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: 20px; }
}

/* ---------- Оповещение о новых заявках ---------- */

.waiting {
  color: var(--s-new);
  font-weight: 700;
}

.queue-banner {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--s-new-bg);
  color: var(--s-new);
  border: 1px solid var(--s-new);
  border-radius: 999px;
  padding: 10px 14px 10px 20px;
  box-shadow: 0 8px 28px -10px rgba(22,28,33,.4);
  font-size: 14.5px;
}
.queue-banner b { font-size: 16px; }

/* Полоса «звук выключен». Висит сверху, пока оператор не щёлкнет по странице:
   браузер до этого не даёт издавать звуки, а молчащая система выглядит
   точно так же, как система без обращений. */
.sound-bar {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 60;
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid #c98a00;
  background: #fff4d6;
  color: #7a5200;
  font: inherit;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.sound-bar:hover { background: #ffecbd; }
/* Подсказка про постоянное разрешение. Показывается только на повторных
   появлениях полосы: с первого раза она лишняя, со второго — суть дела. */
.sound-bar-hint {
  display: block;
  margin-top: 3px;
  font-weight: 500;
  font-size: 12.5px;
  opacity: .85;
}
