/*
 * Digital goods catalog — browse UI.
 * All colors via CSS variables from themes/*.css (see style.css).
 * No hardcoded colors.
 */

/* ── Search ──────────────────────────────────────────────────────────────── */

.dg-search-wrap {
	margin: 0 0 16px 0;
}

.dg-search {
	width: 100%;
	padding: 10px 12px;
	font-family: var(--font-primary);
	font-size: 1rem;
	color: var(--text-primary);
	background: var(--bg-card, var(--bg-main));
	border: 1px solid var(--border);
	border-radius: var(--border-radius, 8px);
	-webkit-appearance: none;
	appearance: none;
	outline: none;
}

.dg-search:focus {
	border-color: var(--accent);
}

/* ── Section headings ────────────────────────────────────────────────────── */

.dg-section {
	margin: 0 0 24px 0;
}

.dg-section-title {
	font-size: 1rem;
	font-weight: 600;
	margin: 0 0 12px 0;
	color: var(--text-secondary, var(--text-primary));
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

.dg-view-heading {
	font-size: 1.25rem;
	font-weight: 700;
	margin: 12px 0 16px 0;
	color: var(--text-primary);
}

/* ── Grid (brands / regions) ────────────────────────────────────────────── */

.dg-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 12px;
}

/* ── Tiles ───────────────────────────────────────────────────────────────── */

.dg-tile {
	display: flex;
	flex-direction: row;
	align-items: center;
	text-align: left;
	gap: 12px;
	padding: 12px 34px 12px 12px;
	background: var(--bg-card, var(--bg-main));
	color: var(--text-primary);
	border: 1px solid var(--border);
	border-radius: var(--border-radius, 10px);
	font-family: var(--font-primary);
	cursor: pointer;
	position: relative;
	min-height: 64px;
	transition: border-color 0.15s, transform 0.05s;
}

.dg-tile-body {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
	flex: 1 1 auto;
}

/*
 * Brand tiles: pale tint background is painted inline via
 * tile.style.backgroundColor (see digital-goods.js → renderBrandTiles).
 * The saturated brand colour lives only in .dg-tile-strip on the left,
 * so 60+ tiles on one screen read as calm shades, not a neon mosaic.
 */
.dg-tile-brand {
	color: var(--text-primary);
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
	/* Leave room for the 5px accent strip + its breathing space. */
	padding-left: 18px;
	overflow: hidden;
}

.dg-tile-brand:hover,
.dg-tile-brand:focus {
	outline: none;
	border-color: var(--accent);
}

/* 5px vertical strip in the saturated brand colour — the "signature"
 * that preserves brand recognition while the body stays calm. Colour
 * itself is set inline per tile. */
.dg-tile-strip {
	position: absolute;
	left: 0;
	top: 0;
	bottom: 0;
	width: 5px;
	background: transparent;
	pointer-events: none;
}

/* Region tiles keep the theme-based border highlight on hover. */
.dg-tile-region:hover,
.dg-tile-region:focus {
	border-color: var(--accent);
	outline: none;
}

.dg-tile:active {
	transform: scale(0.99);
}

