:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --border: #d8dee9;
  --border-focus: #3b6ea5;
  --text: #1a2332;
  --muted: #5c6b7a;
  --accent: #2c5282;
  --accent-hover: #1e3a5f;
  --success-bg: #e8f5e9;
  --success-border: #4caf50;
  --success-text: #2e7d32;
  --danger-bg: #fdecea;
  --danger-border: #e53935;
  --danger-text: #c62828;
  --section-bg: #f7f9fc;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --input-h: 38px;
  --textarea-min: 64px;
  --textarea-tall-min: 96px;
  --gap-field: 12px;
  --gap-section: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 14px;
}

.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

header {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: var(--gap-section);
  box-shadow: var(--shadow);
}

header h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--accent);
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

#message {
  display: none;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: var(--gap-section);
  text-align: center;
  font-weight: 500;
  font-size: 0.9rem;
}

#message.ok {
  display: block;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
}

#message.err {
  display: block;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
}

section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  margin-bottom: var(--gap-section);
  box-shadow: var(--shadow);
}

section h2 {
  margin: 0 0 14px;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--accent);
  padding: 8px 12px;
  background: var(--section-bg);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* --- layout grids --- */

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-field) 16px;
  align-items: start;
}

.grid-1 {
  grid-column: 1 / -1;
}

/* subgrid only for all-textarea 2-col blocks — aligns labels, not field heights */
@supports (grid-template-rows: subgrid) {
  .grid-textareas {
    grid-auto-rows: auto auto;
  }

  .grid-textareas > label {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 2;
    gap: 5px;
  }
}

@supports not (grid-template-rows: subgrid) {
  .grid-textareas > label > span {
    min-height: 3.6em;
    line-height: 1.3;
  }
}

.fields-stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap-field);
}

@media (max-width: 640px) {
  .grid,
  .grid-textareas {
    grid-template-columns: 1fr;
  }

  .grid-textareas > label {
    display: flex;
    flex-direction: column;
    grid-row: auto;
  }
}

/* --- fields --- */

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.85rem;
}

label > span {
  color: var(--text);
  font-weight: 500;
  line-height: 1.3;
}

label.required > span::after {
  content: " *";
  color: var(--danger-text);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
select {
  width: 100%;
  height: var(--input-h);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0 10px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="file"] {
  width: 100%;
  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

textarea {
  width: 100%;
  min-height: var(--textarea-min);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.9rem;
  font-family: inherit;
  line-height: 1.4;
  resize: vertical;
  overflow-y: auto;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea.textarea-tall {
  min-height: var(--textarea-tall-min);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 110, 165, 0.12);
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.4;
}

/* --- photo block --- */

.photo-block {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 640px) {
  .photo-block {
    grid-template-columns: 1fr;
  }
}

.photo-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#photoPreview {
  width: 140px;
  height: 175px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: none;
}

.photo-placeholder {
  width: 140px;
  height: 175px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  background: var(--section-bg);
}

/* --- relatives table --- */

.relatives-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.btn-row-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-row-action:hover:not(:disabled) {
  background: var(--section-bg);
  border-color: var(--border-focus);
}

.btn-row-action:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-add {
  padding: 6px 12px;
}

.btn-remove {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
}

.relatives-wrap {
  overflow-x: auto;
  margin-top: 0;
}

.relatives-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.relatives-table th {
  background: var(--section-bg);
  color: var(--accent);
  font-weight: 600;
  text-align: left;
  padding: 8px 6px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.relatives-table th.col-actions,
.relatives-table td.col-actions {
  width: 40px;
  min-width: 40px;
  padding: 4px;
  text-align: center;
  vertical-align: middle;
  background: var(--section-bg);
}

.relatives-table td {
  border: 1px solid var(--border);
  padding: 0;
  vertical-align: top;
}

.relatives-table td.col-actions {
  background: #fff;
}

.relatives-table textarea {
  display: block;
  width: 100%;
  min-height: 56px;
  height: 56px;
  margin: 0;
  padding: 7px 8px;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  resize: vertical;
  overflow-y: auto;
}

.relatives-table textarea:focus {
  background: #fff;
  outline: none;
  box-shadow: inset 0 0 0 2px rgba(59, 110, 165, 0.3);
}

.relatives-table tr.row-resizing textarea {
  overflow: hidden;
}

/* --- submit --- */

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin: 20px auto 0;
  max-width: 520px;
}

.form-actions .btn-primary,
.form-actions .btn-secondary {
  flex: 1 1 200px;
  margin: 0;
}

.btn-secondary {
  display: block;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--card);
  color: var(--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-secondary:hover {
  background: var(--section-bg);
  color: var(--text);
  border-color: #b8c4d4;
}

.btn-primary {
  display: block;
  width: 100%;
  max-width: 360px;
  margin: 20px auto 0;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.consent-wrap {
  margin: 16px 0 0;
  display: flex;
  justify-content: flex-start;
}

.consent-block {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  max-width: 36rem;
  padding: 10px 12px;
  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.consent-block .consent-checkbox {
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin: 2px 0 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.consent-block .consent-label {
  display: block;
  flex: 1;
  flex-direction: unset;
  gap: 0;
  margin: 0;
  padding: 0;
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text);
  cursor: pointer;
}

.consent-block .consent-required::after {
  content: " *";
  color: var(--danger-text);
}
