/*
 * Muhuga UI — scoped design system (spec §44, §46, §91).
 * Every rule is under .muhuga-ui and inside a cascade layer so themes and wp-admin are never restyled.
 */
@layer muhuga {
	.muhuga-ui {
		--mh-bg: #ffffff;
		--mh-surface: #fffbe6;
		--mh-text: #000029;
		--mh-text-muted: rgba(0, 0, 41, 0.62);
		--mh-border: rgba(0, 0, 41, 0.10);
		--mh-border-strong: rgba(0, 0, 41, 0.18);
		--mh-primary: #000029;
		--mh-primary-text: #ffffff;
		--mh-success: #00a14b;
		--mh-success-strong: #007a39;
		--mh-success-soft: rgba(0, 161, 75, 0.08);
		--mh-danger: #dc2626;
		--mh-danger-soft: #fef2f2;
		--mh-warning-soft: #fffbe6;
		--mh-warning-text: #7a5a00;
		--mh-neutral-soft: rgba(0, 0, 41, 0.04);
		--mh-radius-card: 16px;
		--mh-radius-control: 10px;
		--mh-control-height: 44px;
		--mh-shadow: 0 1px 2px rgba(0, 0, 41, 0.04), 0 4px 16px rgba(0, 0, 41, 0.04);
		--mh-focus: 0 0 0 3px rgba(0, 161, 75, 0.35);
		--mh-gap: 16px;

		color: var(--mh-text);
		font-family: inherit;
		font-size: 15px;
		line-height: 1.5;
		box-sizing: border-box;
	}
	.muhuga-ui *, .muhuga-ui *::before, .muhuga-ui *::after { box-sizing: border-box; }
	.muhuga-ui h2, .muhuga-ui h3, .muhuga-ui h4 { color: var(--mh-text); line-height: 1.25; margin: 0 0 8px; }
	.muhuga-ui h2 { font-size: 22px; font-weight: 650; }
	.muhuga-ui h3 { font-size: 17px; font-weight: 650; }
	.muhuga-ui p { margin: 0 0 12px; }
	.muhuga-ui .muhuga-muted { color: var(--mh-text-muted); }
	.muhuga-ui .muhuga-small { font-size: 13px; }
	.muhuga-ui a { color: var(--mh-primary); text-underline-offset: 3px; }
	.muhuga-ui .screen-reader-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

	/* Layout */
	.muhuga-ui .muhuga-stack > * + * { margin-top: var(--mh-gap); }
	.muhuga-ui .muhuga-grid { display: grid; gap: var(--mh-gap); grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
	.muhuga-ui .muhuga-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
	.muhuga-ui .muhuga-row--between { justify-content: space-between; }
	.muhuga-ui .muhuga-spacer { flex: 1; }

	/* Cards */
	.muhuga-ui .muhuga-card { background: var(--mh-bg); border: 1px solid var(--mh-border); border-radius: var(--mh-radius-card); padding: 20px; box-shadow: var(--mh-shadow); min-width: 0; }
	.muhuga-ui .muhuga-card--soft { background: var(--mh-surface); box-shadow: none; }
	.muhuga-ui .muhuga-card--danger { border-color: rgba(220, 38, 38, 0.35); background: var(--mh-danger-soft); box-shadow: none; }
	.muhuga-ui .muhuga-stat { display: flex; flex-direction: column; gap: 4px; }
	.muhuga-ui .muhuga-stat__label { font-size: 13px; color: var(--mh-text-muted); }
	.muhuga-ui .muhuga-stat__value { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
	.muhuga-ui .muhuga-stat--success .muhuga-stat__value { color: var(--mh-success-strong); }
	.muhuga-ui .muhuga-hero { font-size: 20px; font-weight: 650; margin: 0 0 4px; }

	/* Buttons: 44px, one dominant action, green only for release/confirm/withdraw */
	.muhuga-ui .muhuga-button {
		display: inline-flex; align-items: center; justify-content: center; gap: 8px;
		min-height: var(--mh-control-height); padding: 0 18px; border-radius: var(--mh-radius-control);
		border: 1px solid var(--mh-primary); background: var(--mh-primary); color: var(--mh-primary-text);
		font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
		transition: background-color .15s ease, box-shadow .15s ease;
	}
	.muhuga-ui .muhuga-button:hover { background: #10104a; color: #fff; }
	.muhuga-ui .muhuga-button:focus-visible, .muhuga-ui .muhuga-input:focus-visible, .muhuga-ui a:focus-visible, .muhuga-ui [tabindex]:focus-visible { outline: none; box-shadow: var(--mh-focus); }
	.muhuga-ui .muhuga-button--success { background: var(--mh-success); border-color: var(--mh-success); color: #fff; }
	.muhuga-ui .muhuga-button--success:hover { background: var(--mh-success-strong); }
	.muhuga-ui .muhuga-button--secondary { background: var(--mh-bg); color: var(--mh-text); border-color: var(--mh-border-strong); }
	.muhuga-ui .muhuga-button--secondary:hover { background: var(--mh-neutral-soft); color: var(--mh-text); }
	.muhuga-ui .muhuga-button--danger { background: var(--mh-bg); color: var(--mh-danger); border-color: rgba(220, 38, 38, 0.5); }
	.muhuga-ui .muhuga-button--danger:hover { background: var(--mh-danger-soft); color: var(--mh-danger); }
	.muhuga-ui .muhuga-button--link { background: transparent; border-color: transparent; color: var(--mh-text); text-decoration: underline; padding: 0 8px; }
	.muhuga-ui .muhuga-button--small { min-height: 36px; padding: 0 12px; font-size: 14px; }
	.muhuga-ui .muhuga-button[disabled], .muhuga-ui .muhuga-button[aria-busy="true"] { opacity: .55; cursor: not-allowed; }
	.muhuga-ui .muhuga-button--block { width: 100%; }

	/* Forms */
	.muhuga-ui .muhuga-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
	.muhuga-ui .muhuga-field label, .muhuga-ui .muhuga-label { font-weight: 600; font-size: 14px; }
	.muhuga-ui .muhuga-input, .muhuga-ui select.muhuga-input, .muhuga-ui textarea.muhuga-input {
		width: 100%; min-height: var(--mh-control-height); padding: 8px 12px; border-radius: var(--mh-radius-control);
		border: 1px solid var(--mh-border-strong); background: #fff; color: var(--mh-text); font: inherit; max-width: 100%;
	}
	.muhuga-ui textarea.muhuga-input { min-height: 96px; resize: vertical; }
	.muhuga-ui .muhuga-input[aria-invalid="true"] { border-color: var(--mh-danger); }
	.muhuga-ui .muhuga-help { font-size: 13px; color: var(--mh-text-muted); }
	.muhuga-ui .muhuga-error-text { font-size: 13px; color: var(--mh-danger); }
	.muhuga-ui .muhuga-choice { display: flex; gap: 10px; align-items: center; min-height: var(--mh-control-height); padding: 8px 12px; border: 1px solid var(--mh-border); border-radius: var(--mh-radius-control); cursor: pointer; }
	.muhuga-ui .muhuga-choice:has(input:checked) { border-color: var(--mh-primary); background: var(--mh-neutral-soft); }
	.muhuga-ui .muhuga-choice input { width: 18px; height: 18px; margin: 0; }

	/* Status badges: always text + tone, never colour-only */
	.muhuga-ui .muhuga-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--mh-neutral-soft); color: var(--mh-text); white-space: nowrap; }
	.muhuga-ui .muhuga-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .7; }
	.muhuga-ui .muhuga-badge--success { background: var(--mh-success-soft); color: var(--mh-success-strong); }
	.muhuga-ui .muhuga-badge--warning { background: var(--mh-warning-soft); color: var(--mh-warning-text); }
	.muhuga-ui .muhuga-badge--danger { background: var(--mh-danger-soft); color: var(--mh-danger); }

	/* Notices */
	.muhuga-ui .muhuga-notice { padding: 12px 16px; border-radius: var(--mh-radius-control); background: var(--mh-surface); border: 1px solid var(--mh-border); }
	.muhuga-ui .muhuga-notice--success { background: var(--mh-success-soft); border-color: rgba(0, 161, 75, .3); }
	.muhuga-ui .muhuga-notice--error { background: var(--mh-danger-soft); border-color: rgba(220, 38, 38, .3); color: #7f1d1d; }

	/* Tables -> stacked rows on mobile */
	.muhuga-ui .muhuga-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
	.muhuga-ui .muhuga-table th { text-align: left; font-size: 13px; font-weight: 600; color: var(--mh-text-muted); padding: 10px 12px; border-bottom: 1px solid var(--mh-border); }
	.muhuga-ui .muhuga-table td { padding: 12px; border-bottom: 1px solid var(--mh-border); vertical-align: middle; }
	.muhuga-ui .muhuga-table tr:last-child td { border-bottom: 0; }
	.muhuga-ui .muhuga-num { text-align: right; white-space: nowrap; }
	.muhuga-ui .muhuga-table-scroll { overflow-x: auto; }
	@media (max-width: 720px) {
		.muhuga-ui .muhuga-table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
		.muhuga-ui .muhuga-table--stack tr { display: block; border-bottom: 1px solid var(--mh-border); padding: 8px 0; }
		.muhuga-ui .muhuga-table--stack td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 6px 4px; text-align: right; }
		.muhuga-ui .muhuga-table--stack td::before { content: attr(data-label); font-weight: 600; color: var(--mh-text-muted); text-align: left; }
		.muhuga-ui .muhuga-card { padding: 16px; }
	}

	/* Timeline */
	.muhuga-ui .muhuga-timeline { list-style: none; margin: 0; padding: 0; }
	.muhuga-ui .muhuga-timeline li { position: relative; padding: 0 0 16px 32px; }
	.muhuga-ui .muhuga-timeline li::before { content: ""; position: absolute; left: 0; top: 2px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--mh-border-strong); background: #fff; }
	.muhuga-ui .muhuga-timeline li::after { content: ""; position: absolute; left: 9px; top: 24px; bottom: 0; width: 2px; background: var(--mh-border); }
	.muhuga-ui .muhuga-timeline li:last-child::after { display: none; }
	.muhuga-ui .muhuga-timeline li.is-done::before { border-color: var(--mh-success); background: var(--mh-success); box-shadow: inset 0 0 0 4px #fff; }
	.muhuga-ui .muhuga-timeline li.is-current { font-weight: 650; }
	.muhuga-ui .muhuga-timeline li.is-current::before { border-color: var(--mh-primary); }

	/* Tabs / nav */
	.muhuga-ui .muhuga-tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--mh-border); margin-bottom: 20px; scrollbar-width: thin; }
	.muhuga-ui .muhuga-tabs a { display: inline-flex; align-items: center; min-height: var(--mh-control-height); padding: 0 14px; text-decoration: none; color: var(--mh-text-muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; }
	.muhuga-ui .muhuga-tabs a[aria-current="page"] { color: var(--mh-text); border-bottom-color: var(--mh-primary); }

	/* Dialog (fixed header, focus trap via JS, Escape closes) */
	.muhuga-dialog-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 41, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100000; }
	.muhuga-ui.muhuga-dialog { width: min(520px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: #fff; border-radius: var(--mh-radius-card); box-shadow: 0 24px 64px rgba(0, 0, 41, .25); }
	.muhuga-ui .muhuga-dialog__header { padding: 18px 20px; border-bottom: 1px solid var(--mh-border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
	.muhuga-ui .muhuga-dialog__body { padding: 20px; overflow-y: auto; }
	.muhuga-ui .muhuga-dialog__footer { padding: 14px 20px; border-top: 1px solid var(--mh-border); display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }

	/* Toast */
	.muhuga-toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 100001; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
	.muhuga-ui.muhuga-toast { background: var(--mh-primary); color: #fff; padding: 12px 16px; border-radius: var(--mh-radius-control); box-shadow: var(--mh-shadow); }
	.muhuga-ui.muhuga-toast--error { background: var(--mh-danger); }

	/* Empty / loading */
	.muhuga-ui .muhuga-empty { text-align: center; padding: 32px 16px; color: var(--mh-text-muted); }
	.muhuga-ui .muhuga-loading { padding: 24px; color: var(--mh-text-muted); }
	.muhuga-ui .muhuga-skeleton { background: linear-gradient(90deg, var(--mh-neutral-soft), rgba(0,0,41,.08), var(--mh-neutral-soft)); background-size: 200% 100%; animation: muhuga-shimmer 1.2s infinite; border-radius: 8px; min-height: 16px; }
	@keyframes muhuga-shimmer { to { background-position: -200% 0; } }

	/* Money */
	.muhuga-ui .muhuga-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
	.muhuga-ui .muhuga-money--positive { color: var(--mh-success-strong); }
	.muhuga-ui .muhuga-dl { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 8px 16px; margin: 0; }
	.muhuga-ui .muhuga-dl dt { color: var(--mh-text-muted); }
	.muhuga-ui .muhuga-dl dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

	/* Seller dashboard shell */
	.muhuga-ui.muhuga-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; }
	.muhuga-ui .muhuga-sidenav { display: flex; flex-direction: column; gap: 2px; }
	.muhuga-ui .muhuga-sidenav a { display: flex; align-items: center; min-height: var(--mh-control-height); padding: 0 12px; border-radius: var(--mh-radius-control); text-decoration: none; color: var(--mh-text); font-weight: 550; }
	.muhuga-ui .muhuga-sidenav a[aria-current="page"] { background: var(--mh-primary); color: #fff; }
	.muhuga-ui .muhuga-sidenav a:hover:not([aria-current="page"]) { background: var(--mh-neutral-soft); }
	@media (max-width: 860px) {
		.muhuga-ui.muhuga-shell { grid-template-columns: minmax(0, 1fr); }
		.muhuga-ui .muhuga-sidenav { flex-direction: row; overflow-x: auto; }
		.muhuga-ui .muhuga-sidenav a { white-space: nowrap; }
	}

	/* Checkout */
	.muhuga-ui.muhuga-checkout .muhuga-sources { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
	.muhuga-ui .muhuga-bar { height: 8px; border-radius: 99px; background: var(--mh-neutral-soft); overflow: hidden; }
	.muhuga-ui .muhuga-bar > span { display: block; height: 100%; background: var(--mh-primary); }

	@media (prefers-reduced-motion: reduce) {
		.muhuga-ui *, .muhuga-ui *::before, .muhuga-ui *::after { animation: none !important; transition: none !important; }
	}
}
