:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --ink: #111111;
  --muted: #68686f;
  --line: #dedee4;
  --accent: #e51616;
  --accent-dark: #b90f13;
  --warning: #f2c94c;
  --success: #168a52;
  --danger: #d7193f;
  --vk: #2787f5;
  --shadow: 0 16px 38px rgba(17, 17, 17, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  overflow-x: hidden;
}

body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: Manrope, "Segoe UI", Arial, sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 360px),
    repeating-linear-gradient(
      135deg,
      rgba(229, 22, 22, 0.035) 0,
      rgba(229, 22, 22, 0.035) 1px,
      transparent 1px,
      transparent 28px
    ),
    var(--bg);
  overflow-x: hidden;
}

.vk-miniapp body {
  background: var(--bg);
}

.vk-miniapp-body .app-shell {
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-right: calc(12px + env(safe-area-inset-right));
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  padding-left: calc(12px + env(safe-area-inset-left));
}

.vk-scheme-dark {
  --bg: #111214;
  --surface: #1c1e22;
  --surface-2: #24272d;
  --ink: #f5f5f6;
  --muted: #b8bec8;
  --line: #383c45;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

button,
input {
  font: inherit;
}

button {
  min-width: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
  overflow-wrap: anywhere;
}

h1 {
  font-size: 32px;
  line-height: 1.05;
  letter-spacing: 0;
  font-weight: 900;
}

h2 {
  font-size: 46px;
  line-height: 0.98;
  letter-spacing: 0;
  font-weight: 900;
}

h3 {
  font-size: 19px;
  line-height: 1.15;
  letter-spacing: 0;
  font-weight: 900;
}

.app-shell {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  position: sticky;
  top: 8px;
  z-index: 5;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 74px;
  margin-bottom: 22px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(17, 17, 17, 0.08);
  backdrop-filter: blur(16px);
}

.vk-scheme-dark .topbar {
  background: rgba(28, 30, 34, 0.9);
  border-color: var(--line);
}

.topbar-brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.topbar-brand > div {
  min-width: 0;
}

.brand-mark {
  width: 96px;
  height: 44px;
  object-fit: contain;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.screen {
  display: grid;
  min-width: 0;
  gap: 20px;
}

.icon-button,
.primary-button,
.secondary-button,
.vk-button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    border-color 0.16s ease,
    background 0.16s ease;
}

.icon-button:hover,
.primary-button:hover,
.secondary-button:hover,
.vk-button:hover {
  transform: translateY(-1px);
}

.icon-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.vk-button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(229, 22, 22, 0.2);
  outline-offset: 2px;
}

.icon-button {
  display: grid;
  width: 44px;
  place-items: center;
  padding: 0;
  color: var(--accent-dark);
  background: var(--surface);
  border-color: var(--line);
  font-size: 24px;
}

.primary-button {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  box-shadow: 0 12px 26px rgba(229, 22, 22, 0.22);
}

.primary-button:hover {
  box-shadow: 0 14px 28px rgba(229, 22, 22, 0.28);
}

.secondary-button {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.secondary-button:hover {
  border-color: rgba(229, 22, 22, 0.38);
  box-shadow: 0 8px 20px rgba(17, 17, 17, 0.08);
}

.vk-button {
  width: 100%;
  color: #fff;
  background: var(--vk);
  box-shadow: 0 12px 24px rgba(39, 135, 245, 0.18);
}

.vk-button:hover {
  background: #1f7ee8;
}

.compact-button {
  min-height: 38px;
  padding: 0 12px;
  font-size: 14px;
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
  transform: none;
}

.partner-panel,
.referral-certificate {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(360px, 0.82fr);
  gap: 28px;
  align-items: start;
}

.partner-copy,
.referral-copy {
  display: grid;
  min-width: 0;
  gap: 14px;
  align-content: start;
  padding: 16px 0;
}

.partner-copy p:not(.eyebrow),
.referral-copy p:not(.eyebrow) {
  max-width: 680px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 750;
  line-height: 1.5;
}

.page-art {
  width: min(210px, 48vw);
  max-height: 150px;
  object-fit: contain;
  justify-self: start;
  filter: drop-shadow(0 14px 22px rgba(17, 17, 17, 0.14));
}

.partner-entry-hero {
  display: grid;
  min-height: min(520px, calc(100vh - 140px));
  align-items: center;
}

.partner-entry-card {
  display: grid;
  grid-template-columns: minmax(220px, 0.65fr) minmax(0, 1fr);
  gap: 24px;
  align-items: center;
  min-width: 0;
  padding: clamp(22px, 4vw, 42px);
  color: var(--accent);
  background: #fff;
  border: 1px solid rgba(229, 22, 22, 0.16);
  border-radius: 8px;
  box-shadow: 0 24px 54px rgba(209, 13, 13, 0.12);
}

.partner-entry-card .page-art {
  grid-row: span 2;
  width: min(240px, 44vw);
  max-height: 180px;
  filter: drop-shadow(0 18px 24px rgba(17, 17, 17, 0.18));
}

.partner-entry-card .partner-entry-photo {
  width: min(390px, 100%);
  max-height: none;
  aspect-ratio: 1.12 / 1;
  object-fit: cover;
  object-position: center;
  border: 1px solid rgba(229, 22, 22, 0.12);
  border-radius: 8px;
  box-shadow: 0 18px 36px rgba(17, 17, 17, 0.08);
  filter: none;
}

.partner-entry-copy {
  display: grid;
  gap: 10px;
}

.partner-entry-copy .eyebrow,
.partner-entry-copy h2 {
  color: var(--accent);
}

.partner-entry-copy h2 {
  max-width: 760px;
  font-size: 64px;
}

.partner-entry-action .partner-form {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.partner-entry-action .vk-button {
  min-height: 58px;
  color: #fff;
  background: var(--vk);
  font-size: 18px;
  box-shadow: 0 18px 34px rgba(39, 135, 245, 0.2);
}

.partner-entry-action .vk-button:hover {
  color: #fff;
  background: #1f7ee8;
}

.rule-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.rule-list span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 7px 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 900;
}

.partner-workspace {
  min-width: 0;
}

.cabinet-page {
  display: grid;
  min-width: 0;
  gap: 14px;
}

.cabinet-workspace {
  width: 100%;
}

.partner-form,
.referral-certificate-form,
.loading-panel,
.metric-card,
.link-panel,
.profile-panel,
.qr-panel,
.manual-referral-form,
.list-panel,
.partner-item,
.empty-note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.partner-form,
.referral-certificate-form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.partner-vk-entry {
  align-content: start;
  gap: 12px;
}

.vk-entry-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.45;
}

