/* Минималистичная админка: спокойный фон, один акцент, никакого визуального шума. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1c2024;
  --muted: #6b7280;
  --accent: #2f6f4f;
  --danger: #b3261e;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); font-size: 13px; }

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

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
}

.brand {
  font-weight: 600;
  padding: 0 10px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar nav a {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
}

.sidebar nav a:hover { background: var(--bg); color: var(--text); }
.sidebar nav a.current { background: var(--bg); color: var(--text); font-weight: 500; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.account { display: flex; align-items: center; gap: 12px; }
.account .email { color: var(--muted); font-size: 13px; }

.content { padding: 24px; display: flex; flex-direction: column; gap: 16px; }

/* -- карточки ------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 600; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; }

.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }

.notice { border-left: 3px solid var(--accent); }

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

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* -- формы --------------------------------------------------------------- */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }

input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input:focus, button:focus-visible, .sidebar nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  padding: 9px 14px;
  font-size: 15px;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }
button[disabled] { opacity: .6; cursor: default; }

button.link {
  background: none;
  color: var(--muted);
  padding: 4px 0;
  font-size: 13px;
}

button.link:hover { color: var(--text); filter: none; }

/* -- вход ---------------------------------------------------------------- */

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login { width: 100%; max-width: 340px; }
.login h1 { margin-bottom: 2px; }
.login p { margin: 0 0 18px; }
.login button { width: 100%; margin-top: 4px; }

.alert {
  background: #fdecea;
  color: var(--danger);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
  margin-bottom: 14px;
}

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; flex: none; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .content { padding: 16px; }
}

/* -- каталог ------------------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input, .filters select { width: auto; margin-top: 0; }
.filters input[type="search"] { min-width: 220px; }
.filters .reset { color: var(--muted); font-size: 13px; padding: 0 4px; }
.filters .reset:hover { color: var(--text); }

select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}

.primary-action {
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 15px;
  white-space: nowrap;
}

.primary-action:hover { filter: brightness(1.08); }

.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table-card table { min-width: 720px; }
.table-card th, .table-card td { padding: 10px 14px; }
.table-card .empty { padding: 20px; margin: 0; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--muted);
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

.pill.ok { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }

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

/* -- форма карточки ------------------------------------------------------ */

.form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.form .meta, .card > .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.form .actions { display: flex; align-items: center; gap: 14px; margin-top: 4px; }
.field-error { display: block; margin-top: 4px; color: var(--danger); font-size: 12px; }

.toast {
  background: color-mix(in srgb, var(--accent) 12%, #fff);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  color: var(--accent);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
}

.table-card td a { color: var(--text); }
.table-card td a:hover, .table-card td a:focus-visible { color: var(--accent); text-decoration: underline; }

/* -- медиа упражнения ---------------------------------------------------- */

.media-preview { margin-bottom: 12px; }
.media-preview img, .media-preview video {
  max-width: 320px;
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

.media-form { margin-top: 12px; }
.media-form input[type="file"] { padding: 8px 0; border: none; background: none; }
button.link.danger { color: var(--danger); }
button.link.danger:hover { color: var(--danger); text-decoration: underline; }

/* -- карточка пользователя ----------------------------------------------- */

table.kv td { padding: 6px 0; border-bottom: 1px solid var(--border); }
table.kv td:first-child { color: var(--muted); font-size: 13px; width: 45%; }
table.kv tr:last-child td { border-bottom: none; }

.inline-forms { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-end; }
.inline-forms form { display: flex; gap: 10px; align-items: flex-end; }
.inline-forms label { margin-bottom: 0; }
.inline-forms select { min-width: 170px; }

.danger-zone { border-left: 3px solid var(--danger); }

/* -- контент ------------------------------------------------------------- */

.group-title { padding: 16px 14px 0; }
.table-card .group-title + .table-scroll table { margin-top: 8px; }

.warning {
  background: #fff8e6;
  border: 1px solid #f0d9a0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.warning ul, .alert ul { margin: 6px 0 0; padding-left: 18px; }

.tg-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.default-text {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
  color: var(--muted);
  margin: 0 0 12px;
}

/* -- рассылки ------------------------------------------------------------ */

fieldset.segment {
  margin: 4px 0 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
fieldset.segment legend { padding: 0 6px; color: var(--muted); font-size: 13px; }
fieldset.segment .row { margin-top: 8px; }

.progress {
  height: 8px;
  margin: 14px 0 8px;
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
}
.progress-bar { height: 100%; background: var(--accent); transition: width .3s; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; }

.preview-media {
  display: block;
  max-width: 320px;
  margin-bottom: 12px;
  border-radius: 10px;
}

/* -- аналитика ----------------------------------------------------------- */

.progress.slim { height: 4px; margin: 6px 0 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Заметная потеря между шагами воронки — там и надо разбираться. */
td.num.drop { color: var(--danger); }
.card .cards { margin: 12px 0 4px; }
.card h3 { margin: 18px 0 8px; font-size: 14px; }

/* -- подписки ------------------------------------------------------------ */

.inline-forms label.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.inline-forms label.checkbox input { width: auto; margin: 0; }
.inline-forms input[type="text"] { min-width: 90px; }

.tariff-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.tariff-row:last-of-type { border-bottom: none; }
.tariff-code { min-width: 110px; color: var(--muted); font-size: 13px; }

/* -- программы ----------------------------------------------------------- */

.danger-text { color: var(--danger); }

/* -- журнал -------------------------------------------------------------- */

.pill.danger-pill { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
ul.changes { margin: 0; padding-left: 16px; font-size: 13px; }
ul.changes li { margin: 2px 0; }

/* -- генератор ----------------------------------------------------------- */

button.danger-button { background: var(--danger); }

/* Индикатор загрузки файлов */
.upload-progress { margin-top: 12px; display: flex; align-items: center; gap: 10px; }
.upload-progress progress { flex: 0 0 260px; height: 10px; accent-color: #2e7d5b; }
.upload-percent { font-variant-numeric: tabular-nums; color: #555; }

/* Подсказка-«вопросик»: наведи — увидишь объяснение показателя (title). */
.qhint {
  display: inline-block;
  margin-left: 6px;
  width: 15px;
  height: 15px;
  line-height: 15px;
  text-align: center;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: help;
  vertical-align: 1px;
  user-select: none;
}
.qhint:hover { background: var(--accent); color: #fff; }

/* Переключатель базы страны в шапке */
.shard-switch { display: inline-flex; gap: 2px; margin-right: 12px; border: 1px solid var(--line, #ddd); border-radius: 8px; overflow: hidden; }
.shard-switch a { padding: 4px 10px; font-size: 13px; text-decoration: none; color: inherit; }
.shard-switch a.current { background: var(--accent, #3b5bdb); color: #fff; }
