/*
 * Form Builder / フロント。
 *
 * 各サイトのテーマに埋め込まれる前提なので、フォントも色もできるだけ継承する。
 * ここで決めるのは「構造」と「状態」だけ。見た目はテーマ側の上書きに委ねる。
 */

.afb {
	--afb-border: #d5d8dc;
	--afb-border-strong: #9aa0a6;
	--afb-bg-soft: #f7f8f9;
	--afb-error: #b3261e;
	--afb-gap: 2.75rem;
	--afb-label-gap: 1rem;

	font: inherit;
	color: inherit;
	/*
	 * テーマが親要素で text-align を指定していると中に継承されてしまう。
	 * 中央寄せにしたい箇所（ボタン・ステップ・完了画面）は個別に指定しているので、
	 * ここで左寄せを明示して土台を揃える。
	 */
	text-align: left;
}

.afb *,
.afb *::before,
.afb *::after {
	box-sizing: border-box;
}

/* ステップ表示 ------------------------------------------------ */

.afb-steps {
	display: flex;
	gap: 0.5rem;
	margin: 0 0 4rem;
	padding: 0;
	list-style: none;
	font-size: 0.875em;
}

.afb-steps__item {
	flex: 1;
	padding: 0.5em 0.75em;
	text-align: center;
	background: var(--afb-bg-soft);
	color: #6b7075;
	border-radius: 4px;
}

.afb-steps__item.is-current {
	background: currentColor;
	color: #fff;
	font-weight: 700;
}

.afb-steps__item.is-current {
	background: #333;
}

/* 行 ---------------------------------------------------------- */

.afb-row {
	margin-bottom: var(--afb-gap);
}

.afb-row--inline {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	flex-wrap: wrap;
}

.afb-row--inline > .afb-label {
	flex: 0 0 auto;
	margin-bottom: 0;
}

.afb-row--inline > .afb-field {
	flex: 1 1 260px;
	min-width: 0;
}

.afb-label {
	/* 項目名が入力欄の上に来るときの間隔。2カラムのときは 0 に落とす。 */
	margin-bottom: var(--afb-label-gap, 1rem);
	font-weight: 700;
	line-height: 1.6;
	text-align: left;
}

.afb-label__head {
	display: flex;
	align-items: baseline;
	gap: 0.6em;
}

.afb-label__text {
	min-width: 0;
}

/* タイトル下補足文。項目名と同じ大きさ・太さで続けて置く。 */
.afb-label__note {
	margin-top: 0.2em;
	font-size: inherit;
	font-weight: inherit;
	line-height: 1.6;
}

.afb-required,
.afb-optional {
	flex: 0 0 auto;
	align-self: flex-start;
	margin-top: 0.25em;
	font-size: 0.72em;
	font-weight: 400;
	letter-spacing: 0.08em;
	padding: 0.3em 0.8em;
	border-radius: 2px;
	line-height: 1;
	white-space: nowrap;
}

