/*
 * SalesKing Merchant — responsive layer.
 *
 * Loaded after admin.css and saas.css so it can correct them. Everything here
 * is layout only: no new colours, no new components. The job is to make every
 * screen usable from a phone and to stop wide tables from pushing their last
 * column underneath whatever sits beside them.
 *
 * Breakpoints, and why:
 *   1200px — the two-column "list + side panel" layouts stop fitting a table
 *            of six or more columns beside a 380px panel.
 *    960px — WordPress still shows its sidebar here; panels go full width.
 *    782px — WordPress switches to its own mobile admin. Controls grow to
 *            touch size and tables start scrolling horizontally.
 *    600px — phone. Tables become stacked cards, nothing sits side by side.
 */

/* ---------------------------------------------------------------------
 * 1. Never let anything push the page sideways
 * ------------------------------------------------------------------ */

.skm-wrap,
.skm-app {
	max-width: 100%;
	box-sizing: border-box;
	overflow-x: hidden;
}

.skm-wrap *,
.skm-app * {
	box-sizing: border-box;
}

/* Grid and flex children default to min-width:auto, which lets a wide table
 * inflate its column instead of scrolling. This is the single most common
 * cause of a cut-off Actions column. */
.skm-grid-2 > *,
.skm-panel,
.skm-cards > *,
.skm-plan-grid > * {
	min-width: 0;
}

/* ---------------------------------------------------------------------
 * 2. Tables scroll inside their own box, at every width
 * ------------------------------------------------------------------ */

.skm-table-wrap {
	width: 100%;
	max-width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior-x: contain;
}

/* A hint that there is more to the right, drawn only while scrollable. */
.skm-table-wrap.is-scrollable {
	background:
		linear-gradient(to right, var(--skm-bg, #fff) 30%, rgba(255, 255, 255, 0)),
		linear-gradient(to left, var(--skm-bg, #fff) 30%, rgba(255, 255, 255, 0)) 100% 0,
		radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .12), transparent),
		radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .12), transparent) 100% 0;
	background-repeat: no-repeat;
	background-size: 32px 100%, 32px 100%, 14px 100%, 14px 100%;
	background-attachment: local, local, scroll, scroll;
}

.skm-table-wrap > .skm-table {
	min-width: 640px;
}

/* The two-column screens are tighter, so their tables need less before the
 * scroll kicks in rather than more. */
.skm-grid-2 .skm-table-wrap > .skm-table {
	min-width: 520px;
}

/* Undo the old blanket rule: making the table itself a scroll box broke
 * column alignment and hid the last cell under the neighbouring panel. */
@media screen and (max-width: 782px) {
	.skm-table {
		display: table;
		overflow: visible;
		white-space: normal;
	}
}

/* Action buttons must never be the thing that gets clipped. */
.skm-table td:last-child,
.skm-table th:last-child {
	white-space: nowrap;
}

.skm-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	align-items: center;
}

/* ---------------------------------------------------------------------
 * 3. Filter bars, search and date ranges wrap instead of overflowing
 * ------------------------------------------------------------------ */

.skm-filters,
.skm-daterange,
.skm-browse-bar,
.skm-checklist-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

.skm-filters .skm-table-search,
.skm-search {
	flex: 1 1 220px;
	min-width: 0;
	max-width: 100%;
}

.skm-daterange input[type="date"],
.skm-daterange select {
	min-width: 0;
	max-width: 100%;
}

/* The live-search box keeps its own spinner and clear button inside. */
.skm-search-field {
	position: relative;
	flex: 1 1 240px;
	min-width: 0;
}

.skm-search-field input[type="search"] {
	width: 100%;
	padding-right: 30px;
}

