/**
 * MDS Module 6 — account dashboard, NSFW toggle, balance chips.
 * Depends on mds-system.css (tokens + .mds-btn).
 */

/* ── Balance stars chip (header + shortcode) ─────────────────────────────── */
/* ---- Unified Sparks display ---- */
.mds-stars {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	font-weight: 700;
	white-space: nowrap;
}
.mds-stars__num {
	font-weight: 700;
}
.mds-stars .mds-ai-star {
	margin-top: -1px;
	color: var(--theme-color-text_link, var(--mds-accent));
}

.mds-balance-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 14px;
	border-radius: var(--mds-radius-pill, 999px);
	background: var(--mds-bg2);
	border: 1px solid var(--mds-bd);
	text-decoration: none;
	color: var(--mds-text);
	font-weight: 700;
	font-size: 0.88em;
	transition: background 0.18s;
}
.mds-balance-chip:hover {
	background: var(--mds-bg3);
	color: var(--mds-text);
	text-decoration: none;
}
.mds-balance-chip--header { margin-right: 10px; vertical-align: middle; }

/* ── NSFW toggle ─────────────────────────────────────────────────────────── */
.mds-nsfw-toggle {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
}
.mds-nsfw-toggle__text {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 3px;
}
.mds-nsfw-toggle__text strong {
	font-size: 0.92em;
	font-weight: 700;
	color: var(--mds-text);
}
.mds-nsfw-toggle__text small {
	font-size: 0.75em;
	color: var(--mds-text-muted);
	line-height: 1.3;
}

.mds-switch {
	position: relative;
	display: inline-block;
	flex: 0 0 auto;
	cursor: pointer;
	line-height: 0;
}
.mds-switch__input {
	position: absolute;
	opacity: 0;
	width: 0;
	height: 0;
	pointer-events: none;
}
.mds-switch__track {
	display: block;
	width: 46px;
	height: 26px;
	border-radius: var(--mds-radius-pill, 999px);
	background: var(--mds-bg3);
	border: 1px solid var(--mds-bd);
	position: relative;
	transition: background 0.22s, border-color 0.22s;
}
.mds-switch__thumb {
	position: absolute;
	top: 3px;
	left: 3px;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: var(--mds-on-accent);
	box-shadow: 0 1px 4px rgba(0,0,0,0.35);
	transition: transform 0.22s;
}
/* checked state — works for both sibling (+) and general (~) relationships */
.mds-switch__input:checked + .mds-switch__track,
.mds-switch__input:checked ~ .mds-switch__track {
	background: var(--mds-accent);
	border-color: var(--mds-accent);
}
.mds-switch__input:checked + .mds-switch__track .mds-switch__thumb,
.mds-switch__input:checked ~ .mds-switch__track .mds-switch__thumb {
	transform: translateX(20px);
}

/* ── Dashboard layout ────────────────────────────────────────────────────── */
.mds-dash {
	width: 100%;
}

body.woocommerce-account:has(.mds-dash) .woocommerce-MyAccount-navigation {
	display: none;
}

body.woocommerce-account:has(.mds-dash) .woocommerce-MyAccount-content {
	float: none;
	width: 100%;
}