.form-field {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.form-field[hidden] {
  display: none;
}

.form-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.form-field input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
}

.form-field input::placeholder {
  color: color-mix(in srgb, var(--muted), transparent 20%);
}

.partner-type-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.partner-type-toggle label {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
}

.partner-type-toggle input {
  accent-color: var(--accent);
}

.partner-auth-note {
  padding: 10px 12px;
  color: var(--accent-dark);
  background: #fff8f8;
  border: 1px solid rgba(229, 22, 22, 0.16);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 900;
}

.partner-auth-note[hidden] {
  display: none;
}

.partner-dashboard {
  display: grid;
  min-width: 0;
  gap: 14px;
}

.dashboard-head,
.list-title {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dashboard-head span,
.list-title span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.dashboard-head h3,
.list-title h3,
.manual-referral-form h3,
.qr-copy h3 {
  color: var(--accent-dark);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  min-width: 0;
  padding: 12px;
  box-shadow: none;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1;
}

.metric-card .metric-compact {
  font-size: 18px;
  line-height: 1.15;
}

.link-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  box-shadow: none;
}

.profile-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.72fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  box-shadow: none;
}

.profile-panel h3 {
  color: var(--accent-dark);
}

.profile-panel p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  line-height: 1.4;
}

.profile-panel strong {
  color: var(--ink);
}

.partner-profile-form,
.partner-phone-form {
  display: grid;
  gap: 8px;
}

.field-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.qr-panel {
  display: grid;
  grid-template-columns: 142px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 12px;
  box-shadow: none;
}

.qr-visual {
  display: grid;
  width: 142px;
  aspect-ratio: 1 / 1;
  place-items: center;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.qr-visual svg {
  display: block;
  width: 100%;
  height: 100%;
}

.qr-copy {
  display: grid;
  min-width: 0;
  gap: 8px;
}

.qr-copy p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.86fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.manual-referral-form,
.list-panel,
.loading-panel {
  display: grid;
  gap: 11px;
  min-width: 0;
  padding: 14px;
  box-shadow: none;
}

.loading-panel strong {
  color: var(--accent-dark);
  font-size: 20px;
}

.loading-panel span {
  color: var(--muted);
  font-weight: 800;
}

.cabinet-loader {
  min-height: min(420px, calc(100vh - 170px));
  place-items: center;
  text-align: center;
}

.loading-spinner {
  display: block;
  width: 42px;
  aspect-ratio: 1 / 1;
  border: 5px solid rgba(229, 22, 22, 0.14);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: loading-spin 0.9s linear infinite;
}

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

.partner-list {
  display: grid;
  gap: 10px;
}

.partner-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 10px;
  border-left: 5px solid var(--accent);
  box-shadow: none;
}

.partner-item.paid,
.partner-item.commission {
  border-left-color: var(--success);
}

.partner-item.expired_unpaid {
  border-left-color: var(--muted);
  opacity: 0.82;
}

.partner-item strong,
.partner-item b {
  display: block;
  font-size: 14px;
}

.partner-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.item-status {
  text-align: right;
}

.empty-note {
  padding: 12px;
  color: var(--muted);
  box-shadow: none;
  font-weight: 850;
}

.lead-status {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.35;
}

