/*
 * ACQE LMS Enterprise - shared mobile layer.
 * Loaded on the public site and on ACQE admin screens only.
 * Desktop (>782px, mouse) layouts are intentionally left untouched.
 * Selectors are prefixed with "body" so they win over the inline <style>
 * blocks that some modules print inside page content.
 */

/* =====================================================================
   1. FRONT END - layout (phones and small tablets)
   ===================================================================== */
@media (max-width: 782px) {

	/* Cards and forms: never wider than the screen, small side gutter. */
	body .acqe-cert-form,
	body .acqe-cert-card,
	body .acqe-order-payment,
	body .acqe-payment-instructions,
	body .acqe-payment-card,
	body .acqe-registration-form,
	body .acqe-final-tests {
		box-sizing: border-box;
		width: calc(100% - 24px);
		margin-left: auto;
		margin-right: auto;
		overflow-wrap: anywhere;
	}

	body .acqe-cert-alert,
	body .acqe-alert,
	body .acqe-registration-message {
		box-sizing: border-box;
		width: calc(100% - 24px);
		margin-left: auto;
		margin-right: auto;
		overflow-wrap: anywhere;
	}

	body .acqe-cert-form *,
	body .acqe-cert-card *,
	body .acqe-order-payment *,
	body .acqe-payment-instructions *,
	body .acqe-payment-card *,
	body .acqe-registration-form *,
	body .acqe-portal * {
		max-width: 100%;
	}

	body .acqe-cert-form img,
	body .acqe-cert-card img,
	body .acqe-payment-options img,
	body .acqe-portal img {
		height: auto;
	}

	/* Grids: min() lets a column shrink below the old fixed minimum. */
	body .acqe-course-grid {
		grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
	}
	body .acqe-cert-grid,
	body .acqe-payment-grid {
		grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
	}
	body .acqe-payment-options {
		grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
	}

	/* Student portal */
	body .acqe-portal {
		margin: 20px auto;
		padding: 0 12px;
		overflow-wrap: anywhere;
	}
	body .acqe-portal-header {
		gap: 12px;
	}
	body .acqe-portal-header .acqe-portal-btn {
		width: 100%;
		box-sizing: border-box;
		text-align: center;
	}
	body .acqe-course-card dl div {
		flex-wrap: wrap;
		gap: 4px 12px;
	}
	body .acqe-course-card dd {
		min-width: 0;
		overflow-wrap: anywhere;
	}
	body .acqe-card-actions {
		flex-direction: column;
		align-items: stretch;
	}
	body .acqe-card-actions .acqe-portal-btn,
	body .acqe-card-actions form {
		width: 100%;
		box-sizing: border-box;
		text-align: center;
	}

	/* Registration form */
	body .acqe-registration-form h2 {
		font-size: 1.4rem;
		line-height: 1.25;
	}
	body .acqe-registration-form p {
		margin: 0 0 16px;
	}
	body .acqe-registration-form button {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
	}

	/* Primary action buttons: full width, easy to hit. */
	body .acqe-cert-btn,
	body .acqe-payment-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		box-sizing: border-box;
		text-align: center;
	}
}

@media (max-width: 640px) {
	/* Wrapper of a stacked table: drop the box, the rows become cards. */
	body .acqe-stack-parent {
		overflow: visible !important;
		background: transparent !important;
		border: 0 !important;
		border-radius: 0 !important;
	}
	body .acqe-stack {
		display: block;
		width: 100% !important;
		min-width: 0 !important;
		border: 0;
	}
	body .acqe-stack thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
		white-space: nowrap;
	}
	body .acqe-stack tbody,
	body .acqe-stack tr {
		display: block;
		width: 100%;
	}
	body .acqe-stack tr {
		margin: 0 0 12px;
		background: #fff;
		border: 1px solid #e5e7eb;
		border-radius: 8px;
		overflow: hidden;
	}
	body .acqe-stack td {
		display: block;
		box-sizing: border-box;
		width: 100% !important;
		padding: 10px 12px !important;
		text-align: left !important;
		border: 0;
		border-bottom: 1px solid #edf0f2;
		overflow-wrap: anywhere;
	}
	body .acqe-stack td[data-label] {
		position: relative;
		min-height: 40px;
		padding-left: 42% !important;
	}
	body .acqe-stack td[data-label]::before {
		content: attr(data-label);
		position: absolute;
		left: 12px;
		top: 10px;
		width: calc(42% - 24px);
		font-weight: 600;
		color: #374151;
		overflow-wrap: anywhere;
	}
	body .acqe-stack td:last-child {
		border-bottom: 0;
	}
	body .acqe-stack td .acqe-portal-btn,
	body .acqe-stack td button,
	body .acqe-stack td .button {
		margin: 2px 4px 2px 0;
	}
}

