:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --ink: #111111;
  --ink-muted: #6b6b6b;
  --line: #e6e4dd;
  --accent: #111111;
  --accent-ink: #ffffff;
  --gold: #b58900;
  --silver: #8a8a8a;
  --bronze: #a1662f;
  --danger: #b00020;
  --success: #0a7a3b;
  --radius: 14px;
  --radius-sm: 10px;
  --pad: 20px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 56px;
}

header.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

header.top h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.01em;
}

header.top .sub {
  color: var(--ink-muted);
  font-size: 13px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 16px; }

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

input, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  font: inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus, textarea:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}

textarea { min-height: 96px; resize: vertical; }

.field { margin-bottom: 14px; }

button {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 500;
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  transition: transform .05s ease, opacity .15s ease;
}
button:hover { opacity: .92; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }

.hint { color: var(--ink-muted); font-size: 13px; margin-top: 8px; }
.error {
  color: var(--danger);
  background: #fff5f6;
  border: 1px solid #f4d4d8;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.success {
  color: var(--success);
  background: #f2faf5;
  border: 1px solid #cfe9d9;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
}

.tabs {
  display: flex;
  gap: 4px;
  background: #efece5;
  padding: 4px;
  border-radius: 999px;
  margin-bottom: 16px;
}
.tabs button {
  flex: 1;
  background: transparent;
  color: var(--ink-muted);
  padding: 9px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  width: auto;
}
.tabs button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.rank-list { display: flex; flex-direction: column; gap: 8px; }

.rank-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  animation: fade-up .28s ease both;
}
.rank-row .place { font-variant-numeric: tabular-nums; color: var(--ink-muted); font-weight: 500; }
.rank-row .name { font-weight: 500; display: flex; align-items: center; gap: 8px; min-width: 0; }
.rank-row .name span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .value {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--ink);
  text-align: right;
}
.rank-row .value small { display: block; color: var(--ink-muted); font-family: var(--sans); font-size: 12px; margin-top: 2px; }

.rank-row.top1 {
  background: linear-gradient(180deg, #fff9e6 0%, #fff 100%);
  border-color: #f0d97a;
}
.rank-row.top1 .place::before { content: '★ '; color: var(--gold); }

.badge {
  display: inline-block;
  font-size: 11px;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-muted);
  background: #fafaf7;
  font-weight: 500;
  letter-spacing: .02em;
}
.badge.gold   { color: var(--gold);   border-color: #ecd68a; background: #fff8e2; }
.badge.silver { color: var(--silver); border-color: #dcdcdc; background: #f6f6f6; }
.badge.bronze { color: var(--bronze); border-color: #e2c19e; background: #fbf1e5; }

.empty {
  text-align: center;
  color: var(--ink-muted);
  padding: 32px 8px;
  font-size: 14px;
}
.loading {
  text-align: center;
  color: var(--ink-muted);
  padding: 24px 8px;
  font-size: 14px;
}

footer.bottom {
  margin-top: 28px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 12px;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (min-width: 560px) {
  header.top h1 { font-size: 26px; }
  .page { padding: 36px 16px 72px; }
}

/* ---------- Админка ---------- */

.page.wide { max-width: 900px; }

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.toolbar button {
  width: auto;
  padding: 8px 14px;
  font-size: 13px;
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--line);
}
.toolbar button:hover { color: var(--ink); }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-head h2 {
  font-size: 16px;
  margin: 0;
  letter-spacing: -0.005em;
}
.section-head button.primary {
  width: auto;
  padding: 8px 14px;
  font-size: 13px;
}

.list { display: flex; flex-direction: column; gap: 10px; }

.row-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  animation: fade-up .22s ease both;
}

/* партнёр — компактная строка */
.partner-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: baseline;
}
.partner-row .main { min-width: 0; }
.partner-row .main .n { font-weight: 500; }
.partner-row .main .meta {
  color: var(--ink-muted);
  font-size: 13px;
  margin-top: 2px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.partner-row .main .meta code {
  font-family: var(--mono);
  background: #f2efe7;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12px;
}
.partner-row .stats {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--ink);
}
.partner-row .stats small {
  display: block;
  color: var(--ink-muted);
  font-size: 12px;
  font-family: var(--sans);
}
.partner-row .actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.partner-row .actions button {
  width: auto;
  padding: 7px 12px;
  font-size: 13px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.partner-row .actions button:hover { background: #f5f3ed; }

/* сделка — блочная карточка */
.deal-row .head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 8px;
}
.deal-row .head .who { font-weight: 500; }
.deal-row .head .when { color: var(--ink-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.deal-row .field-line {
  display: flex;
  gap: 8px;
  font-size: 14px;
  padding: 3px 0;
}
.deal-row .field-line .k {
  color: var(--ink-muted);
  min-width: 84px;
}
.deal-row .field-line .v {
  color: var(--ink);
  min-width: 0;
  word-break: break-word;
}
.deal-row .field-line .v code {
  font-family: var(--mono);
  background: #f2efe7;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12px;
}

.stages {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 4px;
}
.stage-btn {
  width: auto;
  padding: 6px 11px;
  font-size: 12px;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--line);
  transition: all .12s ease;
}
.stage-btn:hover { color: var(--ink); background: #f5f3ed; }
.stage-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.stage-btn.saving { opacity: .5; }

.amount-block {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}
.amount-block input {
  flex: 1;
  padding: 9px 12px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.amount-block button {
  width: auto;
  padding: 9px 14px;
  font-size: 13px;
}
.reward-preview {
  color: var(--ink-muted);
  font-size: 13px;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.reward-preview.set { color: var(--ink); }

.row-error {
  margin-top: 8px;
  color: var(--danger);
  background: #fff5f6;
  border: 1px solid #f4d4d8;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* форма добавления партнёра — collapsible */
.collapsible[hidden] { display: none; }
.collapsible {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.inline-form { display: grid; gap: 10px; }
.inline-form .row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.inline-form .actions {
  display: flex;
  gap: 8px;
}
.inline-form .actions button.secondary {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--line);
}
.inline-form .actions button { width: auto; padding: 10px 14px; font-size: 14px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--accent-ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

@media (min-width: 640px) {
  .inline-form .row { grid-template-columns: 1fr 1fr 1fr; }
  .deal-row .field-line .k { min-width: 110px; }
}

