/* Админка «Коуч Аюна» — утилитарная тёмная тема на токенах из SPEC §11 */

:root {
  --bg: #0d0d0d;
  --surface: #161616;
  --surface-2: #1f1f1f;
  --border: #2a2a2a;
  --gold: #d9a441;
  --gold-2: #f0c060;
  --text: #ececec;
  --muted: #a3a3a3;
  --red: #c8392b;
  --red-hover: #d94a3b;
  --green: #3fa66b;
  --radius: 18px;
  --radius-sm: 10px;
  --sidebar-w: 240px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

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

h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.25; }
h1 { font-size: 26px; color: var(--gold); margin-bottom: 20px; }
h2 { font-size: 18px; color: var(--gold); margin: 28px 0 12px; }
h3 { font-size: 15px; color: var(--text); margin: 0 0 8px; }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

.loading, .empty {
  color: var(--muted);
  padding: 32px 16px;
  text-align: center;
}

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

/* ---------- кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #262626; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .nav a:focus-visible, .row-link:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-hover); }
.btn-secondary { background: transparent; border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: transparent; border-color: var(--red); color: #ff8a7d; }
.btn-danger:hover { background: rgba(200, 57, 43, .15); }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
}
.icon-btn:hover { background: #262626; }
.icon-btn.sm { width: 32px; height: 32px; font-size: 13px; }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row.right { justify-content: flex-end; }
.btn-row.between { justify-content: space-between; }

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

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span, .label { font-size: 13px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 10px; }
.field.inline > span { color: var(--text); font-size: 14px; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"],
input[type="url"], textarea, select {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color .15s;
}
textarea { min-height: 80px; resize: vertical; line-height: 1.45; }
textarea.autogrow { resize: none; overflow: hidden; min-height: 40px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--gold); }
input:disabled, textarea:disabled, select:disabled { opacity: .55; cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: #6f6f6f; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--gold); cursor: pointer; }
input[type="file"] { color: var(--muted); font-size: 13px; }
select { appearance: auto; cursor: pointer; }
input.narrow { max-width: 120px; }
input.short { max-width: 200px; }

.form-error { color: #ff8a7d; font-size: 13px; min-height: 18px; margin-bottom: 10px; }
.hint { font-size: 12px; color: var(--muted); }
.warn { color: var(--gold-2); font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.filters .field { margin: 0; flex: 1 1 180px; }
.filters .field.grow { flex: 2 1 240px; }

.counter { font-size: 12px; color: var(--muted); text-align: right; }
.counter.over { color: #ff8a7d; font-weight: 600; }

/* ---------- карточки / тайлы ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card.compact { padding: 14px 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h3 { margin: 0; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.tile-label { font-size: 13px; color: var(--muted); }
.tile-value { font-size: 30px; font-weight: 700; color: var(--gold); line-height: 1.1; margin-top: 6px; }
.tile-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.tile-sub.accent { color: var(--green); }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

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

.table-wrap {
  overflow: auto;
  max-height: 72vh;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.table-wrap.auto { max-height: none; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.row-link { cursor: pointer; }
tbody tr.row-link:hover, tbody tr.row-link:focus-visible { background: var(--surface-2); outline: none; }
tbody tr.row-link:focus-visible td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 4px; }
td input[type="text"], td select { min-height: 34px; padding: 4px 8px; font-size: 13px; }
td .cell-note { min-width: 200px; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ---------- бейджи ---------- */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.green { color: var(--green); border-color: rgba(63, 166, 107, .5); }
.badge.gold { color: var(--gold-2); border-color: rgba(217, 164, 65, .5); }
.badge.red { color: #ff8a7d; border-color: rgba(200, 57, 43, .5); }
.badge.blue { color: #7fb4ff; border-color: rgba(127, 180, 255, .4); }

/* ---------- прогресс ---------- */

.progress {
  height: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress > div {
  height: 100%;
  width: 0;
  background: var(--gold);
  border-radius: 999px;
  transition: width .3s;
}
.progress.red > div { background: var(--red); }
.progress.green > div { background: var(--green); }

/* ---------- экран входа ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
}
.brand { text-align: center; margin-bottom: 24px; }
.brand .brand-mark { margin: 0 auto 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  color: var(--gold);
  font-weight: 700;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-title { font-weight: 700; color: var(--gold); font-size: 17px; }
.brand-sub { font-size: 12px; color: var(--muted); }

/* ---------- каркас панели ---------- */

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

.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 600; color: var(--gold); }
.burger {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  position: relative;
}
.burger::before, .burger::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: var(--text);
}
.burger::before { top: -6px; }
.burger::after { top: 6px; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  z-index: 40;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; }
.nav { list-style: none; margin: 0; padding: 0; flex: 1; }
.nav a {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  margin-bottom: 2px;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--gold); }
.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 35;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 60px;
  outline: none;
}
.page-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .6);
  }
  .sidebar.open { transform: none; }
  .content { padding: 18px 14px 60px; }
  .table-wrap { max-height: none; }
  /* 16px в полях ввода — иначе iOS Safari приближает страницу при фокусе */
  input[type="text"], input[type="password"], input[type="number"], input[type="search"],
  input[type="url"], textarea, select, td input[type="text"], td select { font-size: 16px; }
}