.afb-required {
	background: var(--afb-required-bg, #9a8253);
	color: var(--afb-required-fg, #fff);
}

.afb-optional {
	background: var(--afb-optional-bg, #e8e9ea);
	color: var(--afb-optional-fg, #5f6368);
}

/* PCで左に項目名、右に入力欄 ---------------------------------- */

.afb--cols > form > .afb-row {
	display: grid;
	/*
	 * 列の間隔を gap で取ると、指定した割合から gap の分だけずれる。
	 * ラベル側の padding-right で間隔を作り、35% と指定したら 35:65 になるようにしている。
	 */
	grid-template-columns: var(--afb-label-w, 35%) minmax(0, 1fr);
	gap: 0;
	align-items: start;
}

.afb--cols > form > .afb-row > .afb-label {
	margin-bottom: 0;
	padding-top: 0.7em;
	padding-right: 2rem;
}

/* 繰り返しセットや数量グループの中は、この2カラムを持ち込まない。 */
.afb--cols .afb-repeater__item .afb-row {
	display: block;
}

.afb--cols .afb-repeater__item .afb-row--inline {
	display: flex;
}

.afb--cols .afb-repeater__item .afb-label {
	padding-top: 0;
	padding-right: 0;
}

/* セットの中は外側の広い行間を持ち込まない。 */
.afb-repeater__item .afb-row {
	margin-bottom: 1rem;
}

/* セットの中は外側の間隔を持ち込まない。 */
.afb-repeater__item .afb-label {
	margin-bottom: 0.45em;
}

.afb-repeater__item .afb-row:last-of-type {
	margin-bottom: 0;
}

/* 区切り線と余白 ---------------------------------------------- */

.afb--divided > form > .afb-row,
.afb--divided > form > .afb-block--html {
	padding-bottom: var(--afb-gap);
	border-bottom: 1px solid var(--afb-border);
}

.afb--divided > form > .afb-row:last-of-type {
	border-bottom: 0;
}

.afb--divided .afb-repeater__item .afb-row {
	padding-bottom: 0;
	border-bottom: 0;
}

.afb-note {
	font-size: 0.875em;
	line-height: 1.7;
	text-align: left;
	color: #5f6368;
}

.afb-note--before {
	margin-bottom: 0.5em;
}

.afb-note--after {
	margin-top: 0.6em;
	text-align: left;
	color: var(--afb-note-color, #1c4fb3);
}

.afb-block--html,
.afb-total {
	margin-bottom: var(--afb-gap);
}

/* 入力 -------------------------------------------------------- */

.afb-input,
.afb-select,
.afb-textarea {
	width: 100%;
	padding: 0.7em 0.8em;
	font: inherit;
	color: inherit;
	background: #fff;
	border: 1px solid var(--afb-border);
	border-radius: 4px;
	-webkit-appearance: none;
	appearance: none;
}

.afb-select {
	background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
	background-position: right 1.1em top 50%, right 0.75em top 50%;
	background-size: 0.35em 0.35em, 0.35em 0.35em;
	background-repeat: no-repeat;
	padding-right: 2.2em;
}

.afb-input:focus-visible,
.afb-select:focus-visible,
.afb-textarea:focus-visible {
	outline: 2px solid var(--afb-border-strong);
	outline-offset: 1px;
}

.afb-number {
	max-width: 8em;
}

/* 日付入力 ---------------------------------------------------- */

/*
 * 未入力時の表示も、押せる範囲も、ブラウザごとに違う。
 * とくに iOS Safari は未入力だと何も表示されず、
 * 押せるのは値の文字がある幅だけなので、枠内なのに反応しない箇所ができる。
 * ネイティブの表示は消し、自前のプレースホルダを重ねて挙動を揃える。
 */
.afb-date {
	position: relative;
}

.afb-date__input {
	-webkit-appearance: none;
	appearance: none;
	display: block;
	width: 100%;
	min-height: 2.9em;
}

/* 未入力のあいだはブラウザ標準の文字を隠し、自前の表示に置き換える。 */
.afb-date:not(.is-filled) .afb-date__input {
	color: transparent;
}

.afb-date__placeholder {
	position: absolute;
	top: 50%;
	left: 0.9em;
	transform: translateY(-50%);
	color: #9aa0a6;
	pointer-events: none;
}

.afb-date.is-filled .afb-date__placeholder {
	display: none;
}

.afb-date__input::-webkit-date-and-time-value,
.afb-date__input::-webkit-datetime-edit {
	display: block;
	width: 100%;
	min-height: 1.4em;
	margin: 0;
	text-align: left;
}

.afb-date__input::-webkit-calendar-picker-indicator {
	position: absolute;
	inset: 0;
	width: auto;
	height: auto;
	margin: 0;
	padding: 0;
	opacity: 0;
	cursor: pointer;
}

/* 選択肢 ------------------------------------------------------ */

.afb-choices {
	display: flex;
	flex-direction: column;
	gap: 0.6em;
}

.afb-choices--checkbox,
.afb-choices--radio {
	gap: 0.6em;
}

.afb-choice {
	display: flex;
	align-items: flex-start;
	gap: 0.5em;
	cursor: pointer;
}

.afb-choice input {
	margin-top: 0.25em;
	flex: 0 0 auto;
}

.afb-choice--disabled {
	color: #9aa0a6;
	cursor: not-allowed;
}

.afb-choice__note {
	font-size: 0.875em;
	color: #5f6368;
}

/* 「満席」「受付終了」など、選択肢に添える札。 */
.afb-choice__badge {
	flex: 0 0 auto;
	align-self: center;
	padding: 0.25em 0.9em;
	font-size: 0.75em;
	font-weight: 700;
	line-height: 1.4;
	white-space: nowrap;
	border-radius: 2px;
	background: var(--afb-badge-bg, #a5231c);
	color: var(--afb-badge-fg, #fff);
}

/* リピーター -------------------------------------------------- */

.afb-repeater__item {
	position: relative;
	padding: 1.25rem;
	margin-bottom: 1rem;
	border: 1px solid var(--afb-border);
	border-radius: 6px;
	background: var(--afb-bg-soft);
}

.afb-repeater__title {
	margin-bottom: 1rem;
	padding-bottom: 0.6rem;
	border-bottom: 1px solid var(--afb-border);
	font-weight: 700;
}

.afb-repeater__item .afb-row:last-of-type {
	margin-bottom: 0;
}

.afb-repeater__item-actions {
	margin-top: 1rem;
	padding-top: 0.75rem;
	border-top: 1px dashed var(--afb-border);
	text-align: right;
}

/* ボタン ------------------------------------------------------ */

.afb-btn {
	display: inline-block;
	padding: 0.8em 1.8em;
	font: inherit;
	line-height: 1.4;
	border: 1px solid var(--afb-border-strong);
	border-radius: 4px;
	background: #fff;
	color: inherit;
	cursor: pointer;
}

.afb-btn:hover {
	background: var(--afb-bg-soft);
}

.afb-btn--primary {
	background: #333;
	border-color: #333;
	color: #fff;
	font-weight: 700;
	min-width: 16em;
}

.afb-btn--primary:hover {
	background: #000;
}

.afb-btn--primary[disabled] {
	opacity: 0.5;
	cursor: progress;
}

.afb-btn--add,
.afb-btn--remove {
	padding: 0.5em 1.1em;
	font-size: 0.875em;
}

/* セットを増やすボタンは、押してほしい操作なので色で目立たせる。 */
.afb-btn--add {
	background: var(--afb-add-bg, #e8730c);
	border-color: var(--afb-add-bg, #e8730c);
	color: var(--afb-add-fg, #fff);
	font-weight: 700;
}

.afb-btn--add:hover {
	background: var(--afb-add-hover-bg, #cf6408);
	border-color: var(--afb-add-hover-bg, #cf6408);
}

.afb-btn--add:focus-visible {
	outline: 2px solid var(--afb-add-bg, #e8730c);
	outline-offset: 2px;
}

.afb-actions {
	margin-top: 2rem;
	text-align: center;
}

.afb-actions--confirm {
	display: flex;
	flex-wrap: wrap-reverse;
	gap: 0.75rem;
	justify-content: center;
}

/* 確認画面 ---------------------------------------------------- */

.afb-confirm__lead {
	margin-bottom: 1.5rem;
}

.afb-confirm__list {
	margin: 0;
	border-top: 1px solid var(--afb-border);
}

.afb-confirm__list dt {
	padding: 0.9em 0 0.2em;
	font-weight: 700;
	font-size: 0.9em;
	color: #5f6368;
}

.afb-confirm__list dd {
	margin: 0;
	text-align: left;
	padding: 0 0 0.9em;
	border-bottom: 1px solid var(--afb-border);
	word-break: break-word;
}

.afb-confirm__group {
	margin-top: 0.5em;
	color: inherit !important;
	font-size: 1em !important;
}

/* 確認画面もPCでは左に項目名、右に回答 -------------------------- */

.afb--cols .afb-confirm__list {
	display: grid;
	grid-template-columns: var(--afb-label-w, 35%) minmax(0, 1fr);
	/*
	 * 左右のセルを同じ高さに伸ばす。
	 * baseline のままだと、回答が2行になった項目で
	 * 左右の下線の位置がずれる。
	 */
	align-items: stretch;
	border-top: 1px solid var(--afb-border);
}

.afb--cols .afb-confirm__list dt,
.afb--cols .afb-confirm__list dd {
	padding-top: 0.9em;
	padding-bottom: 0.9em;
	border-bottom: 1px solid var(--afb-border);
}

.afb--cols .afb-confirm__list dt {
	padding-right: 2rem;
}

/* 繰り返しセットの見出しは1行使う。 */
.afb--cols .afb-confirm__list .afb-confirm__group {
	grid-column: 1 / -1;
	padding-bottom: 0;
	border-bottom: 0;
	font-weight: 700;
}

.afb--cols .afb-confirm__list .afb-confirm__group + dd {
	display: none;
}

@media (max-width: 782px) {
	/* スマートフォンでは項目名を上に戻す。 */
	.afb--cols .afb-confirm__list {
		display: block;
		border-top: 0;
	}

	.afb--cols .afb-confirm__list dt {
		padding: 0.9em 0 0.2em;
		border-bottom: 0;
	}

	.afb--cols .afb-confirm__list dd {
		padding: 0 0 0.9em;
	}

	.afb--cols .afb-confirm__list .afb-confirm__group + dd {
		display: block;
	}
}

/* エラー ------------------------------------------------------ */

.afb-errors {
	margin-bottom: 1.5rem;
	padding: 1rem 1.25rem;
	border: 1px solid var(--afb-error);
	border-radius: 4px;
	background: #fdf3f2;
	color: var(--afb-error);
}

.afb-errors__title {
	margin: 0 0 0.5em;
	font-weight: 700;
}

.afb-errors ul {
	margin: 0;
	padding-left: 1.25em;
}

.afb-error {
	margin: 0.4em 0 0;
	font-size: 0.875em;
	text-align: left;
	color: var(--afb-error);
}

.afb-row--error .afb-input,
.afb-row--error .afb-select,
.afb-row--error .afb-textarea {
	border-color: var(--afb-error);
	background: #fffafa;
}

/* 完了画面 ---------------------------------------------------- */

.afb-complete {
	padding: 2rem 0;
	text-align: center;
}

.afb-complete__heading {
	margin: 0 0 1rem;
}

/* 管理者にだけ見せる通知 -------------------------------------- */

.afb-admin-notice {
	padding: 1rem;
	border: 1px dashed var(--afb-error);
	color: var(--afb-error);
	font-size: 0.9em;
}

/*
 * iOS Safari は、文字サイズが16px未満の入力欄をタップすると自動で拡大する。
 * テーマ側の指定が勝つと元に戻ってしまうため、要素＋クラスで詳細度を上げたうえで
 * !important を付ける。見た目の調整ではなく操作性の問題なので、ここは強く当てる。
 * 横向きのスマートフォンやタブレットも拾えるよう、幅だけでなく
 * 指先操作（pointer: coarse）も条件に入れている。
 * ビューポート側で user-scalable=no を指定する方法は、
 * 拡大したい利用者の手段まで奪うので採らない。
 */
@media (max-width: 782px), (pointer: coarse) {
	.afb input,
	.afb select,
	.afb textarea,
	.afb input.afb-input,
	.afb select.afb-select,
	.afb textarea.afb-textarea {
		font-size: 16px !important;
	}
}

@media (max-width: 782px) {
	/* スマートフォンでは項目名を上に戻す。 */
	.afb--cols > form > .afb-row {
		display: block;
	}

	.afb--cols > form > .afb-row > .afb-label {
		padding-top: 0;
		padding-right: 0;
		margin-bottom: var(--afb-label-gap, 1rem);
	}
}

@media (max-width: 600px) {
	.afb-row--inline {
		display: block;
	}

	.afb-btn--primary {
		width: 100%;
		min-width: 0;
	}

	.afb-actions--confirm .afb-btn {
		width: 100%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.afb * {
		transition: none !important;
	}
}

/* 合計金額 ---------------------------------------------------- */

.afb-total {
	margin: var(--afb-gap) 0;
	padding: 1.25rem 1.5rem;
	background: var(--afb-bg-soft);
	border: 1px solid var(--afb-border);
	border-radius: 6px;
}

.afb-total__lines {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 0.4em 1em;
	margin: 0 0 1rem;
	font-size: 0.9em;
}

.afb-total__lines dt {
	margin: 0;
	color: #5f6368;
}

.afb-total__lines dd {
	margin: 0;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.afb-total__detail {
	display: block;
	font-size: 0.85em;
	color: #80868b;
}

.afb-total__empty {
	grid-column: 1 / -1;
	color: #80868b;
}

.afb-total__sum {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1em;
	padding-top: 0.8rem;
	border-top: 1px solid var(--afb-border-strong);
}

.afb-total__label {
	font-weight: 700;
}

.afb-total__value {
	font-size: 1.6em;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
}

.afb-total__tax {
	margin-top: 0.3rem;
	text-align: right;
	font-size: 0.8em;
	color: #5f6368;
}

.afb-confirm__list dd.afb-confirm__total {
	font-size: 1.25em;
	font-weight: 700;
}

/* 数量グループ ------------------------------------------------ */

.afb-qty {
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
}

.afb-qty__row {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 4.6em auto;
	align-items: center;
	gap: 0 0.6em;
}

.afb-qty__label {
	justify-self: end;
	text-align: right;
	line-height: 1.5;
}

.afb-qty__price {
	white-space: nowrap;
}

.afb-qty__input {
	width: 100%;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

select.afb-qty__input {
	padding-left: 0.6em;
	padding-right: 1.4em;
	background-position: right 0.55em top 50%, right 0.32em top 50%;
	text-align: left;
}

.afb-qty__unit {
	white-space: nowrap;
}

.afb-qty__note {
	grid-column: 1 / -1;
	justify-self: end;
	font-size: 0.85em;
	color: #5f6368;
}

.afb-qty__row--total {
	/*
	 * 合計は桁数が多く、数量欄と同じ列幅に入れると狭い画面で潰れる。
	 * この行だけグリッドをやめ、右詰めの一列にして幅の取り合いを避ける。
	 */
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 0.6em;
	margin-top: 0.4rem;
	padding-top: 0.8rem;
	border-top: 1px solid var(--afb-border);
}

.afb-qty__row--total .afb-qty__label {
	justify-self: auto;
	white-space: nowrap;
}

.afb-qty__sum {
	display: block;
	min-width: 6em;
	padding: 0.7em 0.9em;
	background: var(--afb-bg-soft);
	border: 1px solid var(--afb-border);
	border-radius: 4px;
	text-align: right;
	white-space: nowrap;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

@media (max-width: 600px) {
	.afb-qty__row {
		grid-template-columns: minmax(0, 1fr) 4em auto;
		gap: 0 0.4em;
	}

	.afb-qty__label {
		font-size: 0.9em;
	}

	.afb-qty__sum {
		min-width: 5em;
	}
}

/* 送信中の表示 ------------------------------------------------ */

.afb-sending {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1.5rem;
	background: rgba(255, 255, 255, 0.88);
	-webkit-backdrop-filter: blur(2px);
	backdrop-filter: blur(2px);
}

.afb-sending__box {
	max-width: 22em;
	text-align: center;
}

.afb-sending__spinner {
	display: block;
	width: 2.6em;
	height: 2.6em;
	margin: 0 auto 1.2rem;
	border: 3px solid var(--afb-border);
	border-top-color: var(--afb-border-strong);
	border-radius: 50%;
	animation: afb-spin 0.9s linear infinite;
}

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

/*
 * 中央揃えは親から継承させない。
 * テーマに p への指定があると、継承した値より直接の指定が勝つ。
 */
.afb-sending__text {
	margin: 0 0 0.6em;
	font-size: 1.1em;
	font-weight: 700;
	text-align: center;
}

.afb-sending__note {
	margin: 0;
	font-size: 0.875em;
	line-height: 1.8;
	text-align: center;
	color: #5f6368;
}

.afb-btn--primary.is-sending {
	opacity: 0.5;
	cursor: progress;
}

/*
 * 動きを減らす設定にしている人には回さない。
 * 表示自体は残す。何か進んでいることは伝える必要がある。
 */
@media (prefers-reduced-motion: reduce) {
	.afb-sending__spinner {
		animation: none;
		border-top-color: var(--afb-border);
	}
}