/* -- Header row: avatar + greeting + balance -- */
.mds-dash__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	margin-bottom: 24px;
}
.mds-dash__header-left {
	display: flex;
	align-items: center;
	gap: 14px;
}
.mds-dash__avatar-wrap {
	flex-shrink: 0;
}
.mds-dash__avatar-wrap--editable {
	position: relative;
	width: var(--mds-dash-avatar-size, 64px);
	height: var(--mds-dash-avatar-size, 64px);
	flex-shrink: 0;
	overflow: visible;
}
.mds-dash__avatar-inner {
	position: relative;
	width: 100%;
	height: 100%;
	border-radius: 50%;
	overflow: hidden;
	box-sizing: border-box;
	border: 2px solid var(--mds-bd);
}
.mds-dash__avatar {
	width: var(--mds-dash-avatar-size, 64px) !important;
	height: var(--mds-dash-avatar-size, 64px) !important;
	border-radius: 50%;
	object-fit: cover;
	border: 2px solid var(--mds-bd);
}
.mds-dash__avatar-wrap--editable .mds-dash__avatar {
	width: 100% !important;
	height: 100% !important;
	border: none !important;
	border-radius: 0;
	display: block;
}
.mds-dash__avatar-edit {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	border: none;
	border-radius: 0;
	background: color-mix(in srgb, var(--mds-bg, #000) 55%, transparent);
	color: var(--mds-on-accent, #fff);
	opacity: 0;
	cursor: pointer;
	transition: opacity 0.18s;
	z-index: 2;
}
.mds-dash__avatar-wrap--editable:hover .mds-dash__avatar-edit,
.mds-dash__avatar-wrap--editable:focus-within .mds-dash__avatar-edit {
	opacity: 1;
}
.mds-dash__avatar-wrap.is-uploading .mds-dash__avatar-edit {
	opacity: 1;
	cursor: wait;
}
.mds-dash__avatar-wrap.is-uploading .mds-dash__avatar-inner::after {
	content: '';
	position: absolute;
	inset: 0;
	border-radius: 0;
	border: 2px solid color-mix(in srgb, var(--mds-accent) 35%, transparent);
	border-top-color: var(--mds-accent);
	animation: mds-avatar-spin 0.7s linear infinite;
	pointer-events: none;
	z-index: 3;
	box-sizing: border-box;
}
@keyframes mds-avatar-spin {
	to { transform: rotate(360deg); }
}
.mds-dash__avatar-remove {
	position: absolute;
	/* Center sits on the circle edge (~2 o'clock). */
	--mds-avatar-r: calc(var(--mds-dash-avatar-size, 64px) / 2);
	--mds-avatar-remove-half: 8px;
	top: calc(var(--mds-avatar-r) - var(--mds-avatar-r) * 0.70710678 - var(--mds-avatar-remove-half));
	right: calc(var(--mds-avatar-r) - var(--mds-avatar-r) * 0.70710678 - var(--mds-avatar-remove-half));
	z-index: 5;
	width: 16px;
	height: 16px;
	padding: 0;
	border: 1px solid var(--mds-danger);
	border-radius: 50%;
	background: var(--mds-danger);
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.15s, transform 0.15s, background 0.15s;
}
.mds-dash__avatar-wrap--editable:hover .mds-dash__avatar-remove,
.mds-dash__avatar-wrap--editable:focus-within .mds-dash__avatar-remove {
	opacity: 1;
	pointer-events: auto;
}
.mds-dash__avatar-remove:hover {
	background: color-mix(in srgb, var(--mds-danger) 82%, #000);
	border-color: color-mix(in srgb, var(--mds-danger) 82%, #000);
	color: #fff;
	transform: scale(1.06);
}
.mds-dash__header-text {
	display: flex;
	flex-direction: column;
	gap: 0;
}
.mds-dash__hello {
	margin: 0;
	margin-top: 3px;
	font-size: 1.45em;
	font-weight: 700;
	line-height: 1.15;
	color: var(--mds-text-dark);
}
.mds-dash__header-total-label {
	display: none;
}
.mds-dash__level {
	margin-top: -2px;
	font-size: 0.8em;
	color: var(--mds-text-muted);
	font-weight: 500;
}

/* Header balance chip */
.mds-dash__header-balance {
	display: flex;
	align-items: center;
	gap: 6px;
	background: var(--mds-bg2);
	border: 1px solid var(--mds-bd);
	border-radius: var(--mds-radius-pill, 999px);
	padding: 6px 8px 6px 14px;
}
.mds-dash__header-balance-num {
	font-size: 1.05em;
	font-weight: 700;
}
.mds-dash__header-balance-add {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	background: var(--mds-accent);
	color: var(--mds-on-accent);
	font-size: 18px;
	font-weight: 700;
	line-height: 1;
	text-decoration: none;
	flex-shrink: 0;
	transition: background 0.15s;
}
.mds-dash__header-balance-add:hover {
	background: var(--mds-accent-hover);
	text-decoration: none;
	color: var(--mds-on-accent);
}

/* -- 2-col cards grid -- */
.mds-dash__cards {
	display: grid;
	grid-template-columns: 1fr 1fr;
	align-items: stretch;
	gap: 14px;
	margin-bottom: 14px;
}
.mds-dash__card {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 20px 22px;
	border-radius: var(--mds-radius, 14px);
	background: var(--mds-bg2);
	border: 1px solid var(--mds-bd);
	box-sizing: border-box;
}
.mds-dash__card--topup,
.mds-dash__card--balance {
	background: color-mix(in srgb, var(--mds-accent) 10%, transparent);
	border-color: color-mix(in srgb, var(--mds-accent) 28%, transparent);
}
@supports not (background: color-mix(in srgb, red 10%, blue)) {
	.mds-dash__card--topup,
	.mds-dash__card--balance { background: var(--mds-fill-muted); border-color: var(--mds-bd-alt); }
}
.mds-dash__card-value--text {
	font-size: 1.35em;
}
.mds-dash__card-meta {
	font-size: 0.78em;
	line-height: 1.35;
	color: var(--mds-text);
}
.mds-dash__card-meta--muted {
	color: var(--mds-text-muted);
}
.mds-dash__card-sub--plan {
	font-weight: 400;
	color: var(--mds-text);
}

/* Card typography */
.mds-dash__card-label {
	font-size: 0.7em;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.07em;
	color: var(--mds-text-muted);
	margin-bottom: 2px;
}
.mds-dash__card-value {
	font-size: 1.55em;
	font-weight: 700;
	color: var(--mds-text-dark);
	line-height: 1.1;
}
.mds-dash__card-sub {
	font-size: 0.78em;
	color: var(--mds-text-muted);
	margin-bottom: 4px;
}

/* Card CTA */
/* Breathing room before the button. Set on the preceding element so the CTA
   keeps `margin-top: auto` and stays bottom-aligned across both cards. */
.mds-dash__card-value:has(+ .mds-dash__card-cta),
.mds-dash__card-sub:has(+ .mds-dash__card-cta),
.mds-dash__card-meta:has(+ .mds-dash__card-cta) {
	margin-bottom: 10px;
}
.mds-dash__card-cta {
	margin-top: auto;
	align-self: flex-start;
	padding: 6px 16px;
	border-radius: var(--mds-radius-pill, 999px);
	border: 1px solid var(--mds-bd);
	background: transparent;
	color: var(--mds-text);
	text-decoration: none;
	font-weight: 600;
	font-size: 0.82em;
	line-height: 1.25;
	min-height: 2.1em;
	box-sizing: border-box;
	transition: background 0.15s;
}
.mds-dash__card-cta:hover { background: var(--mds-bg3); color: var(--mds-text); text-decoration: none; }
.mds-dash__card-cta--upgrade {
	background: var(--mds-accent);
	border-color: transparent;
	color: var(--mds-on-accent);
}
.mds-dash__card-cta--upgrade:hover {
	background: var(--mds-accent-hover);
	color: var(--mds-on-accent);
}

/* -- NSFW toggle row -- */
.mds-dash__nsfw-row {
	clear: both;
	margin-top: 0;
	margin-bottom: 24px;
	padding: 14px 18px;
	border-radius: var(--mds-radius, 14px);
	background: var(--mds-bg2);
	border: 1px solid var(--mds-bd);
	position: relative;
	z-index: 0;
}

/* -- Action button aliases -- */
.mds-dash__action {
	display: inline-flex;
	align-items: center;
	padding: 10px 22px;
	border-radius: var(--mds-radius-pill, 999px);
	font-weight: 700;
	font-size: 0.9em;
	text-decoration: none;
	transition: background 0.18s, opacity 0.18s;
	cursor: pointer;
	border: 1px solid transparent;
}
.mds-dash__action:hover { text-decoration: none; }
.mds-dash__action--primary {
	background: var(--mds-accent);
	color: var(--mds-on-accent);
	border-color: transparent;
}
.mds-dash__action--primary:hover { background: var(--mds-accent-hover); color: var(--mds-on-accent); }
.mds-dash__action--secondary {
	background: transparent;
	border-color: var(--mds-bd);
	color: var(--mds-text);
}
.mds-dash__action--secondary:hover { background: var(--mds-bg3); color: var(--mds-text); }

/* -- Recent generations -- */
.mds-dash__recent {
	margin-bottom: 24px;
}
.mds-dash__recent-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 14px;
}
.mds-dash__recent-head-left {
	display: flex;
	align-items: center;
	gap: 6px;
	min-width: 0;
}
.mds-dash__recent-head h3 { margin: 0; font-size: 1em; font-weight: 700; }
/* Fixed slot so trash icon show/hide does not shift the heading */
.mds-dash__cache-clear-slot {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 28px;
	height: 28px;
}
.mds-dash__cache-clear {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 28px;
	height: 28px;
	padding: 0;
	border: 0;
	border-radius: 6px;
	background: transparent;
	color: var(--mds-danger);
	cursor: pointer;
	transition: background 0.15s ease, opacity 0.15s ease;
}
.mds-dash__cache-clear:hover:not(:disabled) {
	background: color-mix(in srgb, var(--mds-danger) 14%, transparent);
}
.mds-dash__cache-clear:disabled {
	opacity: 0.55;
	cursor: wait;
}
.mds-dash__cache-clear[hidden] {
	visibility: hidden;
	pointer-events: none;
}
.mds-dash__cache-clear-spinner {
	display: none;
	position: absolute;
	inset: 5px;
	border: 2px solid color-mix(in srgb, var(--mds-danger) 28%, transparent);
	border-top-color: var(--mds-danger);
	border-radius: 50%;
	animation: mds-dash-cache-spin 0.7s linear infinite;
}
.mds-dash__cache-clear.is-busy .mds-dash__cache-clear-icon,
.mds-dash__cache-clear.is-checking .mds-dash__cache-clear-icon {
	opacity: 0;
}
.mds-dash__cache-clear.is-busy .mds-dash__cache-clear-spinner,
.mds-dash__cache-clear.is-checking .mds-dash__cache-clear-spinner {
	display: block;
}
@keyframes mds-dash-cache-spin {
	to { transform: rotate(360deg); }
}
.mds-dash__recent-head a  { font-size: 0.84em; color: var(--mds-accent); text-decoration: none; flex-shrink: 0; }
.mds-dash__recent-head a:hover { text-decoration: underline; }
.mds-dash__recent-grid {
	display: grid;
	grid-template-columns: repeat(6, 1fr);
	gap: 10px;
}
.mds-dash__recent-item {
	display: block;
	position: relative;
	border-radius: 10px;
	overflow: hidden;
	aspect-ratio: 1;
	background: var(--mds-bg2);
	border: 1px solid var(--mds-bd);
	cursor: pointer;
	transition: transform 0.18s, box-shadow 0.18s;
}
.mds-dash__recent-item:hover {
	transform: translateY(-2px);
	box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.mds-dash__recent-item img,
.mds-dash__recent-item video { width: 100%; height: 100%; object-fit: cover; display: block; }

.mds-dash__recent-item.mds-item--batch .mds-item__batch-stack {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	aspect-ratio: auto;
}
.mds-dash__recent-item.mds-item--batch .mds-item__batch-stack-img {
	object-fit: cover;
}

.mds-dash__recent-item.is-unavailable {
	cursor: default;
	pointer-events: none;
}
.mds-dash__recent-item.is-unavailable img,
.mds-dash__recent-item.is-unavailable video {
	display: none;
}
.mds-dash__recent-item.is-unavailable::after {
	content: '';
	position: absolute;
	inset: 0;
	background:
		center / 28px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='none' stroke='%23888' stroke-width='1.4'%3E%3Crect x='3' y='3' width='18' height='18' rx='3'/%3E%3Cpath d='M8 8l8 8M16 8l-8 8'/%3E%3C/svg%3E"),
		var(--mds-bg2);
}

/* Log out */
.mds-dash__logout-wrap {
	display: flex;
	justify-content: flex-end;
	margin-top: 4px;
	padding-top: 8px;
}
.mds-dash__logout {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 8px 2px;
	color: var(--mds-danger);
	text-decoration: none;
	font-size: 0.92rem;
	font-weight: 600;
	line-height: 1.2;
	transition: color 0.18s ease, opacity 0.18s ease;
}
.mds-dash__logout:hover {
	color: color-mix(in srgb, var(--mds-danger) 82%, var(--mds-text));
	text-decoration: none;
	opacity: 0.92;
}
.mds-dash__logout-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.mds-dash__logout-icon svg {
	display: block;
}

/* Empty state */
.mds-dash__recent-empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	padding: 40px 20px;
	border-radius: var(--mds-radius, 14px);
	background: var(--mds-bg2);
	border: 1px dashed var(--mds-bd);
	text-align: center;
}
.mds-dash__recent-empty p {
	margin: 0;
	color: var(--mds-text-muted);
	font-size: 0.9em;
}

/* -- Settings row -- */
.mds-dash__settings {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 6px 0;
	padding: 12px 0 4px;
	border-top: 1px solid var(--mds-bd);
}
.mds-dash__settings-label {
	font-size: 0.72em;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .07em;
	color: var(--mds-text-muted);
	margin-right: 8px;
}
.mds-dash__settings a {
	font-size: 0.82em;
	color: var(--mds-text-muted);
	text-decoration: none;
	padding: 2px 0;
	transition: color 0.15s;
}
.mds-dash__settings a:hover { color: var(--mds-text); }
.mds-dash__settings a + a::before {
	content: '·';
	margin: 0 10px;
	opacity: 0.3;
}
.mds-dash__settings-cancel { color: color-mix(in srgb, var(--mds-danger) 65%, transparent) !important; }
.mds-dash__settings-cancel:hover { color: var(--mds-danger) !important; }

.mds-cache-modal .mds-nsfw-modal__sub { margin-bottom: 18px; }
.mds-cache-modal__confirm {
	background: color-mix(in srgb, var(--mds-danger) 88%, transparent) !important;
}
.mds-cache-modal__confirm:hover {
	background: var(--mds-danger) !important;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
	.mds-dash__cards { grid-template-columns: 1fr; }
	.mds-dash__recent-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
	.mds-dash__header { flex-direction: column; align-items: flex-start; }
	.mds-dash__recent-grid { grid-template-columns: repeat(3, 1fr); }
}

/* NSFW age-confirm modal styles live in assets/mds/core/mds-nsfw-modal.css */
