/**
 * Muri Link Tracker admin styles.
 *
 * @package MuriLinkTracker
 * @since   1.0.0
 */

/* ── Design tokens ──────────────────────────────────────────────── */

/*
 * CSS custom properties allow the plugin to inherit theme tokens where
 * available (WordPress 7.0 "Modern" admin theme exposes its palette via
 * --wp-admin-theme-*) and fall back to the historical WP 6.x palette.
 */
.mltr-app {
	--mltr-color-bg: #fff;
	--mltr-color-border: #ddd;
	--mltr-color-text-muted: var(--wp-admin-theme-color-text-muted, #646970);
	--mltr-color-text-strong: #1d2327;
	--mltr-color-primary: var(--wp-admin-theme-color, #2271b1);
	--mltr-color-primary-hover: var(--wp-admin-theme-color-darker-10, #135e96);
	--mltr-color-ok: #00a32a;
	--mltr-color-broken: #d63638;
	--mltr-color-redirect: #dba617;
	--mltr-color-external: #8c8f94;
	--mltr-color-affiliate: #9b59b6;
	--mltr-color-cloaked: #e67e22;
	--mltr-color-neutral: #757575;
	--mltr-radius: 4px;
	--mltr-z-snackbar: 99999;
	max-width: 1200px;
	margin: 20px 0;

	h1 {
		margin-bottom: 16px;
	}

}

/* ── App layout ─────────────────────────────────────────────────── */


/* ── Dashboard summary cards ────────────────────────────────────── */

.mltr-summary-cards {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
	gap: 16px;
	margin-top: 20px;
}

.mltr-summary-card {
	background: var(--mltr-color-bg);
	border: 1px solid var(--mltr-color-border);
	border-radius: var(--mltr-radius);
	padding: 20px;
	text-align: center;

	&__value {
		display: block;
		font-size: 32px;
		font-weight: 600;
		line-height: 1.2;
	}

	&__label {
		display: block;
		margin-top: 4px;
		font-size: 13px;
		color: var(--mltr-color-text-muted);
	}

	&--broken .mltr-summary-card__value {
		color: var(--mltr-color-broken);
	}

	&--ok .mltr-summary-card__value {
		color: var(--mltr-color-ok);
	}

	&--redirect .mltr-summary-card__value {
		color: var(--mltr-color-redirect);
	}

	&--internal .mltr-summary-card__value {
		color: var(--mltr-color-primary);
	}

	&--external .mltr-summary-card__value {
		color: var(--mltr-color-external);
	}

	&--affiliate .mltr-summary-card__value {
		color: var(--mltr-color-affiliate);
	}

	&--cloaked .mltr-summary-card__value {
		color: var(--mltr-color-cloaked);
	}

	&__hint {
		display: block;
		margin-top: 6px;
		font-size: 11px;
		color: var(--mltr-color-text-muted);
		line-height: 1.4;
	}

	&.is-actionable {
		cursor: pointer;
		transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;

		&:hover {
			border-color: var(--mltr-color-primary);
			transform: translateY(-1px);
			box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
		}

		&:focus-visible {
			outline: 2px solid var(--mltr-color-primary);
			outline-offset: 2px;
		}
	}
}

// Prioritized action list (Affiliates panel — "What needs your attention").
.mltr-action-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 10px;

	&__item {
		display: grid;
		grid-template-columns: 32px 1fr auto;
		align-items: center;
		gap: 16px;
		padding: 14px 16px;
		background: var(--mltr-color-bg);
		border: 1px solid var(--mltr-color-border);
		border-left-width: 4px;
		border-radius: var(--mltr-radius);

		&.is-critical {
			border-left-color: var(--mltr-color-broken);
		}

		&.is-warning {
			border-left-color: var(--mltr-color-redirect);
		}

		&.is-info {
			border-left-color: var(--mltr-color-primary);
		}
	}

	&__icon {
		font-size: 20px;
		text-align: center;
	}

	&__body {

		strong {
			display: block;
			font-size: 14px;
			color: var(--mltr-color-text-strong);
			margin-bottom: 2px;
		}

		p {
			margin: 0;
			font-size: 12px;
			color: var(--mltr-color-text-muted);
		}
	}
}

// Navigation override banner from the Affiliates panel.
.mltr-link-table__overrides {
	margin-bottom: 12px;
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 8px;

	.mltr-link-table__override-chip {
		display: inline-block;
		padding: 2px 10px;
		background: var(--mltr-color-primary, #2271b1);
		color: #fff;
		border-radius: 999px;
		font-size: 11px;
		font-weight: 600;
	}

	.mltr-link-table__override-clear {
		margin-left: auto;
	}
}

// Bulk add-rel confirmation modal (sponsored + nofollow share this).
.mltr-rel-modal {

	&__loading {
		display: flex;
		align-items: center;
		gap: 8px;
		padding: 16px 0;
	}

	&__summary {
		margin: 12px 0;
		padding-left: 18px;

		li {
			margin-bottom: 4px;
			font-size: 13px;
			color: var(--mltr-color-text-strong);

			&.is-muted {
				color: var(--mltr-color-text-muted);
				font-size: 12px;
			}
		}
	}

	&__samples {
		margin-top: 16px;
		padding-top: 12px;
		border-top: 1px solid var(--mltr-color-border);

		h3 {
			margin: 0 0 8px;
			font-size: 13px;
			font-weight: 600;
			color: var(--mltr-color-text-strong);
		}

		ul {
			list-style: none;
			margin: 0;
			padding: 0;
			max-height: 260px;
			overflow-y: auto;
			border: 1px solid var(--mltr-color-border);
			border-radius: var(--mltr-radius);
			background: var(--mltr-color-bg);
		}
	}

	&__sample {
		display: flex;
		justify-content: space-between;
		align-items: center;
		gap: 12px;
		padding: 8px 12px;
		border-bottom: 1px solid var(--mltr-color-border);
		font-size: 12px;

		&:last-child {
			border-bottom: 0;
		}

		a {
			color: var(--mltr-color-primary);
			text-decoration: none;
			word-break: break-all;
			flex: 1;
		}

		a:hover {
			text-decoration: underline;
		}
	}

	&__sample-meta {
		display: flex;
		align-items: center;
		gap: 8px;
		white-space: nowrap;
		color: var(--mltr-color-text-muted);
		font-size: 11px;
	}

	&__sample-network {
		padding: 2px 6px;
		background: var(--mltr-color-affiliate, #8b5cf6);
		color: #fff;
		border-radius: 3px;
		font-size: 10px;
		font-weight: 600;
		text-transform: uppercase;
		letter-spacing: 0.3px;
	}

	&__samples-truncated {
		margin: 8px 0 0;
		font-size: 11px;
		font-style: italic;
		color: var(--mltr-color-text-muted);
	}

	&__actions {
		display: flex;
		justify-content: flex-end;
		gap: 8px;
		margin-top: 16px;
		padding-top: 12px;
		border-top: 1px solid var(--mltr-color-border);
	}
}

.mltr-disclosure-empty {
	background: var(--mltr-color-bg);
	border: 1px dashed var(--mltr-color-border);
	border-radius: var(--mltr-radius);
	padding: 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;

	p {
		margin: 0;
		flex: 1;
		font-size: 13px;
		color: var(--mltr-color-text-muted);
	}
}

.mltr-dashboard__section {
	margin-top: 24px;

	h2,
	h3 {
		margin: 0 0 8px;
		font-size: 16px;
		font-weight: 600;
		color: var(--mltr-color-text-strong);
	}
}

.mltr-dashboard__empty {
	background: var(--mltr-color-bg);
	border: 1px dashed var(--mltr-color-border);
	border-radius: var(--mltr-radius);
	padding: 24px;
	margin-top: 20px;
	text-align: center;
	color: var(--mltr-color-text-muted);

	p {
		margin: 0;
	}
}

/* ── Scan panel ─────────────────────────────────────────────────── */

.mltr-scan-panel {
	background: var(--mltr-color-bg);
	border: 1px solid var(--mltr-color-border);
	border-radius: var(--mltr-radius);
	padding: 16px;

	&__controls {
		display: flex;
		gap: 8px;
	}

	&__progress {
		margin-top: 12px;
	}

	&__status {
		display: block;
		margin-top: 6px;
		font-size: 13px;
		color: var(--mltr-color-text-muted);
	}

	&__complete {
		margin: 8px 0 0;
		font-size: 13px;
		color: var(--mltr-color-ok);
		display: flex;
		justify-content: space-between;
		align-items: center;
		flex-wrap: wrap;
		gap: 10px;
	}

	&__review-link {
		color: var(--mltr-color-primary);
		text-decoration: underline;
		font-weight: 600;

		&:hover {
			color: var(--mltr-color-primary-hover);
		}
	}
}

.mltr-progress-bar {
	height: 8px;
	background: var(--mltr-color-border);
	border-radius: var(--mltr-radius);
	overflow: hidden;

	&__fill {
		height: 100%;
		background: var(--mltr-color-primary);
		border-radius: var(--mltr-radius);
		transition: width 0.3s ease;
	}
}

/* ── Filter bar ─────────────────────────────────────────────────── */

.mltr-filter-bar {
	margin-bottom: 12px;
}

/* ── Link table ─────────────────────────────────────────────────── */

.mltr-link-table {
	margin-top: 16px;

	&__toolbar {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		gap: 12px;
	}

	/* DataViews density overrides */
	&.is-density-comfortable {

		.dataviews-view-table td,
		.dataviews-view-table th {
			padding: 16px 12px !important;
		}
	}

	&.is-density-balanced {

		.dataviews-view-table td,
		.dataviews-view-table th {
			padding: 10px 12px !important;
		}
	}

}

.mltr-link-url {
	display: inline-block;
	max-width: 32rem;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	vertical-align: bottom;
	color: var(--mltr-color-primary);
	text-decoration: none;

	&:hover {
		text-decoration: underline;
	}
}

.mltr-http-status {
	font-weight: 600;

	&--broken,
	&--error {
		color: var(--mltr-color-broken);
	}

	&--redirect {
		color: var(--mltr-color-redirect);
	}

	&--ok {
		color: var(--mltr-color-ok);
	}

	&--pending,
	&--skipped {
		color: var(--mltr-color-neutral);
	}
}

.mltr-badge {
	font-size: 12px;
	font-weight: 600;
	text-transform: uppercase;
}

/* ── Edit modal ─────────────────────────────────────────────────── */

.mltr-edit-modal {

	&__instances {
		margin-top: 16px;
		padding-top: 16px;
		border-top: 1px solid var(--mltr-color-border);

		h3 {
			font-size: 13px;
			margin: 0 0 8px;
		}

		ul {
			margin: 0;
			padding: 0;
			list-style: none;
		}

		li {
			padding: 4px 0;
			font-size: 13px;
		}
	}

	&__anchor {
		color: var(--mltr-color-text-muted);
		font-style: italic;
	}

	&__actions {
		display: flex;
		gap: 8px;
		margin-top: 16px;
		justify-content: flex-end;
	}
}

/* ── Settings ───────────────────────────────────────────────────── */

.mltr-settings {
	margin-top: 16px;

	&__actions {
		margin-top: 16px;
	}
}

/* ── Support Card ────────────────────────────────────────────────── */

.mltr-support-card {
	background: var(--mltr-color-bg);
	border: 1px solid var(--mltr-color-border);
	border-radius: var(--mltr-radius);
	padding: 20px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 20px;
	margin-top: 20px;

	&__content {

		h2,
		h3 {
			margin-top: 0 !important;
			font-size: 16px;
		}

		p {
			margin-bottom: 0;
			color: var(--mltr-color-text-muted);
		}
	}

	&__actions {
		display: flex;
		gap: 10px;
		flex-shrink: 0;
	}

	@media (max-width: 782px) {
		flex-direction: column;
		align-items: flex-start;

		&__actions {
			width: 100%;
			justify-content: flex-start;
		}
	}
}

/* ── Snackbar ───────────────────────────────────────────────────── */

.mltr-snackbar-list {
	position: fixed;
	bottom: 40px;
	left: 50%;
	transform: translateX(-50%);
	z-index: var(--mltr-z-snackbar);
}

/* ── Export Modal (v1.2.0) ──────────────────────────────────────── */

.mltr-export-modal {
	max-width: 640px;

	.mltr-export-presets {
		margin: 16px 0;

		&__label {
			display: block;
			font-weight: 600;
			margin-bottom: 8px;
		}
	}

	.mltr-export-columns {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 4px 16px;
		border: 1px solid var(--mltr-color-border, #dcdcde);
		border-radius: 4px;
		padding: 12px 16px;
		margin: 16px 0;

		legend {
			padding: 0 4px;
			font-weight: 600;
		}

		@media (max-width: 600px) {
			grid-template-columns: 1fr;
		}
	}

	.mltr-export-dates {
		display: flex;
		gap: 16px;
		margin: 12px 0;
		flex-wrap: wrap;

		&__col {
			flex: 1 1 280px;
		}

		&__label {
			display: block;
			font-weight: 600;
			margin-bottom: 4px;
		}
	}

	.mltr-modal-actions {
		display: flex;
		justify-content: flex-end;
		gap: 8px;
		margin-top: 16px;
		padding-top: 16px;
		border-top: 1px solid var(--mltr-color-border, #dcdcde);
	}
}

// Per-link rel-attribute badges in the LinkTable "Rel" column.
.mltr-rel-badges {
	display: inline-flex;
	gap: 4px;
	flex-wrap: wrap;

	&.is-empty {
		color: var(--mltr-color-text-muted, #757575);
	}
}

.mltr-rel-badge {
	display: inline-flex;
	align-items: center;
	padding: 1px 6px;
	border-radius: 3px;
	font-size: 10px;
	font-weight: 600;
	line-height: 1.5;
	letter-spacing: 0.4px;
	text-transform: uppercase;
	border: 1px solid transparent;

	// Tokens use semantic colours rather than the affiliate palette so users
	// can scan the column quickly:
	//   nofollow  = neutral grey (the editorial default for external links)
	//   sponsored = amber       (FTC / Google "monetised" signal)
	//   ugc       = teal        (community content)
	//   dofollow  = muted ghost (purely informational, low visual weight)
	&--nofollow {
		background: #eef0f3;
		color: #475569;
		border-color: #d8dde4;
	}

	&--sponsored {
		background: #fff5e0;
		color: #855108;
		border-color: #f5d99a;
	}

	&--ugc {
		background: #e0f5f2;
		color: #0f5b53;
		border-color: #a4dcd2;
	}

	&--dofollow {
		background: transparent;
		color: var(--mltr-color-text-muted, #757575);
		border-color: var(--mltr-color-border, #dcdcde);
	}
}

// -----------------------------------------------------------------------------
// Destination health (2.2.0)
// -----------------------------------------------------------------------------

.mltr-risk-badge {
	display: inline-flex;
	align-items: center;
	padding: 1px 8px;
	border-radius: 3px;
	font-size: 11px;
	font-weight: 600;
	line-height: 1.6;
	border: 1px solid transparent;
	white-space: nowrap;

	// Deliberately quieter than the HTTP status column: this is a triage aid,
	// not a verdict, and a wall of red would train users to ignore it.
	&--suspect {
		background: #fcf0f1;
		color: #8a2424;
		border-color: #f0c6c9;
	}

	&--watch {
		background: #fff5e0;
		color: #8a6100;
		border-color: #f5dfae;
	}

	&--clean {
		background: #edf7ed;
		color: #14602a;
		border-color: #c6e6c9;
	}

	&.is-empty {
		color: var(--mltr-color-text-muted, #757575);
		border: 0;
		background: none;
		padding: 0;
	}
}

.mltr-risk-evidence {
	margin: 20px 0;
	padding: 12px 16px;
	border-radius: 4px;
	border-left: 4px solid var(--mltr-color-text-muted, #757575);
	background: #f6f7f7;

	&--suspect {
		border-left-color: #d63638;
	}

	&--watch {
		border-left-color: #dba617;
	}

	&--clean {
		border-left-color: #00a32a;
	}

	h3 {
		margin: 0 0 8px;
		font-size: 13px;
	}

	&__reasons {
		margin: 0 0 12px;
		padding-left: 18px;
		list-style: disc;

		li {
			margin: 0 0 4px;
		}
	}

	&__facts {
		display: grid;
		grid-template-columns: max-content 1fr;
		gap: 4px 12px;
		margin: 0 0 12px;
		font-size: 12px;

		dt {
			color: var(--mltr-color-text-muted, #757575);
		}

		dd {
			margin: 0;
			word-break: break-all;
		}
	}

	&__url {
		font-family: monospace;
	}

	&__actions {
		display: flex;
		gap: 8px;
		flex-wrap: wrap;
	}
}

.mltr-dashboard__section-help {
	margin: -4px 0 12px;
	color: var(--mltr-color-text-muted, #757575);
	font-size: 12px;
	max-width: 70ch;
}

.mltr-link-table.is-density-compact {

	.dataviews-view-table td,
	.dataviews-view-table th {
		padding: 4px 8px !important;
		font-size: 12px;
	}

	.mltr-badge {
		font-size: 10px;
		padding: 2px 4px;
	}

	.mltr-http-status {
		font-size: 11px;
	}
}
