/* Mini App — Hebrew RTL form for the miluim bridge.

   Layout strategy: mobile-first, single column, generous tap targets
   (≥44px), no fixed footer (Telegram renders its own MainButton at the
   bottom; we leave bottom padding so content doesn't slip under it).

   Theming: every color comes from a Telegram theme variable. The bot's
   user gets light or dark automatically, matching whatever theme they
   set in Telegram Settings → Appearance. Fallbacks are baseline-safe so
   the app still renders if Telegram ever ships a new theme variable
   without warning. */

:root {
  --bg:               var(--tg-theme-bg-color, #ffffff);
  --secondary-bg:     var(--tg-theme-secondary-bg-color, #f4f4f5);
  --section-bg:       var(--tg-theme-section-bg-color, var(--secondary-bg));
  --section-header:   var(--tg-theme-section-header-text-color, #707579);
  --text:             var(--tg-theme-text-color, #1f1f1f);
  --hint:             var(--tg-theme-hint-color, #707579);
  --link:             var(--tg-theme-link-color, #2481cc);
  --button:           var(--tg-theme-button-color, #2481cc);
  --button-text:      var(--tg-theme-button-text-color, #ffffff);
  --destructive:      var(--tg-theme-destructive-text-color, #cc2929);
  --separator:        var(--tg-theme-section-separator-color, #e7e7ea);
  --accent-text:      var(--tg-theme-accent-text-color, var(--link));

  --radius-card:      14px;
  --radius-input:     10px;
  --gap:              16px;
  --gap-sm:           8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Hebrew",
               "Arial Hebrew", "Heebo", "Noto Sans Hebrew", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

main {
  /* Bottom inset accounts for Telegram's MainButton (~64px) plus safe area. */
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom)) 16px;
  max-width: 640px;
  margin: 0 auto;
}

/* ----- Steps -------------------------------------------------------- */

.step { display: none; }
.step.active { display: block; }

.hero {
  margin: -16px -16px 16px;        /* bleed to viewport edges */
  padding: 0;
  overflow: hidden;
  background: #6d654b;             /* matches cover-640x360.png letterbox tone */
  border-radius: 0 0 var(--radius-card) var(--radius-card);
}
.hero img {
  display: block;
  width: 100%;
  height: auto;
}

.step-header h1 {
  font-size: 22px;
  margin: 8px 0 4px;
  font-weight: 600;
}
.step-header .lede {
  margin: 0 0 20px;
  color: var(--hint);
  font-size: 14px;
}

/* ----- Kind picker -------------------------------------------------- */

.kind-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.kind-card {
  appearance: none;
  background: var(--section-bg);
  border: 2px solid transparent;
  border-radius: var(--radius-card);
  padding: 16px;
  text-align: start;
  display: grid;
  grid-template-columns: 32px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 4px;
  align-items: start;
  cursor: pointer;
  color: var(--text);
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}
.kind-card:hover { transform: translateY(-1px); }
.kind-card[aria-checked="true"] {
  border-color: var(--button);
  background: color-mix(in srgb, var(--button) 8%, var(--section-bg));
}
.kind-emoji {
  grid-row: 1 / span 2;
  font-size: 28px;
  line-height: 1;
}
.kind-title {
  font-weight: 600;
  font-size: 17px;
}
.kind-desc {
  color: var(--hint);
  font-size: 14px;
}

/* ----- Rules collapsible -------------------------------------------- */

.rules-collapsible {
  background: var(--section-bg);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  margin-top: 8px;
  font-size: 14px;
  color: var(--hint);
}
.rules-collapsible summary {
  cursor: pointer;
  list-style: none;
  font-weight: 500;
  color: var(--accent-text);
}
.rules-collapsible summary::-webkit-details-marker { display: none; }
.rules-list {
  margin: 12px 0 0;
  padding-inline-start: 20px;
}
.rules-list li { margin-bottom: 6px; }

/* ----- Form fields -------------------------------------------------- */

.field {
  background: var(--section-bg);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--section-header);
  margin-bottom: 8px;
  text-transform: none;
}
.field-label .field-required {
  color: var(--destructive);
  margin-inline-start: 4px;
}
.field-hint {
  display: block;
  font-size: 12px;
  color: var(--hint);
  margin-top: 6px;
}
.field-input,
.field-textarea,
.field-select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  padding: 10px 12px;
  font: inherit;
  outline: none;
  transition: border-color 120ms ease;
}
.field-textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}
.field-select { appearance: auto; }
.field-input:focus,
.field-textarea:focus,
.field-select:focus {
  border-color: var(--button);
}
.field.invalid .field-input,
.field.invalid .field-textarea,
.field.invalid .field-select {
  border-color: var(--destructive);
}
.field-counter {
  display: block;
  text-align: end;
  font-size: 12px;
  color: var(--hint);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.field-counter.over { color: var(--destructive); }

.field-errors {
  margin: 8px 4px 0;
  font-size: 13px;
  color: var(--destructive);
  min-height: 1em;
}
.field-errors:empty { display: none; }

/* ----- Channel picker ----------------------------------------------- */

.channel-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.channel-card {
  appearance: none;
  background: var(--section-bg);
  border: 2px solid transparent;
  border-radius: var(--radius-card);
  padding: 14px;
  text-align: start;
  display: grid;
  grid-template-columns: 32px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: start;
  cursor: pointer;
  color: var(--text);
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}
.channel-card:hover { transform: translateY(-1px); }
.channel-card[aria-checked="true"] {
  border-color: var(--button);
  background: color-mix(in srgb, var(--button) 8%, var(--section-bg));
}
.channel-emoji {
  grid-row: 1 / span 2;
  font-size: 24px;
  line-height: 1;
}
.channel-title {
  font-weight: 600;
  font-size: 16px;
}
.channel-desc {
  color: var(--hint);
  font-size: 13px;
}

.channel-input-wrap {
  background: var(--section-bg);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  margin: 0 0 16px;
}
.channel-input-wrap[hidden] { display: none; }

.privacy-note {
  margin: 8px 4px 16px;
  font-size: 12px;
  color: var(--hint);
  line-height: 1.5;
}

/* ----- Preview ------------------------------------------------------- */

.preview-body {
  background: var(--section-bg);
  border-radius: var(--radius-card);
  padding: 16px;
  font: inherit;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow-y: auto;
}
.preview-actions, .result-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

/* ----- Buttons (non-Telegram-managed) ------------------------------- */

.ghost-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--accent-text);
  font: inherit;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: var(--radius-input);
}
.ghost-btn:hover { background: var(--secondary-bg); }
