/**
 * Comments UI styles.
 *
 * Mobile-first: bottom sheet (full-width, ~90vh tall, slides up).
 * Desktop (>= 900px): centered modal, post snippet on the left, comments on
 * the right. Same DOM either way — only this stylesheet decides the layout.
 *
 * Custom elements are styled directly (light DOM, no shadow).
 *
 * @package GodamFeed
 */

/* ---------------- Trigger ---------------- */

godam-comments-trigger {
	display: inline-flex;
}
.godam-comments-trigger__btn {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	background: none;
	border: 0;
	padding: 0.25rem;
	color: inherit;
	cursor: pointer;
}
.godam-comments-trigger__count {
	font-size: 0.85rem;
	font-variant-numeric: tabular-nums;
}

/* ---------------- Panel: shell ---------------- */

godam-comments-panel {
	position: fixed;
	inset: 0;
	z-index: 9999;
	display: none;
	pointer-events: none;
}
godam-comments-panel[data-state='open'] {
	display: block;
	pointer-events: auto;
}
.has-godam-comments-open {
	overflow: hidden;
}

.godam-comments__backdrop {
	position: absolute;
	inset: 0;
	background: rgba( 17, 17, 17, 0.55 );
	opacity: 0;
	transition: opacity 180ms ease;
}
godam-comments-panel[data-state='open'] .godam-comments__backdrop {
	opacity: 1;
}

.godam-comments__dialog {
	position: absolute;
	background: #fff;
	color: #111;
	display: grid;
	box-shadow: 0 10px 40px rgba( 0, 0, 0, 0.25 );
	transform: translateY( 100% );
	transition: transform 220ms cubic-bezier( 0.2, 0.8, 0.2, 1 );

	/* Mobile defaults: bottom sheet, comments only — the post media is
	   hidden because at this width there's no room for both. Desktop
	   override below reintroduces the post column. */
	left: 0;
	right: 0;
	bottom: 0;
	top: 10vh;
	border-radius: 16px 16px 0 0;
	grid-template-rows: 1fr;
	grid-template-columns: 1fr;
	grid-template-areas: 'col';
}

.godam-comments__post {
	display: none;
}
godam-comments-panel[data-state='open'] .godam-comments__dialog {
	transform: translateY( 0 );
}

.godam-comments__close {
	position: absolute;
	top: 0.5rem;
	right: 0.5rem;
	width: 36px;
	height: 36px;
	border-radius: 999px;
	background: rgba( 0, 0, 0, 0.06 );
	border: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	color: inherit;
	z-index: 2;
}
.godam-comments__close:hover {
	background: rgba( 0, 0, 0, 0.12 );
}

/* ---------------- Panel: post column (desktop only) ----------------
   The post aside is hidden by default and only shown at the desktop
   breakpoint below. Styles here describe its desktop appearance. */
