@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;600;700&family=Jost:wght@300;400;500&display=swap');

/* ── TOKENS ── */
:root {
  --ink: #1a1a2e;
  --paper: #f5f0e8;
  --accent: #8b1a1a;
  --accent-dark: #6d1515;
  --accent2: #c8a96e;
  --line: rgba(26, 26, 46, 0.15);
  --line-soft: rgba(26, 26, 46, 0.08);
  --field-bg: rgba(255, 255, 255, 0.7);
  --muted: #777;
  --muted-strong: #555;
  --error: #8b1a1a;
  --success: #2d7a2d;
  --radius: 2px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: 'Jost', 'Segoe UI', sans-serif;
  font-weight: 400;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  background-image:
    radial-gradient(
      ellipse at 10% 20%,
      rgba(139, 26, 26, 0.06) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse at 90% 80%,
      rgba(200, 169, 110, 0.08) 0%,
      transparent 50%
    );
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

a {
  color: inherit;
}

/* ── APP SCREEN (no auth gate, no nav bar) ── */
#app-screen {
  display: block;
  min-height: 100vh;
  padding-bottom: 96px; /* room for fixed generate-bar */
}

#app-screen.is-active {
  display: block;
}

header {
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  line-height: 1.15;
}

.header-title span {
  display: block;
  color: var(--accent);
  font-size: 11px;
  font-family: 'Jost', sans-serif;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-weight: 400;
  margin-bottom: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

/* ── MESSAGE BANNER ── */
.banner {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  color: var(--muted-strong);
  border-radius: var(--radius);
}

.banner[data-kind='success'] {
  color: var(--success);
  border-color: rgba(45, 122, 45, 0.3);
}

.banner[data-kind='error'] {
  color: var(--error);
  border-color: rgba(139, 26, 26, 0.3);
}

.banner[hidden] {
  display: none;
}

/* ── MAIN VIEWS ── */
.main-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.view {
  display: block;
}

.view[hidden] {
  display: none;
}

/* ── SECTIONS ── */
.section {
  margin-bottom: 36px;
  background: #fff;
  border: 1px solid var(--line);
  overflow: hidden;
}

.section-header {
  padding: 14px 24px;
  background: var(--ink);
  color: #fff;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-body {
  padding: 24px;
}

.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
}

.fields-grid.cols-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.field-full {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  font-family: 'Jost', sans-serif;
  font-size: 14px;
  color: var(--ink);
  outline: none;
  border-radius: var(--radius);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  width: 100%;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #b6b6b6;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(200, 169, 110, 0.15);
  background: #fff;
}

.field textarea {
  resize: vertical;
  min-height: 56px;
}

.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── DIVIDER ── */
.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 20px 0;
}

/* ── DATE INPUT WITH CALENDAR EMOJI ── */
.date-wrap {
  position: relative;
}

.date-wrap input[type='date'] {
  cursor: pointer;
  color: var(--ink);
  padding-left: 36px;
  width: 100%;
}

.date-wrap::before {
  content: '📅';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
  z-index: 1;
}

.date-wrap input[type='date']::-webkit-calendar-picker-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 36px;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* ── GENERATE BAR ── */
.generate-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 30px rgba(26, 26, 46, 0.08);
  z-index: 10;
}

.generate-bar-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.generate-bar .status-msg {
  font-size: 13px;
  color: var(--muted-strong);
  display: flex;
  align-items: center;
  gap: 8px;
}

.generate-bar .status-msg.success {
  color: var(--success);
}

.generate-bar .status-msg.error {
  color: var(--accent);
}

#btn-generate {
  padding: 13px 40px;
  background: var(--accent);
  color: #fff;
  border: none;
  font-family: 'Jost', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius);
  transition:
    background 0.2s,
    transform 0.1s,
    box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(139, 26, 26, 0.3);
}

#btn-generate:hover {
  background: var(--accent-dark);
  box-shadow: 0 6px 25px rgba(139, 26, 26, 0.4);
}

#btn-generate:active {
  transform: scale(0.98);
}

#btn-generate:disabled {
  background: #bbb;
  box-shadow: none;
  cursor: not-allowed;
}

/* ── SPINNER ── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #ddd;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.spinner.is-active {
  display: inline-block;
}

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

/* ── FILE INPUT ── */
.file-hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

input[type='file'] {
  font-family: 'Jost', sans-serif;
  font-size: 13px;
  color: var(--ink);
}

/* ── DROPZONE (Шаблон документа) ──
 * Wraps the native <input type="file"> for the "Шаблон документа" field.
 * The dropzone is a pure front-end wrapper — the underlying input stays
 * the single source of truth for the picked file, and the form payload
 * is unchanged. The four states are driven by [data-state] on
 * #template-dropzone: empty | dragover | selected | error.
 *
 * The dashed frame uses the same --line token as the rest of the form
 * separators so the empty state stays in the page's neutral tone — no
 * bright accent. dragover darkens / densifies the frame to signal the
 * zone is ready to receive. error swaps the dashed border for a solid
 * --error frame and shows the inline message.
 */
.dropzone {
  position: relative;
  margin-top: 6px;
  padding: 18px 18px 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--field-bg);
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease,
    box-shadow 0.15s ease;
}

.dropzone[data-state='dragover'] {
  border-style: solid;
  border-color: var(--ink);
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--line);
}

.dropzone[data-state='selected'] {
  border-style: solid;
  border-color: var(--line);
  background: #fff;
}