.dg-tile-title {
	font-size: 0.95rem;
	font-weight: 500;
	line-height: 1.25;
	display: flex;
	align-items: center;
	gap: 8px;
	width: 100%;
}
.dg-tile-flag {
	width: 20px;
	height: 14px;
	flex: 0 0 auto;
	border-radius: 2px;
	object-fit: cover;
	box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.dg-tile-meta {
	font-size: 0.85rem;
	color: var(--text-secondary, var(--text-primary));
	margin-top: 4px;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	width: 100%;
	opacity: 0.75;
	line-height: 1.3;
	word-break: break-word;
}

.dg-tile-chevron {
	position: absolute;
	right: 14px;
	top: 50%;
	transform: translateY(-50%);
	font-size: 1.4rem;
	color: var(--text-secondary, var(--text-primary));
	opacity: 0.6;
}

/* ── Back button ─────────────────────────────────────────────────────────── */

.dg-back-btn {
	margin-bottom: 12px;
	background: var(--bg-card);
	border: 1px solid var(--border);
	color: var(--text-primary);
}
.dg-back-btn:hover,
.dg-back-btn:focus {
	border-color: var(--accent);
}

/* ── Sticky back-bar (vpn-43) ───────────────────────────────────────────────
 * Sits at the top of each drill-down view (regions / denominations / checkout /
 * orders) and stays visible while the user scrolls. `top` value matches the
 * height of .cabinet-header (style.css: 56px desktop, 48px ≤620px) so the
 * sticky bar lands flush below the page header instead of underneath it.
 *
 * .tab-panel / .cabinet-content do NOT set overflow, so sticky resolves
 * against the page-scrolling viewport — confirmed compatible with Safari 14.1+
 * (per CLAUDE.md browser-support floor). z-index 5 is well below the page
 * header (z-index 100) and below the dg-modal (z-index 1000).
 */
.dg-sticky-back {
	position: sticky;
	top: 56px;
	z-index: 5;
	margin: -12px 0 12px 0;
	padding: 8px 0;
	background: var(--bg-main);
	border-bottom: 1px solid var(--border);
}

.dg-sticky-back-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 36px;
	padding: 6px 12px 6px 10px;
	font-family: var(--font-primary);
	font-size: 0.95rem;
	font-weight: 500;
	line-height: 1.3;
	color: var(--text-primary);
	background: transparent;
	border: 1px solid transparent;
	border-radius: var(--border-radius-sm, 6px);
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

.dg-sticky-back-btn:hover {
	background: var(--bg-hover, var(--bg-card));
}

.dg-sticky-back-btn:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.dg-sticky-back-btn:active {
	transform: scale(0.98);
}

/* Collapse the default top margin of the first .dg-view-heading right after
 * the sticky bar so the view doesn't show a double-gap underneath the bar. */
.dg-sticky-back + .dg-view-heading {
	margin-top: 6px;
}

@media (max-width: 620px) {
	.dg-sticky-back {
		top: 48px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.dg-sticky-back-btn:active {
		transform: none;
	}
}

/* ── Denominations list ─────────────────────────────────────────────────── */

.dg-denom-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	border: 1px solid var(--border);
	border-radius: var(--border-radius, 10px);
	overflow: hidden;
	background: var(--bg-card, var(--bg-main));
}

.dg-denom-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 12px 14px;
	border-bottom: 1px solid var(--border);
}

.dg-denom-row:last-child {
	border-bottom: none;
}

.dg-denom-row:hover {
	background: var(--bg-hover, transparent);
}

.dg-denom-info {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
	flex: 1 1 auto;
}

.dg-denom-name {
	font-size: 0.95rem;
	color: var(--text-primary);
	line-height: 1.3;
	word-break: break-word;
}

.dg-denom-price {
	font-size: 1.05rem;
	font-weight: 700;
	color: var(--text-primary);
	margin-top: 2px;
}

.dg-denom-empty {
	padding: 24px;
	text-align: center;
	color: var(--text-secondary, var(--text-primary));
	opacity: 0.7;
}

.dg-buy-btn {
	flex: 0 0 auto;
	min-width: 100px;
}

.dg-buy-btn:disabled,
.dg-buy-btn[disabled] {
	opacity: 0.55;
	cursor: not-allowed;
}

.dg-delivery-info {
	margin: 14px 0 0 0;
	font-size: 0.85rem;
	color: var(--text-secondary, var(--text-primary));
	opacity: 0.8;
	line-height: 1.4;
}

/* ── Nothing found ───────────────────────────────────────────────────────── */

.dg-nothing-found {
	padding: 24px;
	text-align: center;
	color: var(--text-secondary, var(--text-primary));
	opacity: 0.7;
}

/* ── Views (stacked; only one visible at a time) ────────────────────────── */

.dg-view {
	display: block;
}
.dg-view[hidden] {
	display: none;
}

/* ── Mobile tweaks ───────────────────────────────────────────────────────── */

@media (max-width: 600px) {
	.dg-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 10px;
	}

	.dg-tile {
		min-height: 68px;
		padding: 12px 32px 12px 12px;
	}

	.dg-tile-brand {
		padding-left: 18px;
	}

	.dg-tile-title {
		font-size: 0.95rem;
	}

	.dg-tile-meta {
		font-size: 0.8rem;
	}

	.dg-denom-row {
		padding: 10px 12px;
	}

	.dg-buy-btn {
		min-width: 80px;
		padding: 6px 10px;
		font-size: 0.9rem;
	}
}

/* ── Very narrow (<=340px) ───────────────────────────────────────────────── */

