:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --border: #e0e2e7;
  --text: #1f2430;
  --text-muted: #6b7280;
  --accent: #2f5ce0;
  --accent-hover: #2447b8;
  --preview-bg: #ffffff;
  --highlight-bg: #fff3c4;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app { max-width: 1400px; margin: 0 auto; padding: 24px 32px 64px; }

.app-header h1 { font-size: 24px; margin: 0 0 4px; }
.subtitle { color: var(--text-muted); margin: 0 0 24px; font-size: 14px; }

.layout {
  display: grid;
  grid-template-columns: minmax(380px, 560px) 1fr;
  gap: 24px;
  align-items: start;
}

.form-panel { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card h2 { font-size: 15px; margin: 0 0 14px; color: var(--text); }

.row { display: flex; gap: 12px; margin-bottom: 12px; }
.row .field { flex: 1; }
.field-sm { flex: 0 0 120px !important; }
.field-grow { flex: 2 !important; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.row .field { margin-bottom: 0; }

.field:last-child { margin-bottom: 0; }

label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }

input[type="text"], input[type="date"], select, textarea {
  font: inherit;
  font-size: 14px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fbfbfc;
  color: var(--text);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

textarea { resize: vertical; font-family: inherit; }

.checkbox-field label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.checkbox-field input { width: auto; }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }

.mini-btn {
  flex-shrink: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 0 14px;
  border-radius: 7px;
  border: 1px solid var(--accent);
  background: #eef2fd;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}
.mini-btn:hover { background: #e2e9fc; }
.mini-btn:disabled { opacity: 0.5; cursor: wait; }

.hint-line { font-size: 12px; color: var(--text-muted); margin-top: 6px; min-height: 15px; line-height: 1.5; }
.hint-line.hint-ok { color: #197a3d; }
.hint-line.hint-warn { color: #9a6a00; }
.hint-line.hint-error { color: #c22; }

.field-missing {
  border-color: #e0a400 !important;
  background: #fff8e6 !important;
}
.field-missing::placeholder { color: #b8860b; }

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  width: fit-content;
}
.segmented-opt {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13.5px;
  cursor: pointer;
  background: #fbfbfc;
  color: var(--text);
}
.segmented-opt:not(:last-child) { border-right: 1px solid var(--border); }
.segmented-opt:has(input:checked) { background: var(--accent); color: #fff; }
.segmented-opt input { width: auto; margin: 0; }

.declension-box {
  margin-top: 12px;
  padding: 12px;
  background: #f8f7ef;
  border: 1px dashed #d8cf9e;
  border-radius: 8px;
}
.declension-box .hint { font-size: 12.5px; color: #7a6a2a; margin: 0 0 10px; line-height: 1.4; }

.submit-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 9px;
  cursor: pointer;
  position: sticky;
  bottom: 16px;
  box-shadow: 0 4px 16px rgba(47,92,224,0.35);
}
.submit-btn:hover { background: var(--accent-hover); }
.submit-btn:disabled { opacity: 0.6; cursor: wait; }

.preview-panel { position: sticky; top: 24px; }
.preview-panel h2 { font-size: 15px; margin: 0 0 12px; color: var(--text); }

.preview-doc {
  background: var(--preview-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 40px;
  font-family: "Times New Roman", Georgia, serif;
  font-size: 14px;
  line-height: 1.55;
  min-height: 400px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}

.preview-header {
  text-align: right;
  font-style: italic;
  font-size: 12px;
  color: #444;
  margin-bottom: 18px;
}

.preview-title { text-align: center; font-weight: bold; margin-bottom: 14px; }

.preview-date { display: flex; justify-content: space-between; margin-bottom: 14px; font-style: italic; }

#p-preamble { text-indent: 2em; text-align: justify; margin-bottom: 16px; }
#p-subject { margin-bottom: 20px; }

.mark { background: var(--highlight-bg); padding: 0 1px; border-radius: 2px; }

.preview-sign-block { border-top: 1px solid var(--border); padding-top: 16px; font-size: 12.5px; }
.preview-sign-block strong { display: block; margin-bottom: 6px; }
.req-line { margin: 2px 0; }
.req-line span { font-weight: 600; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
}