.dropzone[data-state='error'] {
  border-style: solid;
  border-color: var(--error);
  background: #fff;
}

.dropzone-hint {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
}

.dropzone[data-state='selected'] .dropzone-hint,
.dropzone[data-state='error'] .dropzone-hint {
  display: none;
}

.dropzone-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 160px; /* room for the hint label on the empty state */
}

.dropzone[data-state='selected'] .dropzone-body,
.dropzone[data-state='error'] .dropzone-body {
  padding-right: 0;
}

.dropzone-error {
  margin-top: 4px;
  font-size: 12px;
  color: var(--error);
  letter-spacing: 0.02em;
}

/* ── HELP LINK (header) ──
 * The "Помощь" entry point lives in the page header as a plain
 * `<a href="#help">` so it inherits the header's text rhythm. The
 * leading `?` is a visual cue, not a real query string — the hash
 * is what triggers the modal in app.js. */
.help-link {
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-strong);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.help-link:hover,
.help-link:focus-visible {
  color: var(--accent);
  background: rgba(200, 169, 110, 0.1);
  outline: none;
}

/* ── HELP MODAL ──
 * Operator-facing help modal: two blocks inside a single card
 * (walkthrough + placeholder list + archive download). The overlay
 * is a separate full-screen layer so click-on-overlay can be
 * distinguished from click-on-card. The modal is hidden by default
 * (the `hidden` attribute) and only revealed via app.js so a
 * non-JS visitor never sees a half-open modal. */
.help-modal[hidden] {
  display: none;
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.help-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 46, 0.45);
  cursor: pointer;
}

.help-modal__card {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(26, 26, 46, 0.18);
  max-width: 640px;
  width: 100%;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 28px 28px 24px;
  font-family: 'Jost', sans-serif;
}

.help-modal__close {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 24px;
  line-height: 1;
  color: var(--muted-strong);
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.help-modal__close:hover,
.help-modal__close:focus-visible {
  color: var(--accent);
  background: rgba(139, 26, 26, 0.06);
  outline: none;
}

.help-modal__title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 16px;
  padding-right: 32px;
  letter-spacing: 0.02em;
}

.help-block {
  border-top: 1px solid var(--line);
  padding: 18px 0 4px;
  margin-top: 14px;
}

.help-block:first-of-type {
  border-top: none;
  margin-top: 0;
  padding-top: 4px;
}

.help-block__header {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.help-block__steps {
  margin: 0 0 10px 22px;
  padding: 0;
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.55;
}

.help-block__steps li {
  margin-bottom: 6px;
}

.help-block__steps code,
.help-block__lead code,
.help-block__note code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-size: 12.5px;
  background: rgba(200, 169, 110, 0.12);
  padding: 1px 5px;
  border-radius: var(--radius);
  color: var(--ink);
}

.help-block__lead {
  font-size: 14px;
  color: var(--muted-strong);
  line-height: 1.55;
  margin: 0 0 12px;
}

.help-block__placeholders {
  list-style: none;
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-size: 12.5px;
  color: var(--ink);
  line-height: 1.7;
  column-count: 2;
  column-gap: 18px;
}

.help-block__placeholders li {
  break-inside: avoid;
}

.help-block__placeholders .placeholder-group {
  display: block;
  font-family: 'Jost', sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 6px;
  break-after: avoid;
}

.help-block__placeholders .placeholder-group:first-child {
  margin-top: 0;
}

.help-block__placeholders code {
  font-family: inherit;
  font-size: inherit;
  background: transparent;
  padding: 0;
  color: inherit;
}

.help-block__placeholders .placeholder-empty {
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

/* ── MAINTENANCE BANNER ──
 * Rendered by the page handler when the maintenance flag is on,
 * in place of the form. Reuses the .section shell (white card,
 * ink-coloured uppercase header, 24px body padding) so the visual
 * rhythm matches the rest of the page; the body is then
 * re-laid out as a centred stack with a single accent rule.
 *
 * The banner is rendered server-side; no JS state, no client
 * toggle, no flicker. The card is full-width inside the existing
 * .main-content (max-width 900px) so it lines up with the form
 * sections it replaces. */
.section--maintenance {
  margin-top: 16px;
}

.section--maintenance .section-body {
  text-align: center;
  padding: 36px 32px 32px;
}

.maintenance-card__lead {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
}

.maintenance-card__message {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
  margin: 0 auto 18px;
  max-width: 560px;
}

.maintenance-card__note {
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted-strong);
  margin: 0 auto;
  max-width: 480px;
}

.help-block__download {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 10px 22px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(139, 26, 26, 0.3);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.help-block__download:hover,
.help-block__download:focus-visible {
  background: var(--accent-dark);
  box-shadow: 0 6px 25px rgba(139, 26, 26, 0.4);
  outline: none;
}

.help-block__note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── RESPONSIVE ── */
@media (max-width: 720px) {
  .header-inner {
    padding: 14px 16px;
    flex-wrap: wrap;
  }

  .main-content {
    padding: 24px 12px 100px;
  }

  .section-body {
    padding: 16px;
  }

  .fields-grid,
  .fields-grid.cols-3 {
    grid-template-columns: 1fr;
  }

  .generate-bar-inner {
    padding: 12px 16px;
  }

  #btn-generate {
    padding: 12px 20px;
    font-size: 12px;
  }

  .help-modal {
    padding: 12px;
  }

  .help-modal__card {
    padding: 22px 18px 18px;
    max-height: calc(100vh - 24px);
  }

  .help-block__placeholders {
    column-count: 1;
  }
}