@media (max-width: 340px) {
	.dg-grid {
		grid-template-columns: 1fr;
	}
}

/* ── My orders ──────────────────────────────────────────────────────────── */

/* Header button "Мои заказы →" (sits next to the tab title on brands view) */
.dg-orders-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 14px;
	font-family: var(--font-primary);
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--accent-text);
	background: var(--accent);
	border: 1px solid var(--accent);
	border-radius: var(--border-radius, 8px);
	cursor: pointer;
	transition: background 0.15s, border-color 0.15s;
	-webkit-appearance: none;
	appearance: none;
}

.dg-orders-btn:hover,
.dg-orders-btn:focus {
	background: var(--accent-hover, var(--accent));
	border-color: var(--accent-hover, var(--accent));
	outline: none;
}

.dg-orders-btn-count {
	display: inline-block;
	min-width: 20px;
	padding: 0 6px;
	font-size: 0.8rem;
	font-weight: 700;
	line-height: 1.3;
	text-align: center;
	color: var(--accent);
	background: var(--accent-text);
	border-radius: 10px;
}

.dg-orders-btn-arrow {
	font-size: 1rem;
	opacity: 0.85;
}

/* Orders list */
.dg-orders-list {
	list-style: none;
	margin: 0 0 12px 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.dg-order-card {
	border: 1px solid var(--border);
	border-radius: var(--border-radius, 10px);
	background: var(--bg-card, var(--bg-main));
	overflow: hidden;
	transition: border-color 0.15s;
}

.dg-order-card.is-expanded {
	border-color: var(--accent);
}

.dg-order-head {
	display: grid;
	grid-template-columns: auto 1fr auto auto;
	gap: 10px;
	align-items: center;
	padding: 12px 14px;
	cursor: pointer;
	background: transparent;
	border: none;
	width: 100%;
	text-align: left;
	font-family: inherit;
	color: var(--text-primary);
	-webkit-appearance: none;
	appearance: none;
}

.dg-order-head:hover {
	background: var(--bg-hover, transparent);
}

.dg-order-head:focus {
	outline: none;
}

.dg-order-head:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: -2px;
}

.dg-order-status {
	display: inline-block;
	padding: 3px 10px;
	font-size: 0.78rem;
	font-weight: 600;
	line-height: 1.3;
	border-radius: 999px;
	white-space: nowrap;
	border: 1px solid var(--border);
	color: var(--text-secondary, var(--text-primary));
	background: var(--bg-main);
}

.dg-order-status.is-delivered {
	border-color: var(--accent);
	color: var(--accent);
	background: transparent;
}

.dg-order-status.is-awaiting {
	border-color: var(--text-secondary, var(--text-primary));
	color: var(--text-primary);
	background: var(--bg-main);
	font-weight: 700;
}

.dg-order-status.is-failed {
	border-color: var(--text-secondary, var(--text-primary));
	color: var(--text-primary);
	background: var(--bg-main);
	opacity: 0.75;
	text-decoration: line-through;
}

.dg-order-status.is-pending,
.dg-order-status.is-refunded {
	opacity: 0.6;
}

