/**
 * B2B Tool for Woocommerce — My Account dashboard.
 *
 * Design goals:
 *  - Blend into ANY theme, light or dark, without looking like bare HTML.
 *  - Derive colors from the theme where possible (currentColor + inherited
 *    font), and expose CSS variables the theme (or a child theme) can override.
 *  - Never hardcode a white background or black text; use semi-transparent
 *    overlays on top of whatever the theme provides so cards read correctly on
 *    light and dark backgrounds alike.
 */

.b2btfw-dashboard {
	/* Tokens — overridable by the theme via :root or .b2btfw-dashboard. */
	--b2btfw-accent: var( --wp--preset--color--primary, #2271b1 );
	--b2btfw-radius: 10px;
	--b2btfw-gap: 1.25rem;

	/* Surfaces built from currentColor so they invert automatically:
	   a faint overlay of the text color reads as a subtle card on both
	   light and dark themes. */
	--b2btfw-border: color-mix( in srgb, currentColor 15%, transparent );
	--b2btfw-border-strong: color-mix( in srgb, currentColor 28%, transparent );
	--b2btfw-surface: color-mix( in srgb, currentColor 4%, transparent );
	--b2btfw-surface-2: color-mix( in srgb, currentColor 8%, transparent );
	--b2btfw-muted: color-mix( in srgb, currentColor 65%, transparent );

	color: inherit;
	font-size: inherit;
	line-height: 1.5;
}

/* Fallback for browsers without color-mix(): use rgba on currentColor via
   @supports negation. These still avoid hardcoded black/white. */
@supports not ( color: color-mix( in srgb, red, blue ) ) {
	.b2btfw-dashboard {
		--b2btfw-border: rgba( 128, 128, 128, 0.35 );
		--b2btfw-border-strong: rgba( 128, 128, 128, 0.55 );
		--b2btfw-surface: rgba( 128, 128, 128, 0.06 );
		--b2btfw-surface-2: rgba( 128, 128, 128, 0.12 );
		--b2btfw-muted: rgba( 128, 128, 128, 1 );
	}
}

.b2btfw-dashboard * { box-sizing: border-box; }

/* ---- Sections as cards ---- */
.b2btfw-dashboard .b2btfw-section {
	margin: 0 0 var( --b2btfw-gap );
	padding: 1.25rem 1.4rem;
	border: 1px solid var( --b2btfw-border );
	border-radius: var( --b2btfw-radius );
	background: var( --b2btfw-surface );
}

.b2btfw-dashboard .b2btfw-section__title {
	display: flex;
	align-items: center;
	gap: 0.5em;
	margin: 0 0 1rem;
	font-size: 1.15em;
	font-weight: 700;
}

.b2btfw-dashboard .b2btfw-section__title .b2btfw-count {
	font-weight: 600;
	font-size: 0.75em;
	padding: 0.15em 0.6em;
	border-radius: 1em;
	background: var( --b2btfw-surface-2 );
	color: var( --b2btfw-muted );
}
.b2btfw-dashboard .b2btfw-section__title .b2btfw-count.is-alert {
	background: var( --b2btfw-accent );
	color: #fff;
}

.b2btfw-dashboard .b2btfw-muted { color: var( --b2btfw-muted ); }
.b2btfw-dashboard .b2btfw-empty {
	color: var( --b2btfw-muted );
	font-style: italic;
	margin: 0;
}

/* ---- Tables ---- */
.b2btfw-dashboard .b2btfw-table {
	width: 100%;
	border-collapse: collapse;
	margin: 0;
	font-size: 0.95em;
}
.b2btfw-dashboard .b2btfw-table th,
.b2btfw-dashboard .b2btfw-table td {
	padding: 0.7em 0.8em;
	text-align: left;
	vertical-align: middle;
	border-bottom: 1px solid var( --b2btfw-border );
}
.b2btfw-dashboard .b2btfw-table thead th {
	font-weight: 700;
	font-size: 0.82em;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: var( --b2btfw-muted );
	border-bottom: 1px solid var( --b2btfw-border-strong );
}
.b2btfw-dashboard .b2btfw-table tbody tr:last-child td { border-bottom: 0; }
.b2btfw-dashboard .b2btfw-table tbody tr:hover { background: var( --b2btfw-surface ); }

/* ---- Units (departments) ---- */
.b2btfw-dashboard .b2btfw-unit {
	border: 1px solid var( --b2btfw-border );
	border-radius: var( --b2btfw-radius );
	padding: 0.9rem 1.1rem;
	margin-bottom: 0.9rem;
	background: var( --b2btfw-surface );
}
.b2btfw-dashboard .b2btfw-unit__head {
	display: flex;
	align-items: center;
	gap: 0.5em;
	margin-bottom: 0.5rem;
	font-size: 1.02em;
}

/* ---- Pills / tags ---- */
.b2btfw-dashboard .b2btfw-pill {
	display: inline-block;
	font-size: 0.7em;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	padding: 0.2em 0.6em;
	border-radius: 1em;
	background: var( --b2btfw-surface-2 );
	color: var( --b2btfw-muted );
	white-space: nowrap;
}

/* ---- Status chips (derive hue, keep readable on any bg) ---- */
.b2btfw-dashboard .b2btfw-status {
	display: inline-block;
	padding: 0.25em 0.7em;
	border-radius: 1em;
	font-size: 0.85em;
	font-weight: 600;
	border: 1px solid var( --b2btfw-border-strong );
	background: var( --b2btfw-surface-2 );
}
.b2btfw-dashboard .b2btfw-status--pending-approval {
	border-color: color-mix( in srgb, #b8860b 55%, transparent );
	background: color-mix( in srgb, #f5c518 22%, transparent );
}
.b2btfw-dashboard .b2btfw-status--processing,
.b2btfw-dashboard .b2btfw-status--completed {
	border-color: color-mix( in srgb, #2e7d32 55%, transparent );
	background: color-mix( in srgb, #2e7d32 20%, transparent );
}
.b2btfw-dashboard .b2btfw-status--cancelled,
.b2btfw-dashboard .b2btfw-status--failed {
	border-color: color-mix( in srgb, #c62828 55%, transparent );
	background: color-mix( in srgb, #c62828 18%, transparent );
}

/* ---- Pending approval cards ---- */
.b2btfw-dashboard .b2btfw-order-card {
	border: 1px solid var( --b2btfw-border );
	border-left: 3px solid var( --b2btfw-accent );
	border-radius: var( --b2btfw-radius );
	padding: 1rem 1.1rem;
	margin-bottom: 0.8rem;
	background: var( --b2btfw-surface );
}
.b2btfw-dashboard .b2btfw-order-card__head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.5em 1em;
	margin-bottom: 0.6rem;
}
.b2btfw-dashboard .b2btfw-order-card__title { font-weight: 700; font-size: 1.05em; }
.b2btfw-dashboard .b2btfw-order-card__meta { color: var( --b2btfw-muted ); font-size: 0.9em; }
.b2btfw-dashboard .b2btfw-order-card__items {
	margin: 0.5rem 0;
	padding: 0.6rem 0.8rem;
	border-radius: 8px;
	background: var( --b2btfw-surface-2 );
	font-size: 0.92em;
}
.b2btfw-dashboard .b2btfw-order-card__items ul { margin: 0; padding-left: 1.2em; }
.b2btfw-dashboard .b2btfw-order-card__items li { margin: 0.15em 0; }

/* ---- Action buttons: inherit theme .button, add layout only ---- */
.b2btfw-dashboard .b2btfw-actions {
	display: flex;
	gap: 0.5em;
	flex-wrap: wrap;
	margin-top: 0.4rem;
}
.b2btfw-dashboard .b2btfw-actions .button { margin: 0; }
.b2btfw-dashboard .b2btfw-btn-reject.button {
	/* Subtle danger accent without fighting the theme button base. */
	filter: none;
	opacity: 0.92;
}

/* ---- Toolbar row (links to full order view) ---- */
.b2btfw-dashboard .b2btfw-view-link {
	text-decoration: none;
	font-weight: 600;
}

/* ---- Feedback messages ---- */
.b2btfw-dashboard .b2btfw-notice {
	padding: 0.7em 1em;
	border-radius: 8px;
	border: 1px solid var( --b2btfw-border-strong );
	background: var( --b2btfw-surface-2 );
	margin-bottom: 0.8rem;
}
.b2btfw-dashboard .b2btfw-notice--success { border-left: 3px solid #2e7d32; }
.b2btfw-dashboard .b2btfw-notice--error { border-left: 3px solid #c62828; }

/* ---- Responsive ---- */
@media ( max-width: 600px ) {
	.b2btfw-dashboard .b2btfw-table thead { display: none; }
	.b2btfw-dashboard .b2btfw-table tbody tr {
		display: block;
		border: 1px solid var( --b2btfw-border );
		border-radius: 8px;
		margin-bottom: 0.6rem;
		padding: 0.3rem 0.6rem;
	}
	.b2btfw-dashboard .b2btfw-table td {
		display: flex;
		justify-content: space-between;
		gap: 1em;
		border-bottom: 1px solid var( --b2btfw-border );
		padding: 0.5em 0.2em;
	}
	.b2btfw-dashboard .b2btfw-table td::before {
		content: attr( data-label );
		font-weight: 700;
		font-size: 0.82em;
		text-transform: uppercase;
		color: var( --b2btfw-muted );
	}
	.b2btfw-dashboard .b2btfw-table td:last-child { border-bottom: 0; }

	/* The expandable order-detail row must span full width and not inherit the
	   two-column flex/label treatment used by normal cells. */
	.b2btfw-dashboard .b2btfw-table tr.b2btfw-detail-row { padding: 0; }
	.b2btfw-dashboard .b2btfw-table tr.b2btfw-detail-row td {
		display: block;
		padding: 0;
		border-bottom: 0;
	}
	.b2btfw-dashboard .b2btfw-table tr.b2btfw-detail-row td::before { content: none; }
}

/* ---------- Hidden/open state for expandable detail (all viewports) ---------- */
.b2btfw-order-detail[hidden],
.b2btfw-detail-row[hidden] { display: none !important; }

/* ---------- Touch-friendly controls (tablet + mobile) ---------- */
@media ( max-width: 782px ) {
	/* Bigger tap targets for the action buttons. */
	.b2btfw-actions {
		display: flex;
		flex-wrap: wrap;
		gap: 8px;
	}
	.b2btfw-actions .button,
	.b2btfw-actions .b2btfw-view-order {
		flex: 1 1 auto;
		min-height: 44px;
		padding: 10px 14px;
		font-size: 1rem;
		text-align: center;
	}
	/* Full-width buttons on the narrowest screens so they're easy to tap. */
	.b2btfw-linkbtn { min-height: 32px; display: inline-flex; align-items: center; }
	/* Order-detail tables reflow: items table stays readable, addresses stack. */
	.b2btfw-od__items th, .b2btfw-od__items td { padding: 6px 6px; font-size: 0.9rem; }
	.b2btfw-od__addr { flex-direction: column; gap: 10px; }
	.b2btfw-od__meta { gap: 4px 12px; font-size: 0.9rem; }
}

@media ( max-width: 480px ) {
	.b2btfw-actions .button,
	.b2btfw-actions .b2btfw-view-order { flex: 1 1 100%; }
	.b2btfw-fe-kpis { gap: 8px; }
	.b2btfw-fe-kpi { flex: 1 1 100%; }
	.b2btfw-section { padding-left: 0; padding-right: 0; }
	/* Order-detail items: let the product column wrap, keep numbers tight. */
	.b2btfw-od__items td:first-child { word-break: break-word; }
}

/* ---- Explicit dark-theme nudge (in case theme sets a dark bg but light text
   without a color-scheme hint). currentColor already handles most cases. ---- */
@media ( prefers-color-scheme: dark ) {
	.b2btfw-dashboard {
		--b2btfw-border: color-mix( in srgb, currentColor 22%, transparent );
		--b2btfw-surface: color-mix( in srgb, currentColor 6%, transparent );
		--b2btfw-surface-2: color-mix( in srgb, currentColor 12%, transparent );
	}
}

/* ---- Forced color modes (from plugin Settings) ----
   'auto' inherits the theme (default behavior above). Light/dark set an explicit
   base so the card surfaces have a known background + text color to build on. */
.b2btfw-dashboard.b2btfw-mode-light {
	color: #1d2327;
	background: #ffffff;
	padding: 4px; /* ensures the base bg is visible behind cards */
	border-radius: var( --b2btfw-radius );
}
.b2btfw-dashboard.b2btfw-mode-dark {
	color: #e4e6eb;
	background: #14161a;
	padding: 4px;
	border-radius: var( --b2btfw-radius );
}
/* In forced dark, lift the surface overlays a touch for contrast. */
.b2btfw-dashboard.b2btfw-mode-dark {
	--b2btfw-border: color-mix( in srgb, currentColor 24%, transparent );
	--b2btfw-surface: color-mix( in srgb, currentColor 8%, transparent );
	--b2btfw-surface-2: color-mix( in srgb, currentColor 14%, transparent );
}
.b2btfw-dashboard.b2btfw-mode-light,
.b2btfw-dashboard.b2btfw-mode-dark { padding: 16px; }

/* ---------- Front-end statistics summary ---------- */
.b2btfw-fe-kpis { display:flex; gap:12px; flex-wrap:wrap; margin-bottom:16px; }
.b2btfw-fe-kpi {
	flex:1 1 120px; padding:12px 14px; border-radius:10px;
	border:1px solid var(--b2btfw-border); background:var(--b2btfw-surface);
}
.b2btfw-fe-kpi__value { display:block; font-size:1.4em; font-weight:700; }
.b2btfw-fe-kpi__label { display:block; font-size:.8em; opacity:.7; margin-top:2px; }
.b2btfw-fe-chart {
	position:relative; height:150px; margin:6px 0 18px; padding:8px 8px 26px;
	border:1px solid var(--b2btfw-border); border-radius:10px; background:var(--b2btfw-surface);
}
.b2btfw-fe-bar { position:absolute; bottom:26px; top:8px; display:flex; flex-direction:column; justify-content:flex-end; align-items:center; box-sizing:border-box; padding:0 3px; }
.b2btfw-fe-bar__fill { width:100%; max-width:38px; min-height:2px; border-radius:4px 4px 0 0;
	background:var(--b2btfw-accent, currentColor); opacity:.85; }
.b2btfw-fe-bar__fill:hover { opacity:1; }
.b2btfw-fe-bar__label { position:absolute; bottom:-20px; font-size:9px; opacity:.6; white-space:nowrap; }
.b2btfw-fe-subtitle { margin:14px 0 6px; font-size:1em; }

/* ---------- Inline order detail ---------- */
.b2btfw-linkbtn {
	background:none; border:none; padding:0; cursor:pointer;
	color:var(--b2btfw-accent, currentColor); text-decoration:underline; font:inherit;
}
.b2btfw-order-detail { margin-top:10px; }
.b2btfw-od {
	border:1px solid var(--b2btfw-border); border-radius:10px; padding:12px 14px;
	background:var(--b2btfw-surface); font-size:.92em;
}
.b2btfw-od__meta { display:flex; flex-wrap:wrap; gap:6px 18px; margin-bottom:10px; }
.b2btfw-od__items { width:100%; border-collapse:collapse; margin-bottom:10px; }
.b2btfw-od__items th, .b2btfw-od__items td { padding:5px 8px; border-bottom:1px solid var(--b2btfw-border); text-align:left; }
.b2btfw-od__items .b2btfw-num { text-align:right; white-space:nowrap; }
.b2btfw-od__items tfoot th { border-top:2px solid var(--b2btfw-border); border-bottom:none; }
.b2btfw-od__addr { display:flex; flex-wrap:wrap; gap:18px; }
.b2btfw-od__addr > div { flex:1 1 200px; }
.b2btfw-od__addr strong { display:block; margin-bottom:3px; }
.b2btfw-od__loading, .b2btfw-od__error { margin:8px 0; opacity:.8; }
.b2btfw-od__error { color:#b32d2e; }
