/* ── Telegram Mini App form ──────────────────────────────────── */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f2f4f7);
  --text: var(--tg-theme-text-color, #0f172a);
  --muted: var(--tg-theme-hint-color, #7d8b9c);
  --accent: var(--tg-theme-button-color, #2563eb);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e5484d;
  --success: #12a594;
  --border: color-mix(in srgb, var(--muted) 28%, transparent);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 0 0 96px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

.head {
  padding: 16px 16px 12px;
  display: flex; align-items: center; gap: 12px;
}
.head .ava {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 20px;
}
.head b { display: block; font-size: 16px; }
.head span { color: var(--muted); font-size: 13px; }
.head .count {
  margin-left: auto; text-align: right;
  font-size: 22px; font-weight: 700; color: var(--accent);
  line-height: 1;
}
.head .count small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }

form { padding: 0 16px; }

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px;
}
.field label .opt { color: var(--muted); font-weight: 400; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.field .err { color: var(--danger); font-size: 12.5px; margin-top: 5px; display: none; }
.field.bad .err { display: block; }
.field.bad input, .field.bad select { border-color: var(--danger); }

/* "why is this empty" block: attached to the field it explains */
.field.reason {
  margin: -6px 0 16px; padding: 10px 12px;
  background: var(--surface-2, rgba(128, 128, 128, .08));
  border-radius: 12px;
}
.field.reason label { font-size: 12.5px; color: var(--muted); }

/* soft duplicate note — the value may still be correct, so it is not an error */
.warn {
  color: #b7791f; font-size: 12.5px; margin-top: 5px;
  background: color-mix(in srgb, #f6ad37 16%, transparent);
  border-radius: 8px; padding: 7px 9px;
}
.warn:empty { display: none; }
.field.warned input { border-color: #f6ad37; }

input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  appearance: none;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; font: inherit; padding: 12px; border-radius: 12px;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
}
.seg button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.rowbtn {
  width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px;
  border: 1.5px dashed var(--border); background: transparent; color: var(--text);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.rowbtn.ok { border-style: solid; border-color: var(--success); color: var(--success); }
.preview { margin-top: 10px; width: 100%; border-radius: 12px; display: none; }
.preview.on { display: block; }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.bar button {
  width: 100%; font: inherit; font-weight: 600; font-size: 16px;
  padding: 15px; border: none; border-radius: 13px;
  background: var(--accent); color: var(--accent-text);
}
.bar button:disabled { opacity: .55; }

.msg {
  margin: 0 16px 14px; padding: 12px 14px; border-radius: 12px;
  font-size: 14px; display: none;
}
.msg.on { display: block; }
.msg.error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.msg.ok { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }

.done { text-align: center; padding: 60px 24px; display: none; }
.done.on { display: block; }
.done .tick { font-size: 58px; }
.done h2 { margin: 12px 0 6px; }
.done p { color: var(--muted); margin: 0 0 24px; }
.done button {
  font: inherit; padding: 14px 22px; border: none; border-radius: 13px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.hidden { display: none !important; }