@media (max-width: 480px) {
	body .acqe-cert-form,
	body .acqe-cert-card,
	body .acqe-order-payment,
	body .acqe-payment-instructions,
	body .acqe-payment-card {
		padding: 18px 16px;
	}
	body .acqe-course-card,
	body .acqe-empty,
	body .acqe-portal-login {
		padding: 16px;
	}
	body .acqe-history-table th,
	body .acqe-history-table td {
		padding: 10px 12px;
	}
	body .acqe-stack td[data-label] {
		padding-left: 12px !important;
	}
	body .acqe-stack td[data-label]::before {
		position: static;
		display: block;
		width: auto;
		margin-bottom: 2px;
	}
}

/* =====================================================================
   2. FRONT END - touch comfort (any touch device, plus small screens)
   ===================================================================== */
@media (max-width: 782px), (pointer: coarse) {

	body .acqe-portal-btn,
	body .acqe-cert-btn,
	body .acqe-payment-btn,
	body .acqe-registration-form button {
		min-height: 44px;
		box-sizing: border-box;
		touch-action: manipulation;
		-webkit-tap-highlight-color: rgba(215, 25, 45, .15);
	}
	body .acqe-portal-btn {
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}

	/* 16px stops iOS Safari from zooming the page when a field is focused. */
	body .acqe-registration-form input:not([type="checkbox"]):not([type="radio"]),
	body .acqe-registration-form select,
	body .acqe-registration-form textarea,
	body .acqe-cert-form select,
	body .acqe-cert-form textarea,
	body .acqe-order-payment input:not([type="checkbox"]):not([type="radio"]),
	body .acqe-order-payment select,
	body .acqe-order-payment textarea {
		font-size: 16px;
		min-height: 44px;
	}
	body .acqe-registration-form textarea,
	body .acqe-cert-form textarea,
	body .acqe-order-payment textarea {
		min-height: 96px;
	}

	/* Final tests list: large, separated tap targets. */
	body .acqe-final-tests ol {
		padding-left: 1.5em;
	}
	body .acqe-final-tests li {
		margin: 4px 0;
	}
	body .acqe-final-tests li a {
		display: block;
		min-height: 44px;
		padding: 12px 4px;
		box-sizing: border-box;
	}
}

/* Charts and canvases never exceed their container. */
body .acqe-chart-grid canvas,
body canvas[data-acqe-chart] {
	max-width: 100%;
}

/* =====================================================================
   3. INSTALL PANEL (pwa.js) - reachable controls, safe-area aware
   ===================================================================== */
#acqe-next-install-panel .acqe-next-install-close {
	min-width: 44px;
	min-height: 44px;
	line-height: 1;
	touch-action: manipulation;
}
#acqe-next-install-panel .acqe-next-install-action {
	min-height: 44px;
	touch-action: manipulation;
}
@media (max-width: 480px) {
	#acqe-next-install-panel .acqe-next-install-action {
		width: 100%;
	}
}

/* =====================================================================
   4. ADMIN SCREENS (only on pages whose slug starts with "acqe")
   ===================================================================== */

