/*
	GoToSocial
	Copyright (C) GoToSocial Authors admin@gotosocial.org
	SPDX-License-Identifier: AGPL-3.0-or-later

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.

	You should have received a copy of the GNU Affero General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

@import "./_status-media.css";

.status {
	background: $status-bg;
	box-shadow: $boxshadow;
	border: $boxshadow-border;
	border-radius: $br;
	position: relative;
	padding-top: 0.75rem;

	a {
		color: inherit;
		text-decoration: none;
	}

	.status-header > address {
		/*
			Avoid stretching so wide that user
			can't click on open thread link that's
			behind the status header link.
		*/
		width: fit-content;

		> a {
			padding: 0 0.75rem;
			display: grid;
			grid-template-columns: 3.5rem 1fr auto;
			grid-template-rows: auto auto;
			grid-template-areas:
				"avatar author-strap author-strap"
				"avatar author-strap author-strap";
			gap: 0 0.5rem;
			font-style: normal;
	
			.avatar {
				grid-area: avatar;
				height: 3.5rem;
				width: 3.5rem;
				object-fit: cover;
	
				border: 0.15rem solid $avatar-border;
				border-radius: $br;
				overflow: hidden; /* hides corners from img overflowing */
	
				img {
					height: 100%;
					width: 100%;
					object-fit: cover;
					background: $bg;
				}
			}
	
			.author-strap {
				grid-area: author-strap;
				display: grid;
				grid-template-columns: 1fr auto;
				grid-template-rows: auto;
				grid-template-areas:
					"display display"
					"user    user";
				gap: 0 0.5rem;
	
				.displayname, .username {
					justify-self: start;
					align-self: start;
					max-width: 100%;
					font-size: 1rem;
					line-height: 1.3rem;
				}
			
				.displayname {
					grid-area: display;
					font-weight: bold;
				}
		
				.username {
					grid-area: user;
					color: $link-fg;
				}
			}
		}
	}

	.status-body {
		padding: 0.5rem 0.75rem;
		display: flex;
		flex-direction: column;
		gap: 0.5rem;
	}

	.text-spoiler > summary {
		list-style: none;
		display: flex;
		flex-direction: column;
		gap: 0.5rem;
		padding-bottom: 0.5rem;

		&::-webkit-details-marker {
			display: none; /* Safari */
		}

		.button {
			width: fit-content;
			white-space: nowrap;
			cursor: pointer;
			padding: 0.2rem 0.3rem;
			font-size: 1rem;
		}
	}

	.text > .content,
	.text-spoiler > summary > .spoiler-content {
		word-break: break-word;
		line-height: 1.6rem;
		width: 100%;

		a {
			color: $link-fg;
			text-decoration: underline;
		}

		/*
			Normalize header sizes to fit better
			with the line-height we use for statuses.
		*/
		h1 {
			margin: 0;
			font-size: 1.8rem;
			line-height: initial;
		}

		h2 {
			margin: 0;
			font-size: 1.6rem;
			line-height: initial;
		}

		h3 {
			margin: 0;
			font-size: 1.4rem;
			line-height: initial;
		}

		h4 {
			margin: 0;
			font-size: 1.2rem;
			line-height: initial;
		}

		h5 {
			margin: 0;
			font-size: 1rem;
			line-height: initial;
		}
	}

	.text {
		margin: 0;
		grid-row: span 1;
		grid-column: 1 / span 3;

		display: flex;
		flex-direction: column;
		gap: 0.5rem;

		width: 100%;

		.poll {
			background-color: $gray2;
			
			display: flex;
			flex-direction: column;
			border-radius: $br;
			padding: 0.5rem;
			margin: 0;
			gap: 1rem;
	
			.poll-options {
				margin: 0;
				padding: 0;
				display: flex;
				flex-direction: column;
				gap: 1rem;
	
				.poll-option {
					display: flex;
					flex-direction: column;
					gap: 0.1rem;
		
					label {
						cursor: default;
					}
		
					meter {
						width: 100%;
					}
		
					.poll-vote-summary {
						display: flex;
						flex-wrap: wrap;
						justify-content: space-between;
						white-space: nowrap;
					}
				}
			}
	
			.poll-info {
				background-color: $gray4;
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;
				border-radius: $br-inner;
				padding: 0.25rem;
				gap: 0.25rem;
	
				span {
					justify-self: center;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
		}
	}

	.status-info {
		background: $status-info-bg;
		color: $fg-reduced;
		border-top: 0.15rem solid $status-info-border;
		padding: 0.5rem 0.75rem;

		.status-stats {
			display: flex;
			gap: 1rem;

			.stats-grouping,
			.stats-more-info-content {
				display: flex;
				flex-wrap: wrap;
			}

			.stats-grouping {
				column-gap: 1rem;
				row-gap: 0.25rem;
			}

			.stats-item {
				display: flex;
				gap: 0.4rem;
				width: fit-content;
			}

			details.stats-more-info {
				margin-left: auto;
				
				& > summary {
					display: flex;

					/*
						Make it easy to touch.
					*/
					width: 3rem;
					height: 2rem;
					margin: -0.25rem -0.5rem;

					/*
						Remove details/summary
						arrow and use our own.
					*/
					list-style: none;
					&::-webkit-details-marker {
						display: none; /* Safari */
					}

					/*
						Don't display the
						"hide" button initially.
					*/
					i.hide {
						display: none;
					}

					/*
						Normalize fa
						icon alignment.
					*/
					align-items: center;
					i.fa {
						text-align: center;
					}

					cursor: pointer;
					border-radius: $br-inner;
					&:focus-visible {
						outline: $button-focus-outline;
					}

					&:hover {
						outline: 0.1rem solid $fg-reduced;
					}
				}

				@keyframes fade-in {
					0%    {opacity: 0}
					100%  {opacity: 1}
				}

				&[open] {
					.stats-more-info-content {
						animation: fade-in .1s;
					}

					& > summary i.show {
						display: none;
					}

					& > summary i.hide {
						display: block;
					}
				}
			}

			.stats-more-info-content {
				position: absolute;
				right: 0;
				z-index: 2;
				
				flex-direction: column;
				max-width: 100%;
				row-gap: 0.5rem;

				background: $status-info-bg;
				padding: 0.5rem 0.75rem;
				border: $boxshadow-border;
				box-shadow: $boxshadow;

				opacity: 1;

				.stats-grouping {
					width: 100%;
					justify-content: space-between;
				}
			}

			.stats-item.published-at dd a {
				time.dt-published {
					text-decoration: underline;
				}

				&:focus-visible {
					outline: 0;
					time.dt-published {
						outline: $link-focus-outline;
						outline-offset: -0.25rem;
					}
				}
			}

			.stats-item:not(.published-at):not(.edit-timeline) {
				user-select: none;
			}

			.stats-item.edit-timeline {
				flex-direction: column;
				width: 100%;
				border-top: $boxshadow-border;
				padding-top: 0.4rem;
				
				dd {
					display: flex;
					align-items: center;
					gap: 0.4rem;
				}
			}
		}

		grid-column: span 3;
	}

	&:first-child {
		/* top left, top right */
		border-top-left-radius: $br;
		border-top-right-radius: $br;
	}

	&:last-child, &:last-child .info {
		/* bottom left, bottom right */
		border-bottom-left-radius: $br;
		border-bottom-right-radius: $br;
	}

	&.expanded {
		background: $status-focus-bg;
		.status-info,
		.status-info .status-stats .stats-more-info-content {
			background: $status-focus-info-bg;
		}
	}
}
