/**
 * Curlo Table — desktop grid; stacked labeled cards on tablet/phone.
 */

.curlo-table {
	display: block;
	width: 100%;
	max-width: 100%;
	margin: 1.5rem 0;
	box-sizing: border-box;
}

.curlo-table__caption:empty {
	display: none;
}

.curlo-table__caption {
	display: block;
	margin: 0 0 0.55rem;
	font-family: var(--curlo-font-mono, "JetBrains Mono", monospace);
	font-size: 0.72rem;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--curlo-muted, #5b6675);
}

.curlo-table__scroll {
	width: 100%;
	max-width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	border: 1px solid var(--curlo-line, #d8dee6);
	border-radius: var(--curlo-radius, 8px);
	background: var(--curlo-surface, #fff);
	box-sizing: border-box;
}

.curlo-table table {
	width: 100%;
	border-collapse: collapse;
	margin: 0;
	font-family: var(--curlo-font-sans, Inter, sans-serif);
}

.curlo-table th,
.curlo-table td {
	padding: 0.75rem 1rem;
	text-align: left;
	vertical-align: top;
	border-bottom: 1px solid var(--curlo-line, #d8dee6);
	color: var(--curlo-text);
	font-size: 0.925rem;
	line-height: 1.45;
	overflow-wrap: anywhere;
	word-break: break-word;
}

.curlo-table th.has-text-align-center,
.curlo-table td.has-text-align-center {
	text-align: center;
}

.curlo-table th.has-text-align-right,
.curlo-table td.has-text-align-right {
	text-align: right;
}

.curlo-table tr:last-child th,
.curlo-table tr:last-child td {
	border-bottom: none;
}

.curlo-table thead th {
	font-family: var(--curlo-font-mono, "JetBrains Mono", monospace);
	font-size: 0.7rem;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	font-weight: 600;
	color: var(--curlo-muted, #5b6675);
	background: var(--curlo-surface-2, #f4f6f8);
	white-space: nowrap;
}

.curlo-table tbody th {
	font-weight: 600;
	color: var(--curlo-text);
	background: var(--curlo-surface, #fff);
}

.curlo-table--striped tbody tr:nth-child(even) td,
.curlo-table--striped tbody tr:nth-child(even) th {
	background: color-mix(in srgb, var(--curlo-ink, #F5F7FA) 70%, transparent);
}

.curlo-table--compact th,
.curlo-table--compact td {
	padding: 0.5rem 0.75rem;
	font-size: 0.85rem;
}

.curlo-text--pro .curlo-table__scroll,
.curlo-text--code .curlo-table__scroll,
.curlo-article-entry--pro .curlo-table__scroll,
.curlo-article-entry--code .curlo-table__scroll {
	background: rgba(255, 255, 255, 0.03);
	border-color: rgba(255, 255, 255, 0.12);
}

.curlo-text--pro .curlo-table thead th,
.curlo-text--code .curlo-table thead th,
.curlo-article-entry--pro .curlo-table thead th,
.curlo-article-entry--code .curlo-table thead th {
	background: rgba(255, 255, 255, 0.04);
	color: var(--curlo-code-muted, #7e8ca0);
	border-bottom-color: rgba(255, 255, 255, 0.12);
}

.curlo-text--pro .curlo-table th,
.curlo-text--pro .curlo-table td,
.curlo-text--code .curlo-table th,
.curlo-text--code .curlo-table td,
.curlo-article-entry--pro .curlo-table th,
.curlo-article-entry--pro .curlo-table td,
.curlo-article-entry--code .curlo-table th,
.curlo-article-entry--code .curlo-table td {
	color: var(--curlo-code-text, #e6edf3);
	border-bottom-color: rgba(255, 255, 255, 0.12);
}

.curlo-text--pro .curlo-table tbody th,
.curlo-text--code .curlo-table tbody th,
.curlo-article-entry--pro .curlo-table tbody th,
.curlo-article-entry--code .curlo-table tbody th {
	background: transparent;
}

.curlo-text--pro .curlo-table--striped tbody tr:nth-child(even) td,
.curlo-text--pro .curlo-table--striped tbody tr:nth-child(even) th,
.curlo-text--code .curlo-table--striped tbody tr:nth-child(even) td,
.curlo-text--code .curlo-table--striped tbody tr:nth-child(even) th,
.curlo-article-entry--pro .curlo-table--striped tbody tr:nth-child(even) td,
.curlo-article-entry--pro .curlo-table--striped tbody tr:nth-child(even) th,
.curlo-article-entry--code .curlo-table--striped tbody tr:nth-child(even) td,
.curlo-article-entry--code .curlo-table--striped tbody tr:nth-child(even) th {
	background: rgba(255, 255, 255, 0.04);
}

.curlo-text--pro .curlo-table__caption,
.curlo-text--code .curlo-table__caption,
.curlo-article-entry--pro .curlo-table__caption,
.curlo-article-entry--code .curlo-table__caption {
	color: var(--curlo-code-muted, #7e8ca0);
}

/*
 * Tablet + phone: each row becomes a card; column titles sit beside values.
 * Editor keeps a real grid (see .curlo-table--editing).
 */
@media (max-width: 959px) {
	.curlo-table--stack:not(.curlo-table--editing) .curlo-table__scroll {
		overflow: visible;
		border: none;
		background: transparent;
		border-radius: 0;
	}

	.curlo-table--stack:not(.curlo-table--editing) table,
	.curlo-table--stack:not(.curlo-table--editing) thead,
	.curlo-table--stack:not(.curlo-table--editing) tbody,
	.curlo-table--stack:not(.curlo-table--editing) tfoot {
		display: block;
		width: 100%;
	}

	.curlo-table--stack:not(.curlo-table--editing) thead {
		position: absolute;
		width: 1px;
		height: 1px;
		padding: 0;
		margin: -1px;
		overflow: hidden;
		clip: rect(0, 0, 0, 0);
		white-space: nowrap;
		border: 0;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody tr {
		display: block;
		margin: 0 0 0.75rem;
		border: 1px solid var(--curlo-line, #d8dee6);
		border-radius: var(--curlo-radius, 8px);
		background: var(--curlo-surface, #fff);
		overflow: hidden;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody tr:last-child {
		margin-bottom: 0;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody th,
	.curlo-table--stack:not(.curlo-table--editing) tbody td {
		display: grid;
		grid-template-columns: minmax(7rem, 38%) minmax(0, 1fr);
		gap: 0.65rem 0.85rem;
		width: 100%;
		box-sizing: border-box;
		padding: 0.7rem 0.9rem;
		border-bottom: none;
		border-top: 1px solid var(--curlo-line, #d8dee6);
		background: transparent;
		white-space: normal;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody tr > *:first-child {
		border-top: none;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody th[scope="row"] {
		display: block;
		font-family: var(--curlo-font-sans, Inter, sans-serif);
		font-size: 0.95rem;
		font-weight: 700;
		letter-spacing: -0.01em;
		background: var(--curlo-surface-2, #f4f6f8);
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody td::before,
	.curlo-table--stack:not(.curlo-table--editing) tbody th:not([scope="row"])::before {
		content: attr(data-label);
		font-family: var(--curlo-font-mono, "JetBrains Mono", monospace);
		font-size: 0.65rem;
		font-weight: 600;
		letter-spacing: 0.08em;
		text-transform: uppercase;
		color: var(--curlo-muted, #5b6675);
		align-self: start;
		padding-top: 0.15rem;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody td[data-label=""] {
		grid-template-columns: 1fr;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody td[data-label=""]::before {
		display: none;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody td.has-text-align-center > span,
	.curlo-table--stack:not(.curlo-table--editing) tbody th.has-text-align-center:not([scope="row"]) > span {
		justify-self: center;
		text-align: center;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody td.has-text-align-right > span,
	.curlo-table--stack:not(.curlo-table--editing) tbody th.has-text-align-right:not([scope="row"]) > span {
		justify-self: end;
		text-align: right;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody th[scope="row"].has-text-align-center {
		text-align: center;
	}

	.curlo-table--stack:not(.curlo-table--editing) tbody th[scope="row"].has-text-align-right {
		text-align: right;
	}

	.curlo-table--stack:not(.curlo-table--editing).curlo-table--striped tbody tr:nth-child(even) td,
	.curlo-table--stack:not(.curlo-table--editing).curlo-table--striped tbody tr:nth-child(even) th {
		background: transparent;
	}

	.curlo-table--stack:not(.curlo-table--editing).curlo-table--striped tbody tr:nth-child(even) {
		background: color-mix(in srgb, var(--curlo-ink, #F5F7FA) 80%, var(--curlo-surface, #fff));
	}

	.curlo-text--pro .curlo-table--stack:not(.curlo-table--editing) tbody tr,
	.curlo-text--code .curlo-table--stack:not(.curlo-table--editing) tbody tr,
	.curlo-article-entry--pro .curlo-table--stack:not(.curlo-table--editing) tbody tr,
	.curlo-article-entry--code .curlo-table--stack:not(.curlo-table--editing) tbody tr {
		background: rgba(255, 255, 255, 0.03);
		border-color: rgba(255, 255, 255, 0.12);
	}

	.curlo-text--pro .curlo-table--stack:not(.curlo-table--editing) tbody th,
	.curlo-text--pro .curlo-table--stack:not(.curlo-table--editing) tbody td,
	.curlo-text--code .curlo-table--stack:not(.curlo-table--editing) tbody th,
	.curlo-text--code .curlo-table--stack:not(.curlo-table--editing) tbody td,
	.curlo-article-entry--pro .curlo-table--stack:not(.curlo-table--editing) tbody th,
	.curlo-article-entry--pro .curlo-table--stack:not(.curlo-table--editing) tbody td,
	.curlo-article-entry--code .curlo-table--stack:not(.curlo-table--editing) tbody th,
	.curlo-article-entry--code .curlo-table--stack:not(.curlo-table--editing) tbody td {
		border-top-color: rgba(255, 255, 255, 0.12);
	}

	.curlo-text--pro .curlo-table--stack:not(.curlo-table--editing) tbody th[scope="row"],
	.curlo-text--code .curlo-table--stack:not(.curlo-table--editing) tbody th[scope="row"],
	.curlo-article-entry--pro .curlo-table--stack:not(.curlo-table--editing) tbody th[scope="row"],
	.curlo-article-entry--code .curlo-table--stack:not(.curlo-table--editing) tbody th[scope="row"] {
		background: rgba(255, 255, 255, 0.05);
	}

	/* Scroll fallback when stacking is turned off. */
	.curlo-table:not(.curlo-table--stack) table {
		min-width: 32rem;
	}

	.curlo-table:not(.curlo-table--stack) thead th:first-child,
	.curlo-table:not(.curlo-table--stack) tbody th[scope="row"] {
		position: sticky;
		left: 0;
		z-index: 1;
		box-shadow: 1px 0 0 var(--curlo-line, #d8dee6);
	}
}
