:root {
  --ink: #1c2333;
  --ink-soft: #3c4557;
  --paper: #f4f1ea;
  --paper-deep: #eae5d8;
  --card: #fffdf7;
  --line: #dcd5c3;
  --accent: #b3372b;
  --accent-ink: #fff8f0;
  --muted: #7a7f8a;
  --ok: #1f7a4d;
  --shadow: 0 20px 60px -20px rgba(28, 35, 51, 0.45);
  --radius: 16px;
  --font-display: Georgia, "Times New Roman", serif;
  --font-body: "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Атрибут hidden всегда побеждает (важно: .modal-backdrop задаёт display:grid) */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(179, 55, 43, 0.08), transparent 60%),
    radial-gradient(900px 400px at -10% 110%, rgba(28, 35, 51, 0.12), transparent 60%),
    var(--paper);
  background-attachment: fixed;
}

/* Лёгкая зернистость «бумаги» */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: radial-gradient(rgba(28,35,51,0.045) 1px, transparent 1px);
  background-size: 18px 18px;
  z-index: 0;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 920px;
  margin: 0 auto;
  padding: 56px 24px 80px;
}

/* Шапка */
.masthead {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 44px;
}

.masthead .btn {
  margin-left: auto;
  flex: 0 0 auto;
  padding: 10px 18px;
  font-size: 14px;
}

.masthead__nav {
  margin-left: auto;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.masthead__nav .btn {
  margin-left: 0;
}

.masthead__mark {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 30px;
  color: var(--accent-ink);
  background: var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transform: rotate(-3deg);
}

.masthead h1 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(26px, 4vw, 36px);
  letter-spacing: -0.01em;
}

.masthead p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

/* Приглашение */
.invite {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 48px 32px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}

.invite__hint {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.invite__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

/* Кнопки */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 14px 26px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  text-decoration: none;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 24px -10px rgba(179, 55, 43, 0.7);
}

.btn--primary:hover, .btn--primary:focus-visible {
  background: #9c2f25;
  transform: translateY(-1px);
}

.btn--ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}

.btn--ghost:hover {
  background: var(--paper-deep);
}

.btn__plus {
  font-size: 20px;
  line-height: 1;
}

/* Прогресс */
.steps {
  list-style: none;
  margin: 34px 0 0;
  padding: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 8px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  transition: all 0.2s ease;
}

.step span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--paper-deep);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink-soft);
}

.step.is-active {
  border-color: var(--accent);
  color: var(--ink);
  box-shadow: 0 8px 20px -12px rgba(179, 55, 43, 0.6);
}

.step.is-active span {
  background: var(--accent);
  color: var(--accent-ink);
}

.step.is-done span {
  background: var(--ok);
  color: #fff;
}

/* Модалка */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 24, 34, 0.55);
  backdrop-filter: blur(4px);
  animation: fade 0.2s ease both;
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px;
  box-shadow: var(--shadow);
  animation: pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.modal__kicker {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.modal__title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 28px;
}

.modal__desc {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

.field input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-family: var(--font-body);
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: border 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(179, 55, 43, 0.15);
}

/* Карточки услуг */
.services {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.service-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  transition: border 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.service-card:hover {
  border-color: var(--accent);
  background: #fffaf5;
}

.service-card input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.service-card.is-checked {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(179, 55, 43, 0.12);
}

.service-card__desc {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.service-card__name {
  font-weight: 600;
}

/* Ошибки */
.form-error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fdecea;
  border: 1px solid #f3c1bb;
  color: #a03127;
  font-size: 13px;
}

.field input:invalid:not(:placeholder-shown) {
  border-color: #d66;
}

/* Навигация модалки */
.modal__nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 26px;
}

/* Результат */
.done {
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 44px 28px;
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}

.done__badge {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  font-size: 26px;
}

.done h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 30px;
}

.done__summary {
  margin: 0 auto 24px;
  max-width: 420px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.done__actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Страница «Готовые документы» */
.docs__count {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--muted);
}

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

.docs__empty,
.docs__error {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.docs__error {
  color: #a03127;
  background: #fdecea;
  border-color: #f3c1bb;
}

.docs__wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.docs__toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.docs__search {
  flex: 1 1 260px;
  padding: 11px 14px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.docs__search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(179, 55, 43, 0.12);
}

.docs__stats {
  padding: 10px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  color: var(--muted);
  box-shadow: var(--shadow);
}

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

.docs__none {
  text-align: center;
  color: var(--muted);
  padding: 26px !important;
}

.docs__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.docs__table th,
.docs__table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.docs__table th {
  background: var(--paper-deep);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.docs__table tr:last-child td {
  border-bottom: none;
}

.docs__table td.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.docs__table td:first-child {
  font-weight: 600;
}

.docs__del {
  appearance: none;
  border: 1px solid #f3c1bb;
  background: #fff;
  color: #a03127;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.docs__del:hover {
  background: #fdecea;
}

.docs__actions {
  display: flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
}

.docs__dl {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  font-size: 13px;
}

.docs__dl:hover {
  text-decoration: underline;
}

.docs__no {
  color: var(--line);
}

.docs__footer {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.docs__pass {
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.docs__pass:focus {
  outline: none;
  border-color: var(--accent);
}

@media (max-width: 640px) {
  .docs__wrap {
    overflow-x: auto;
  }
  .docs__table {
    min-width: 680px;
  }
}

/* Анимации */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop {
  from { opacity: 0; transform: translateY(18px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 520px) {
  .page { padding: 32px 16px 56px; }
  .masthead__mark { width: 52px; height: 52px; }
  .invite { padding: 36px 20px; }
  .masthead { flex-wrap: wrap; }
  .masthead__nav { width: 100%; }
}

/* Страница «Настройки услуг» */
.settings {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.settings + .settings {
  margin-top: 20px;
}

.settings__password-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: 18px;
}

.service-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.service-row:last-of-type {
  border-bottom: none;
}

.service-row__num {
  flex: 0 0 26px;
  padding-top: 10px;
  font-weight: 700;
  color: var(--muted);
}

.service-row__inputs {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.service-row__del {
  flex: 0 0 auto;
  padding: 10px 14px;
  font-size: 13px;
  color: #a03127;
  border-color: #f3c1bb;
}

.settings__actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
  flex-wrap: wrap;
}

.settings__hint {
  margin: 14px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.settings__hint--ok {
  color: var(--ok);
}

.settings__hint--err {
  color: #a03127;
}

.settings__number {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px dashed var(--line);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: end;
}

@media (max-width: 640px) {
  .settings__number {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 720px) {
  .service-row__inputs {
    grid-template-columns: 1fr 2fr;
  }
}