/* ---------- модалка ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .7); }
.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.modal-title { font-size: 18px; color: var(--gold); margin-bottom: 12px; }
.modal-body { color: var(--text); margin-bottom: 20px; white-space: pre-wrap; word-break: break-word; }
.modal-body .preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 10px;
  max-height: 200px;
  overflow: auto;
  font-size: 13px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- тосты ---------- */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  animation: toast-in .2s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- профиль / детали ---------- */

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

details.attempt {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  margin-bottom: 8px;
}
details.attempt > summary {
  cursor: pointer;
  padding: 12px 16px;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
}
details.attempt > summary::-webkit-details-marker { display: none; }
details.attempt > summary::before { content: "▸"; color: var(--muted); }
details.attempt[open] > summary::before { content: "▾"; }
details.attempt > summary:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; border-radius: 12px; }
details.attempt .attempt-body { padding: 0 16px 14px; }

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

.media-preview {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-top: 10px;
}
.media-preview img, .media-preview video {
  max-width: 260px;
  max-height: 200px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #000;
}
.media-preview audio { width: 260px; }
.media-preview .media-info { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }

.summary-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-top: 10px;
}

/* ---------- редактор тестов ---------- */

.editor-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 8px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
@media (max-width: 900px) { .editor-toolbar { top: 60px; } }

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.item-title { font-weight: 600; color: var(--gold-2); font-size: 14px; }
.item-tools { display: flex; gap: 4px; }
.item-card .field { margin-bottom: 10px; }

.options-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 8px; }
.option-row { display: grid; grid-template-columns: 1fr 100px 32px; gap: 6px; align-items: center; }
.option-row input { min-height: 34px; }

.q-grid { display: grid; grid-template-columns: 1fr 260px; gap: 0 12px; }
@media (max-width: 720px) { .q-grid { grid-template-columns: 1fr; } }

.followup-row { display: grid; grid-template-columns: 110px 1fr 32px; gap: 8px; align-items: start; margin-bottom: 8px; }
@media (max-width: 720px) { .followup-row { grid-template-columns: 90px 1fr 32px; } }

.offer-row { display: grid; grid-template-columns: 110px 1fr 90px 1fr 60px 60px; gap: 8px; align-items: center; margin-bottom: 6px; }
.offer-row textarea { min-height: 34px; }
@media (max-width: 900px) { .offer-row { grid-template-columns: 1fr 1fr; } }

.home-photo {
  width: 180px;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: block;
}
.home-photo-placeholder {
  width: 180px;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
