/**
 * MW Engine - Universal Responsive Tables.
 *
 * Ensures every HTML table across posts, pages, services, and Elementor widgets
 * never overflows horizontally on mobile while staying clean and readable.
 */

/* Prevent CSS Grid / Flexbox parents from expanding wider than the viewport */
.mw-single-main,
.mw-single-sheet,
.mw-prose,
.mwm-pf-main,
.mwm-pf-prose,
.entry-content,
.elementor-widget-text-editor,
.elementor-widget-text-editor > .elementor-widget-container,
.elementor-widget-html,
.elementor-widget-html > .elementor-widget-container,
.elementor-widget-accordion .elementor-tab-content,
.elementor-widget-tabs .elementor-tab-content {
	min-width: 0;
	max-width: 100%;
}

/* Outer wrapper */
.mw-table-wrap {
	position: relative;
	display: block;
	width: 100%;
	max-width: 100%;
	margin: 1.5rem 0;
}

/* Mobile swipe hint (shown only when JS detects horizontal overflow) */
.mw-table-wrap::before {
	content: "\2190  Geser ke samping untuk melihat seluruh tabel  \2192";
	display: none;
	align-items: center;
	justify-content: center;
	margin-bottom: 8px;
	padding: 6px 12px;
	border-radius: 8px;
	background: var(--mw-primary-soft, #eff5ff);
	color: var(--mw-primary-dark, #0a49b8);
	font-size: 11.5px;
	font-weight: 700;
	letter-spacing: 0.01em;
	line-height: 1.3;
	text-align: center;
}

.mw-table-wrap.is-scrollable::before {
	display: flex;
}

/* Scrollable container */
.mw-table-scroll {
	position: relative;
	display: block;
	width: 100%;
	max-width: 100%;
	overflow-x: auto;
	overflow-y: hidden;
	-webkit-overflow-scrolling: touch;
	border: 1px solid var(--mw-border, #e2e8f0);
	border-radius: 12px;
	background: var(--mw-surface, #ffffff);
	box-shadow: 0 6px 20px -14px rgba(15, 23, 42, 0.2);
	scrollbar-width: thin;
	scrollbar-color: #cbd5e1 transparent;
}

.mw-table-scroll::-webkit-scrollbar {
	height: 7px;
}

.mw-table-scroll::-webkit-scrollbar-track {
	background: #f8fafc;
}

.mw-table-scroll::-webkit-scrollbar-thumb {
	background: #cbd5e1;
	border-radius: 999px;
}

/* Subtle right-edge scroll cue when scrollable and not at scroll end */
.mw-table-wrap.is-scrollable:not(.is-scrolled-end)::after {
	content: "";
	position: absolute;
	right: 1px;
	bottom: 1px;
	width: 28px;
	height: calc(100% - 38px);
	border-radius: 0 11px 11px 0;
	background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(15, 23, 42, 0.08) 100%);
	pointer-events: none;
}

/* Base responsive table typography & clean styling */
.mw-table-scroll > table,
.wp-block-table > table {
	width: 100% !important;
	max-width: none !important;
	margin: 0 !important;
	border: 0 !important;
	border-collapse: collapse;
	border-spacing: 0;
	font-size: 14px;
	line-height: 1.6;
	color: var(--mw-text, #334155);
	background: var(--mw-surface, #ffffff);
}

.mw-table-scroll > table thead th,
.mw-table-scroll > table thead td,
.wp-block-table > table thead th {
	padding: 12px 15px;
	border: 0;
	border-bottom: 2px solid #dbe4f0;
	border-right: 1px solid #e6ecf5;
	background: #f1f5fb;
	color: var(--mw-dark, #0f172a);
	font-weight: 700;
	text-align: left;
	vertical-align: middle;
}

.mw-table-scroll > table thead th:last-child,
.mw-table-scroll > table thead td:last-child {
	border-right: 0;
}

.mw-table-scroll > table tbody th,
.mw-table-scroll > table tbody td,
.wp-block-table > table tbody td {
	padding: 11px 15px;
	border: 0;
	border-bottom: 1px solid #edf2f7;
	border-right: 1px solid #edf2f7;
	text-align: left;
	vertical-align: top;
	overflow-wrap: break-word;
	word-break: normal;
}

.mw-table-scroll > table tbody td:last-child,
.mw-table-scroll > table tbody th:last-child {
	border-right: 0;
}

.mw-table-scroll > table tbody tr:last-child td,
.mw-table-scroll > table tbody tr:last-child th {
	border-bottom: 0;
}

.mw-table-scroll > table tbody tr:nth-child(even) {
	background: #fafcff;
}

.mw-table-scroll > table tbody tr:hover {
	background: #f1f6ff;
}

/* Group header rows (e.g. car price lists with <tr class="group">) */
.mw-table-scroll > table tr.group td {
	background: #eff5ff;
	color: var(--mw-primary-deep, #072a75);
	font-weight: 800;
	letter-spacing: 0.01em;
}

/* Nested paragraphs inside cells shouldn't add giant spacing */
.mw-table-scroll > table td > p:first-child,
.mw-table-scroll > table th > p:first-child {
	margin-top: 0;
}

.mw-table-scroll > table td > p:last-child,
.mw-table-scroll > table th > p:last-child {
	margin-bottom: 0;
}

/* Gutenberg wp-block-table guard */
.wp-block-table {
	width: 100%;
	max-width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	margin: 1.5rem 0;
}

/* Legacy Blogger image caption tables (post 2761) */
table.tr-caption-container {
	width: auto !important;
	max-width: 100% !important;
	margin: 1.25rem auto !important;
	border: 0 !important;
	border-collapse: collapse;
}

table.tr-caption-container td {
	border: 0 !important;
	padding: 4px 0 !important;
	text-align: center !important;
}

table.tr-caption-container img {
	max-width: 100%;
	height: auto;
}

/* --------------------------------------------------
 * Mobile Optimization (<= 767px)
 * -------------------------------------------------- */
@media (max-width: 767px) {
	.mw-table-scroll > table {
		font-size: 13px;
		line-height: 1.5;
	}

	/* Neutralize hardcoded HTML pixel widths so columns flow naturally */
	.mw-table-scroll > table[width],
	.mw-table-scroll > table td[width],
	.mw-table-scroll > table th[width] {
		width: auto !important;
	}

	.mw-table-scroll > table thead th,
	.mw-table-scroll > table thead td {
		padding: 10px 12px;
		white-space: nowrap;
	}

	.mw-table-scroll > table tbody td,
	.mw-table-scroll > table tbody th {
		padding: 9px 12px;
	}

	/* Keep multi-column (3+ cols) standard tables comfortably readable while scrolling */
	.mw-table-wrap:not(.mw-table-wrap--stacked) .mw-table-scroll > table.mw-table-wide {
		min-width: 540px;
	}

	/* --------------------------------------------------
	 * Stacked Mobile Card Mode for .mw-responsive-table (with data-label)
	 * -------------------------------------------------- */
	.mw-table-wrap--stacked::before,
	.mw-table-wrap--stacked::after {
		display: none !important;
	}

	.mw-table-wrap--stacked > .mw-table-scroll {
		overflow: visible;
		border: 0;
		border-radius: 0;
		background: transparent;
		box-shadow: none;
	}

	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table,
	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table tbody {
		display: block;
		width: 100% !important;
		background: transparent;
	}

	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table thead {
		display: none;
	}

	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table tbody tr {
		display: block;
		margin: 0 0 14px;
		border: 1px solid var(--mw-border, #e2e8f0);
		border-radius: 14px;
		background: var(--mw-surface, #ffffff);
		box-shadow: 0 6px 18px -12px rgba(15, 23, 42, 0.22);
		overflow: hidden;
	}

	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table tbody tr:last-child {
		margin-bottom: 0;
	}

	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table tbody tr:hover {
		background: var(--mw-surface, #ffffff);
	}

	/* First cell without data-label acts as card title banner */
	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table tbody td:first-child:not([data-label]) {
		display: block;
		width: 100% !important;
		padding: 12px 15px;
		border: 0;
		border-bottom: 1px solid #dbe8fe;
		background: var(--mw-primary-soft, #eff5ff);
		color: var(--mw-dark, #0f172a);
		font-size: 14px;
		font-weight: 800;
		line-height: 1.4;
		text-align: left;
	}

	/* Labeled cells render as crisp 2-column key/value rows */
	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table tbody td[data-label] {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		gap: 12px;
		width: 100% !important;
		padding: 10px 15px;
		border: 0;
		border-bottom: 1px solid #f1f5f9;
		font-size: 13.5px;
		line-height: 1.5;
		text-align: right;
	}

	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table tbody td[data-label]:last-child {
		border-bottom: 0;
	}

	.mw-table-wrap--stacked > .mw-table-scroll > table.mw-responsive-table tbody td[data-label]::before {
		content: attr(data-label);
		flex: 0 1 52%;
		color: #475569;
		font-size: 12.5px;
		font-weight: 700;
		line-height: 1.45;
		text-align: left;
	}
}