.lead-status[hidden] {
  display: none;
}

.lead-status[data-tone="success"] {
  color: var(--success);
}

.lead-status[data-tone="warning"],
.lead-status[data-tone="loading"] {
  color: #9a6700;
}

.lead-status[data-tone="error"] {
  color: var(--danger);
}

.admin-panel {
  display: grid;
  gap: 18px;
}

.admin-hero {
  display: grid;
  max-width: 920px;
  gap: 10px;
  padding: 4px 0 2px;
}

.admin-hero p:not(.eyebrow) {
  max-width: 760px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 750;
  line-height: 1.5;
}

.admin-workspace,
.admin-dashboard {
  display: grid;
  min-width: 0;
  gap: 14px;
}

.admin-login-form {
  max-width: 480px;
  box-shadow: none;
}

.admin-toolbar,
.admin-list-panel,
.admin-item {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
}

.admin-toolbar h3 {
  color: var(--accent-dark);
}

.admin-toolbar span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.admin-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.admin-tab {
  min-height: 40px;
  min-width: max-content;
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
}

.admin-tab[aria-selected="true"] {
  color: #fff;
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.admin-list-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.admin-list {
  display: grid;
  gap: 10px;
}

.admin-item {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(180px, 0.8fr) minmax(180px, 0.9fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  box-shadow: none;
}

.admin-item-main,
.admin-meta,
.admin-stats,
.admin-actions {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.admin-item-main strong {
  color: var(--ink);
  font-size: 15px;
}

.admin-item-main span,
.admin-meta span,
.admin-stats span,
.admin-actions span,
.admin-meta a {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.admin-meta a {
  color: var(--accent-dark);
  text-decoration: none;
}

.admin-stats {
  justify-items: end;
  text-align: right;
}

.status-pill {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  justify-self: start;
  padding: 4px 8px;
  color: var(--accent-dark);
  background: #fff8f8;
  border: 1px solid rgba(229, 22, 22, 0.18);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.status-pill.paid {
  color: var(--success);
  background: rgba(22, 138, 82, 0.08);
  border-color: rgba(22, 138, 82, 0.22);
}

.status-pill.expired_unpaid {
  color: var(--muted);
  background: var(--surface-2);
  border-color: var(--line);
}

.amount-field {
  display: grid;
  gap: 5px;
}

.amount-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.amount-field input {
  width: min(180px, 100%);
  min-height: 38px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 900;
}

.admin-actions {
  grid-template-columns: repeat(2, minmax(0, max-content));
  justify-content: end;
  align-items: center;
  text-align: right;
}

.admin-actions span {
  grid-column: 1 / -1;
}

.vk-scheme-dark .partner-auth-note {
  color: #ffb3b3;
  background: rgba(229, 22, 22, 0.12);
  border-color: rgba(229, 22, 22, 0.24);
}

.vk-scheme-dark .qr-visual {
  background: #fff;
}

@media (max-width: 980px) {
  .partner-panel,
  .referral-certificate {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .partner-entry-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .partner-entry-card .page-art {
    grid-row: auto;
  }

  .partner-copy,
  .referral-copy {
    padding: 6px 0 0;
  }

  h2 {
    max-width: 720px;
  }

  .workspace-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-item {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 0.72fr);
  }

  .admin-stats,
  .admin-actions {
    justify-items: start;
    text-align: left;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    top: 0;
    min-height: 68px;
    margin-bottom: 16px;
    padding: 10px;
  }

  .brand-mark {
    width: 78px;
    height: 36px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 34px;
  }

  .partner-copy p:not(.eyebrow),
  .referral-copy p:not(.eyebrow) {
    font-size: 15px;
  }

  .partner-entry-hero {
    min-height: auto;
  }

  .partner-entry-card {
    padding: 22px;
  }

  .partner-entry-copy h2 {
    font-size: 40px;
  }

  .page-art {
    width: 150px;
    max-height: 110px;
  }

  .partner-form,
  .referral-certificate-form {
    padding: 14px;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .link-panel,
  .profile-panel,
  .qr-panel,
  .partner-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .field-action-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .link-panel .compact-button {
    width: 100%;
  }

  .qr-visual {
    width: min(190px, 100%);
    justify-self: center;
  }

  .item-status {
    text-align: left;
  }

  .dashboard-head,
  .list-title {
    align-items: flex-start;
  }

  .admin-hero p:not(.eyebrow) {
    font-size: 15px;
  }

  .admin-toolbar,
  .admin-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-toolbar {
    display: grid;
  }

  .admin-toolbar-actions,
  .admin-actions {
    justify-content: start;
  }

  .amount-field input {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .icon-button:not([hidden]) + .topbar-brand {
    margin-top: 8px;
  }

  .icon-button[hidden] {
    display: none;
  }

  h2 {
    font-size: 29px;
  }

  .partner-entry-copy h2 {
    font-size: 34px;
  }

  .rule-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .partner-type-toggle,
  .metrics-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
