/**
 * My Account > Orders: the document buttons.
 *
 * The Actions cell carries four links from three sources (WooCommerce core,
 * SkyVerge Print Invoices, PDF Invoices & Packing Slips, and the AMS receipt).
 * At their natural widths they need about 372px in a 283px cell, so they wrap
 * into a ragged block. This lays them out as a fixed two column grid instead,
 * so every row is even whatever the labels say.
 *
 * Everything is scoped to the orders table's actions cell, so no other button
 * on the site is affected.
 */

.woocommerce-orders-table__cell-order-actions {
	--ams-doc-gap: 8px;
}

.woocommerce-orders-table__cell-order-actions .ams-doc-actions {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--ams-doc-gap);
	align-items: stretch;
	max-width: 320px;
}

/* Right aligned columns are common in this table; keep the grid with them. */
.woocommerce-orders-table__cell-order-actions[align="right"] .ams-doc-actions,
.woocommerce-orders-table__cell-order-actions.align-right .ams-doc-actions {
	margin-left: auto;
}

.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a {
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0 !important;
	padding: 9px 10px !important;
	width: 100%;
	min-height: 40px;
	box-sizing: border-box;
	font-size: 12px !important;
	line-height: 1.25;
	text-align: center;
	border-radius: 4px !important;
	border: 1px solid #333;
	transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

/* "View" is the primary action: it goes to the order itself. */
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.view {
	background-color: #333 !important;
	border-color: #333;
	color: #fff !important;
}

/* The three documents are secondary, so they read as a set. */
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.wc_pip_view_invoice,
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.invoice,
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.receipt {
	background-color: transparent !important;
	border-color: #c9ccd2;
	color: #333 !important;
}

.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.view:hover,
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.view:focus-visible {
	background-color: #000 !important;
	border-color: #000;
}

.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.wc_pip_view_invoice:hover,
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.wc_pip_view_invoice:focus-visible,
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.invoice:hover,
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.invoice:focus-visible,
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.receipt:hover,
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a.receipt:focus-visible {
	background-color: #f2f4f7 !important;
	border-color: #333;
}

/* Keyboard users must be able to see where they are. */
.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a:focus-visible {
	outline: 2px solid #569ed3;
	outline-offset: 2px;
}

/**
 * The tooltip.
 *
 * One element, appended to <body> and positioned by script, rather than a
 * child of the button. A tooltip inside the table is clipped by the cell and
 * can be covered by later rows; out in the body it is always whole and always
 * on top.
 */
.ams-doc-tooltip {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 100000;
	max-width: 260px;
	padding: 9px 11px;
	border-radius: 5px;
	background-color: #1b154b;
	color: #fff;
	font-size: 12px;
	line-height: 1.45;
	text-align: left;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.12s ease;
}

.ams-doc-tooltip.is-visible {
	opacity: 1;
	visibility: visible;
}

/* The pointer. The script picks a side and sets the matching class, plus
   --ams-arrow-x or --ams-arrow-y so the point still meets the button even when
   the tooltip had to be nudged away from centre at the edge of the screen. */
.ams-doc-tooltip::after {
	content: "";
	position: absolute;
	border: 6px solid transparent;
}

.ams-doc-tooltip.is-right::after,
.ams-doc-tooltip.is-left::after {
	top: var(--ams-arrow-y, 50%);
	margin-top: -6px;
}

.ams-doc-tooltip.is-above::after,
.ams-doc-tooltip.is-below::after {
	left: var(--ams-arrow-x, 50%);
	margin-left: -6px;
}

/* Tooltip sits to the RIGHT of the button, so the point is on its left edge. */
.ams-doc-tooltip.is-right::after {
	right: 100%;
	border-right-color: #1b154b;
}

.ams-doc-tooltip.is-left::after {
	left: 100%;
	border-left-color: #1b154b;
}

.ams-doc-tooltip.is-above::after {
	top: 100%;
	border-top-color: #1b154b;
}

.ams-doc-tooltip.is-below::after {
	bottom: 100%;
	border-bottom-color: #1b154b;
}

@media (prefers-reduced-motion: reduce) {
	.ams-doc-tooltip,
	.woocommerce-orders-table__cell-order-actions .ams-doc-actions > a {
		transition: none;
	}
}

/* One column on phones, where the table itself stacks and the cell is full
   width. Touch devices get no hover, so the labels carry the meaning there. */
@media (max-width: 768px) {
	.woocommerce-orders-table__cell-order-actions .ams-doc-actions {
		grid-template-columns: 1fr;
		max-width: none;
	}
}
