/* ══════════════════════════════════════════════════════════════════════
   FileDrop — WooCommerce File Uploader (Frontend)

   Styles the drag-drop uploader on the single product page.
   Components: drop zone, file table, progress bars, summary, cart list.
   Uses CSS custom properties that inherit from the theme when available,
   falling back to sensible defaults for standalone use.
   ══════════════════════════════════════════════════════════════════════ */

/* ─── Design Tokens ───
   Inherit from the active theme's CSS variables when possible (Thread and Film
   defines --color-primary, --radius, etc. in base.css). Fallback values ensure
   the plugin still looks good on themes that don't define these properties. */
.taffd-wrapper {
	--fd-primary: var(--color-primary, #0073aa);
	--fd-accent: var(--color-accent, #2271b1);
	--fd-border: var(--color-border, #ddd);
	--fd-bg: var(--color-bg-alt, #f9f9f9);
	--fd-radius: var(--radius, 6px);
	--fd-text: #333;
	--fd-text-muted: #777;
	--fd-success: #28a745;
	--fd-error: #dc3545;
	--fd-bar: var(--fd-primary);             /* progress bar fill color */

	margin-bottom: 1.5em;
	font-size: 14px;
	color: var(--fd-text);
}

/* ─── Drop Zone ───
   Dashed border area where users drag files or click to browse.
   .hover class is toggled by JS during dragover to provide visual feedback. */

.taffd-dropzone {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	padding: 32px 24px;
	border: 2px dashed var(--fd-border);
	border-radius: var(--fd-radius);
	background: var(--fd-bg);
	text-align: center;
	cursor: pointer;
	transition: border-color 0.2s, background 0.2s;
}

.taffd-dropzone.hover {
	border-color: var(--fd-primary);
	background: rgba(0, 115, 170, 0.04);
}

.taffd-icon {
	color: var(--fd-text-muted);
	margin-bottom: 4px;
}

.taffd-text {
	color: var(--fd-text-muted);
	font-size: 14px;
}

.taffd-browse-btn {
	display: inline-block;
	padding: 8px 20px;
	background: var(--fd-primary);
	color: #fff;
	border-radius: var(--fd-radius);
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.2s;
}

.taffd-browse-btn:hover {
	background: var(--fd-accent);
}

.taffd-counter {
	font-size: 12px;
	color: var(--fd-text-muted);
}

/* ─── Notes ───
   Yellow info box below the drop zone showing file requirements
   (accepted formats, max size, min DPI). Warm amber palette for attention. */

.taffd-notes {
	margin: 12px 0;
	padding: 10px 14px;
	background: #fff8e1;
	border: 1px solid #ffe082;
	border-radius: var(--fd-radius);
	font-size: 13px;
	line-height: 1.5;
	color: #5d4037;
}

/* ─── File Table ───
   Uploaded files display in a grid table: File name | DPI | Qty | Length |
   Width | Price/in | Total | × (remove). Uses CSS Grid for column alignment.
   The 1.5fr first column gives the filename more room; 32px last column
   holds the remove button. Each row is a separate card with border/radius. */

.taffd-table-header,
.taffd-file-row {
	display: grid;
	grid-template-columns: 1.5fr repeat(6, 1fr) 32px;  /* name | 6 data cols | remove btn */
	gap: 4px;
	align-items: center;
	padding: 8px 12px;
	font-size: 13px;
}

.taffd-table-header {
	margin-top: 12px;
	border-bottom: 2px solid var(--fd-border);
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--fd-text-muted);
	padding-bottom: 6px;
}

.taffd-file-row {
	border: 1px solid var(--fd-border);
	border-radius: var(--fd-radius);
	background: #fff;
	margin-top: 4px;
}

.taffd-col {
	text-align: center;
	white-space: nowrap;
}

.taffd-col-name {
	text-align: left;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	min-width: 0;
}

.taffd-col-x {
	width: 24px;
	text-align: center;
}

.taffd-file-name {
	font-weight: 500;
}

.taffd-file-size {
	font-size: 11px;
	color: var(--fd-text-muted);
	margin-left: 4px;
}

.taffd-file-detail {
	color: var(--fd-text-muted);
}

.taffd-file-row input[type="number"] {
	width: 52px;
	padding: 4px 4px;
	border: 1px solid var(--fd-border);
	border-radius: 4px;
	font-size: 13px;
	text-align: center;
	margin: 0 auto;
	display: block;
}

.taffd-file-total {
	font-weight: 600;
	color: var(--fd-text);
	text-align: center;
}

.taffd-file-remove {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	border: none;
	background: none;
	color: var(--fd-text-muted);
	font-size: 18px;
	cursor: pointer;
	border-radius: 50%;
	transition: color 0.2s, background 0.2s;
	padding: 0;
	line-height: 1;
}

.taffd-file-remove:hover {
	color: var(--fd-error);
	background: rgba(220, 53, 69, 0.08);
}

/* ─── Progress Row ───
   Shown during XHR upload — displays filename, animated progress bar, and
   percentage. Row is removed and replaced with a file-row on completion.
   .error class turns the row red when upload fails. */

.taffd-progress-row {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 12px;
	margin-top: 6px;
	border: 1px solid var(--fd-border);
	border-radius: var(--fd-radius);
	background: #fff;
}

.taffd-progress-name {
	flex: 1;
	font-size: 13px;
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	min-width: 0;
}

.taffd-progress-bar {
	flex: 2;
	height: 6px;
	background: #eee;
	border-radius: 3px;
	overflow: hidden;
}

.taffd-progress-fill {
	height: 100%;
	width: 0;
	background: var(--fd-bar);
	border-radius: 3px;
	transition: width 0.15s ease;
}

.taffd-progress-pct {
	font-size: 12px;
	color: var(--fd-text-muted);
	min-width: 36px;
	text-align: right;
}

/* ─── Error State ─── */

.taffd-progress-row.error {
	border-color: var(--fd-error);
	background: #fff5f5;
}

.taffd-progress-row.error .taffd-progress-name {
	color: var(--fd-error);
}

.taffd-error-msg {
	font-size: 12px;
	color: var(--fd-error);
}

/* ─── Summary ───
   Running totals bar below the file list showing file count, total inches,
   and total price. Updates dynamically via JS as files are added/removed. */

.taffd-summary {
	display: flex;
	gap: 16px;
	margin-top: 12px;
	padding: 12px 16px;
	border: 1px solid var(--fd-border);
	border-radius: var(--fd-radius);
	background: var(--fd-bg);
}

.taffd-summary-item {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.taffd-summary-label {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--fd-text-muted);
}

.taffd-summary-value {
	font-size: 16px;
	font-weight: 600;
}

.taffd-summary-total .taffd-summary-value {
	color: var(--fd-primary);
}

/* ─── Cart File List ───
   Compact list of uploaded filenames shown on the cart and checkout pages
   beneath the product name. Small font, muted color to stay unobtrusive. */

.taffd-cart-files {
	margin: 4px 0 0;
	padding: 0;
	list-style: none;
	font-size: 12px;
	color: #666;
}

.taffd-cart-files li {
	padding: 2px 0;
}

/* ─── Hide WooCommerce Quantity for FileDrop Products ───
   FileDrop products don't use the standard WooCommerce quantity selector
   because quantity is implicit (number of files × quantity per file).
   !important needed to override WooCommerce's inline display styles. */

.taffd-wrapper ~ .quantity,
.has-taffd .quantity {
	display: none !important;
}

/* ─── Responsive (768px) ───
   On mobile, the 8-column file table is too wide.  Strategy:
   1. Hide the table header row (column labels)
   2. Collapse to a 3-column grid (3 data values per row)
   3. Inject column labels via ::before pseudo-elements on each cell
   4. Filename spans full width; remove button positioned absolutely
   5. Summary switches from horizontal to vertical stacked layout */

@media (max-width: 768px) {
	/* Hide desktop column headers — replaced by ::before labels */
	.taffd-table-header {
		display: none;
	}

	/* 3-column grid: row 1 = filename (full width), row 2 = DPI/Qty/Length,
	   row 3 = Width/Price/Total */
	.taffd-file-row {
		grid-template-columns: repeat(3, 1fr);
		gap: 8px;
		padding: 10px 12px;
		position: relative;
	}

	.taffd-col-name {
		grid-column: 1 / -1;
		padding-right: 28px;
		margin-bottom: 2px;
	}

	.taffd-file-row .taffd-col {
		text-align: left;
		font-size: 13px;
	}

	.taffd-file-row .taffd-col::before {
		display: block;
		font-size: 9px;
		font-weight: 600;
		text-transform: uppercase;
		letter-spacing: 0.5px;
		color: var(--fd-text-muted);
		margin-bottom: 1px;
	}

	/* Row 2: DPI, Qty, Length */
	.taffd-file-row .taffd-col:nth-child(2)::before { content: 'DPI'; }
	.taffd-file-row .taffd-col:nth-child(3)::before { content: 'Qty'; }
	.taffd-file-row .taffd-col:nth-child(4)::before { content: 'Length (in)'; }
	/* Row 3: Width, Price, Total */
	.taffd-file-row .taffd-col:nth-child(5)::before { content: 'Width (in)'; }
	.taffd-file-row .taffd-col:nth-child(6)::before { content: 'Price/in'; }
	.taffd-file-row .taffd-col:nth-child(7)::before { content: 'Total'; }

	.taffd-file-row .taffd-file-total {
		text-align: left;
		font-size: 14px;
	}

	.taffd-file-row input[type="number"] {
		margin: 0;
		width: 48px;
	}

	.taffd-file-remove {
		position: absolute;
		top: 10px;
		right: 10px;
	}

	.taffd-summary {
		flex-direction: column;
		gap: 8px;
	}

	.taffd-summary-item {
		flex-direction: row;
		justify-content: space-between;
	}

	.taffd-dropzone {
		padding: 24px 16px;
	}
}