.skm-search-field .skm-spinner {
	position: absolute;
	top: 50%;
	right: 8px;
	width: 14px;
	height: 14px;
	margin-top: -7px;
	border: 2px solid var(--skm-border, #dcdfe4);
	border-top-color: var(--skm-accent, #2563eb);
	border-radius: 50%;
	opacity: 0;
	animation: skm-spin .7s linear infinite;
}

.skm-search-field.is-busy .skm-spinner {
	opacity: 1;
}

@keyframes skm-spin {
	to { transform: rotate(360deg); }
}

.skm-search-count {
	flex: 0 0 auto;
	font-size: 12px;
	color: var(--skm-muted, #6b7280);
}

/* ---------------------------------------------------------------------
 * 4. Breakpoints
 * ------------------------------------------------------------------ */

@media screen and (max-width: 1200px) {
	.skm-grid-2 {
		grid-template-columns: 1fr;
	}
}

@media screen and (max-width: 960px) {
	.skm-header {
		flex-direction: column;
		align-items: stretch;
	}

	.skm-header .skm-actions {
		width: 100%;
	}

	.skm-cards {
		grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
	}

	.skm-fee-grid {
		max-width: 100%;
	}
}

@media screen and (max-width: 782px) {
	.skm-wrap,
	.skm-app {
		margin-right: 10px;
	}

	.skm-panel {
		padding: 14px;
		border-radius: 8px;
	}

	.skm-cards {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.skm-card-value {
		font-size: 20px;
	}

	/* Touch targets. WordPress already enlarges its own controls at this
	 * width; these are ours. */
	.skm-wrap .button,
	.skm-app .button,
	.skm-wrap input[type="text"],
	.skm-wrap input[type="search"],
	.skm-wrap input[type="tel"],
	.skm-wrap input[type="url"],
	.skm-wrap input[type="number"],
	.skm-wrap input[type="date"],
	.skm-wrap select {
		min-height: 38px;
		font-size: 16px; /* stops iOS zooming the page on focus */
	}

	.skm-filters {
		gap: 6px;
	}

	.skm-tab {
		flex: 0 0 auto;
	}

	.skm-daterange {
		width: 100%;
	}

	.skm-daterange label {
		flex: 0 0 auto;
	}

	.skm-daterange input[type="date"] {
		flex: 1 1 130px;
	}

	.skm-daterange select {
		flex: 1 1 100%;
	}

	.skm-daterange .button {
		flex: 1 1 100%;
	}

	.skm-field-row {
		grid-template-columns: 1fr 1fr;
	}

	.skm-field-row .skm-f-value {
		grid-column: 1 / -1;
	}

	.skm-code-row {
		flex-direction: column;
	}

	.skm-code-row .button {
		width: 100%;
	}

	.skm-banner {
		flex-direction: column;
		align-items: flex-start;
	}

	.skm-setting-head {
		flex-direction: column;
		align-items: flex-start;
		gap: 4px;
	}
}

@media screen and (max-width: 600px) {
	.skm-cards {
		grid-template-columns: 1fr;
	}

	.skm-header h1 {
		font-size: 20px;
	}

	/* Stacked table. Each row becomes a card and each cell carries its own
	 * heading, taken from the column header by the responsive script. This
	 * only applies where that script could read the headers — a table it
	 * could not label keeps scrolling instead, which is still readable. */
	.skm-table.is-stacked,
	.skm-table.is-stacked thead,
	.skm-table.is-stacked tbody,
	.skm-table.is-stacked tr,
	.skm-table.is-stacked td {
		display: block;
		width: auto;
	}

	.skm-table.is-stacked {
		min-width: 0;
	}

	.skm-table.is-stacked thead {
		display: none;
	}

	.skm-table.is-stacked tr {
		border: 1px solid var(--skm-border, #dcdfe4);
		border-radius: 8px;
		padding: 10px 12px;
		margin-bottom: 10px;
		background: var(--skm-bg, #fff);
	}

	.skm-table.is-stacked td {
		border: 0;
		padding: 5px 0;
		display: grid;
		grid-template-columns: minmax(84px, 38%) 1fr;
		gap: 10px;
		align-items: start;
		white-space: normal;
	}

	.skm-table.is-stacked td::before {
		content: attr(data-label);
		font-weight: 600;
		font-size: 11px;
		text-transform: uppercase;
		letter-spacing: .03em;
		color: var(--skm-muted, #6b7280);
		padding-top: 2px;
	}

	/* A cell whose header was blank — the actions column, normally — gets
	 * the full width rather than an empty label gutter. */
	.skm-table.is-stacked td.is-unlabelled {
		grid-template-columns: 1fr;
		padding-top: 10px;
		margin-top: 4px;
		border-top: 1px solid var(--skm-border, #dcdfe4);
	}

	.skm-table.is-stacked td.is-unlabelled::before {
		display: none;
	}

	.skm-table.is-stacked .skm-actions .button {
		flex: 1 1 auto;
		text-align: center;
	}

	.skm-table-wrap.is-stacked {
		overflow-x: visible;
		background: none;
	}

	.skm-browse-bar > * {
		flex: 1 1 100%;
	}

	.skm-plan-grid {
		grid-template-columns: 1fr;
	}

	.skm-pair-inline {
		flex-direction: column;
		align-items: stretch;
	}
}

/* ---------------------------------------------------------------------
 * 5. Dark scheme — WordPress admin colour schemes and OS dark mode
 * ------------------------------------------------------------------ */

@media screen and (prefers-color-scheme: dark) {
	.skm-table-wrap.is-scrollable {
		background-image:
			linear-gradient(to right, rgba(0, 0, 0, .2) 30%, rgba(0, 0, 0, 0)),
			linear-gradient(to left, rgba(0, 0, 0, .2) 30%, rgba(0, 0, 0, 0)),
			radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .3), transparent),
			radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .3), transparent);
	}
}