.dg-order-title-block {
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.dg-order-title {
	font-size: 0.95rem;
	font-weight: 600;
	color: var(--text-primary);
	line-height: 1.3;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.dg-order-date {
	font-size: 0.8rem;
	color: var(--text-secondary, var(--text-primary));
	opacity: 0.75;
}

.dg-order-price {
	font-size: 1rem;
	font-weight: 700;
	color: var(--text-primary);
	white-space: nowrap;
}

.dg-order-chevron {
	width: 16px;
	font-size: 1rem;
	color: var(--text-secondary, var(--text-primary));
	opacity: 0.6;
	transition: transform 0.15s;
	text-align: center;
}

.dg-order-card.is-expanded .dg-order-chevron {
	transform: rotate(180deg);
}

.dg-order-body {
	padding: 0 14px 14px 14px;
	border-top: 1px solid var(--border);
	padding-top: 12px;
}

.dg-order-body-loading {
	padding: 8px 0;
	color: var(--text-secondary, var(--text-primary));
	font-size: 0.9rem;
}

.dg-order-body-error {
	padding: 8px 0;
	color: var(--text-primary);
	font-size: 0.9rem;
	opacity: 0.85;
}

/* Codes block */
.dg-codes {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.dg-code-row {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
}

.dg-code {
	flex: 1 1 200px;
	font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
	font-size: 0.95rem;
	padding: 8px 10px;
	background: var(--bg-main);
	border: 1px solid var(--border);
	border-radius: 6px;
	color: var(--text-primary);
	word-break: break-all;
	-webkit-user-select: all;
	-moz-user-select: all;
	-ms-user-select: all;
	user-select: all;
}

.dg-copy-btn {
	flex: 0 0 auto;
	padding: 6px 12px;
	font-size: 0.85rem;
}

.dg-copy-flash {
	font-size: 0.8rem;
	color: var(--accent);
	margin-left: 4px;
}

/* Awaiting payment body */
.dg-pay-block {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.dg-pay-hint {
	font-size: 0.85rem;
	color: var(--text-secondary, var(--text-primary));
	opacity: 0.85;
	line-height: 1.4;
}

.dg-pay-link {
	align-self: flex-start;
	display: inline-block;
	text-decoration: none;
}

/* Failed body */
.dg-failed-text {
	font-size: 0.9rem;
	color: var(--text-primary);
	line-height: 1.45;
	opacity: 0.9;
}

/* Mobile tweaks for orders */
@media (max-width: 600px) {
	.dg-order-head {
		grid-template-columns: auto 1fr auto;
		grid-template-areas:
			"status title chevron"
			"status price chevron"
			"date   date  chevron";
		row-gap: 4px;
	}

	.dg-order-status { grid-area: status; }
	.dg-order-title-block { grid-area: title; display: contents; }
	.dg-order-title { grid-area: title; }
	.dg-order-date { grid-area: date; }
	.dg-order-price { grid-area: price; justify-self: end; }
	.dg-order-chevron { grid-area: chevron; }

	.dg-orders-btn {
		padding: 5px 10px;
		font-size: 0.85rem;
	}
}

/* ── Checkout view ──────────────────────────────────────────────────── */

.dg-checkout-summary {
	background: var(--bg-card);
	border: 1px solid var(--border);
	border-radius: var(--border-radius-md);
	padding: 14px 16px;
	margin-bottom: 18px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.dg-checkout-summary-title {
	font-weight: 600;
	font-size: 1rem;
	color: var(--text-primary);
	line-height: 1.35;
}

.dg-checkout-summary-sub {
	font-size: 0.82rem;
	color: var(--text-secondary);
	margin-top: 3px;
}

.dg-checkout-summary-price {
	font-weight: 700;
	font-size: 1.1rem;
	color: var(--text-heading);
	white-space: nowrap;
}

.dg-checkout-form {
	display: flex;
	flex-direction: column;
	gap: 20px;
	margin-bottom: 18px;
}

.dg-checkout-section {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.dg-checkout-label {
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--text-heading);
}

.dg-checkout-hint {
	font-size: 0.82rem;
	color: var(--text-secondary);
	line-height: 1.4;
}

.dg-checkout-warning {
	background: var(--warning-bg);
	border: 1px solid var(--warning-border);
	color: var(--warning-text);
	padding: 8px 10px;
	border-radius: var(--border-radius-sm);
	font-size: 0.82rem;
	line-height: 1.4;
}

.dg-checkout-radio-group {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.dg-checkout-radio-row {
	display: flex;
	align-items: center;
	gap: 8px;
	cursor: pointer;
	font-size: 0.92rem;
	color: var(--text-primary);
	padding: 4px 0;
}

.dg-checkout-radio-row input[type="radio"] {
	width: 20px;
	height: 20px;
	margin: 0;
	cursor: pointer;
	flex-shrink: 0;
	/* Brand-tint the radio dot on supporting browsers (Safari 13.1+, Chrome 80+).
	   Older browsers get the platform default — graceful degradation. */
	accent-color: var(--accent);
}

.dg-checkout-radio-row .dg-checkout-radio-label {
	display: flex;
	flex-direction: column;
	min-width: 0;
	flex: 1 1 auto;
	gap: 1px;
}

.dg-checkout-radio-row .dg-checkout-radio-value {
	overflow-wrap: anywhere;
	word-break: break-word;
}

.dg-checkout-radio-row .dg-checkout-radio-sub {
	color: var(--text-secondary);
	font-size: 0.82rem;
}

.dg-checkout-email-input {
	width: 100%;
	box-sizing: border-box;
	padding: 9px 12px;
	border: 1px solid var(--border);
	border-radius: var(--border-radius-sm);
	font-size: 0.95rem;
	font-family: var(--font-primary);
	background: var(--bg-main);
	color: var(--text-primary);
}

.dg-checkout-email-input:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.dg-checkout-channels {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.dg-checkout-channel {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	padding: 8px 10px;
	border: 1px solid var(--border);
	border-radius: var(--border-radius-sm);
	background: var(--bg-main);
}

.dg-checkout-channel input[type="checkbox"] {
	margin: 2px 0 0 0;
	flex-shrink: 0;
}

.dg-checkout-channel-body {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
	flex: 1;
}

.dg-checkout-channel-title {
	font-size: 0.92rem;
	font-weight: 500;
	color: var(--text-primary);
	line-height: 1.3;
	word-break: break-word;
}

.dg-checkout-channel-hint {
	font-size: 0.78rem;
	color: var(--text-secondary);
	line-height: 1.3;
}

.dg-checkout-channel.is-disabled {
	opacity: 0.75;
}

.dg-checkout-channel.is-disabled input[type="checkbox"] {
	cursor: not-allowed;
}

.dg-checkout-pay-btn {
	align-self: flex-start;
	min-width: 200px;
}

.dg-checkout-error {
	background: var(--danger-bg);
	border: 1px solid var(--danger);
	color: var(--danger);
	padding: 8px 10px;
	border-radius: var(--border-radius-sm);
	font-size: 0.88rem;
	line-height: 1.4;
	margin-bottom: 14px;
}

/* State C: order-created block with external payment anchor. */

.dg-checkout-result {
	display: flex;
	flex-direction: column;
	gap: 14px;
	padding: 18px;
	border: 1px solid var(--border);
	border-radius: var(--border-radius-md);
	background: var(--bg-card);
	margin-bottom: 18px;
}

.dg-checkout-result-badge {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	align-self: flex-start;
	padding: 6px 12px;
	border-radius: 999px;
	background: var(--success-bg);
	color: var(--success);
	font-size: 0.88rem;
	font-weight: 600;
	line-height: 1.2;
}

.dg-checkout-result-badge-icon {
	font-weight: 700;
	font-size: 0.95rem;
	line-height: 1;
}

.dg-checkout-pay-link {
	align-self: flex-start;
	min-width: 200px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	text-decoration: none;
}

.dg-checkout-pay-link:hover,
.dg-checkout-pay-link:focus {
	text-decoration: none;
}

.dg-checkout-pay-link-icon {
	font-size: 1.05rem;
	line-height: 1;
}

.dg-checkout-result-hint {
	margin: 0;
	font-size: 0.85rem;
	color: var(--text-secondary);
	line-height: 1.45;
}

.dg-checkout-goto-orders {
	align-self: flex-start;
	min-width: 200px;
}

/* Modal — reuses the qr-modal pattern but DG-scoped so we don't couple styles. */

.dg-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	width: 100%;
	/* iOS Safari shrinks 100vh under the bottom URL bar — 100dvh fixes that
	   on Safari 15.4+; older browsers fall back to 100vh on the previous line. */
	height: 100vh;
	height: 100dvh;
	z-index: 1000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
}

.dg-modal-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.6);
}

.dg-modal-card {
	position: relative;
	z-index: 1;
	background: var(--bg-main);
	border-radius: var(--border-radius-lg);
	box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
	padding: 24px;
	max-width: 440px;
	width: 100%;
}

.dg-modal-title {
	font-family: var(--font-heading);
	font-size: 1.05rem;
	font-weight: 700;
	color: var(--text-heading);
	margin: 0 0 12px 0;
}

.dg-modal-body {
	font-size: 0.92rem;
	color: var(--text-primary);
	line-height: 1.5;
	margin: 0 0 20px 0;
}

.dg-modal-actions {
	display: flex;
	gap: 10px;
	justify-content: flex-end;
}

@media (max-width: 600px) {
	.dg-checkout-summary {
		flex-direction: column;
		align-items: flex-start;
	}

	.dg-checkout-pay-btn {
		width: 100%;
		min-width: 0;
	}

	.dg-checkout-pay-link,
	.dg-checkout-goto-orders {
		width: 100%;
		min-width: 0;
	}

	.dg-modal-actions {
		flex-direction: column-reverse;
	}

	.dg-modal-actions .btn {
		width: 100%;
	}
}
