/* Палитра снята с dr-mun.ru: графитовый корпоративный, коралловый акцент, светлый фон. */
:root {
  --ink: #26262b;
  --ink-soft: #3a3a42;
  --accent: #ff8562;
  --accent-soft: #fff1ec;
  --bg: #f5f5f6;
  --card: #ffffff;
  --line: #e7e7ea;
  --line-strong: #d3d3d8;
  --muted: #8a8a93;
  --green: #1f7a4d;
  --green-bg: #e8f5ee;
  --red: #c0392b;
  --red-bg: #fdeeec;
  --blue: #3d4f9f;
  --blue-bg: #eef1fb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ink); }

/* ---------- шапка ---------- */
.topbar {
  background: var(--ink);
  color: #fff;
  padding: 15px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand img {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  flex: 0 0 auto;
}

.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .01em; }
.topbar .sub { color: rgba(255, 255, 255, .62); font-size: 13px; margin-top: 3px; }

.topbar button.ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .28);
  color: #fff;
}

.topbar button.ghost:hover { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .5); }

.wrap { max-width: 1140px; margin: 26px auto; padding: 0 28px; }

/* ---------- карточки ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 18px;
}

.card h2 { margin: 0 0 15px; font-size: 15px; font-weight: 600; }

/* ---------- поля ---------- */
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }

input[type="text"], input[type="password"], input[type="date"], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: inherit;
}

input:focus, select:focus, .ms-toggle:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(38, 38, 43, .09);
}

button {
  padding: 10px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

button:hover { background: var(--ink-soft); }
button:disabled { background: #c9c9cf; cursor: default; }

button.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line-strong); }
button.ghost:hover { background: #f2f2f4; }
button.danger { background: #fff; color: var(--red); border: 1px solid #f0cdc8; }
button.danger:hover { background: var(--red-bg); }
button.small { padding: 7px 13px; font-size: 13px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > div { flex: 1 1 180px; }
.row > .fit { flex: 0 0 auto; }

/* ---------- таблица ---------- */
table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--line);
}

td { padding: 12px; border-bottom: 1px solid #f1f1f3; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafafb; }

.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.time { color: var(--muted); font-size: 12.5px; }
.phone { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- плашки стадий ---------- */
.badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 12.5px;
  white-space: nowrap;
  background: #f1f1f3;
  color: #5c5c66;
}

.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.green, .badge.won { background: var(--green-bg); color: var(--green); }
.badge.red, .badge.lost { background: var(--red-bg); color: var(--red); }
.badge.off, .badge.gray { background: #f1f1f3; color: #5c5c66; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- вкладки филиалов ---------- */
.branches {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  background: #ebebee;
  border-radius: 10px;
  padding: 4px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}

.branch-tab {
  background: transparent;
  color: #5c5c66;
  font-weight: 500;
  padding: 8px 20px;
  border-radius: 7px;
  white-space: nowrap;
}

.branch-tab:hover { background: rgba(255, 255, 255, .6); color: var(--ink); }

.branch-tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(38, 38, 43, .12);
}

.branch-tab.active:hover { background: #fff; }

/* ---------- сводка ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 15px 17px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.tile:hover { background: var(--card); border-color: var(--line-strong); }

.tile.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tile-value { font-size: 26px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-label { font-size: 13px; color: var(--muted); font-weight: 400; }

.tile[data-filter="arrived"] .tile-value { color: var(--green); }
.tile[data-filter="rejected"] .tile-value { color: var(--red); }

/* ---------- мультивыбор стадий ---------- */
.ms { position: relative; }

.ms-toggle {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ms-toggle:hover { background: #fff; border-color: var(--ink); }
.ms-toggle .caret { color: var(--muted); font-size: 11px; }

.ms-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 260px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(38, 38, 43, .13);
  padding: 8px;
}

.ms-all {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 6px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  border-radius: 7px 7px 0 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.ms-all:hover { background: #f5f5f6; }
.ms-all input { width: auto; }

.ms-list { max-height: 260px; overflow-y: auto; }

.ms-list label {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
}

.ms-list label:hover { background: #f5f5f6; }
.ms-list input { width: auto; }

.ms-actions {
  display: flex;
  gap: 8px;
  padding: 8px 4px 2px;
  border-top: 1px solid var(--line);
  margin-top: 6px;
}

.ms-actions button { flex: 1; }

/* ---------- служебное ---------- */
.msg { padding: 12px 15px; border-radius: 9px; font-size: 14px; margin-bottom: 15px; }
.msg.error { background: var(--red-bg); color: var(--red); }
.msg.ok { background: var(--green-bg); color: var(--green); }

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

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  min-height: 28px;
}

.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 16px; }

.source-blocks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.branch-line { margin-bottom: 6px; }
.branch-line:last-child { margin-bottom: 0; }
.branch-line .small { display: block; margin-bottom: 3px; }

.sources-box {
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

.sources-box label {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  padding: 5px 0;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
}

.sources-box input { width: auto; }

/* ---------- вход ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--ink);
}

.login-box { width: 100%; max-width: 350px; padding: 28px; border: 0; }
.login-box .logo { width: 52px; height: 52px; border-radius: 12px; margin-bottom: 16px; }
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
.login-box button { width: 100%; margin-top: 8px; }
.login-box label { margin-top: 14px; }