.godam-comments__post-meta {
	min-width: 0;
}
.godam-comments__post-author {
	display: block;
	font-size: 0.95rem;
	font-weight: 600;
}
.godam-comments__post-caption {
	margin: 0.25rem 0 0;
	font-size: 0.9rem;
	color: #555;
	overflow: hidden;
	display: -webkit-box;
	-webkit-line-clamp: 5;
	-webkit-box-orient: vertical;
}
.godam-comments__post-media {
	/* Match the post's clamped display ratio (passed in as --gf-ratio, same
	   value the feed uses) so the media fills the column width edge-to-edge —
	   no letterbox bars on the sides. object-fit: cover crops to the same shape
	   the feed card shows, so the two views stay visually consistent. */
	width: 100%;
	aspect-ratio: var( --gf-ratio, 0.8 );
	max-height: 100%;
	border-radius: 12px;
	overflow: hidden;
	background: #0f0f12;
}
.godam-comments__post-media img,
.godam-comments__post-media video {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* ---------------- Panel: comments column ---------------- */

.godam-comments__column {
	grid-area: col;
	display: grid;
	grid-template-rows: auto 1fr auto auto auto;
	min-height: 0;
}
.godam-comments__header {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.75rem 1rem 0.5rem;
}
.godam-comments__header h2 {
	margin: 0;
	font-size: 1rem;
	font-weight: 700;
}
/* Count badge sits right next to the "Comments" heading. Hidden while empty
   so the slot doesn't show as a bare dot during the first paint / loading. */
.godam-comments__total {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 22px;
	height: 22px;
	padding: 0 7px;
	border-radius: 999px;
	background: #111;
	color: #fff;
	font-size: 0.72rem;
	font-weight: 600;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}
.godam-comments__total:empty {
	display: none;
}

.godam-comments__list {
	overflow-y: auto;
	padding: 0.25rem 1rem 0.5rem;
	overscroll-behavior: contain;
}
.godam-comments__item {
	display: grid;
	grid-template-columns: 32px 1fr;
	gap: 0.6rem;
	padding: 0.5rem 0;
}
.godam-comments__avatar {
	width: 32px;
	height: 32px;
	border-radius: 999px;
	background: #eee;
	object-fit: cover;
}
.godam-comments__body {
	min-width: 0;
}
.godam-comments__byline {
	display: flex;
	gap: 0.5rem;
	align-items: baseline;
	flex-wrap: wrap;
}
.godam-comments__byline strong {
	font-size: 0.88rem;
}
.godam-comments__byline time {
	font-size: 0.75rem;
	color: #999;
}
.godam-comments__text {
	margin: 0.2rem 0 0;
	font-size: 0.92rem;
	line-height: 1.4;
	word-wrap: break-word;
}

/* Reply button under each top-level comment. Suppressed entirely on replies. */
.godam-comments__reply-btn {
	background: none;
	border: 0;
	padding: 0.2rem 0;
	margin-top: 0.15rem;
	color: #555;
	font: inherit;
	font-size: 0.78rem;
	font-weight: 600;
	cursor: pointer;
}
.godam-comments__reply-btn:hover {
	color: #111;
}

/* Replies are nested visually — indented and slightly smaller avatar. The
   server enforces the 1-level cap, but we also drop the Reply button on
   `.godam-comments__item--reply` so the UX never even hints at depth 2.
   The parent `.godam-comments__item` is a 2-column grid (32px avatar | 1fr
   body); placing replies into column 2 naturally aligns them with the
   body and gives them the full body width to flow text in. */
.godam-comments__replies {
	grid-column: 2;
	margin-top: 0.25rem;
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
}
.godam-comments__item--reply {
	grid-template-columns: 24px 1fr;
	gap: 0.5rem;
	padding: 0.35rem 0;
}

/* "View N replies" toggle — sits in column 2 below the comment body, picks
   up the same indent rhythm replies use. Instagram-style: leading rule + text. */
.godam-comments__view-replies {
	grid-column: 2;
	display: inline-flex;
	align-items: center;
	gap: 0.6rem;
	background: none;
	border: 0;
	padding: 0.3rem 0;
	margin-top: 0.15rem;
	color: #555;
	font: inherit;
	font-size: 0.78rem;
	font-weight: 600;
	cursor: pointer;
	width: max-content;
}
.godam-comments__view-replies::before {
	content: '';
	display: inline-block;
	width: 24px;
	height: 1px;
	background: currentColor;
	opacity: 0.55;
}
.godam-comments__view-replies:hover { color: #111; }
.godam-comments__view-replies:disabled { opacity: 0.6; cursor: progress; }

.godam-comments__replies-more {
	background: none;
	border: 0;
	padding: 0.25rem 0;
	color: #555;
	font: inherit;
	font-size: 0.75rem;
	font-weight: 600;
	cursor: pointer;
	align-self: flex-start;
}
.godam-comments__replies-more:hover { color: #111; }
.godam-comments__replies-more:disabled { opacity: 0.6; cursor: progress; }
.godam-comments__item--reply .godam-comments__avatar {
	width: 24px;
	height: 24px;
}
.godam-comments__item--reply .godam-comments__text {
	font-size: 0.88rem;
}

/* "Replying to @x · ×" bar above the input when in reply mode. */
.godam-comments__reply-ctx {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.4rem 1rem;
	background: #f3f4f6;
	font-size: 0.82rem;
	color: #555;
	border-top: 1px solid #eee;
}
.godam-comments__reply-ctx[hidden] {
	display: none;
}
.godam-comments__reply-ctx strong {
	color: #111;
}
.godam-comments__reply-cancel {
	background: none;
	border: 0;
	font-size: 1.1rem;
	line-height: 1;
	width: 22px;
	height: 22px;
	border-radius: 999px;
	cursor: pointer;
	color: #555;
}
.godam-comments__reply-cancel:hover {
	background: rgba(0, 0, 0, 0.08);
}

.godam-comments__status {
	margin: 0;
	padding: 0.5rem 1rem;
	font-size: 0.85rem;
	color: #777;
	min-height: 1.2em;
}
.godam-comments__status:empty {
	padding: 0;
	min-height: 0;
}

.godam-comments__form {
	display: flex;
	gap: 0.5rem;
	padding: 0.65rem 1rem max( 0.65rem, env( safe-area-inset-bottom ) );
	border-top: 1px solid #eee;
	align-items: end;
}
.godam-comments__input {
	flex: 1;
	border: 1px solid #ddd;
	border-radius: 12px;
	padding: 0.55rem 0.75rem;
	font: inherit;
	resize: none;
	max-height: 160px;
	min-height: 38px;
	line-height: 1.35;
	background: #fafafa;
}
.godam-comments__input:focus {
	outline: 2px solid #5344f4;
	outline-offset: 1px;
	background: #fff;
}
.godam-comments__submit {
	width: 38px;
	height: 38px;
	border-radius: 999px;
	border: 0;
	background: #111;
	color: #fff;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
}
.godam-comments__submit:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

/* ---------------- Desktop: side-by-side modal ---------------- */

@media ( min-width: 900px ) {
	.godam-comments__dialog {
		top: 50%;
		left: 50%;
		right: auto;
		bottom: auto;
		transform: translate( -50%, -45% );
		width: min( 1100px, 94vw );
		height: min( 720px, 88vh );
		border-radius: 16px;
		grid-template-columns: 1.1fr 1fr;
		grid-template-rows: 1fr;
		grid-template-areas: 'post col';
	}
	godam-comments-panel[data-state='open'] .godam-comments__dialog {
		transform: translate( -50%, -50% );
	}
	.godam-comments__post {
		grid-area: post;
		display: grid;
		/* Media sizes to its own ratio, caption below it; the block is centered
		   in the column so a short (landscape) media doesn't leave a lopsided
		   gap. No stretched 1fr row, so the media keeps its true shape. */
		grid-template-rows: auto auto;
		align-content: center;
		gap: 1rem;
		padding: 1.25rem;
		border-right: 1px solid #eee;
		min-height: 0;
	}
	.godam-comments__post-media {
		min-height: 0;
		max-height: 100%;
	}
	/* On desktop the close button sits in the comments column's top-right
	   corner — clear room so the total count doesn't slide under it. */
	.godam-comments__header {
		padding-right: 3rem;
	}
}