/* Horizontal-scroll wrapper added by acqe-mobile.js around admin tables. */
body.acqe-admin-page .acqe-scroll {
	max-width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

/* Touch reorder buttons for the Google Sheets column editor. */
body.acqe-admin-page .acqe-move {
	display: none;
	gap: 6px;
	justify-content: center;
	margin-top: 6px;
}
body.acqe-admin-page .acqe-move .button {
	min-width: 40px;
	min-height: 40px;
	padding: 0 10px;
	line-height: 1;
}

@media (max-width: 782px), (pointer: coarse) {
	body.acqe-admin-page .acqe-move {
		display: flex;
	}
}

@media (max-width: 782px) {

	body.acqe-admin-page .wrap {
		margin-right: 12px;
	}
	body.acqe-admin-page .wrap h1 {
		font-size: 1.5em;
		line-height: 1.3;
	}

	/* Fields: fill the row, no fixed minimums. */
	body.acqe-admin-page .wrap input[type="text"],
	body.acqe-admin-page .wrap input[type="url"],
	body.acqe-admin-page .wrap input[type="email"],
	body.acqe-admin-page .wrap input[type="number"],
	body.acqe-admin-page .wrap input[type="search"],
	body.acqe-admin-page .wrap input[type="password"],
	body.acqe-admin-page .wrap input[type="date"],
	body.acqe-admin-page .wrap select,
	body.acqe-admin-page .wrap textarea,
	body.acqe-admin-page .wrap .regular-text,
	body.acqe-admin-page .wrap .large-text {
		box-sizing: border-box;
		min-width: 0;
		max-width: 100%;
	}
	body.acqe-admin-page .wrap .regular-text,
	body.acqe-admin-page .wrap .large-text {
		width: 100%;
	}

	body.acqe-admin-page .form-table th {
		width: auto !important;
	}
	body.acqe-admin-page .acqe-details-table th {
		width: auto;
	}

	/* Inline forms and toolbars wrap instead of overflowing. */
	body.acqe-admin-page .acqe-cert-inline-form,
	body.acqe-admin-page .acqe-inline-form,
	body.acqe-admin-page .acqe-student-filter,
	body.acqe-admin-page .acqe-quiz-controls,
	body.acqe-admin-page .acqe-instructor-head,
	body.acqe-admin-page .acqe-inline-reset {
		flex-wrap: wrap;
	}
	body.acqe-admin-page .acqe-cert-inline-form input[type="url"],
	body.acqe-admin-page .acqe-cert-inline-form input[type="text"],
	body.acqe-admin-page .acqe-inline-form input[type="text"],
	body.acqe-admin-page .acqe-student-filter input,
	body.acqe-admin-page .acqe-student-filter select {
		min-width: 0;
		flex: 1 1 100%;
		width: 100%;
	}
	body.acqe-admin-page .acqe-quiz-search {
		min-width: 0;
		max-width: 100%;
		flex: 1 1 100%;
	}
	body.acqe-admin-page .acqe-quiz-kpi {
		flex: 1 1 calc(50% - 10px);
		min-width: 0;
	}
	body.acqe-admin-page .acqe-export-actions {
		margin-left: 0;
		width: 100%;
		flex-wrap: wrap;
	}
	body.acqe-admin-page .acqe-filter-bar {
		align-items: stretch;
	}
	body.acqe-admin-page .acqe-filter-bar label {
		width: 100%;
	}
	body.acqe-admin-page .acqe-filter-bar input,
	body.acqe-admin-page .acqe-filter-bar select {
		min-width: 0;
		width: 100%;
	}
	body.acqe-admin-page .acqe-filter-bar input:not([type="checkbox"]):not([type="radio"]),
	body.acqe-admin-page .acqe-filter-bar select,
	body.acqe-admin-page .acqe-student-filter input,
	body.acqe-admin-page .acqe-student-filter select,
	body.acqe-admin-page .acqe-quiz-search,
	body.acqe-admin-page .acqe-cert-inline-form input,
	body.acqe-admin-page .acqe-inline-form input,
	body.acqe-admin-page #acqe-sheet-editor td input,
	body.acqe-admin-page #acqe-sheet-editor td select {
		font-size: 16px;
		min-height: 40px;
	}
	body.acqe-admin-page .acqe-cert-help {
		max-width: 100%;
	}
	body.acqe-admin-page .acqe-progress {
		max-width: 100%;
	}
	body.acqe-admin-page .acqe-kpi strong {
		font-size: 22px;
	}

	/* Two-column course list in the registration editor becomes one column. */
	body.acqe-admin-page div[style*="columns:2"] {
		columns: 1 !important;
	}

	/* Tables stay readable and scroll sideways inside their own wrapper. */
	body.acqe-admin-page .acqe-scroll > table,
	body.acqe-admin-page .acqe-table-wrap > table {
		min-width: 620px;
	}

	/* Google Sheets column editor: one card per row instead of 7 columns. */
	body.acqe-admin-page #acqe-sheet-editor,
	body.acqe-admin-page #acqe-sheet-editor tbody,
	body.acqe-admin-page #acqe-sheet-editor tr,
	body.acqe-admin-page #acqe-sheet-editor td {
		display: block;
		box-sizing: border-box;
		width: 100%;
	}
	body.acqe-admin-page #acqe-sheet-editor thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
		white-space: nowrap;
	}
	body.acqe-admin-page #acqe-sheet-editor tr {
		margin: 0 0 12px;
		padding: 6px 0;
		background: #fff;
		border: 1px solid #dcdcde;
	}
	body.acqe-admin-page #acqe-sheet-editor td {
		padding: 8px 12px;
		border: 0;
		text-align: left;
	}
	body.acqe-admin-page #acqe-sheet-editor td[data-label]::before {
		content: attr(data-label);
		display: block;
		margin-bottom: 4px;
		font-weight: 600;
	}
	body.acqe-admin-page #acqe-sheet-editor td input,
	body.acqe-admin-page #acqe-sheet-editor td select {
		width: 100%;
		max-width: 100%;
		min-height: 40px;
	}
	body.acqe-admin-page #acqe-sheet-editor td.acqe-drag-handle {
		text-align: left;
		cursor: default;
	}
	body.acqe-admin-page #acqe-sheet-editor td.acqe-drag-handle .acqe-move {
		justify-content: flex-start;
	}
	body.acqe-admin-page .acqe-sheet-editor-help {
		display: block;
	}
	body.acqe-admin-page .acqe-sheet-editor-help span {
		display: inline;
	}
}

