:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --ink: #1d1e36;
  --muted: #6b6f8d;
  --accent: #5929e2;
  --accent-soft: #efeafe;
  --green: #1ea672;
  --red: #e2455a;
  --blue: #5988ff;
  --border: #e6e8f2;
  --shadow: 0 1px 3px rgba(29, 30, 54, 0.06), 0 6px 18px rgba(29, 30, 54, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--ink);
  color: #fff;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.brand-mark {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.3px;
  background: linear-gradient(90deg, #875cff, #5988ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  color: #c7c9e6;
  font-size: 13px;
}

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

.cache-note {
  color: #9fa2c8;
  font-size: 12px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  padding: 18px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 100;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.field > input,
.field > select {
  height: 38px;
  min-width: 150px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
}

.field select {
  max-width: 240px;
}

.field-apply {
  margin-left: auto;
}

/* --- Мультиселект с галочками --- */
.ms {
  position: relative;
  min-width: 180px;
}

.ms-button {
  height: 38px;
  width: 100%;
  padding: 0 32px 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6f8d' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
    no-repeat right 10px center;
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.ms.open .ms-button {
  border-color: var(--accent);
}

.ms-button.has-value {
  color: var(--accent);
  font-weight: 600;
}

.ms-panel {
  position: absolute;
  z-index: 1000;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-width: 320px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 8px;
  display: none;
}

.ms.open .ms-panel {
  display: block;
}

.ms-search {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  margin-bottom: 6px;
  box-sizing: border-box;
}

.ms-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.ms-actions button {
  flex: 1;
  height: 28px;
  border: 1px solid var(--border);
  background: #fafbfe;
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}

.ms-actions button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

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

.ms-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.ms-option:hover {
  background: #fafbfe;
}

.ms-option input {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  min-width: 0;
  padding: 0;
  accent-color: var(--accent);
  margin: 0;
  cursor: pointer;
}

.ms-option span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ms-empty {
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}

.presets {
  display: flex;
  gap: 6px;
}

.presets button {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}

.presets button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.btn {
  height: 38px;
  padding: 0 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: #4a1fc4;
}

.btn-ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

main {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.kpi .kpi-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.kpi .kpi-value {
  font-size: 26px;
  font-weight: 700;
}

.kpi .kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.kpi.accent .kpi-value {
  color: var(--accent);
}
.kpi.green .kpi-value {
  color: var(--green);
}
.kpi.red .kpi-value {
  color: var(--red);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

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

.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 200px;
  padding-top: 10px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.bar-stack {
  width: 70%;
  max-width: 34px;
  display: flex;
  flex-direction: column-reverse;
  border-radius: 4px 4px 0 0;
  overflow: hidden;
  transition: opacity 0.15s;
}

.bar-stack:hover {
  opacity: 0.8;
}

.bar-answered {
  background: var(--accent);
}

.bar-lost {
  background: #d9b3ff;
}

.bar-label {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  transform: rotate(-40deg);
  transform-origin: center;
  height: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: #fafbfe;
  position: sticky;
  top: 0;
  z-index: 1;
}

th.num,
td.num {
  text-align: right;
}

tbody tr:hover {
  background: #fafbfe;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.pill.good {
  background: #e3f6ee;
  color: var(--green);
}
.pill.warn {
  background: #fdeef0;
  color: var(--red);
}

.loader {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 30px;
  color: var(--muted);
  justify-content: center;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error {
  background: #fdeef0;
  color: var(--red);
  border: 1px solid #f5c6cd;
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 20px;
}

.hidden {
  display: none !important;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px;
}

@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .field-apply {
    margin-left: 0;
  }
}