@media (max-width: 480px) {
	body.acqe-admin-page .acqe-profile-heading,
	body.acqe-admin-page .acqe-instructor-head,
	body.acqe-admin-page .acqe-instructor-course,
	body.acqe-admin-page .acqe-course-record {
		padding: 14px;
	}
	body.acqe-admin-page .acqe-quiz-kpi {
		flex-basis: 100%;
	}
}

/* ACQE v1.7.3: touch-friendly forms and course content on narrow screens. */
@media (max-width: 767px) {
  .acqe-registration-form, .acqe-student-portal, .acqe-student-dashboard,
  .acqe-next-registration, .acqe-form-wrap { box-sizing: border-box; width: 100%; max-width: 100%; padding-inline: 12px; }
  .acqe-registration-form *, .acqe-student-portal *, .acqe-student-dashboard *,
  .acqe-next-registration * { box-sizing: border-box; }
  .acqe-registration-form input:not([type="checkbox"]):not([type="radio"]),
  .acqe-registration-form select, .acqe-registration-form textarea,
  .acqe-next-registration input:not([type="checkbox"]):not([type="radio"]),
  .acqe-next-registration select, .acqe-next-registration textarea {
    max-width: 100%; width: 100%; min-height: 44px; font-size: 16px;
  }
  .acqe-registration-form button, .acqe-next-registration button,
  .acqe-student-portal button { min-height: 44px; }
  .tutor-course-single-content-wrapper video,
  .tutor-course-single-content-wrapper iframe,
  .tutor-lesson-content-area video,
  .tutor-lesson-content-area iframe { max-width: 100%; }
  .tutor-course-single-content-wrapper iframe { aspect-ratio: 16 / 9; height: auto; }
  body.acqe-admin-page .wrap { max-width: 100%; overflow-wrap: anywhere; }
  body.acqe-admin-page .wrap .widefat { display: block; max-width: 100%; overflow-x: auto; }
}
@media (max-width: 420px) {
  .acqe-registration-form, .acqe-next-registration { padding-inline: 8px; }
  .tutor-course-single-content-wrapper { min-width: 0; }
}
